ly119399 yingda.chen 3 years ago
parent
commit
8246174104
8 changed files with 45 additions and 36 deletions
  1. +1
    -1
      modelscope/metainfo.py
  2. +4
    -3
      modelscope/models/nlp/space/space_for_dialog_modeling.py
  3. +1
    -1
      modelscope/outputs.py
  4. +2
    -2
      modelscope/pipelines/builder.py
  5. +3
    -2
      modelscope/pipelines/nlp/__init__.py
  6. +4
    -3
      modelscope/pipelines/nlp/task_oriented_conversation_pipeline.py
  7. +1
    -1
      modelscope/utils/constant.py
  8. +29
    -23
      tests/pipelines/test_task_oriented_conversation.py

+ 1
- 1
modelscope/metainfo.py View File

@@ -112,7 +112,7 @@ class Pipelines(object):
csanmt_translation = 'csanmt-translation'
nli = 'nli'
dialog_intent_prediction = 'dialog-intent-prediction'
dialog_modeling = 'dialog-modeling'
task_oriented_conversation = 'task-oriented-conversation'
dialog_state_tracking = 'dialog-state-tracking'
zero_shot_classification = 'zero-shot-classification'
text_error_correction = 'text-error-correction'


+ 4
- 3
modelscope/models/nlp/space/space_for_dialog_modeling.py View File

@@ -15,7 +15,8 @@ from modelscope.utils.constant import ModelFile, Tasks
__all__ = ['SpaceForDialogModeling']


@MODELS.register_module(Tasks.dialog_modeling, module_name=Models.space)
@MODELS.register_module(
Tasks.task_oriented_conversation, module_name=Models.space)
class SpaceForDialogModeling(TorchModel):

def __init__(self, model_dir: str, *args, **kwargs):
@@ -33,8 +34,8 @@ class SpaceForDialogModeling(TorchModel):
Config.from_file(
os.path.join(self.model_dir, ModelFile.CONFIGURATION)))

import torch
self.config.use_gpu = self.config.use_gpu and torch.cuda.is_available()
self.config.use_gpu = True if 'device' not in kwargs or kwargs[
'device'] == 'gpu' else False

