mindformers.pipeline.TranslationPipeline

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

Pipeline for Translation

Args:
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.

Raises:

TypeError: If input model and tokenizer’s types are not corrected. ValueError: if the input model is not in support list.

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

The Forward Process of Model

Args:

inputs (dict): The output of preprocess. forward_params (dict): The parameter dict for model forward.

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

Postprocess

Args:

model_outputs (dict): Outputs of forward process.

Return:

translation results.

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

The Preprocess For Translation

Args:

inputs (Union[str, dict, Tensor]): The text to be classified. preprocess_params (dict): The parameter dict for preprocess.

Return:

Processed text.