SLIMER / README.md
andrewzamai's picture
Update README.md
307c3b5 verified
---
license: llama2
datasets:
- Universal-NER/Pile-NER-type
language:
- en
pipeline_tag: text-generation
tags:
- zero-shot NER
- NER
---
# SLIMER: Show Less Instruct More Entity Recognition
GitHub repository: https://github.com/andrewzamai/SLIMER
SLIMER is an LLM specifically instructed for zero-shot NER on English language.
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 NE 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, .guidelines {
padding: 5px;
border-radius: 10px; /* Rounded borders for definition and guidelines */
}
.definition {
background-color: #ffc773;
}
.guidelines {
background-color: #73d7ff;
}
.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">Instruction Tuning Prompt</div>
<div class="content">
<p><b>[INST]</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 Named Entities of type <b>DATE</b> from the text chunk you have read.</p>
<p>You are given a <b>DEFINITION</b> and some <b>GUIDELINES</b>.</p>
<div class="definition">
<p><b>DEFINITION:</b> <b>DATE</b> refers to specific points in time, including days, months, years, and relative time expressions like 'Week 2'.</p>
</div>
<div class="guidelines">
<p><b>GUIDELINES:</b> Avoid labeling non-specific time references like 'recently' or 'soon'. Exercise caution with ambiguous terms like 'May' (month or verb) and 'Wednesday Adams' (person's name which includes a day of the week).</p>
</div>
<p>Return a JSON list of instances of this Named Entity type. Return an empty list if no instances are present.</p>
<p><b>[/INST]</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">UniNER-def</td>
<td class="col-backbone">LLaMA-1</td>
<td class="col-params">7B</td>
<td class="col-mit">27.1</td>
<td class="col-mit">27.9</td>
<td class="col-crossner">44.5</td>
<td class="col-crossner">49.2</td>
<td class="col-crossner">55.8</td>
<td class="col-crossner">57.5</td>
<td class="col-crossner">52.9</td>
<td class="col-buster">33.6</td>
<td class="col-avg">43.6</td>
</tr>
<tr>
<td class="col-model">UniNER-type+sup.</td>
<td class="col-backbone">LLaMA-1</td>
<td class="col-params">7B</td>
<td class="col-mit">61.2</td>
<td class="col-mit">35.2</td>
<td class="col-crossner">62.9</td>
<td class="col-crossner">64.9</td>
<td class="col-crossner">70.6</td>
<td class="col-crossner">66.9</td>
<td class="col-crossner">70.8</td>
<td class="col-buster">37.8</td>
<td class="col-avg">58.8</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">SLIMER w/o D&amp;G</td>
<td class="col-backbone">LLaMA-2-chat</td>
<td class="col-params">7B</td>
<td class="col-mit">46.4</td>
<td class="col-mit">36.3</td>
<td class="col-crossner">49.6</td>
<td class="col-crossner">58.4</td>
<td class="col-crossner">56.8</td>
<td class="col-crossner">57.9</td>
<td class="col-crossner">53.8</td>
<td class="col-buster">40.4</td>
<td class="col-avg">49.9</td>
</tr>
<tr>
<td class="col-model"><b>SLIMER</b></td>
<td class="col-backbone"><b>LLaMA-2-chat</b></td>
<td class="col-params"><b>7B</b></td>
<td class="col-mit"><b>50.9</b></td>
<td class="col-mit"><b>38.2</b></td>
<td class="col-crossner"><b>50.1</b></td>
<td class="col-crossner"><b>58.7</b></td>
<td class="col-crossner"><b>60.0</b></td>
<td class="col-crossner"><b>63.9</b></td>
<td class="col-crossner"><b>56.3</b></td>
<td class="col-buster"><b>45.3</b></td>
<td class="col-avg"><b>52.9</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 prompt",
"prompt_input": "[INST] You 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 Named Entities of type {<span class="highlight-orange">NE_name</span>} from the text chunk you have read. You are given a DEFINITION and some GUIDELINES.\nDEFINITION: {<span class="highlight-orange">definition</span>}\nGUIDELINES: {<span class="highlight-orange">guidelines</span>}\nReturn a JSON list of instances of this Named Entity type. Return an empty list if no instances are present.\n[/INST]\n"
}</pre>
</div>
</body>
</html>
```python
from vllm import LLM, SamplingParams
vllm_model = LLM(model="expertai/SLIMER")
sampling_params = SamplingParams(temperature=0, max_tokens=128, stop=['</s>'])
prompts = [prompter.generate_prompt(instruction, input) for instruction, input in instruction_input_pairs]
responses = vllm_model.generate(prompts, 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},
}
```