def getPrediction(in_sentences):
labels = ["Negative", "Positive"]
input_examples = [run_classifier.InputExample(guid="", text_a = x, text_b = None, label = 0)
for x in in_sentences] # here, "" is just a dummy label
input_features = run_classifier.convert_examples_to_features(input_examples, label_list, MAX_SEQ_LENGTH, tokenizer)
predict_input_fn = run_classifier.input_fn_builder(features=input_features,
seq_length=MAX_SEQ_LENGTH,
is_training=False, drop_remainder=False)
predictions = estimator.predict(predict_input_fn)
return [(sentence, prediction['probabilities'], labels[prediction['labels']]) for sentence, prediction in zip(in_sentences, predictions)]
然后你可以传递一个示例列表:
pred_sentences = [
"That movie was absolutely awful",
"The acting was a bit lacking",
"The film was creative and surprising",
"Absolutely fantastic!"
]
predictions = getPrediction(pred_sentences)
4条答案
按热度按时间pkln4tw61#
uqdfh47h2#
请有人能帮助我,谢谢@jacobdevlin-google
rnmwe5a23#
也许可以尝试这样做:
然后你可以传递一个示例列表:
这个示例来自示例笔记本: https://colab.research.google.com/github/google-research/bert/blob/master/predicting_movie_reviews_with_bert_on_tf_hub.ipynb
zd287kbt4#
你好,这个给我的负概率像在例子中。有人能告诉我如何从这个得到正概率吗?这样阈值处理就可以应用到这个上。
这个的一个用例场景是用于双类分类,并且有一个输入不属于任何类别