Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# FSNER
|
2 |
+
|
3 |
+
Implemented by [sayef](https://huggingface.co/sayef).
|
4 |
+
|
5 |
+
## Overview
|
6 |
+
|
7 |
+
The FSNER model was proposed in [Example-Based Named Entity Recognition](https://arxiv.org/abs/2008.10570) by Morteza Ziyadi, Yuting Sun, Abhishek Goswami, Jade Huang, Weizhu Chen. To identify entity spans in a new domain, it uses a train-free few-shot learning approach inspired by question-answering.
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
## Abstract
|
12 |
+
----
|
13 |
+
> We present a novel approach to named entity recognition (NER) in the presence of scarce data that we call example-based NER. Our train-free few-shot learning approach takes inspiration from question-answering to identify entity spans in a new and unseen domain. In comparison with the current state-of-the-art, the proposed method performs significantly better, especially when using a low number of support examples.
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
## Model Training Details
|
18 |
+
-----
|
19 |
+
|
20 |
+
| identifier | epochs | datasets |
|
21 |
+
| ---------- |:----------:| :-----:|
|
22 |
+
| [sayef/fsner-bert-base-uncased](https://huggingface.co/sayef/fsner-bert-base-uncased) | 10 | ontonotes5, conll2003, wnut2017, and fin (Alvarado et al.). |
|
23 |
+
|
24 |
+
|
25 |
+
## Installation and Example Usage
|
26 |
+
------
|
27 |
+
You need to clone `transformers` repository and go to this directory: `transformers/examples/research_projects/fsner`. Then, you will be able to use the FSNER model in two ways:
|
28 |
+
|
29 |
+
1. Install as a package: `python setup.py install` and import the model as shown in the code example below
|
30 |
+
|
31 |
+
or
|
32 |
+
|
33 |
+
2. Change directory to `src` and import the model as shown in the code example below
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
```python
|
38 |
+
from fsner import FSNERModel, FSNERTokenizerUtils
|
39 |
+
|
40 |
+
model = FSNERModel("sayef/fsner-bert-base-uncased")
|
41 |
+
|
42 |
+
tokenizer = FSNERTokenizerUtils("sayef/fsner-bert-base-uncased")
|
43 |
+
|
44 |
+
# size of query and supports must be the same. If you want to find all the entitites in one particular query, just repeat the same query n times where n is equal to the number of supports (or entities).
|
45 |
+
|
46 |
+
|
47 |
+
query = [
|
48 |
+
'KWE 4000 can reach with a maximum speed from up to 450 P/min an accuracy from 50 mg',
|
49 |
+
'I would like to order a computer from eBay.',
|
50 |
+
]
|
51 |
+
|
52 |
+
# each list in supports are the examples of one entity type
|
53 |
+
# wrap entities around with [E] and [/E] in the examples
|
54 |
+
|
55 |
+
supports = [
|
56 |
+
[
|
57 |
+
'Horizontal flow wrapper [E] Pack 403 [/E] features the new retrofit-kit „paper-ON-form“',
|
58 |
+
'[E] Paloma Pick-and-Place-Roboter [/E] arranges the bakery products for the downstream tray-forming equipment',
|
59 |
+
'Finally, the new [E] Kliklok ACE [/E] carton former forms cartons and trays without the use of glue',
|
60 |
+
'We set up our pilot plant with the right [E] FibreForm® [/E] configuration to make prototypes for your marketing tests and package validation',
|
61 |
+
'The [E] CAR-T5 [/E] is a reliable, purely mechanically driven cartoning machine for versatile application fields'
|
62 |
+
],
|
63 |
+
[
|
64 |
+
"[E] Walmart [/E] is a leading e-commerce company",
|
65 |
+
"I recently ordered a book from [E] Amazon [/E]",
|
66 |
+
"I ordered this from [E] ShopClues [/E]",
|
67 |
+
"Fridge can be ordered in [E] Amazon [/E]",
|
68 |
+
"[E] Flipkart [/E] started it's journey from zero"
|
69 |
+
]
|
70 |
+
]
|
71 |
+
|
72 |
+
device = 'cpu'
|
73 |
+
|
74 |
+
W_query = tokenizer.tokenize(query).to(device)
|
75 |
+
W_supports = tokenizer.tokenize([s for support in supports for s in support]).to(device)
|
76 |
+
|
77 |
+
start_prob, end_prob = model(W_query, W_supports)
|
78 |
+
|
79 |
+
output = tokenizer.extract_entity_from_scores(query, W_query, start_prob, end_prob, thresh=0.50)
|
80 |
+
|
81 |
+
print(output)
|
82 |
+
```
|