Skip to main content

metric4coref

codecov PyPI - Python Version PyPI Downloads

共指消解任务CoNLL的官方评测库是Perl语言完成的,但是近些年基于Python语言为主的深度学习在共指消解任务上的应用越来越普遍,所以同时也非常需要一个基于Python的便捷评测库。

使用方法

  • 安装
pip install metric4coref
  • 使用
from metric4coref import muc, ceaf, b_cubed, conll_coref_f1
# "a", "b" 等代表mention id
# predict_clusters、gold_clusters分别代表模型生成mention簇和标注mention簇
predict_clusters = [["a", "b", "c"], ["d", "e", "f", "g"], ["h", "i", "j"], ["k"]]
gold_clusters = [["a", "b", "d"], ["c", "e", "f", "g"], ["h", "i", "j", "k"]]

print(muc(predict_clusters, gold_clusters))
# -> 准确率、召回率、f1:(0.5833333333333334, 0.4666666666666667, 0.5185185185185186)
print(b_cubed(predict_clusters, gold_clusters))
# -> 准确率、召回率、f1:(0.7424242424242423, 0.606060606060606, 0.6673476336397685)
print(ceaf(predict_clusters, gold_clusters))
# -> 准确率、召回率、f1:(0.7272727272727273, 0.7272727272727273, 0.7272727272727273)
print(conll_coref_f1(predict_clusters, gold_clusters))
# -> 以上三个f1平均值: 0.6377129598103382

共指消解的评测方法

  • the link based MUC
  • B cubed metric
  • the entity based CEAF metric
  • BLANC
  • Link-Based Entity-Aware metric (LEA).

共指消解任务

算法解读

  • the link based MUC
    • 解释:基于簇中两两mention连接的边作为评测依据
      • precision: 分子:所有系统预测边与所有标注边的交集的个数 分母:所有预测边的个数
      • recall: 分子:所有系统预测边与所有标注边的交集的个数 分母:所有标注边的个数
      • f1: precision * recall * 2 / (precision + recall)
    • 例子:
      • 预测边: ab、bc、ac、de、df、dg、ef、eg、fg、hi、ij、hj共12个
      • 标注边: ab、ad、bd、ce、cf、cg、ef、eg、fg、hi、hj、hk、ij、ik、jk共15个
      • 预测边和标注边的交集: ab、ef、eg、fg、hi、hj、ij共7个
      • precision: 7/12=0.5833333
      • recall: 7/15=0.4666667
      • f1: 0.5833333 * 0.4666667 * 2 / (0.5833333 + 0.4666667)=0.5185185
    • 特点:
      • 不考虑单个mention的簇,因为没有边
      • 倾向于生成很多mention的簇,容易得高分
  • B cubed metric
    • 解释:以mention为单位,每个mention计算一个precision和recall,在加权平均所有mention的precision和recall
      • 每个mention的计算方法:
        • precision: 分子:系统预测的包含mention的簇与人工标注的包含mention的簇的mention交集个数 分母:系统生成的包含mention的簇的个数
        • recall: 分子:系统预测的包含mention的簇与人工标注的包含mention的簇的mention交集个数 分母:人工标注的包含mention的簇的个数
        • f1: precision * recall * 2 / (precision + recall)
    • 例子:
      • mention a: 所在预测簇: ["a", "b", "c"] 所在标注簇: ["a", "b", "d"] precision: 分子: a、b共2个 分母: a、b、c共3个 =2/3=0.666 recall: 分子: a、b共2个 分母: a、b、d共3个 =2/3=0.666
      • mention b: 所在预测簇: ["a", "b", "c"] 所在标注簇: ["a", "b", "d"] precision: 分子: a、b共2个 分母: a、b、c共3个 =2/3=0.666 recall: 分子: a、b共2个 分母: a、b、d共3个 =2/3=0.666
      • mention c 所在预测簇: ["a", "b", "c"] 所在标注簇: ["c", "e", "f", "g"] precision: 分子: c共1个 分母: a、b、c共3个 =1/3=0.333 recall: 分子: c共1个 分母: c、e、f、g共4个 =1/4=0.25 ...
      • 对所有mention的precision、recall求平均值
    • 特点:
      • 对每个mention等权重看待
  • the entity based CEAF metric
    • 解释:
      1. 标注的实体簇为R、系统生成的实体簇为S,R中每个mention为r、S中每个mention为s
      2. R的个数与S的个数的少者为m
      3. 建立从R到S的一一映射map,每个映射对应从R中的r到S中的s,映射的个数为m
      4. 计算每个映射中,r和s中相同mention个数
      5. 计算整个map映射中,所有相同mention的个数
      6. 遍历所有可能的map,取所有相同mention的个数的最大的映射map,相同mention个数为n
      7. precision = n/S的mention个数
      8. recall = n/R的mention个数
    • 例子:
      • 预测的实体簇个数为4
      • 标注的实体簇个数为3 那么m=3
      • 遍历可知,映射关系为 标注实体簇1 --> 预测实体簇1 标注实体簇2 --> 预测实体簇2 标注实体簇3 --> 预测实体簇3
      • 计数: 正确的mention有: a、b、e、f、g、h、i、j共8个 预测的mention个数共11个 标注的mention个数共11个
      • 指标: precision=8/11=0.7272727 recall=8/11=0.7272727

Metadata

Release files for metric4coref 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metric4coref 0.0.2
File Size Uploaded
metric4coref-0.0.2.tar.gz 5.0 kB Details

Release files / metric4coref-0.0.2.tar.gz

Download URL metric4coref-0.0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
88f6858e63a0ad0553c7b281653d9bec19a641e42809f9c07b6d469d04957bba
BLAKE2b-256 checksum
How to use checksums
7f892ea6c7ee6d536b8412321ac41206eafa29c80ac1fe5e660d8bde534f9dec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page