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_state_tracking.py 4.9 kB

3 years ago
3 years ago
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 years ago
3 years ago
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 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
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 years ago
3 years ago
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
[to #42322933] NLP 1030 Refactor Features: 1. Refactor the directory structure of nlp models. All model files are placed into either the model folder or the task_model folder 2. Refactor all the comments to google style 3. Add detail comments to important tasks and nlp models, to list the description of the model, and its preprocessor&trainer 4. Model Exporting now supports a direct all to TorchModelExporter(no need to derive from it) 5. Refactor model save_pretrained method to support direct running(independent from trainer) 6. Remove the judgement of Model in the pipeline base class, to support outer register models running in our pipelines 7. Nlp trainer now has a NLPTrainingArguments class , user can pass arguments into the dataclass, and use it as a normal cfg_modify_fn, to simplify the operation of modify cfg. 8. Merge the BACKBONES and the MODELS, so user can get a backbone with the Model.from_pretrained call 9. Model.from_pretrained now support a task argument, so user can use a backbone and load it with a specific task class. 10. Support Preprocessor.from_pretrained method 11. Add standard return classes to important nlp tasks, so some of the pipelines and the models are independent now, the return values of the models will always be tensors, and the pipelines will take care of the conversion to numpy and the following stuffs. 12. Split the file of the nlp preprocessors, to make the dir structure more clear. Bugs Fixing: 1. Fix a bug that lr_scheduler can be called earlier than the optimizer's step 2. Fix a bug that the direct call of Pipelines (not from pipeline(xxx)) throws error 3. Fix a bug that the trainer will not call the correct TaskDataset class 4. Fix a bug that the internal loading of dataset will throws error in the trainer class Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10490585
2 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 SpaceForDST
  6. from modelscope.pipelines import pipeline
  7. from modelscope.pipelines.nlp import DialogStateTrackingPipeline
  8. from modelscope.preprocessors import DialogStateTrackingPreprocessor
  9. from modelscope.utils.constant import Tasks
  10. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  11. from modelscope.utils.nlp.space.utils_dst import \
  12. tracking_and_print_dialog_states
  13. from modelscope.utils.test_utils import test_level
  14. class DialogStateTrackingTest(unittest.TestCase, DemoCompatibilityCheck):
  15. def setUp(self) -> None:
  16. self.task = Tasks.task_oriented_conversation
  17. self.model_id = 'damo/nlp_space_dialog-state-tracking'
  18. test_case = [{
  19. 'User-1':
  20. 'Hi, I\'m looking for a train that is going to cambridge and arriving there by 20:45, '
  21. 'is there anything like that?'
  22. }, {
  23. 'System-1':
  24. 'There are over 1,000 trains like that. Where will you be departing from?',
  25. 'Dialog_Act-1': {
  26. 'Train-Inform': [['Choice', 'over 1'], ['Choice', '000']],
  27. 'Train-Request': [['Depart', '?']]
  28. },
  29. 'User-2': 'I am departing from birmingham new street.'
  30. }, {
  31. 'System-2': 'Can you confirm your desired travel day?',
  32. 'Dialog_Act-2': {
  33. 'Train-Request': [['Day', '?']]
  34. },
  35. 'User-3': 'I would like to leave on wednesday'
  36. }, {
  37. 'System-3':
  38. 'I show a train leaving birmingham new street at 17:40 and arriving at 20:23 on Wednesday. '
  39. 'Will this work for you?',
  40. 'Dialog_Act-3': {
  41. 'Train-Inform': [['Arrive', '20:23'], ['Leave', '17:40'],
  42. ['Day', 'Wednesday'],
  43. ['Depart', 'birmingham new street']]
  44. },
  45. 'User-4':
  46. 'That will, yes. Please make a booking for 5 people please.',
  47. }, {
  48. 'System-4':
  49. 'I\'ve booked your train tickets, and your reference number is A9NHSO9Y.',
  50. 'Dialog_Act-4': {
  51. 'Train-OfferBooked': [['Ref', 'A9NHSO9Y']]
  52. },
  53. 'User-5':
  54. 'Thanks so much. I would also need a place to say. '
  55. 'I am looking for something with 4 stars and has free wifi.'
  56. }, {
  57. 'System-5':
  58. 'How about the cambridge belfry? '
  59. 'It has all the attributes you requested and a great name! '
  60. 'Maybe even a real belfry?',
  61. 'Dialog_Act-5': {
  62. 'Hotel-Recommend': [['Name', 'the cambridge belfry']]
  63. },
  64. 'User-6':
  65. 'That sounds great, could you make a booking for me please?',
  66. }, {
  67. 'System-6':
  68. 'What day would you like your booking for?',
  69. 'Dialog_Act-6': {
  70. 'Booking-Request': [['Day', '?']]
  71. },
  72. 'User-7':
  73. 'Please book it for Wednesday for 5 people and 5 nights, please.',
  74. }, {
  75. 'System-7': 'Booking was successful. Reference number is : 5NAWGJDC.',
  76. 'Dialog_Act-7': {
  77. 'Booking-Book': [['Ref', '5NAWGJDC']]
  78. },
  79. 'User-8': 'Thank you, goodbye',
  80. }]
  81. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  82. def test_run_by_direct_model_download(self):
  83. cache_path = snapshot_download(self.model_id)
  84. model = SpaceForDST.from_pretrained(cache_path)
  85. preprocessor = DialogStateTrackingPreprocessor(model_dir=cache_path)
  86. pipelines = [
  87. DialogStateTrackingPipeline(
  88. model=model, preprocessor=preprocessor),
  89. pipeline(
  90. task=Tasks.task_oriented_conversation,
  91. model=model,
  92. preprocessor=preprocessor)
  93. ]
  94. tracking_and_print_dialog_states(self.test_case, pipelines)
  95. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  96. def test_run_with_model_from_modelhub(self):
  97. model = Model.from_pretrained(self.model_id)
  98. preprocessor = DialogStateTrackingPreprocessor(
  99. model_dir=model.model_dir)
  100. pipelines = [
  101. DialogStateTrackingPipeline(
  102. model=model, preprocessor=preprocessor),
  103. pipeline(task=self.task, model=model, preprocessor=preprocessor)
  104. ]
  105. tracking_and_print_dialog_states(self.test_case, pipelines)
  106. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  107. def test_run_with_model_name(self):
  108. pipelines = [pipeline(task=self.task, model=self.model_id)]
  109. tracking_and_print_dialog_states(self.test_case, pipelines)
  110. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  111. def test_demo_compatibility(self):
  112. self.compatibility_check()
  113. if __name__ == '__main__':
  114. unittest.main()