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 2.9 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
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.test_utils import test_level
  11. class DialogIntentPredictionTest(unittest.TestCase):
  12. model_id = 'damo/nlp_space_dialog-intent-prediction'
  13. test_case = [
  14. 'How do I locate my card?',
  15. 'I still have not received my new card, I ordered over a week ago.'
  16. ]
  17. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  18. def test_run_by_direct_model_download(self):
  19. cache_path = snapshot_download(self.model_id)
  20. preprocessor = DialogIntentPredictionPreprocessor(model_dir=cache_path)
  21. model = SpaceForDialogIntent(
  22. model_dir=cache_path,
  23. text_field=preprocessor.text_field,
  24. config=preprocessor.config)
  25. pipelines = [
  26. DialogIntentPredictionPipeline(
  27. model=model, preprocessor=preprocessor),
  28. pipeline(
  29. task=Tasks.dialog_intent_prediction,
  30. model=model,
  31. preprocessor=preprocessor)
  32. ]
  33. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  34. print(my_pipeline(item))
  35. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  36. def test_run_with_model_from_modelhub(self):
  37. model = Model.from_pretrained(self.model_id)
  38. preprocessor = DialogIntentPredictionPreprocessor(
  39. model_dir=model.model_dir)
  40. pipelines = [
  41. DialogIntentPredictionPipeline(
  42. model=model, preprocessor=preprocessor),
  43. pipeline(
  44. task=Tasks.dialog_intent_prediction,
  45. model=model,
  46. preprocessor=preprocessor)
  47. ]
  48. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  49. print(my_pipeline(item))
  50. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  51. def test_run_with_model_name(self):
  52. pipelines = [
  53. pipeline(task=Tasks.dialog_intent_prediction, model=self.model_id)
  54. ]
  55. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  56. print(my_pipeline(item))
  57. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  58. def test_run_with_default_model(self):
  59. pipelines = [pipeline(task=Tasks.dialog_intent_prediction)]
  60. for my_pipeline, item in list(zip(pipelines, self.test_case)):
  61. print(my_pipeline(item))
  62. if __name__ == '__main__':
  63. unittest.main()