shamaayan commited on
Commit
a640db1
·
1 Parent(s): bd138fe
Files changed (1) hide show
  1. handler.py +19 -0
handler.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from typing import Dict, List, Any
3
+ from tokenizers.decoders import WordPiece
4
+
5
+
6
+ class EndpointDictaBertNERHandler:
7
+ def __init__(self):
8
+ self.model = pipeline('ner', model='dicta-il/dictabert-ner', aggregation_strategy='simple')
9
+ self.model.tokenizer.backend_tokenizer.decoder = WordPiece()
10
+
11
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
12
+ """
13
+ data args:
14
+ inputs (:obj: `str` | `PIL.Image` | `np.array`)
15
+ kwargs
16
+ Return:
17
+ A :obj:`list` | `dict`: will be serialized and returned
18
+ """
19
+ return self.model(data['inputs'])