Update QAPipeline.py
Browse files- QAPipeline.py +20 -13
QAPipeline.py
CHANGED
|
@@ -1,9 +1,4 @@
|
|
| 1 |
-
# qapipeline.py
|
| 2 |
-
|
| 3 |
-
from transformers import PreTrainedModel, Pipeline
|
| 4 |
-
from typing import Any, Dict
|
| 5 |
from transformers import Pipeline
|
| 6 |
-
from transformers import PreTrainedTokenizer
|
| 7 |
from transformers.utils import ModelOutput
|
| 8 |
|
| 9 |
from transformers import PreTrainedModel, Pipeline
|
|
@@ -13,7 +8,6 @@ class QApipeline(Pipeline):
|
|
| 13 |
def __init__(
|
| 14 |
self,
|
| 15 |
model: PreTrainedModel,
|
| 16 |
-
tokenizer: PreTrainedTokenizer,
|
| 17 |
**kwargs
|
| 18 |
):
|
| 19 |
super().__init__(
|
|
@@ -23,30 +17,43 @@ class QApipeline(Pipeline):
|
|
| 23 |
|
| 24 |
print("in __init__")
|
| 25 |
|
| 26 |
-
def __call__( self,
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
answer = self._process_output(outputs)
|
|
|
|
| 29 |
print("in __call___")
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
def _process_output(self, outputs: Any) -> str:
|
|
|
|
| 33 |
print("in process outputs")
|
|
|
|
|
|
|
| 34 |
format = {'guess': outputs[1], 'confidence': outputs[0]}
|
| 35 |
return format
|
| 36 |
-
|
|
|
|
| 37 |
def _sanitize_parameters(self, **kwargs):
|
| 38 |
-
print("in
|
|
|
|
| 39 |
return {}, {}, {}
|
| 40 |
|
| 41 |
def preprocess(self, inputs):
|
| 42 |
print("in preprocess")
|
|
|
|
| 43 |
return inputs
|
| 44 |
|
| 45 |
def postprocess(self, outputs):
|
| 46 |
print("in postprocess")
|
| 47 |
format = {'guess': outputs[1], 'confidence': float(outputs[0])}
|
| 48 |
return format
|
| 49 |
-
|
| 50 |
def _forward(self, input_tensors, **forward_parameters: Dict) -> ModelOutput:
|
| 51 |
print("in _forward")
|
| 52 |
-
return super()._forward(input_tensors, **forward_parameters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import Pipeline
|
|
|
|
| 2 |
from transformers.utils import ModelOutput
|
| 3 |
|
| 4 |
from transformers import PreTrainedModel, Pipeline
|
|
|
|
| 8 |
def __init__(
|
| 9 |
self,
|
| 10 |
model: PreTrainedModel,
|
|
|
|
| 11 |
**kwargs
|
| 12 |
):
|
| 13 |
super().__init__(
|
|
|
|
| 17 |
|
| 18 |
print("in __init__")
|
| 19 |
|
| 20 |
+
def __call__( self, question: str, **kwargs) -> Dict[str, Any]:
|
| 21 |
+
inputs = {
|
| 22 |
+
"question": question,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
outputs = self.model.predict(question)
|
| 26 |
+
|
| 27 |
answer = self._process_output(outputs)
|
| 28 |
+
|
| 29 |
print("in __call___")
|
| 30 |
+
|
| 31 |
+
return answer
|
| 32 |
|
| 33 |
def _process_output(self, outputs: Any) -> str:
|
| 34 |
+
|
| 35 |
print("in process outputs")
|
| 36 |
+
print(outputs)
|
| 37 |
+
|
| 38 |
format = {'guess': outputs[1], 'confidence': outputs[0]}
|
| 39 |
return format
|
| 40 |
+
|
| 41 |
+
|
| 42 |
def _sanitize_parameters(self, **kwargs):
|
| 43 |
+
print("in sanatize params")
|
| 44 |
+
|
| 45 |
return {}, {}, {}
|
| 46 |
|
| 47 |
def preprocess(self, inputs):
|
| 48 |
print("in preprocess")
|
| 49 |
+
|
| 50 |
return inputs
|
| 51 |
|
| 52 |
def postprocess(self, outputs):
|
| 53 |
print("in postprocess")
|
| 54 |
format = {'guess': outputs[1], 'confidence': float(outputs[0])}
|
| 55 |
return format
|
| 56 |
+
|
| 57 |
def _forward(self, input_tensors, **forward_parameters: Dict) -> ModelOutput:
|
| 58 |
print("in _forward")
|
| 59 |
+
return super()._forward(input_tensors, **forward_parameters)
|