mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
fix: text error correction batch run bug (#1052)
Co-authored-by: Mark <smartmark-pro@qq.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -326,7 +326,7 @@ class TextErrorCorrectionOutput(ModelOutputBase):
|
||||
"""The output class for information extraction models.
|
||||
"""
|
||||
|
||||
predictions: np.ndarray = None
|
||||
predictions: List = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user