MCPcopy Create free account
hub / github.com/SooLab/CGFormer / from_pretrained

Method from_pretrained

bert/tokenization_utils_base.py:1088–1140  ·  view source on GitHub ↗

r""" Instantiate a :class:`~transformers.PreTrainedTokenizer` (or a derived class) from a predefined tokenizer. Args: pretrained_model_name_or_path: either: - a string with the `shortcut name` of a predefined tokenizer to load from cache or download, e.g

(cls, *inputs, **kwargs)

Source from the content-addressed store, hash-verified

1086
1087 @classmethod
1088 def from_pretrained(cls, *inputs, **kwargs):
1089 r"""
1090 Instantiate a :class:`~transformers.PreTrainedTokenizer` (or a derived class) from a predefined tokenizer.
1091
1092 Args:
1093 pretrained_model_name_or_path: either:
1094
1095 - a string with the `shortcut name` of a predefined tokenizer to load from cache or download, e.g.: ``bert-base-uncased``.
1096 - a string with the `identifier name` of a predefined tokenizer that was user-uploaded to our S3, e.g.: ``dbmdz/bert-base-german-cased``.
1097 - a path to a `directory` containing vocabulary files required by the tokenizer, for instance saved using the :func:`~transformers.PreTrainedTokenizer.save_pretrained` method, e.g.: ``./my_model_directory/``.
1098 - (not applicable to all derived classes, deprecated) a path or url to a single saved vocabulary file if and only if the tokenizer only requires a single vocabulary file (e.g. Bert, XLNet), e.g.: ``./my_model_directory/vocab.txt``.
1099
1100 cache_dir: (`optional`) string:
1101 Path to a directory in which a downloaded predefined tokenizer vocabulary files should be cached if the standard cache should not be used.
1102
1103 force_download: (`optional`) boolean, default False:
1104 Force to (re-)download the vocabulary files and override the cached versions if they exists.
1105
1106 resume_download: (`optional`) boolean, default False:
1107 Do not delete incompletely recieved file. Attempt to resume the download if such a file exists.
1108
1109 proxies: (`optional`) dict, default None:
1110 A dictionary of proxy servers to use by protocol or endpoint, e.g.: {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.
1111 The proxies are used on each request.
1112
1113 inputs: (`optional`) positional arguments: will be passed to the Tokenizer ``__init__`` method.
1114
1115 kwargs: (`optional`) keyword arguments: will be passed to the Tokenizer ``__init__`` method. Can be used to set special tokens like ``bos_token``, ``eos_token``, ``unk_token``, ``sep_token``, ``pad_token``, ``cls_token``, ``mask_token``, ``additional_special_tokens``. See parameters in the doc string of :class:`~transformers.PreTrainedTokenizer` for details.
1116
1117 Examples::
1118
1119 # We can't instantiate directly the base class `PreTrainedTokenizer` so let's show our examples on a derived class: BertTokenizer
1120
1121 # Download vocabulary from S3 and cache.
1122 tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
1123
1124 # Download vocabulary from S3 (user-uploaded) and cache.
1125 tokenizer = BertTokenizer.from_pretrained('dbmdz/bert-base-german-cased')
1126
1127 # If vocabulary files are in a directory (e.g. tokenizer was saved using `save_pretrained('./test/saved_model/')`)
1128 tokenizer = BertTokenizer.from_pretrained('./test/saved_model/')
1129
1130 # If the tokenizer uses a single vocabulary file, you can point directly to this file
1131 tokenizer = BertTokenizer.from_pretrained('./test/saved_model/my_vocab.txt')
1132
1133 # You can link tokens to special vocabulary when instantiating
1134 tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', unk_token='<unk>')
1135 # You should be sure '<unk>' is in the vocabulary when doing that.
1136 # Otherwise use tokenizer.add_special_tokens({'unk_token': '<unk>'}) instead)
1137 assert tokenizer.unk_token == '<unk>'
1138
1139 """
1140 return cls._from_pretrained(*inputs, **kwargs)
1141
1142 @classmethod
1143 def _from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs):

Callers

nothing calls this directly

Calls 1

_from_pretrainedMethod · 0.80

Tested by

no test coverage detected