hanlp

hanlp

hanlp.load(save_dir: str, verbose=None, **kwargs) hanlp.common.component.Component[source]

Load a pretrained component from an identifier.

Parameters
  • save_dir (str) – The identifier to the saved component. It could be a remote URL or a local path.

  • verboseTrue to print loading progress.

  • **kwargs – Arguments passed to hanlp.common.torch_component.TorchComponent.load(), e.g., devices is a useful argument to specify which GPU devices a PyTorch component will use.

Examples:

import hanlp
# Load component onto the 0-th GPU.
hanlp.load(..., devices=0)
# Load component onto the 0-th and 1-st GPUs using data parallelization.
hanlp.load(..., devices=[0, 1])

Note

A component can have dependencies on other components or resources, which will be recursively loaded. So it’s common to see multiple downloading messages per single load.

Returns

A pretrained component.

Return type

hanlp.common.component.Component

hanlp.pipeline(*pipes) hanlp.components.pipeline.Pipeline[source]

Creates a pipeline of components. It’s made for bundling KerasComponents. For TorchComponent, use MultiTaskLearning instead.

Parameters

*pipes – Components if pre-defined any.

Returns

A pipeline, which is a list of components in order.

Return type

hanlp.components.pipeline.Pipeline