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_dialog_intent_prediction.py 3.0 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.hub.snapshot_download import snapshot_download
  4. from modelscope.models import Model
  5. from modelscope.models.nlp import SpaceForDialogIntent
  6. from modelscope.pipelines import pipeline
  7. from modelscope.pipelines.nlp import DialogIntentPredictionPipeline
  8. from modelscope.preprocessors import DialogIntentPredictionPreprocessor
  9. from modelscope.utils.constant import Tasks
  10. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  11. from modelscope.utils.test_utils import test_level
  12. class DialogIntentPredictionTest(unittest.TestCase, DemoCompatibilityCheck):
  13. def setUp(self) -> None:
  14. self.task = Tasks.task_oriented_conversation
  15. self.model_id = 'damo/nlp_space_dialog-intent-prediction'
  16. test_case = [
  17. 'How do I locate my card?',
  18. 'I still have not received my new card, I ordered over a week ago.'
  19. ]
  20. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  21. def test_run_by_direct_model_download(self):
  22. cache_path = snapshot_download(self.model_id, revision='update')
  23. preprocessor = DialogIntentPredictionPreprocessor(model_dir=cache_path)
  24. model = SpaceForDialogIntent(
  25. model_dir=cache_path,
  26. text_field=preprocessor.text_field,
  27. config=preprocessor.config)
  28. pipelines = [
  29. DialogIntentPredictionPipeline(
  30. model=model, preprocessor=preprocessor),
  31. pipeline(
  32. task=Tasks.task_oriented_conversation,
  33. model=model,
  34. preprocessor=preprocessor)
  35. ]
  36. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  37. print(my_pipeline(item))
  38. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  39. def test_run_with_model_from_modelhub(self):
  40. model = Model.from_pretrained(self.model_id, revision='update')
  41. preprocessor = DialogIntentPredictionPreprocessor(
  42. model_dir=model.model_dir)
  43. pipelines = [
  44. DialogIntentPredictionPipeline(
  45. model=model, preprocessor=preprocessor),
  46. pipeline(
  47. task=Tasks.task_oriented_conversation,
  48. model=model,
  49. preprocessor=preprocessor)
  50. ]
  51. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  52. print(my_pipeline(item))
  53. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  54. def test_run_with_model_name(self):
  55. pipelines = [
  56. pipeline(
  57. task=self.task, model=self.model_id, model_revision='update')
  58. ]
  59. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  60. print(my_pipeline(item))
  61. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  62. def test_demo_compatibility(self):
  63. self.compatibility_check()
  64. if __name__ == '__main__':
  65. unittest.main()