Update pipeline.py
#2
by
E-katrin - opened
- pipeline.py +5 -5
pipeline.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from typing import override
|
| 2 |
|
| 3 |
from transformers import Pipeline
|
| 4 |
|
|
@@ -17,7 +17,7 @@ class ConlluTokenClassificationPipeline(Pipeline):
|
|
| 17 |
self.tokenizer = tokenizer
|
| 18 |
self.sentenizer = sentenizer
|
| 19 |
|
| 20 |
-
|
| 21 |
def _sanitize_parameters(self, output_format: str = 'list', **kwargs):
|
| 22 |
if output_format not in ['list', 'str']:
|
| 23 |
raise ValueError(
|
|
@@ -26,7 +26,7 @@ class ConlluTokenClassificationPipeline(Pipeline):
|
|
| 26 |
# capture output_format for postprocessing
|
| 27 |
return {}, {}, {'output_format': output_format}
|
| 28 |
|
| 29 |
-
|
| 30 |
def preprocess(self, inputs: str) -> dict:
|
| 31 |
if not isinstance(inputs, str):
|
| 32 |
raise ValueError("pipeline input must be string (text)")
|
|
@@ -40,11 +40,11 @@ class ConlluTokenClassificationPipeline(Pipeline):
|
|
| 40 |
self._texts = sentences
|
| 41 |
return {"words": words}
|
| 42 |
|
| 43 |
-
|
| 44 |
def _forward(self, model_inputs: dict) -> dict:
|
| 45 |
return self.model(**model_inputs, inference_mode=True)
|
| 46 |
|
| 47 |
-
|
| 48 |
def postprocess(self, model_outputs: dict, output_format: str) -> list[dict] | str:
|
| 49 |
sentences = self._decode_model_output(model_outputs)
|
| 50 |
# Format sentences into CoNLL-U string if requested.
|
|
|
|
| 1 |
+
#from typing import override
|
| 2 |
|
| 3 |
from transformers import Pipeline
|
| 4 |
|
|
|
|
| 17 |
self.tokenizer = tokenizer
|
| 18 |
self.sentenizer = sentenizer
|
| 19 |
|
| 20 |
+
#@override
|
| 21 |
def _sanitize_parameters(self, output_format: str = 'list', **kwargs):
|
| 22 |
if output_format not in ['list', 'str']:
|
| 23 |
raise ValueError(
|
|
|
|
| 26 |
# capture output_format for postprocessing
|
| 27 |
return {}, {}, {'output_format': output_format}
|
| 28 |
|
| 29 |
+
#@override
|
| 30 |
def preprocess(self, inputs: str) -> dict:
|
| 31 |
if not isinstance(inputs, str):
|
| 32 |
raise ValueError("pipeline input must be string (text)")
|
|
|
|
| 40 |
self._texts = sentences
|
| 41 |
return {"words": words}
|
| 42 |
|
| 43 |
+
#@override
|
| 44 |
def _forward(self, model_inputs: dict) -> dict:
|
| 45 |
return self.model(**model_inputs, inference_mode=True)
|
| 46 |
|
| 47 |
+
#@override
|
| 48 |
def postprocess(self, model_outputs: dict, output_format: str) -> list[dict] | str:
|
| 49 |
sentences = self._decode_model_output(model_outputs)
|
| 50 |
# Format sentences into CoNLL-U string if requested.
|