๐ Rethinking Negative Instances for Generative Named Entity Recognition
This project introduces GNER, a Generative Named Entity Recognition framework. It shows enhanced zero - shot capabilities across unseen entity domains. Integrating negative instances into the training of LLaMA and Flan - T5 models leads to significant performance improvements, with GNER - LLaMA and GNER - T5 outperforming SoTA approaches by 8 and 11 points in $F_1$ score respectively. The code and models are publicly available.
๐ Quick Start
We introduce GNER, a Generative Named Entity Recognition framework, which demonstrates enhanced zero - shot capabilities across unseen entity domains. Experiments on two representative generative models, i.e., LLaMA and Flan - T5, show that the integration of negative instances into the training process yields substantial performance enhancements. The resulting models, GNER - LLaMA and GNER - T5, outperform state - of - the - art (SoTA) approaches by a large margin, achieving improvements of 8 and 11 points in $F_1$ score, respectively.
โจ Features
- Demonstrates enhanced zero - shot capabilities across unseen entity domains.
- Integrating negative instances into training leads to significant performance improvements.
- The resulting models outperform state - of - the - art approaches by a large margin in $F_1$ score.
๐ฆ Installation
You should install the dependencies:
pip install torch datasets deepspeed accelerate transformers protobuf
๐ป Usage Examples
Basic Usage
Please check out Example Jupyter Notebooks for guidance on utilizing GNER models.
Advanced Usage
A simple inference example is as follows:
Below is an example using 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 = "Please analyze the sentence provided, identifying the type of entity for each word on a token - by - token basis.\nOutput format is: word_1(label_1), word_2(label_2), ...\nWe'll use the BIO - format to label the entities, where:\n1. B - (Begin) indicates the start of a named entity.\n2. I - (Inside) is used for words within a named entity but are not the first word.\n3. O (Outside) denotes words that are not part of a named entity.\n"
>>> sentence = "did george clooney make a musical in the 1980s"
>>> entity_labels = ["genre", "rating", "review", "plot", "song", "average ratings", "director", "character", "trailer", "year", "actor", "title"]
>>> instruction = f"{instruction_template}\nUse the specific entity tags: {', '.join(entity_labels)} and O.\nSentence: {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 - actor) clooney(I - actor) make(O) a(O) musical(B - genre) in(O) the(O) 1980s(B - year)"
๐ Documentation
PreTrained Models
We release five GNER models based on LLaMA (7B) and Flan - T5 (base, large, xl and xxl).
Property |
Details |
Model Type |
We have GNER - LLaMA and GNER - T5 series models, including GNER - LLaMA (7B), GNER - T5 - base (248M), GNER - T5 - large (783M), GNER - T5 - xl (3B), GNER - T5 - xxl (11B). |
Training Data |
Not specified in the original document. |
Zero - shot Average $F_1$ |
GNER - LLaMA: 66.1; GNER - T5 - base: 59.5; GNER - T5 - large: 63.5; GNER - T5 - xl: 66.1; GNER - T5 - xxl: 69.1 |
Supervised Average $F_1$ |
GNER - LLaMA: 86.09; GNER - T5 - base: 83.21; GNER - T5 - large: 85.45; GNER - T5 - xl: 85.94; GNER - T5 - xxl: 86.15 |
๐ค HuggingFace Download Link |
[GNER - LLaMA](https://huggingface.co/dyyyyyyyy/GNER - LLaMA - 7B); [GNER - T5 - base](https://huggingface.co/dyyyyyyyy/GNER - T5 - base); [GNER - T5 - large](https://huggingface.co/dyyyyyyyy/GNER - T5 - large); [GNER - T5 - xl](https://huggingface.co/dyyyyyyyy/GNER - T5 - xl); [GNER - T5 - xxl](https://huggingface.co/dyyyyyyyy/GNER - T5 - xxl) |
๐ License
The model is licensed under Apache - 2.0.
๐ Citation
@misc{ding2024rethinking,
title={Rethinking Negative Instances for Generative Named Entity Recognition},
author={Yuyang Ding and Juntao Li and Pinzheng Wang and Zecheng Tang and Bowen Yan and Min Zhang},
year={2024},
eprint={2402.16602},
archivePrefix={arXiv},
primaryClass={cs.CL}
}