2022-07-04 10:28:38 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
2022-07-27 17:29:16 +08:00
|
|
|
from modelscope.pipelines import pipeline
|
2022-07-04 10:28:38 +08:00
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
class TranslationTest(unittest.TestCase):
|
2022-09-08 14:08:51 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.translation
|
|
|
|
|
self.model_id = 'damo/nlp_csanmt_translation_zh2en'
|
2022-07-04 10:28:38 +08:00
|
|
|
|
2022-08-06 23:17:21 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-08-30 22:08:27 +08:00
|
|
|
def test_run_with_model_name_for_zh2en(self):
|
|
|
|
|
inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task, model=self.model_id)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2zh(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2zh'
|
|
|
|
|
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
2022-07-04 10:28:38 +08:00
|
|
|
|
2023-02-02 04:07:38 +00:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2zh_batch(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2zh'
|
|
|
|
|
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.' + \
|
|
|
|
|
'<SENT_SPLIT>' + "Alibaba Group's mission is to let the world have no difficult business" + \
|
|
|
|
|
'<SENT_SPLIT>' + 'Beijing is the capital of China.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-11-29 13:44:06 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2zh_base(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2zh_base'
|
|
|
|
|
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-10-20 17:35:27 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2fr(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2fr'
|
|
|
|
|
inputs = 'When I was in my 20s, I saw my very first psychotherapy client.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-11-29 13:44:06 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2es(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2es'
|
|
|
|
|
inputs = 'When I was in my 20s, I saw my very first psychotherapy client.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2023-02-06 05:26:55 +00:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2ru(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2ru_base'
|
|
|
|
|
inputs = 'When I was in my 20s, I saw my very first psychotherapy client.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-10-20 17:35:27 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_fr2en(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_fr2en'
|
|
|
|
|
inputs = "Quand j'avais la vingtaine, j'ai vu mes tout premiers clients comme psychothérapeute."
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-11-29 13:44:06 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_es2en(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_es2en'
|
|
|
|
|
inputs = 'Los físicos clasifican las partículas en dos categorías.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2023-02-06 05:26:55 +00:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_ru2en(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_ru2en_base'
|
|
|
|
|
inputs = 'Это всего лишь пример.'
|
|
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
|
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
2022-08-05 23:48:46 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_default_model(self):
|
2022-08-30 22:08:27 +08:00
|
|
|
inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
2022-08-05 23:48:46 +08:00
|
|
|
|
2022-07-04 10:28:38 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|