| @@ -1,4 +1,4 @@ | |||||
| from .sequence_classification_model import * # noqa F403 | from .sequence_classification_model import * # noqa F403 | ||||
| from .space.dialog_generation_model import * # noqa F403 | |||||
| from .space.dialog_intent_model import * # noqa F403 | |||||
| from .space.dialog_intent_prediction_model import * # noqa F403 | |||||
| from .space.dialog_modeling_model import * # noqa F403 | |||||
| from .text_generation_model import * # noqa F403 | from .text_generation_model import * # noqa F403 | ||||
| @@ -14,7 +14,8 @@ from .model.model_base import ModelBase | |||||
| __all__ = ['DialogIntentModel'] | __all__ = ['DialogIntentModel'] | ||||
| @MODELS.register_module(Tasks.dialog_intent, module_name=r'space') | |||||
| @MODELS.register_module( | |||||
| Tasks.dialog_intent_prediction, module_name=r'space-intent') | |||||
| class DialogIntentModel(Model): | class DialogIntentModel(Model): | ||||
| def __init__(self, model_dir: str, *args, **kwargs): | def __init__(self, model_dir: str, *args, **kwargs): | ||||
| @@ -11,12 +11,11 @@ from ...builder import MODELS | |||||
| from .model.generator import Generator | from .model.generator import Generator | ||||
| from .model.model_base import ModelBase | from .model.model_base import ModelBase | ||||
| __all__ = ['DialogGenerationModel'] | |||||
| __all__ = ['DialogModelingModel'] | |||||
| @MODELS.register_module( | |||||
| Tasks.dialog_generation, module_name=r'space-generation') | |||||
| class DialogGenerationModel(Model): | |||||
| @MODELS.register_module(Tasks.dialog_modeling, module_name=r'space-modeling') | |||||
| class DialogModelingModel(Model): | |||||
| def __init__(self, model_dir: str, *args, **kwargs): | def __init__(self, model_dir: str, *args, **kwargs): | ||||
| """initialize the test generation model from the `model_dir` path. | """initialize the test generation model from the `model_dir` path. | ||||
| @@ -1,4 +1,4 @@ | |||||
| from .sequence_classification_pipeline import * # noqa F403 | from .sequence_classification_pipeline import * # noqa F403 | ||||
| from .space.dialog_generation_pipeline import * # noqa F403 | |||||
| from .space.dialog_intent_pipeline import * # noqa F403 | |||||
| from .space.dialog_intent_prediction_pipeline import * # noqa F403 | |||||
| from .space.dialog_modeling_pipeline import * # noqa F403 | |||||
| from .text_generation_pipeline import * # noqa F403 | from .text_generation_pipeline import * # noqa F403 | ||||
| @@ -1,19 +1,20 @@ | |||||
| from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
| from modelscope.models.nlp import DialogIntentModel | from modelscope.models.nlp import DialogIntentModel | ||||
| from modelscope.preprocessors import DialogIntentPreprocessor | |||||
| from modelscope.preprocessors import DialogIntentPredictionPreprocessor | |||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| from ...base import Input, Pipeline | from ...base import Input, Pipeline | ||||
| from ...builder import PIPELINES | from ...builder import PIPELINES | ||||
| __all__ = ['DialogIntentPipeline'] | |||||
| __all__ = ['DialogIntentPredictionPipeline'] | |||||
| @PIPELINES.register_module(Tasks.dialog_intent, module_name=r'space') | |||||
| class DialogIntentPipeline(Pipeline): | |||||
| @PIPELINES.register_module( | |||||
| Tasks.dialog_intent_prediction, module_name=r'space-intent') | |||||
| class DialogIntentPredictionPipeline(Pipeline): | |||||
| def __init__(self, model: DialogIntentModel, | def __init__(self, model: DialogIntentModel, | ||||
| preprocessor: DialogIntentPreprocessor, **kwargs): | |||||
| preprocessor: DialogIntentPredictionPreprocessor, **kwargs): | |||||
| """use `model` and `preprocessor` to create a nlp text classification pipeline for prediction | """use `model` and `preprocessor` to create a nlp text classification pipeline for prediction | ||||
| Args: | Args: | ||||
| @@ -1,20 +1,20 @@ | |||||
| from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
| from modelscope.models.nlp import DialogGenerationModel | |||||
| from modelscope.preprocessors import DialogGenerationPreprocessor | |||||
| from modelscope.models.nlp import DialogModelingModel | |||||
| from modelscope.preprocessors import DialogModelingPreprocessor | |||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| from ...base import Pipeline, Tensor | from ...base import Pipeline, Tensor | ||||
| from ...builder import PIPELINES | from ...builder import PIPELINES | ||||
| __all__ = ['DialogGenerationPipeline'] | |||||
| __all__ = ['DialogModelingPipeline'] | |||||
| @PIPELINES.register_module( | @PIPELINES.register_module( | ||||
| Tasks.dialog_generation, module_name=r'space-generation') | |||||
| class DialogGenerationPipeline(Pipeline): | |||||
| Tasks.dialog_modeling, module_name=r'space-modeling') | |||||
| class DialogModelingPipeline(Pipeline): | |||||
| def __init__(self, model: DialogGenerationModel, | |||||
| preprocessor: DialogGenerationPreprocessor, **kwargs): | |||||
| def __init__(self, model: DialogModelingModel, | |||||
| preprocessor: DialogModelingPreprocessor, **kwargs): | |||||
| """use `model` and `preprocessor` to create a nlp text classification pipeline for prediction | """use `model` and `preprocessor` to create a nlp text classification pipeline for prediction | ||||
| Args: | Args: | ||||
| @@ -6,5 +6,5 @@ from .common import Compose | |||||
| from .image import LoadImage, load_image | from .image import LoadImage, load_image | ||||
| from .nlp import * # noqa F403 | from .nlp import * # noqa F403 | ||||
| from .nlp import TextGenerationPreprocessor | from .nlp import TextGenerationPreprocessor | ||||
| from .space.dialog_generation_preprocessor import * # noqa F403 | |||||
| from .space.dialog_intent_preprocessor import * # noqa F403 | |||||
| from .space.dialog_intent_prediction_preprocessor import * # noqa F403 | |||||
| from .space.dialog_modeling_preprocessor import * # noqa F403 | |||||
| @@ -11,11 +11,11 @@ from modelscope.utils.type_assert import type_assert | |||||
| from ..base import Preprocessor | from ..base import Preprocessor | ||||
| from ..builder import PREPROCESSORS | from ..builder import PREPROCESSORS | ||||
| __all__ = ['DialogIntentPreprocessor'] | |||||
| __all__ = ['DialogIntentPredictionPreprocessor'] | |||||
| @PREPROCESSORS.register_module(Fields.nlp, module_name=r'space') | |||||
| class DialogIntentPreprocessor(Preprocessor): | |||||
| @PREPROCESSORS.register_module(Fields.nlp, module_name=r'space-intent') | |||||
| class DialogIntentPredictionPreprocessor(Preprocessor): | |||||
| def __init__(self, model_dir: str, *args, **kwargs): | def __init__(self, model_dir: str, *args, **kwargs): | ||||
| """preprocess the data via the vocab.txt from the `model_dir` path | """preprocess the data via the vocab.txt from the `model_dir` path | ||||
| @@ -12,11 +12,11 @@ from modelscope.utils.type_assert import type_assert | |||||
| from ..base import Preprocessor | from ..base import Preprocessor | ||||
| from ..builder import PREPROCESSORS | from ..builder import PREPROCESSORS | ||||
| __all__ = ['DialogGenerationPreprocessor'] | |||||
| __all__ = ['DialogModelingPreprocessor'] | |||||
| @PREPROCESSORS.register_module(Fields.nlp, module_name=r'space-generation') | |||||
| class DialogGenerationPreprocessor(Preprocessor): | |||||
| @PREPROCESSORS.register_module(Fields.nlp, module_name=r'space-modeling') | |||||
| class DialogModelingPreprocessor(Preprocessor): | |||||
| def __init__(self, model_dir: str, *args, **kwargs): | def __init__(self, model_dir: str, *args, **kwargs): | ||||
| """preprocess the data via the vocab.txt from the `model_dir` path | """preprocess the data via the vocab.txt from the `model_dir` path | ||||
| @@ -38,8 +38,8 @@ class Tasks(object): | |||||
| token_classification = 'token-classification' | token_classification = 'token-classification' | ||||
| conversational = 'conversational' | conversational = 'conversational' | ||||
| text_generation = 'text-generation' | text_generation = 'text-generation' | ||||
| dialog_generation = 'dialog-generation' | |||||
| dialog_intent = 'dialog-intent' | |||||
| dialog_modeling = 'dialog_modeling' | |||||
| dialog_intent_prediction = 'dialog-intent-prediction' | |||||
| table_question_answering = 'table-question-answering' | table_question_answering = 'table-question-answering' | ||||
| feature_extraction = 'feature-extraction' | feature_extraction = 'feature-extraction' | ||||
| sentence_similarity = 'sentence-similarity' | sentence_similarity = 'sentence-similarity' | ||||
| @@ -5,13 +5,13 @@ from maas_hub.snapshot_download import snapshot_download | |||||
| from modelscope.models import Model | from modelscope.models import Model | ||||
| from modelscope.models.nlp import DialogIntentModel | from modelscope.models.nlp import DialogIntentModel | ||||
| from modelscope.pipelines import DialogIntentPipeline, pipeline | |||||
| from modelscope.preprocessors import DialogIntentPreprocessor | |||||
| from modelscope.pipelines import DialogIntentPredictionPipeline, pipeline | |||||
| from modelscope.preprocessors import DialogIntentPredictionPreprocessor | |||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| class DialogGenerationTest(unittest.TestCase): | |||||
| model_id = 'damo/nlp_space_dialog-intent' | |||||
| class DialogIntentPredictionTest(unittest.TestCase): | |||||
| model_id = 'damo/nlp_space_dialog-intent-prediction' | |||||
| test_case = [ | test_case = [ | ||||
| 'How do I locate my card?', | 'How do I locate my card?', | ||||
| 'I still have not received my new card, I ordered over a week ago.' | 'I still have not received my new card, I ordered over a week ago.' | ||||
| @@ -20,16 +20,17 @@ class DialogGenerationTest(unittest.TestCase): | |||||
| @unittest.skip('test with snapshot_download') | @unittest.skip('test with snapshot_download') | ||||
| def test_run(self): | def test_run(self): | ||||
| cache_path = snapshot_download(self.model_id) | cache_path = snapshot_download(self.model_id) | ||||
| preprocessor = DialogIntentPreprocessor(model_dir=cache_path) | |||||
| preprocessor = DialogIntentPredictionPreprocessor(model_dir=cache_path) | |||||
| model = DialogIntentModel( | model = DialogIntentModel( | ||||
| model_dir=cache_path, | model_dir=cache_path, | ||||
| text_field=preprocessor.text_field, | text_field=preprocessor.text_field, | ||||
| config=preprocessor.config) | config=preprocessor.config) | ||||
| pipelines = [ | pipelines = [ | ||||
| DialogIntentPipeline(model=model, preprocessor=preprocessor), | |||||
| DialogIntentPredictionPipeline( | |||||
| model=model, preprocessor=preprocessor), | |||||
| pipeline( | pipeline( | ||||
| task=Tasks.dialog_intent, | |||||
| task=Tasks.dialog_intent_prediction, | |||||
| model=model, | model=model, | ||||
| preprocessor=preprocessor) | preprocessor=preprocessor) | ||||
| ] | ] | ||||
| @@ -39,12 +40,14 @@ class DialogGenerationTest(unittest.TestCase): | |||||
| def test_run_with_model_from_modelhub(self): | def test_run_with_model_from_modelhub(self): | ||||
| model = Model.from_pretrained(self.model_id) | model = Model.from_pretrained(self.model_id) | ||||
| preprocessor = DialogIntentPreprocessor(model_dir=model.model_dir) | |||||
| preprocessor = DialogIntentPredictionPreprocessor( | |||||
| model_dir=model.model_dir) | |||||
| pipelines = [ | pipelines = [ | ||||
| DialogIntentPipeline(model=model, preprocessor=preprocessor), | |||||
| DialogIntentPredictionPipeline( | |||||
| model=model, preprocessor=preprocessor), | |||||
| pipeline( | pipeline( | ||||
| task=Tasks.dialog_intent, | |||||
| task=Tasks.dialog_intent_prediction, | |||||
| model=model, | model=model, | ||||
| preprocessor=preprocessor) | preprocessor=preprocessor) | ||||
| ] | ] | ||||
| @@ -7,14 +7,14 @@ import unittest | |||||
| from maas_hub.snapshot_download import snapshot_download | from maas_hub.snapshot_download import snapshot_download | ||||
| from modelscope.models import Model | from modelscope.models import Model | ||||
| from modelscope.models.nlp import DialogGenerationModel | |||||
| from modelscope.pipelines import DialogGenerationPipeline, pipeline | |||||
| from modelscope.preprocessors import DialogGenerationPreprocessor | |||||
| from modelscope.models.nlp import DialogModelingModel | |||||
| from modelscope.pipelines import DialogModelingPipeline, pipeline | |||||
| from modelscope.preprocessors import DialogModelingPreprocessor | |||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| class DialogGenerationTest(unittest.TestCase): | |||||
| model_id = 'damo/nlp_space_dialog-generation' | |||||
| class DialogModelingTest(unittest.TestCase): | |||||
| model_id = 'damo/nlp_space_dialog-modeling' | |||||
| test_case = { | test_case = { | ||||
| 'sng0073': { | 'sng0073': { | ||||
| 'goal': { | 'goal': { | ||||
| @@ -92,21 +92,21 @@ class DialogGenerationTest(unittest.TestCase): | |||||
| } | } | ||||
| } | } | ||||
| @unittest.skip('test with snapshot_download') | |||||
| # @unittest.skip('test with snapshot_download') | |||||
| def test_run(self): | def test_run(self): | ||||
| cache_path = '/Users/yangliu/Space/maas_model/nlp_space_dialog-generation' | |||||
| # cache_path = snapshot_download(self.model_id) | |||||
| # cache_path = '/Users/yangliu/Space/maas_model/nlp_space_dialog-modeling' | |||||
| cache_path = snapshot_download(self.model_id) | |||||
| preprocessor = DialogGenerationPreprocessor(model_dir=cache_path) | |||||
| model = DialogGenerationModel( | |||||
| preprocessor = DialogModelingPreprocessor(model_dir=cache_path) | |||||
| model = DialogModelingModel( | |||||
| model_dir=cache_path, | model_dir=cache_path, | ||||
| text_field=preprocessor.text_field, | text_field=preprocessor.text_field, | ||||
| config=preprocessor.config) | config=preprocessor.config) | ||||
| pipelines = [ | pipelines = [ | ||||
| DialogGenerationPipeline(model=model, preprocessor=preprocessor), | |||||
| DialogModelingPipeline(model=model, preprocessor=preprocessor), | |||||
| pipeline( | pipeline( | ||||
| task=Tasks.dialog_generation, | |||||
| task=Tasks.dialog_modeling, | |||||
| model=model, | model=model, | ||||
| preprocessor=preprocessor) | preprocessor=preprocessor) | ||||
| ] | ] | ||||