diff --git a/modelscope/models/nlp/bart/text_error_correction.py b/modelscope/models/nlp/bart/text_error_correction.py index 97c3a7a9..09b867c4 100644 --- a/modelscope/models/nlp/bart/text_error_correction.py +++ b/modelscope/models/nlp/bart/text_error_correction.py @@ -82,5 +82,5 @@ class BartForTextErrorCorrection(TorchModel): batch_preds = [] for i in range(batch_size): # get 1-best List[Tensor] - batch_preds.append(translations[i][0]['tokens']) + batch_preds.append(translations[i][0]['tokens'].tolist()) return TextErrorCorrectionOutput(predictions=batch_preds) diff --git a/modelscope/outputs/nlp_outputs.py b/modelscope/outputs/nlp_outputs.py index ed42cb5a..747f5bd3 100644 --- a/modelscope/outputs/nlp_outputs.py +++ b/modelscope/outputs/nlp_outputs.py @@ -326,7 +326,7 @@ class TextErrorCorrectionOutput(ModelOutputBase): """The output class for information extraction models. """ - predictions: np.ndarray = None + predictions: List = None @dataclass diff --git a/modelscope/pipelines/nlp/text_error_correction_pipeline.py b/modelscope/pipelines/nlp/text_error_correction_pipeline.py index dc4bc40a..9fa5a2a8 100644 --- a/modelscope/pipelines/nlp/text_error_correction_pipeline.py +++ b/modelscope/pipelines/nlp/text_error_correction_pipeline.py @@ -80,7 +80,8 @@ class TextErrorCorrectionPipeline(Pipeline): sc_tensor = inputs['predictions'] if isinstance(sc_tensor, list): - sc_tensor = sc_tensor[0] + if isinstance(sc_tensor[0], list): + sc_tensor = sc_tensor[0] sc_sent = self.vocab.string( sc_tensor, extra_symbols_to_ignore={self.vocab.pad()}) sc_sent = (sc_sent + ' ').replace('##', '').rstrip() diff --git a/tests/pipelines/test_text_error_correction.py b/tests/pipelines/test_text_error_correction.py index b4bf5be9..b2a5fd4d 100644 --- a/tests/pipelines/test_text_error_correction.py +++ b/tests/pipelines/test_text_error_correction.py @@ -41,12 +41,16 @@ class TextErrorCorrectionTest(unittest.TestCase): @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') def test_run_with_model_name_batch(self): - run_kwargs = {'batch_size': 2} pipeline_ins = pipeline( task=Tasks.text_error_correction, model=self.model_id) - print( - 'batch: ', - pipeline_ins([self.input, self.input_2, self.input_3], run_kwargs)) + sents = [ + self.input, self.input_2, self.input_3, self.input_4, + self.input_law + ] + rs1 = pipeline_ins(sents, batch_size=2) + rs2 = pipeline_ins(sents) + print('batch: ', rs1, rs2) + self.assertEqual(rs1, rs2) @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_run_with_model_from_modelhub(self):