【问题标题】:AllenNLP Reading Comprehension results are different in UI Demo and Python LibraryUI Demo 和 Python 库中 AllenNLP 阅读理解结果不同
【发布时间】:2021-02-16 01:19:49
【问题描述】:

我正在尝试AllenNLP reading comprehensionTransformer QA Model 从文章"ABB opened its first dedicated global healthcare research center for robotics in October 2019." 中得到问题"Who is CEO of ABB?" 的答案。

正如预期的那样,UI 演示显示no answer returned。网络选项卡中的 API 响应也显示了这一点。在 json 响应中,best_span_str 为空,但best_span_scores9.9Screenshot of demo UI and API response in network tab.

当我通过 python 库执行类似的代码时,我得到了不同的结果。

from allennlp.predictors.predictor import Predictor
import pandas

def allen_nlp_demo_1():
  import allennlp_models.structured_prediction
  import allennlp_models.rc
  predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-05-26.tar.gz")
  data = predictor.predict(
    passage="ABB opened its first dedicated global healthcare research center for robotics in October 2019.",
    question= "Who is CEO of ABB?"
  )
  print(data)

if __name__ == '__main__':
  allen_nlp_demo_1()

提供以下 json 输出

{
  "span_start_logits": [...],
  "best_span": [
    7,
    15
  ],
  "best_span_scores": -10.418445587158203,
  "loss": 0,
  "best_span_str": "healthcare research center for robotics in October 2019",
  "context_tokens": [...],
  "id": "1",
  "answers": []
}

我看到 best_span_str 出现了,best_span_scores 变成了 -10.418445587158203Attaching python code and output snippet.

为什么 UI 演示与库中的输出存在这种差异?另外,best_span_scores 的范围是多少,我在哪里可以确定丢弃错误结果的阈值?

【问题讨论】:

    标签: python nlp allennlp


    【解决方案1】:
    1. 关于演示输出和您的运行的差异,这是因为实际演示使用不同的存档文件。演示中的使用代码现已更新,以反映新的文件路径 (transformer-qa-2020-10-03.tar.gz)。

    2. 为了找到 best_span,模型认为 cls 标记的预测意味着该问题不可回答。这由best_spans 表示,当问题无法回答时,它是 [-1, -1]。对于问题实际上可以回答的情况,跨度分数是相互关联的;我们选择得分最高的跨度。所以,没有一个固定的阈值可以在所有情况下都使用。

    【讨论】:

      猜你喜欢
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 2018-04-12
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多