From 48da1619a74cc17d2e9c2028e79e448b9da0b404 Mon Sep 17 00:00:00 2001 From: "fubang.zfb" Date: Wed, 15 Jun 2022 17:07:04 +0800 Subject: [PATCH] [to #42322933] init --- modelscope/preprocessors/nlp.py | 3 +-- tests/pipelines/test_sentiment_classification.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modelscope/preprocessors/nlp.py b/modelscope/preprocessors/nlp.py index 31d5acb3..c6632ce7 100644 --- a/modelscope/preprocessors/nlp.py +++ b/modelscope/preprocessors/nlp.py @@ -28,8 +28,7 @@ class Tokenize(Preprocessor): @PREPROCESSORS.register_module( - Fields.sentiment_classification, - module_name=r'sbert-sentiment-classification') + Fields.nlp, module_name=r'sbert-sentiment-classification') class SentimentClassificationPreprocessor(Preprocessor): def __init__(self, model_dir: str, *args, **kwargs): diff --git a/tests/pipelines/test_sentiment_classification.py b/tests/pipelines/test_sentiment_classification.py index 1576b335..9a1a8484 100644 --- a/tests/pipelines/test_sentiment_classification.py +++ b/tests/pipelines/test_sentiment_classification.py @@ -11,8 +11,8 @@ from modelscope.utils.constant import Tasks class SentimentClassificationTest(unittest.TestCase): - model_id = 'damo/nlp_structbert_sentence-similarity_chinese-base' - sentence1 = '四川商务职业学院和四川财经职业学院哪个好?' + model_id = 'damo/nlp_structbert_sentiment-classification_chinese-base' + sentence1 = '启动的时候很大声音,然后就会听到1.2秒的卡察的声音,类似齿轮摩擦的声音' def test_run_from_local(self): cache_path = snapshot_download(self.model_id) @@ -22,7 +22,9 @@ class SentimentClassificationTest(unittest.TestCase): pipeline1 = SentimentClassificationPipeline( model, preprocessor=tokenizer) pipeline2 = pipeline( - Tasks.sentence_similarity, model=model, preprocessor=tokenizer) + Tasks.sentiment_classification, + model=model, + preprocessor=tokenizer) print(f'sentence1: {self.sentence1}\n' f'pipeline1:{pipeline1(input=self.sentence1)}') print() @@ -33,18 +35,18 @@ class SentimentClassificationTest(unittest.TestCase): model = Model.from_pretrained(self.model_id) tokenizer = SentimentClassificationPreprocessor(model.model_dir) pipeline_ins = pipeline( - task=Tasks.sentence_similarity, + task=Tasks.sentiment_classification, model=model, preprocessor=tokenizer) print(pipeline_ins(input=self.sentence1)) def test_run_with_model_name(self): pipeline_ins = pipeline( - task=Tasks.sentence_similarity, model=self.model_id) + task=Tasks.sentiment_classification, model=self.model_id) print(pipeline_ins(input=self.sentence1)) def test_run_with_default_model(self): - pipeline_ins = pipeline(task=Tasks.sentence_similarity) + pipeline_ins = pipeline(task=Tasks.sentiment_classification) print(pipeline_ins(input=self.sentence1))