Пример #1
0
def load(save_dir: str, meta_filename='meta.json', **kwargs) -> hanlp.common.component.Component:
    """
    Load saved component from identifier.
    :param save_dir: The identifier to the saved component.
    :param meta_filename: The meta file of that saved component, which stores the class_path and version.
    :param kwargs: Additional arguments parsed to the `from_meta` method.
    :return: A pretrained component.
    """
    save_dir = hanlp.pretrained.ALL.get(save_dir, save_dir)
    from hanlp.utils.component_util import load_from_meta_file
    return load_from_meta_file(save_dir, meta_filename, **kwargs)
Пример #2
0
def load(save_dir: str,
         verbose=None,
         **kwargs) -> hanlp.common.component.Component:
    """Load 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 `Component.load`

    ``devices`` is a useful arguments to specify the GPU devices 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-th GPU 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 per single load.

    Returns:
      A pretrained component.

    """
    save_dir = hanlp.pretrained.ALL.get(save_dir, save_dir)
    from hanlp.utils.component_util import load_from_meta_file
    if verbose is None:
        from hanlp_common.constant import HANLP_VERBOSE
        verbose = HANLP_VERBOSE
    return load_from_meta_file(save_dir,
                               'meta.json',
                               verbose=verbose,
                               **kwargs)
Пример #3
0
def load(save_dir,
         meta_filename='meta.json',
         **kwargs) -> hanlp.common.component.Component:
    save_dir = hanlp.pretrained.ALL.get(save_dir, save_dir)
    from hanlp.utils.component_util import load_from_meta_file
    return load_from_meta_file(save_dir, meta_filename, **kwargs)