【发布时间】:2023-03-23 07:19:02
【问题描述】:
以下是 NER 拥抱面部转换器的简单示例:
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-large-NER")
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-large-NER")
nlp = pipeline("ner", model=model, tokenizer=tokenizer)
example = "My name is jonathan davis and I live in Chicago, Illinois"
ner_results = nlp(example)
print(ner_results)
output: [{'entity': 'B-PER', 'score': 0.95571744, 'index': 4, 'word': 'j', 'start': 11, 'end':
12}, {'entity': 'B-PER', 'score': 0.6131773, 'index': 5, 'word': '##ona', 'start': 12, 'end':
15}, {'entity': 'I-PER', 'score': 0.6707376, 'index': 6, 'word': '##than', 'start': 15, 'end':
19}, {'entity': 'I-PER', 'score': 0.97754997, 'index': 7, 'word': 'da', 'start': 20, 'end': 22},
{'entity': 'I-PER', 'score': 0.4608973, 'index': 8, 'word': '##vis', 'start': 22, 'end': 25},
{'entity': 'B-LOC', 'score': 0.9990302, 'index': 13, 'word': 'Chicago', 'start': 40, 'end': 47}]
例如我有关于我的句子的信息:
jonathan davis - PER
Chicago - LOC
Illinois - LOC (The model did not recognize this entity)
鉴于我的数据按如下方式拆分,我如何正确计算 Precision 和 Recall:
j, ##ona, ##than
在此之前,我使用了正则表达式并使用了一个度量,这点在article 中有描述。但我不知道它是否适合这个任务。
请帮助我找到计算指标的正确方法。也许我错过了拥抱脸中的一些内置功能?
【问题讨论】:
标签: python nlp huggingface-transformers