license: apache-2.0
datasets:
- Universal-NER/Pile-NER-type
language:
- en
metrics:
- f1
library_name: transformers
pipeline_tag: text-generation
生成式命名实体识别中的负样本重构思考
GNER-LLaMA-7B模型卡片
我们提出GNER框架(Generative Named Entity Recognition),该框架在未见过的实体领域展现出更强的零样本识别能力。基于LLaMA和Flan-T5两大代表性生成模型的实验表明,将负样本纳入训练过程能显著提升性能。最终模型GNER-LLaMA和GNER-T5以8分和11分的F1值优势大幅超越当前最优方案。代码与模型均已开源。
预训练模型
我们发布了基于LLaMA(7B)和Flan-T5(base/large/xl/xxl)的五款GNER模型。
模型 |
参数量 |
零样本平均F1 |
监督学习平均F1 |
🤗模型下载链接 |
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-LLaMA为例):
>>> import torch
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("dyyyyyyyy/GNER-LLaMA-7B")
>>> model = AutoModelForCausalLM.from_pretrained("dyyyyyyyy/GNER-LLaMA-7B", 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}"
>>> instruction = f"[INST] {instruction} [/INST]"
>>> 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)
>>> response = response[response.find("[/INST]") + len("[/INST]"):].strip()
>>> 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}
}