【问题标题】:How can I get the confusion matrix used to calculate the metrics for NER models?如何获得用于计算 NER 模型指标的混淆矩阵?
【发布时间】:2020-07-27 13:46:23
【问题描述】:

类似于上一个问题How to calculate the overall accuracy of custom trained spacy ner model with confusion matrix?

spaCy 在写出经过训练的 NER 模型时,会在 meta.json 文件中提供 Precision、Recall、F1 分数。当运行评估命令python -m spacy evaluate 时,这些值也可用。但是,是否可以获得用于计算这些值的 TP、FP、FN 的计数?

此外,是否可以输出导致误报或误报的实际文本/标记?

【问题讨论】:

    标签: spacy


    【解决方案1】:

    我认为您可以在使用评估所有实体类型时获得 TP、FP、FN 的计数

    scorer = nlp.evaluate(testset)
    TP = scorer.ner.tp
    FP = scorer.ner.fp
    FN = scorer.ner.fn
    

    在评估每个实体类型时使用

    scorer = nlp.evaluate(testset)
    for ent_type, scorer_ent_type in scorer.ner_per_ents.items():
        TP = scorer_ent_type.tp
        FP = scorer_ent_type.fp
        FN = scorer_ent_type.fn
        print('Ent_type:', ent_type, 'TP:', TP, 'FP:', FP, 'FN:', FN)
    

    据我了解,在训练和评估您的 spacy NER 模型时,所有实体的分数都是在 spacy 代码中的 this line 中计算的。每个实体的分数在this line 中计算。在这两种情况下,都会调用 score_set 函数。它更新记分器中的 TP、FP 和 FN。如果您在这些行设置断点并进行调试,您可以查看变量doccand_entsgold_ents,并查看 FP 和 FN

    print(doc)
    print(cand_ents-gold_ents) #FP
    print(gold_ents-cand_ents) #FN
    

    迟到的答案,但我希望它有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 2019-12-28
      • 2017-02-25
      • 2018-04-01
      • 2018-04-09
      • 2019-10-08
      • 2018-10-16
      • 2019-03-09
      相关资源
      最近更新 更多