mindformers.pipeline.TranslationPipeline

class mindformers.pipeline.TranslationPipeline(model: Union[str, mindformers.models.base_model.BaseModel, mindspore.train.model.Model], tokenizer: Optional[mindformers.models.base_tokenizer.BaseTokenizer] = None, **kwargs)[源代码]

Pipeline for Translation

参数
  • model (Union[str, BaseModel]) – The model used to perform task, the input could be a supported model name, or a model instance inherited from BaseModel.

  • tokenizer (Optional[BaseTokenizer]) – A tokenizer (None or Tokenizer) for text processing.

引发
  • TypeError – If input model and tokenizer’s types are not corrected.

  • ValueError – if the input model is not in support list.

实际案例

>>> from mindformers.pipeline import TranslationPipeline
>>> translator = TranslationPipeline("t5_small")
>>> output = translator("abc")
forward(model_inputs: dict, **forward_params)[源代码]

The Forward Process of Model

参数
  • inputs (dict) – The output of preprocess.

  • forward_params (dict) – The parameter dict for model forward.

postprocess(model_outputs: dict, **postprocess_params)[源代码]

Postprocess

参数

model_outputs (dict) – Outputs of forward process.

返回

translation results.

preprocess(inputs: Union[str, dict, mindspore.common.tensor.Tensor], **preprocess_params)[源代码]

The Preprocess For Translation

参数
  • inputs (Union[str, dict, Tensor]) – The text to be classified.

  • preprocess_params (dict) – The parameter dict for preprocess.

返回

Processed text.