cguynup commited on
Commit
c5d740a
·
1 Parent(s): c0592b4

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +15 -9
handler.py CHANGED
@@ -1,20 +1,26 @@
1
- from typing import Dict, List, Any
2
- from optimum.onnxruntime import ORTModelForSequenceClassification
3
- from transformers import AutoTokenizer, pipeline
4
-
5
 
6
  class EndpointHandler():
7
  def __init__(self, path=""):
8
  # load the optimized model
9
- model = ORTModelForSequenceClassification.from_pretrained(path)
10
- tokenizer = AutoTokenizer.from_pretrained(path, do_lower_case=True)
11
 
12
  self.pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
13
 
14
 
15
- def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
16
  inputs = data.pop("inputs", data)
17
 
18
- prediction = self.pipeline(inputs, padding=True, truncation=True, max_length=253)
 
 
 
 
 
 
19
 
20
- return prediction
 
 
 
 
1
+ from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification, pipeline
 
 
 
2
 
3
  class EndpointHandler():
4
  def __init__(self, path=""):
5
  # load the optimized model
6
+ model = DistilBertForSequenceClassification.from_pretrained(path)
7
+ tokenizer = DistilBertTokenizerFast.from_pretrained(path, do_lower_case=True)
8
 
9
  self.pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
10
 
11
 
12
+ def __call__(self, data):
13
  inputs = data.pop("inputs", data)
14
 
15
+ def iterator():
16
+ for i in inputs:
17
+ yield i
18
+
19
+ labels = []
20
+ for out in pipeline(iterator(), padding=True, truncation=True, max_length=253):
21
+ labels.append(int(out["label"][-1]))
22
 
23
+ return {
24
+ "pairs": inputs,
25
+ "evaluations": labels
26
+ }