fix: text error correction batch run bug (#1052)

Co-authored-by: Mark <smartmark-pro@qq.com>
This commit is contained in:
Mark
2024-11-01 09:35:19 +08:00
committed by GitHub
parent fac865fd97
commit 250b72fce7
4 changed files with 12 additions and 7 deletions

View File

@@ -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)

View File

@@ -326,7 +326,7 @@ class TextErrorCorrectionOutput(ModelOutputBase):
"""The output class for information extraction models.
"""
predictions: np.ndarray = None
predictions: List = None
@dataclass

View File

@@ -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()

View File

@@ -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):