Abstract Class

Backbones

class mindnlp.abc.BaseModel(auto_prefix=True, flags=None)[source]

Basic class for models

class mindnlp.abc.Seq2seqModel(encoder, decoder)[source]

Basic class for seq2seq models

Parameters:
class mindnlp.abc.Seq2vecModel(encoder, head, dropout: Optional[float] = None)[source]

Basic class for seq2vec models

Parameters:
  • encoder (EncoderBase) – The encoder.

  • head (nn.Cell) – The module to process encoder output.

  • dropout (float) – The drop out rate, greater than 0 and less equal than 1. If None, not dropping out input units. Drfault: None.

class mindnlp.abc.PreTrainedModel(config)[source]

Abstract class for Pretrained models

class mindnlp.abc.PreTrainedConfig(**kwargs)[source]

Abstract class for Pretrained models config.

Callback

class mindnlp.abc.Callback[source]

Abstract base class used to build a callback class. Callbacks are context managers which will be entered and exited when passing into the Model. You can use this mechanism to do some custom operations.

Callback function can perform some operations before and after step or epoch. To create a custom callback, subclass Callback and override the method associated with the stage of interest.

Metric

class mindnlp.abc.Metric[source]

Base class of all metrics. Never use this class directly, but instantiate one of its subclasses instead.

Functions update will accumulate intermediate results in the evaluation process, eval will evaluate the final result, and clear will reinitialize the intermediate results. Function get_metric_name will provide class name.

Modules

class mindnlp.abc.EncoderBase(embedding)[source]

Basic class for encoders

Parameters:

embedding (Cell) – The embedding layer.

class mindnlp.abc.DecoderBase(embedding)[source]

Basic class for dedcoders

Parameters:

embedding (Cell) – The embedding layer.

class mindnlp.abc.TokenEmbedding(init_embed, requires_grad: bool = True, dropout=0.0)[source]

Create Embedding from a given pre-trained vector file.

Parameters:
  • init_embed (Tensor) – Passing into Vocab and Tensor,use these values to initialize Embedding directly.

  • requires_grad (bool) – Whether this parameter needs to be gradient to update.

  • dropout (float) – Dropout of the output of Embedding.

Mixins

class mindnlp.abc.CellUtilMixin[source]

A few utilities to be used as a mixin.

class mindnlp.abc.GenerationMixin[source]

class GenerationMixin A class containing all functions for auto-regressive text generation, to be used as a mixin in [PreTrainedModel].

class mindnlp.abc.SpecialTokensMixin(verbose=True, **kwargs)[source]

A mixin derived by [PreTrainedTokenizer] to handle specific behaviors related to special tokens. In particular, this class hold the attributes which can be used to directly access these special tokens in a model-independent manner and allow to set and update the special tokens.

Parameters:
  • bos_token (str or tokenizers.AddedToken, optional) – A special token representing the beginning of a sentence.

  • eos_token (str or tokenizers.AddedToken, optional) – A special token representing the end of a sentence.

  • unk_token (str or tokenizers.AddedToken, optional) – A special token representing an out-of-vocabulary token.

  • sep_token (str or tokenizers.AddedToken, optional) – A special token separating two different sentences in the same input (used by BERT for instance).

  • pad_token (str or tokenizers.AddedToken, optional) – A special token used to make arrays of tokens the same size for batching purpose. Will then be ignored by attention mechanisms or loss computation.

  • cls_token (str or tokenizers.AddedToken, optional) – A special token representing the class of the input (used by BERT for instance).

  • mask_token (str or tokenizers.AddedToken, optional) – A special token representing a masked token (used by masked-language modeling pretraining objectives, like BERT).

  • additional_special_tokens (tuple or list of str or tokenizers.AddedToken, optional) – A tuple or a list of additional special tokens.

Transforms

class mindnlp.abc.PreTrainedTokenizer(**kwargs)[source]

Pretrained Tokenizer abstract class.