gpt4 book ai didi

python - spacy 3 NER Scorer() 抛出 TypeError : score() takes 2 positional arguments but 3 were given

转载 作者:行者123 更新时间:2023-12-04 07:45:20 25 4
gpt4 key购买 nike

尝试使用 Scorer 在我的测试集上获取分数时遇到以下错误

TypeError: score() takes 2 positional arguments but 3 were given

import spacy 
from spacy.tokens import Span
from spacy import displacy
from spacy.training import *
from spacy.scorer import Scorer
from spacy.util import minibatch, compounding

def evaluate(ner_model, testing_data):
scorer = Scorer()

for input_, annot in testing_data:
doc_gold_text = ner_model.make_doc(input_)
example = Example.from_dict(doc_gold_text, {"entities": annot})
pred_value = ner_model(input_)

return scorer.score(pred_value, example)

print(evaluate(nlp_updated, testing_tagged))
其中 testing_tagged:
testing_tagged = [
("Who was Hamlet?", [(8,14,'PERSON')]),
("Have you ever met Rome?", [(18,22,'LOC')])
]
预期输出在哪里 p , rf不是 0:
{'uas': 0.0, 'las': 0.0, 'las_per_type': {'': {'p': 0.0, 'r': 0.0, 'f': 0.0}}, 'ents_p': 0.0, 'ents_r': 0.0, 'ents_f': 0.0, 'ents_per_type': {'PERSON': {'p': 0.0, 'r': 0.0, 'f': 0.0}, 'LOC': {'p': 0.0, 'r': 0.0, 'f': 0.0}}, 'tags_acc': 0.0, 'token_acc': 100.0, 'textcat_score': 0.0, 'textcats_per_cat': {}}
我最初与 GoldParse 一起工作函数而不是 Example.from_dict - 但我升级到了 Spacy 3.0.5,我不明白为什么会发生这个错误。

最佳答案

从 spaCy v3,scorer.score只需要一个例子列表。每个Example对象包含两个 Doc对象:

  • reference带有黄金标准注释的文档,为
    来自给定的示例 annot字典
  • predicted doc与预测。然后记分员将两者进行比较。

  • 所以你想要这样的东西:
    from spacy.training import Example
    examples = []
    for ...:
    example = Example.from_dict(text, {"entities": annot})
    example.predicted = ner_model(example.predicted)
    examples.append(example)
    scorer.score(examples)

    关于python - spacy 3 NER Scorer() 抛出 TypeError : score() takes 2 positional arguments but 3 were given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67229277/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com