MCPcopy
hub / github.com/HIT-SCIR/ltp / from_pretrained

Method from_pretrained

python/interface/ltp/mixin.py:30–150  ·  view source on GitHub ↗

r""" Instantiate a pretrained LTP model from a pre-trained model configuration from huggingface-hub. The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train the model, you should first set

(
        cls,
        pretrained_model_name_or_path: str,
        force_download: bool = False,
        resume_download: bool = False,
        proxies: Dict = None,
        use_auth_token: Optional[str] = None,
        cache_dir: Optional[str] = None,
        local_files_only: bool = False,
        **model_kwargs,
    )

Source from the content-addressed store, hash-verified

28
29 @classmethod
30 def from_pretrained(
31 cls,
32 pretrained_model_name_or_path: str,
33 force_download: bool = False,
34 resume_download: bool = False,
35 proxies: Dict = None,
36 use_auth_token: Optional[str] = None,
37 cache_dir: Optional[str] = None,
38 local_files_only: bool = False,
39 **model_kwargs,
40 ):
41 r"""
42 Instantiate a pretrained LTP model from a pre-trained model
43 configuration from huggingface-hub. The model is set in
44 evaluation mode by default using `model.eval()` (Dropout modules
45 are deactivated). To train the model, you should first set it
46 back in training mode with `model.train()`.
47
48 Parameters:
49 pretrained_model_name_or_path (`str` or `os.PathLike`):
50 Can be either:
51 - A string, the `model id` of a pretrained model
52 hosted inside a model repo on huggingface.co.
53 Valid model ids are [`LTP/tiny`, `LTP/small`,
54 `LTP/base`, `LTP/base1`, `LTP/base1`, `LTP/legacy`
55 ], the legacy model only support cws, pos and ner,
56 but more fast.
57 - You can add `revision` by appending `@` at the end
58 of model_id simply like this:
59 `dbmdz/bert-base-german-cased@main` Revision is
60 the specific model version to use. It can be a
61 branch name, a tag name, or a commit id, since we
62 use a git-based system for storing models and
63 other artifacts on huggingface.co, so `revision`
64 can be any identifier allowed by git.
65 - A path to a `directory` containing model weights
66 saved using
67 [`~transformers.PreTrainedModel.save_pretrained`],
68 e.g., `./my_model_directory/`.
69 - `None` if you are both providing the configuration
70 and state dictionary (resp. with keyword arguments
71 `config` and `state_dict`).
72 force_download (`bool`, *optional*, defaults to `False`):
73 Whether to force the (re-)download of the model weights
74 and configuration files, overriding the cached versions
75 if they exist.
76 resume_download (`bool`, *optional*, defaults to `False`):
77 Whether to delete incompletely received files. Will
78 attempt to resume the download if such a file exists.
79 proxies (`Dict[str, str]`, *optional*):
80 A dictionary of proxy servers to use by protocol or
81 endpoint, e.g., `{'http': 'foo.bar:3128',
82 'http://hostname': 'foo.bar:4012'}`. The proxies are
83 used on each request.
84 use_auth_token (`str` or `bool`, *optional*):
85 The token to use as HTTP bearer authorization for remote
86 files. If `True`, will use the token generated when
87 running `transformers-cli login` (stored in

Callers 6

mainFunction · 0.80
_from_pretrainedMethod · 0.80
mainFunction · 0.80
__init__Method · 0.80
__init__Method · 0.80
mainFunction · 0.80

Calls 3

downloadMethod · 0.80
updateMethod · 0.45
_from_pretrainedMethod · 0.45

Tested by

no test coverage detected