File size: 14,531 Bytes
26b46c0
 
fc743ec
 
 
 
 
6909d87
 
 
 
26b46c0
d069798
fc743ec
 
e994eb8
 
31d5efc
 
b54d17c
5dc088a
b5c1274
5b28de0
f3340d5
30be815
 
 
5d5ae7a
30be815
 
18eb22c
0fcd9a7
e61d685
ab4bd73
 
 
 
 
ba62150
30be815
864cf7c
30be815
 
ab4bd73
 
30be815
ab4bd73
 
 
4070c70
30be815
ab4bd73
 
 
 
 
30be815
 
b062090
30be815
 
7ad8ffc
864cf7c
 
 
 
 
 
 
 
30be815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab4bd73
30be815
 
 
 
 
864cf7c
497b810
e0ae669
7068ade
e0ae669
2d7e780
4946b33
12a6fed
 
 
 
 
 
 
 
 
 
e42769f
12a6fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307c3b5
12a6fed
 
 
 
 
 
 
 
 
 
 
 
 
99d30d4
12a6fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f3f7d
51fc4df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff13965
 
 
 
 
f4fa6dc
51cc6c6
 
 
 
 
 
 
 
 
0979f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13f6ffa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
---
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}, 
}
```