mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-02 12:09:36 +02:00
[to #42322933] refactor model name
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9068994
This commit is contained in:
@@ -4,11 +4,11 @@ from modelscope.utils.constant import Tasks
|
||||
from ..base import Model, Tensor
|
||||
from ..builder import MODELS
|
||||
|
||||
__all__ = ['PalmForTextGenerationModel']
|
||||
__all__ = ['PalmForTextGeneration']
|
||||
|
||||
|
||||
@MODELS.register_module(Tasks.text_generation, module_name=r'palm')
|
||||
class PalmForTextGenerationModel(Model):
|
||||
class PalmForTextGeneration(Model):
|
||||
|
||||
def __init__(self, model_dir: str, *args, **kwargs):
|
||||
"""initialize the text generation model from the `model_dir` path.
|
||||
|
||||
@@ -16,7 +16,7 @@ DEFAULT_MODEL_FOR_PIPELINE = {
|
||||
Tasks.sentence_similarity:
|
||||
('sbert-base-chinese-sentence-similarity',
|
||||
'damo/nlp_structbert_sentence-similarity_chinese-base'),
|
||||
Tasks.image_matting: ('image-matting', 'damo/cv_unet_image-matting_damo'),
|
||||
Tasks.image_matting: ('image-matting', 'damo/cv_unet_image-matting'),
|
||||
Tasks.text_classification:
|
||||
('bert-sentiment-analysis', 'damo/bert-base-sst2'),
|
||||
Tasks.text_generation: ('palm', 'damo/nlp_palm_text-generation_chinese'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
from modelscope.models import Model
|
||||
from modelscope.models.nlp import PalmForTextGenerationModel
|
||||
from modelscope.models.nlp import PalmForTextGeneration
|
||||
from modelscope.preprocessors import TextGenerationPreprocessor
|
||||
from modelscope.utils.constant import Tasks
|
||||
from ..base import Pipeline, Tensor
|
||||
@@ -14,7 +14,7 @@ __all__ = ['TextGenerationPipeline']
|
||||
class TextGenerationPipeline(Pipeline):
|
||||
|
||||
def __init__(self,
|
||||
model: Union[PalmForTextGenerationModel, str],
|
||||
model: Union[PalmForTextGeneration, str],
|
||||
preprocessor: Optional[TextGenerationPreprocessor] = None,
|
||||
**kwargs):
|
||||
"""use `model` and `preprocessor` to create a nlp text classification pipeline for prediction
|
||||
@@ -24,8 +24,7 @@ class TextGenerationPipeline(Pipeline):
|
||||
preprocessor (SequenceClassificationPreprocessor): a preprocessor instance
|
||||
"""
|
||||
sc_model = model if isinstance(
|
||||
model,
|
||||
PalmForTextGenerationModel) else Model.from_pretrained(model)
|
||||
model, PalmForTextGeneration) else Model.from_pretrained(model)
|
||||
if preprocessor is None:
|
||||
preprocessor = TextGenerationPreprocessor(
|
||||
sc_model.model_dir,
|
||||
|
||||
Reference in New Issue
Block a user