license: apache-2.0
datasets:
- Universal-NER/Pile-NER-type
language:
- en
metrics:
- f1
library_name: transformers
pipeline_tag: text2text-generation
生成式命名实体识别中的负实例再思考
GNER-T5-xl 模型卡片
我们推出GNER框架(Generative Named Entity Recognition),该框架在未见过的实体领域展现出更强的零样本识别能力。基于LLaMA和Flan-T5两大代表性生成模型的实验表明,将负实例纳入训练过程能显著提升性能。由此产生的GNER-LLaMA和GNER-T5模型以显著优势超越现有最优方法,F1分数分别提升8分和11分。代码与模型均已开源。
预训练模型
我们发布了基于LLaMA(7B)和Flan-T5(base/large/xl/xxl)的五款GNER模型。
模型 |
参数量 |
零样本平均F1 |
监督学习平均F1 |
🤗 HuggingFace 下载链接 |
GNER-LLaMA |
7B |
66.1 |
86.09 |
链接 |
GNER-T5-base |
248M |
59.5 |
83.21 |
链接 |
GNER-T5-large |
783M |
63.5 |
85.45 |
链接 |
GNER-T5-xl |
3B |
66.1 |
85.94 |
链接 |
GNER-T5-xxl |
11B |
69.1 |
86.15 |
链接 |
使用演示
需安装依赖项:
pip install torch datasets deepspeed accelerate transformers protobuf
详细使用方法请参考示例Notebook。
基础推理示例如下:
使用GNER-T5
的示例:
>>> import torch
>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
>>> tokenizer = AutoTokenizer.from_pretrained("dyyyyyyyy/GNER-T5-xxl")
>>> model = AutoModelForSeq2SeqLM.from_pretrained("dyyyyyyyy/GNER-T5-xxl", torch_dtype=torch.bfloat16).cuda()
>>> model = model.eval()
>>> instruction_template = "请分析给定句子,逐词标注实体类型。\n输出格式为:词_1(标签_1), 词_2(标签_2), ...\n采用BIO标注体系:\n1. B-表示命名实体起始词\n2. I-表示命名实体非起始词\n3. O表示非命名实体\n"
>>> sentence = "did george clooney make a musical in the 1980s"
>>> entity_labels = ["题材类型", "评分", "影评", "剧情", "歌曲", "平均分", "导演", "角色", "预告片", "年份", "演员", "片名"]
>>> instruction = f"{instruction_template}\n可用实体标签:{', '.join(entity_labels)} 和 O。\n句子:{sentence}"
>>> inputs = tokenizer(instruction, return_tensors="pt").to("cuda")
>>> outputs = model.generate(**inputs, max_new_tokens=640)
>>> response = tokenizer.decode(outputs[0], skip_special_tokens=True)
>>> print(response)
"did(O) george(B-演员) clooney(I-演员) make(O) a(O) musical(B-题材类型) in(O) the(O) 1980s(B-年份)"
引用文献
@misc{ding2024rethinking,
title={生成式命名实体识别中的负实例再思考},
author={丁宇航 and 李俊涛 and 王品正 and 唐泽成 and 严博文 and 张敏},
year={2024},
eprint={2402.16602},
archivePrefix={arXiv},
primaryClass={cs.CL}
}