Skip to content





class TransformerSpec(NamedTuple)


class TransformerSpec(NamedTuple):
 | ...
 | model_name: str = None


class TransformerSpec(NamedTuple):
 | ...
 | override_weights_file: Optional[str] = None


class TransformerSpec(NamedTuple):
 | ...
 | override_weights_strip_prefix: Optional[str] = None


def get(
    model_name: str,
    make_copy: bool,
    override_weights_file: Optional[str] = None,
    override_weights_strip_prefix: Optional[str] = None,
    load_weights: bool = True,
) -> transformers.PreTrainedModel

Returns a transformer model from the cache.


  • model_name : str
    The name of the transformer, for example "bert-base-cased"
  • make_copy : bool
    If this is True, return a copy of the model instead of the cached model itself. If you want to modify the parameters of the model, set this to True. If you want only part of the model, set this to False, but make sure to copy.deepcopy() the bits you are keeping.
  • override_weights_file : str, optional (default = None)
    If set, this specifies a file from which to load alternate weights that override the weights from huggingface. The file is expected to contain a PyTorch state_dict, created with
  • override_weights_strip_prefix : str, optional (default = None)
    If set, strip the given prefix from the state dict when loading it.
  • load_weights : bool, optional (default = True)
    If set to False, no weights will be loaded. This is helpful when you only want to initialize the architecture, like when you've already fine-tuned a model and are going to load the weights from a state dict elsewhere.


def get_tokenizer(
    model_name: str,
) -> transformers.PreTrainedTokenizer