MCPcopy
hub / github.com/hankcs/HanLP / load

Function load

hanlp/__init__.py:13–43  ·  view source on GitHub ↗

Load a pretrained component from an identifier. Args: save_dir (str): The identifier to the saved component. It could be a remote URL or a local path. verbose: ``True`` to print loading progress. **kwargs: Arguments passed to :func:`hanlp.common.torch_component.TorchComponent.

(save_dir: str, verbose=None, **kwargs)

Source from the content-addressed store, hash-verified

11
12
13def load(save_dir: str, verbose=None, **kwargs) -> hanlp.common.component.Component:
14 """Load a pretrained component from an identifier.
15
16 Args:
17 save_dir (str): The identifier to the saved component. It could be a remote URL or a local path.
18 verbose: ``True`` to print loading progress.
19 **kwargs: Arguments passed to :func:`hanlp.common.torch_component.TorchComponent.load`, e.g.,
20 ``devices`` is a useful argument to specify which GPU devices a PyTorch component will use.
21
22 Examples::
23
24 import hanlp
25 # Load component onto the 0-th GPU.
26 hanlp.load(..., devices=0)
27 # Load component onto the 0-th and 1-st GPUs using data parallelization.
28 hanlp.load(..., devices=[0, 1])
29
30 .. Note::
31 A component can have dependencies on other components or resources, which will be recursively loaded. So it's
32 common to see multiple downloading messages per single load.
33
34 Returns:
35 hanlp.common.component.Component: A pretrained component.
36
37 """
38 save_dir = hanlp.pretrained.ALL.get(save_dir, save_dir)
39 from hanlp.utils.component_util import load_from_meta_file
40 if verbose is None:
41 from hanlp_common.constant import HANLP_VERBOSE
42 verbose = HANLP_VERBOSE
43 return load_from_meta_file(save_dir, 'meta.json', verbose=verbose, **kwargs)
44
45
46def pipeline(*pipes) -> hanlp.components.pipeline.Pipeline:

Callers

nothing calls this directly

Calls 2

load_from_meta_fileFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…