|
--- |
|
license: llama3.1 |
|
datasets: |
|
- Universal-NER/Pile-NER-type |
|
language: |
|
- en |
|
pipeline_tag: text-generation |
|
tags: |
|
- zero-shot NER |
|
- NER |
|
base_model: |
|
- meta-llama/Llama-3.1-8B-Instruct |
|
--- |
|
|
|
# SLIMER-PARALLEL-LLaMA3 |
|
|
|
SLIMER is an LLM specifically instructed for zero-shot NER on English language. |
|
|
|
This LLaMA-3 based SLIMER scores __+17 %__ over paper's original SLIMER LLaMA-2, |
|
while allowing up to 16 NEs to be extracted __in parallel__ per prompt. |
|
|
|
GitHub repository: https://github.com/andrewzamai/SLIMER/tree/v2.0 |
|
|
|
SLIMER for Italian language can be found at: https://huggingface.co/expertai/LLaMAntino-3-SLIMER-IT |
|
|
|
Instructed on a reduced number of samples, it is designed to tackle never-seen-before Named Entity tags by leveraging a prompt enriched with a DEFINITION and GUIDELINES for the NEs to be extracted. |
|
|
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>Instruction Tuning Prompt</title> |
|
<style> |
|
.container { |
|
border: none; |
|
padding: 5px; |
|
width: 300px; |
|
margin: 0 auto; |
|
font-family: Arial, sans-serif; |
|
font-size: 8px; |
|
border-radius: 10px; /* Rounded borders for container */ |
|
overflow: hidden; /* Ensure child elements respect container's rounded borders */ |
|
background-color: #f0f0f0 |
|
} |
|
.header { |
|
background-color: black; |
|
color: white; |
|
padding: 5px; |
|
text-align: center; |
|
font-weight: bold; |
|
font-size: 14px; |
|
border-top-left-radius: 10px; /* Rounded top-left corner */ |
|
border-top-right-radius: 10px; /* Rounded top-right corner */ |
|
} |
|
.content { |
|
padding: 5px; |
|
} |
|
.definition, { |
|
padding: 5px; |
|
border-radius: 10px; /* Rounded borders for definition and guidelines */ |
|
} |
|
.definition { |
|
background-color: #ffc773; |
|
} |
|
.footer { |
|
background-color: black; |
|
color: white; |
|
padding: 10px; |
|
font-weight: bold; |
|
border-bottom-left-radius: 10px; |
|
border-bottom-right-radius: 10px; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="container"> |
|
<div class="header">SLIMER-3-PARALLEL prompt</div> |
|
<div class="content"> |
|
<p><b><|start_header_id|>user<|end_header_id|></b></p> |
|
<p>You are given a text chunk (delimited by triple quotes) and an instruction.<br> |
|
Read the text and answer to the instruction in the end.</p> |
|
<p>"""<br> |
|
{input text}<br> |
|
"""</p> |
|
<p><b>Instruction:</b> Extract the entities of type <b>[NEs_list]</b> from the text chunk you have read. Be aware that not all of these entities are necessarily present. Do not extract entities that do not exist in the text, return an empty list for that tag. Ensure each entity is assigned to only one appropriate class.</p> |
|
<p>To help you, here are dedicated Definition and Guidelines for each entity tag.</p> |
|
<div class="definition"> |
|
<p>{</p> |
|
<p>{<b>"NE_type_1":</b> {"Definition": "", "Guidelines": ""}</p> |
|
<p><b> ... </b> |
|
<p>{<b>"NE_type_N":</b> {"Definition": "", "Guidelines": ""}</p> |
|
<p>}</p> |
|
</div> |
|
<p>Return only a JSON object. The JSON should strictly follow this format: {"NE_type_1": [], ..., "NE_type_N":[]}. DO NOT output anything else, just the JSON itself.</p> |
|
<p><b><|eot_id|><|start_header_id|>assistant<|end_header_id|></b></p> |
|
</div> |
|
<div class="footer"></div> |
|
</div> |
|
</body> |
|
</html> |
|
|
|
|
|
|
|
Currently existing approaches fine-tune on an extensive number of entity classes (around 13K) and assess zero-shot NER capabilities on Out-Of-Distribution input domains. |
|
SLIMER performs comparably to these state-of-the-art models on OOD input domains, while being trained only a reduced number of samples and a set of NE tags that overlap in lesser degree with test sets. |
|
|
|
We extend the standard zero-shot evaluations (CrossNER and MIT) with BUSTER, which is characterized by financial entities that are rather far from the more traditional tags observed by all models during training. |
|
An inverse trend can be observed, with SLIMER emerging as the most effective in dealing with these unseen labels, thanks to its lighter instruction tuning methodology and the use of definition and guidelines. |
|
|
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<style> |
|
table { |
|
width: 100%; |
|
border-collapse: collapse; |
|
font-size: 12px; |
|
} |
|
th, td { |
|
border: 1px none; |
|
padding: 4px; |
|
text-align: center; |
|
} |
|
th { |
|
background-color: #f2f2f2; |
|
} |
|
.col-model { width: 10%; } |
|
.col-backbone { width: 15%; } |
|
.col-params { width: 10%; } |
|
.col-mit, .col-crossner, .col-buster, .col-avg { width: 7%; } |
|
</style> |
|
</head> |
|
<body> |
|
|
|
<table> |
|
<thead> |
|
<tr> |
|
<th class="col-model">Model</th> |
|
<th class="col-backbone">Backbone</th> |
|
<th class="col-params">#Params</th> |
|
<th class="col-mit" colspan="2">MIT</th> |
|
<th class="col-crossner" colspan="5">CrossNER</th> |
|
<th class="col-buster">BUSTER</th> |
|
<th class="col-avg">AVG</th> |
|
</tr> |
|
<tr> |
|
<th></th> |
|
<th></th> |
|
<th></th> |
|
<th class="col-mit">Movie</th> |
|
<th class="col-mit">Restaurant</th> |
|
<th class="col-crossner">AI</th> |
|
<th class="col-crossner">Literature</th> |
|
<th class="col-crossner">Music</th> |
|
<th class="col-crossner">Politics</th> |
|
<th class="col-crossner">Science</th> |
|
<th class="col-buster"></th> |
|
<th class="col-avg"></th> |
|
</tr> |
|
</thead> |
|
<tbody> |
|
<tr> |
|
<td class="col-model">ChatGPT</td> |
|
<td class="col-backbone">gpt-3.5-turbo</td> |
|
<td class="col-params">-</td> |
|
<td class="col-mit">5.3</td> |
|
<td class="col-mit">32.8</td> |
|
<td class="col-crossner">52.4</td> |
|
<td class="col-crossner">39.8</td> |
|
<td class="col-crossner">66.6</td> |
|
<td class="col-crossner">68.5</td> |
|
<td class="col-crossner">67.0</td> |
|
<td class="col-buster">-</td> |
|
<td class="col-avg">-</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">InstructUIE</td> |
|
<td class="col-backbone">Flan-T5-xxl</td> |
|
<td class="col-params">11B</td> |
|
<td class="col-mit">63.0</td> |
|
<td class="col-mit">21.0</td> |
|
<td class="col-crossner">49.0</td> |
|
<td class="col-crossner">47.2</td> |
|
<td class="col-crossner">53.2</td> |
|
<td class="col-crossner">48.2</td> |
|
<td class="col-crossner">49.3</td> |
|
<td class="col-buster">-</td> |
|
<td class="col-avg">-</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">UniNER-type</td> |
|
<td class="col-backbone">LLaMA-1</td> |
|
<td class="col-params">7B</td> |
|
<td class="col-mit">42.4</td> |
|
<td class="col-mit">31.7</td> |
|
<td class="col-crossner">53.5</td> |
|
<td class="col-crossner">59.4</td> |
|
<td class="col-crossner">65.0</td> |
|
<td class="col-crossner">60.8</td> |
|
<td class="col-crossner">61.1</td> |
|
<td class="col-buster">34.8</td> |
|
<td class="col-avg">51.1</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">GoLLIE</td> |
|
<td class="col-backbone">Code-LLaMA</td> |
|
<td class="col-params">7B</td> |
|
<td class="col-mit">63.0</td> |
|
<td class="col-mit">43.4</td> |
|
<td class="col-crossner">59.1</td> |
|
<td class="col-crossner">62.7</td> |
|
<td class="col-crossner">67.8</td> |
|
<td class="col-crossner">57.2</td> |
|
<td class="col-crossner">55.5</td> |
|
<td class="col-buster" style="color: red;">27.7</td> |
|
<td class="col-avg">54.6</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">GLiNER-L</td> |
|
<td class="col-backbone">DeBERTa-v3</td> |
|
<td class="col-params">0.3B</td> |
|
<td class="col-mit">57.2</td> |
|
<td class="col-mit">42.9</td> |
|
<td class="col-crossner">57.2</td> |
|
<td class="col-crossner">64.4</td> |
|
<td class="col-crossner">69.6</td> |
|
<td class="col-crossner">72.6</td> |
|
<td class="col-crossner">62.6</td> |
|
<td class="col-buster" style="color: red;">26.6</td> |
|
<td class="col-avg">56.6</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">GNER-T5</td> |
|
<td class="col-backbone">Flan-T5-xxl</td> |
|
<td class="col-params">11B</td> |
|
<td class="col-mit">62.5</td> |
|
<td class="col-mit">51.0</td> |
|
<td class="col-crossner">68.2</td> |
|
<td class="col-crossner">68.7</td> |
|
<td class="col-crossner">81.2</td> |
|
<td class="col-crossner">75.1</td> |
|
<td class="col-crossner">76.7</td> |
|
<td class="col-buster" style="color: red;">27.9</td> |
|
<td class="col-avg">63.9</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model">GNER-LLaMA</td> |
|
<td class="col-backbone">LLaMA-1</td> |
|
<td class="col-params">7B</td> |
|
<td class="col-mit">68.6</td> |
|
<td class="col-mit">47.5</td> |
|
<td class="col-crossner">63.1</td> |
|
<td class="col-crossner">68.2</td> |
|
<td class="col-crossner">75.7</td> |
|
<td class="col-crossner">69.4</td> |
|
<td class="col-crossner">69.9</td> |
|
<td class="col-buster" style="color: red;">23.6</td> |
|
<td class="col-avg">60.8</td> |
|
</tr> |
|
<tr> |
|
<td class="col-model"><b>SLIMER</b></td> |
|
<td class="col-backbone"><b>LLaMA-3.1-Instruct</b></td> |
|
<td class="col-params"><b>8B</b></td> |
|
<td class="col-mit"><b>58.4</b></td> |
|
<td class="col-mit"><b>45.3</b></td> |
|
<td class="col-crossner"><b>58.0</b></td> |
|
<td class="col-crossner"><b>65.0</b></td> |
|
<td class="col-crossner"><b>77.0</b></td> |
|
<td class="col-crossner"><b>71.2</b></td> |
|
<td class="col-crossner"><b>67.3</b></td> |
|
<td class="col-buster"><b>39.32</b></td> |
|
<td class="col-avg"><b>60.2</b></td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
|
|
</body> |
|
</html> |
|
|
|
|
|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>JSON Template</title> |
|
<style> |
|
body { |
|
font-family: Arial, sans-serif; |
|
line-height: 1.6; |
|
padding: 20px; |
|
} |
|
.description { |
|
font-weight: bold; |
|
color: #333; |
|
margin-bottom: 10px; |
|
} |
|
.template { |
|
background-color: #f0f0f0; |
|
padding: 10px; |
|
border-radius: 5px; |
|
margin-bottom: 20px; |
|
} |
|
.highlight-orange { |
|
color: orange; |
|
font-weight: bold; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="description">JSON SLIMER prompt</div> |
|
<div class="template"> |
|
<pre>{ |
|
"description": "SLIMER PARALLEL 3 prompt", |
|
"prompt_input": "<|start_header_id|>system<|end_header_id|>\n\nYou are a helpful NER assistant designed to output JSON.<|eot_id|>\n<|start_header_id|>user<|end_header_id|>\n\nYou are given a text chunk (delimited by triple quotes) and an instruction.\nRead the text and answer to the instruction in the end.\n\"\"\"\n{<span class="highlight-orange">input</span>}\n\"\"\"\nInstruction: Extract the entities of type {ne_tags} from the text chunk you have read. Be aware that not all of these entities are necessarily present. Do not extract entities that do not exist in the text, return an empty list for that tag. Ensure each entity is assigned to only one appropriate class.\nTo help you, here are dedicated Definition and Guidelines for each entity tag.\n{Def_and_Guidelines}\nReturn only a JSON object. The JSON should strictly follow this format:\n{expected_json_format}.\nDO NOT output anything else, just the JSON itself." |
|
}</pre> |
|
</div> |
|
</body> |
|
</html> |
|
|
|
|
|
```python |
|
from vllm import LLM, SamplingParams |
|
|
|
vllm_model = LLM(model="expertai/SLIMER-PARALLEL-LLaMA3") |
|
tokenizer = vllm_model.get_tokenizer() |
|
|
|
# suggested temperature 0, max_tokens hyperparam |
|
cutoff_len = 4096 |
|
sampling_params = SamplingParams(temperature=0, max_tokens=1000, stop=tokenizer.eos_token) |
|
|
|
# given list of NE types and dictionary of Def and Guidelines for each --> returns instruction |
|
slimer_prompter = SLIMER_PARALLEL_instruction_prompter("SLIMER_PARALLEL_instruction_template", './src/SFT_finetuning/templates') |
|
|
|
# create a dictionary of dictionaries, each NE_type as key should have a {Definition: str, Guidelines: str} value |
|
ne_types_list = ['ORGANIZATION', 'UNIVERSITY', 'LOCATION', 'PERSON', 'CONFERENCE'] |
|
def_guidelines_per_NE_dict = {'ORGANIZATION': {'Definition': "'organization' refers to structured groups, institutions, companies, or associations.", 'Guidelines': "Avoid labeling generic terms like 'team' or 'group'. Exercise caution with ambiguous entities like 'Apple' (company vs. fruit) and 'Manchester United' (sports team vs. fan club)."}, 'UNIVERSITY': {'Definition': 'UNIVERSITY represents educational institutions that offer higher education and academic research programs.', 'Guidelines': "Avoid labeling general concepts such as 'education' or 'academia' as UNIVERSITY. Exercise caution with ambiguous terms like 'Cambridge' (can refer to different institutions) and 'Harvard' (can refer to a person)."}, 'LOCATION': {'Definition': 'LOCATION refers to specific geographic entities such as venues, facilities, and institutions that represent physical places with distinct addresses or functions.', 'Guidelines': "Exercise caution with ambiguous terms, e.g., 'Amazon' (company, river, and region) and 'Cambridge' (U.S. city, UK city, and university). Consider the context and specificity to accurately classify locations."}, 'PERSON': {'Definition': 'PERSON refers to individuals, including public figures, celebrities, and notable personalities.', 'Guidelines': 'If a person is working on research (including professor, Ph.D. student, researcher in companies, and etc) avoid labeling it as PERSON entity.'}, 'CONFERENCE': {'Definition': 'CONFERENCE refers to specific events or gatherings where experts, researchers, and professionals convene to present and discuss their work in a particular field or discipline.', 'Guidelines': "Exercise caution when labeling entities that could refer to institutions, organizations, or associations rather than specific events. Take care with ambiguous terms like 'International Journal of Computer Vision', which may refer to a publication rather than a conference."}} |
|
|
|
instruction = slimer_prompter.generate_prompt( |
|
ne_tags=", ".join(ne_types_list), |
|
def_and_guidelines=json.dumps(def_guidelines_per_NE_dict, indent=2), |
|
expected_json_format=json.dumps({k: [] for k in def_guidelines_per_NE_dict.keys()}, indent=2) |
|
) |
|
|
|
input_text = 'Typical generative model approaches include naive Bayes classifier s , Gaussian mixture model s , variational autoencoders and others .' |
|
|
|
# this promper formats the input text to analize with SLIMER instruction |
|
input_instruction_prompter = Prompter('LLaMA3-chat-NOheaders', template_path='./src/SFT_finetuning/templates') |
|
|
|
system_message = "You are a helpful NER assistant designed to output JSON." |
|
conversation = [ |
|
{"role": "system", "content": system_message}, |
|
{"role": "user", "content": input_instruction_prompter.generate_prompt(input=input_text, instruction=instruction)}, # the input_text + instruction |
|
] |
|
prompt = tokenizer.apply_chat_template(conversation, tokenize=False, truncation=True, max_length=cutoff_len, add_generation_prompt=True) |
|
|
|
responses = vllm_model.generate(prompt, sampling_params) |
|
``` |
|
|
|
## Citation |
|
|
|
If you find SLIMER useful in your research or work, please cite the following paper: |
|
|
|
``` latex |
|
@misc{zamai2024lessinstructmoreenriching, |
|
title={Show Less, Instruct More: Enriching Prompts with Definitions and Guidelines for Zero-Shot NER}, |
|
author={Andrew Zamai and Andrea Zugarini and Leonardo Rigutini and Marco Ernandes and Marco Maggini}, |
|
year={2024}, |
|
eprint={2407.01272}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL}, |
|
url={https://arxiv.org/abs/2407.01272}, |
|
} |
|
``` |