philschmid HF staff commited on
Commit
ae9bb66
1 Parent(s): 0e7e1e8

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +13 -5
pipeline.py CHANGED
@@ -12,15 +12,23 @@ class PreTrainedPipeline():
12
  self.pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
13
 
14
 
15
- def __call__(self, inputs: Any) -> List[List[Dict[str, float]]]:
16
  """
17
  Args:
18
- inputs (:obj:`str`):
19
- a string containing some text
20
  Return:
21
  A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
22
  - "label": A string representing what the label/class is. There can be multiple labels.
23
  - "score": A score between 0 and 1 describing how confident the model is for this label/class.
24
  """
25
- # pop inputs for pipeline
26
- return self.pipeline(inputs)
 
 
 
 
 
 
 
 
 
12
  self.pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
13
 
14
 
15
+ def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
16
  """
17
  Args:
18
+ data (:obj:):
19
+ includes the input data and the parameters for the inference.
20
  Return:
21
  A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
22
  - "label": A string representing what the label/class is. There can be multiple labels.
23
  - "score": A score between 0 and 1 describing how confident the model is for this label/class.
24
  """
25
+ inputs = data.pop("inputs", data)
26
+ parameters = data.pop("parameters", None)
27
+
28
+ # pass inputs with all kwargs in data
29
+ if parameters is not None:
30
+ prediction = self.pipeline(inputs, **parameters)
31
+ else:
32
+ prediction = self.pipeline(inputs)
33
+ # postprocess the prediction
34
+ return prediction