(cls, pretrained_model_name_or_path, *init_inputs, **kwargs)
| 1141 | |
| 1142 | @classmethod |
| 1143 | def _from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs): |
| 1144 | cache_dir = kwargs.pop("cache_dir", None) |
| 1145 | force_download = kwargs.pop("force_download", False) |
| 1146 | resume_download = kwargs.pop("resume_download", False) |
| 1147 | proxies = kwargs.pop("proxies", None) |
| 1148 | local_files_only = kwargs.pop("local_files_only", False) |
| 1149 | |
| 1150 | s3_models = list(cls.max_model_input_sizes.keys()) |
| 1151 | vocab_files = {} |
| 1152 | init_configuration = {} |
| 1153 | if pretrained_model_name_or_path in s3_models: |
| 1154 | # Get the vocabulary from AWS S3 bucket |
| 1155 | for file_id, map_list in cls.pretrained_vocab_files_map.items(): |
| 1156 | vocab_files[file_id] = map_list[pretrained_model_name_or_path] |
| 1157 | if ( |
| 1158 | cls.pretrained_init_configuration |
| 1159 | and pretrained_model_name_or_path in cls.pretrained_init_configuration |
| 1160 | ): |
| 1161 | init_configuration = cls.pretrained_init_configuration[pretrained_model_name_or_path].copy() |
| 1162 | else: |
| 1163 | # Get the vocabulary from local files |
| 1164 | logger.info( |
| 1165 | "Model name '{}' not found in model shortcut name list ({}). " |
| 1166 | "Assuming '{}' is a path, a model identifier, or url to a directory containing tokenizer files.".format( |
| 1167 | pretrained_model_name_or_path, ", ".join(s3_models), pretrained_model_name_or_path |
| 1168 | ) |
| 1169 | ) |
| 1170 | |
| 1171 | if os.path.isfile(pretrained_model_name_or_path) or is_remote_url(pretrained_model_name_or_path): |
| 1172 | if len(cls.vocab_files_names) > 1: |
| 1173 | raise ValueError( |
| 1174 | "Calling {}.from_pretrained() with the path to a single file or url is not supported." |
| 1175 | "Use a model identifier or the path to a directory instead.".format(cls.__name__) |
| 1176 | ) |
| 1177 | logger.warning( |
| 1178 | "Calling {}.from_pretrained() with the path to a single file or url is deprecated".format( |
| 1179 | cls.__name__ |
| 1180 | ) |
| 1181 | ) |
| 1182 | file_id = list(cls.vocab_files_names.keys())[0] |
| 1183 | vocab_files[file_id] = pretrained_model_name_or_path |
| 1184 | else: |
| 1185 | # At this point pretrained_model_name_or_path is either a directory or a model identifier name |
| 1186 | additional_files_names = { |
| 1187 | "added_tokens_file": ADDED_TOKENS_FILE, |
| 1188 | "special_tokens_map_file": SPECIAL_TOKENS_MAP_FILE, |
| 1189 | "tokenizer_config_file": TOKENIZER_CONFIG_FILE, |
| 1190 | "full_tokenizer_file": FULL_TOKENIZER_FILE, |
| 1191 | } |
| 1192 | # Look for the tokenizer files |
| 1193 | for file_id, file_name in {**cls.vocab_files_names, **additional_files_names}.items(): |
| 1194 | if os.path.isdir(pretrained_model_name_or_path): |
| 1195 | full_file_name = os.path.join(pretrained_model_name_or_path, file_name) |
| 1196 | if not os.path.exists(full_file_name): |
| 1197 | logger.info("Didn't find file {}. We won't load it.".format(full_file_name)) |
| 1198 | full_file_name = None |
| 1199 | else: |
| 1200 | full_file_name = hf_bucket_url( |
no test coverage detected