You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_csanmt_translation.py 3.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.pipelines import pipeline
  4. from modelscope.utils.constant import Tasks
  5. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  6. from modelscope.utils.test_utils import test_level
  7. class TranslationTest(unittest.TestCase, DemoCompatibilityCheck):
  8. def setUp(self) -> None:
  9. self.task = Tasks.translation
  10. self.model_id = 'damo/nlp_csanmt_translation_zh2en'
  11. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  12. def test_run_with_model_name_for_zh2en(self):
  13. inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
  14. pipeline_ins = pipeline(self.task, model=self.model_id)
  15. print(pipeline_ins(input=inputs))
  16. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  17. def test_run_with_model_name_for_en2zh(self):
  18. model_id = 'damo/nlp_csanmt_translation_en2zh'
  19. inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.'
  20. pipeline_ins = pipeline(self.task, model=model_id)
  21. print(pipeline_ins(input=inputs))
  22. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  23. def test_run_with_model_name_for_en2zh_base(self):
  24. model_id = 'damo/nlp_csanmt_translation_en2zh_base'
  25. inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.'
  26. pipeline_ins = pipeline(self.task, model=model_id)
  27. print(pipeline_ins(input=inputs))
  28. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  29. def test_run_with_model_name_for_en2fr(self):
  30. model_id = 'damo/nlp_csanmt_translation_en2fr'
  31. inputs = 'When I was in my 20s, I saw my very first psychotherapy client.'
  32. pipeline_ins = pipeline(self.task, model=model_id)
  33. print(pipeline_ins(input=inputs))
  34. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  35. def test_run_with_model_name_for_en2es(self):
  36. model_id = 'damo/nlp_csanmt_translation_en2es'
  37. inputs = 'When I was in my 20s, I saw my very first psychotherapy client.'
  38. pipeline_ins = pipeline(self.task, model=model_id)
  39. print(pipeline_ins(input=inputs))
  40. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  41. def test_run_with_model_name_for_fr2en(self):
  42. model_id = 'damo/nlp_csanmt_translation_fr2en'
  43. inputs = "Quand j'avais la vingtaine, j'ai vu mes tout premiers clients comme psychothérapeute."
  44. pipeline_ins = pipeline(self.task, model=model_id)
  45. print(pipeline_ins(input=inputs))
  46. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  47. def test_run_with_model_name_for_es2en(self):
  48. model_id = 'damo/nlp_csanmt_translation_es2en'
  49. inputs = 'Los físicos clasifican las partículas en dos categorías.'
  50. pipeline_ins = pipeline(self.task, model=model_id)
  51. print(pipeline_ins(input=inputs))
  52. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  53. def test_run_with_default_model(self):
  54. inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
  55. pipeline_ins = pipeline(self.task)
  56. print(pipeline_ins(input=inputs))
  57. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  58. def test_demo_compatibility(self):
  59. self.compatibility_check()
  60. if __name__ == '__main__':
  61. unittest.main()