self.text_field = kwargs.pop(
'text_field',


+ 1
- 1
modelscope/outputs.py View File

@@ -326,7 +326,7 @@ TASK_OUTPUTS = {

# (Deprecated) dialog modeling prediction result for single sample
# sys : ['you', 'are', 'welcome', '.', 'have', 'a', 'great', 'day', '!']
Tasks.dialog_modeling: [OutputKeys.RESPONSE],
Tasks.task_oriented_conversation: [OutputKeys.RESPONSE],

# (Deprecated) dialog state tracking result for single sample
# {


+ 2
- 2
modelscope/pipelines/builder.py View File

@@ -51,8 +51,8 @@ DEFAULT_MODEL_FOR_PIPELINE = {
Tasks.dialog_intent_prediction:
(Pipelines.dialog_intent_prediction,
'damo/nlp_space_dialog-intent-prediction'),
Tasks.dialog_modeling: (Pipelines.dialog_modeling,
'damo/nlp_space_dialog-modeling'),
Tasks.task_oriented_conversation: (Pipelines.task_oriented_conversation,
'damo/nlp_space_dialog-modeling'),
Tasks.dialog_state_tracking: (Pipelines.dialog_state_tracking,
'damo/nlp_space_dialog-state-tracking'),
Tasks.text_error_correction:


+ 3
- 2
modelscope/pipelines/nlp/__init__.py View File

@@ -5,7 +5,7 @@ from modelscope.utils.import_utils import LazyImportModule

if TYPE_CHECKING:
from .dialog_intent_prediction_pipeline import DialogIntentPredictionPipeline
from .dialog_modeling_pipeline import DialogModelingPipeline
from .task_oriented_conversation_pipeline import TaskOrientedConversationPipeline
from .dialog_state_tracking_pipeline import DialogStateTrackingPipeline
from .fill_mask_pipeline import FillMaskPipeline
from .named_entity_recognition_pipeline import NamedEntityRecognitionPipeline
@@ -24,7 +24,8 @@ else:
_import_structure = {
'dialog_intent_prediction_pipeline':
['DialogIntentPredictionPipeline'],
'dialog_modeling_pipeline': ['DialogModelingPipeline'],
'task_oriented_conversation_pipeline':
['TaskOrientedConversationPipeline'],
'dialog_state_tracking_pipeline': ['DialogStateTrackingPipeline'],
'fill_mask_pipeline': ['FillMaskPipeline'],
'single_sentence_classification_pipeline':


modelscope/pipelines/nlp/dialog_modeling_pipeline.py → modelscope/pipelines/nlp/task_oriented_conversation_pipeline.py View File

@@ -11,12 +11,13 @@ from modelscope.pipelines.builder import PIPELINES
from modelscope.preprocessors import DialogModelingPreprocessor
from modelscope.utils.constant import Tasks

__all__ = ['DialogModelingPipeline']
__all__ = ['TaskOrientedConversationPipeline']


@PIPELINES.register_module(
Tasks.dialog_modeling, module_name=Pipelines.dialog_modeling)
class DialogModelingPipeline(Pipeline):
Tasks.task_oriented_conversation,
module_name=Pipelines.task_oriented_conversation)
class TaskOrientedConversationPipeline(Pipeline):

def __init__(self,
model: Union[SpaceForDialogModeling, str],

+ 1
- 1
modelscope/utils/constant.py View File

@@ -79,7 +79,7 @@ class NLPTasks(object):
token_classification = 'token-classification'
conversational = 'conversational'
text_generation = 'text-generation'
dialog_modeling = 'dialog-modeling'
task_oriented_conversation = 'task-oriented-conversation'
dialog_intent_prediction = 'dialog-intent-prediction'
dialog_state_tracking = 'dialog-state-tracking'
table_question_answering = 'table-question-answering'


tests/pipelines/test_dialog_modeling.py → tests/pipelines/test_task_oriented_conversation.py View File

@@ -6,13 +6,13 @@ from modelscope.hub.snapshot_download import snapshot_download
from modelscope.models import Model
from modelscope.models.nlp import SpaceForDialogModeling
from modelscope.pipelines import pipeline
from modelscope.pipelines.nlp import DialogModelingPipeline
from modelscope.pipelines.nlp import TaskOrientedConversationPipeline
from modelscope.preprocessors import DialogModelingPreprocessor
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level


class DialogModelingTest(unittest.TestCase):
class TaskOrientedConversationTest(unittest.TestCase):
model_id = 'damo/nlp_space_dialog-modeling'
test_case = {
'sng0073': {
@@ -92,7 +92,7 @@ class DialogModelingTest(unittest.TestCase):
}

def generate_and_print_dialog_response(
self, pipelines: List[DialogModelingPipeline]):
self, pipelines: List[TaskOrientedConversationPipeline]):

result = {}
for step, item in enumerate(self.test_case['sng0073']['log']):
@@ -108,39 +108,37 @@ class DialogModelingTest(unittest.TestCase):
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
def test_run_by_direct_model_download(self):

cache_path = snapshot_download(self.model_id)
cache_path = snapshot_download(
self.model_id, revision='task_oriented_conversation')

preprocessor = DialogModelingPreprocessor(model_dir=cache_path)
model = SpaceForDialogModeling(
model_dir=cache_path,
text_field=preprocessor.text_field,
config=preprocessor.config,
device='cpu')
config=preprocessor.config)
pipelines = [
DialogModelingPipeline(
model=model, preprocessor=preprocessor, device='cpu'),
TaskOrientedConversationPipeline(
model=model, preprocessor=preprocessor),
pipeline(
task=Tasks.dialog_modeling,
task=Tasks.task_oriented_conversation,
model=model,
preprocessor=preprocessor,
device='cpu')
preprocessor=preprocessor)
]
self.generate_and_print_dialog_response(pipelines)

@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_from_modelhub(self):
model = Model.from_pretrained(self.model_id)
preprocessor = DialogModelingPreprocessor(
model_dir=model.model_dir, device='cpu')
model = Model.from_pretrained(
self.model_id, revision='task_oriented_conversation')
preprocessor = DialogModelingPreprocessor(model_dir=model.model_dir)

pipelines = [
DialogModelingPipeline(
model=model, preprocessor=preprocessor, device='cpu'),
TaskOrientedConversationPipeline(
model=model, preprocessor=preprocessor),
pipeline(
task=Tasks.dialog_modeling,
task=Tasks.task_oriented_conversation,
model=model,
preprocessor=preprocessor,
device='cpu')
preprocessor=preprocessor)
]

self.generate_and_print_dialog_response(pipelines)
@@ -149,17 +147,25 @@ class DialogModelingTest(unittest.TestCase):
def test_run_with_model_name(self):
pipelines = [
pipeline(
task=Tasks.dialog_modeling, model=self.model_id, device='cpu'),
task=Tasks.task_oriented_conversation,
model=self.model_id,
model_revision='task_oriented_conversation'),
pipeline(
task=Tasks.dialog_modeling, model=self.model_id, device='cpu')
task=Tasks.task_oriented_conversation,
model=self.model_id,
model_revision='task_oriented_conversation')
]
self.generate_and_print_dialog_response(pipelines)

@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
def test_run_with_default_model(self):
pipelines = [
pipeline(task=Tasks.dialog_modeling, device='cpu'),
pipeline(task=Tasks.dialog_modeling, device='cpu')
pipeline(
task=Tasks.task_oriented_conversation,
model_revision='task_oriented_conversation'),
pipeline(
task=Tasks.task_oriented_conversation,
model_revision='task_oriented_conversation')
]
self.generate_and_print_dialog_response(pipelines)


Loading…
Cancel
Save