Load a model from a package or data path. name (str): Package name or model path. vocab (Vocab / True): Optional vocab to pass in on initialization. If True, a new Vocab object will be created. disable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to disable.
(
name: Union[str, Path],
*,
vocab: Union["Vocab", bool] = True,
disable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES,
enable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES,
exclude: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES,
config: Union[Dict[str, Any], Config] = SimpleFrozenDict(),
)
| 490 | |
| 491 | |
| 492 | def load_model( |
| 493 | name: Union[str, Path], |
| 494 | *, |
| 495 | vocab: Union["Vocab", bool] = True, |
| 496 | disable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 497 | enable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 498 | exclude: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 499 | config: Union[Dict[str, Any], Config] = SimpleFrozenDict(), |
| 500 | ) -> "Language": |
| 501 | """Load a model from a package or data path. |
| 502 | |
| 503 | name (str): Package name or model path. |
| 504 | vocab (Vocab / True): Optional vocab to pass in on initialization. If True, |
| 505 | a new Vocab object will be created. |
| 506 | disable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to disable. |
| 507 | enable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to enable. All others will be disabled. |
| 508 | exclude (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to exclude. |
| 509 | config (Dict[str, Any] / Config): Config overrides as nested dict or dict |
| 510 | keyed by section values in dot notation. |
| 511 | RETURNS (Language): The loaded nlp object. |
| 512 | """ |
| 513 | kwargs = { |
| 514 | "vocab": vocab, |
| 515 | "disable": disable, |
| 516 | "enable": enable, |
| 517 | "exclude": exclude, |
| 518 | "config": config, |
| 519 | } |
| 520 | if isinstance(name, str): # name or string path |
| 521 | if name.startswith("blank:"): # shortcut for blank model |
| 522 | return get_lang_class(name.replace("blank:", ""))() |
| 523 | if is_package(name): # installed as package |
| 524 | return load_model_from_package(name, **kwargs) # type: ignore[arg-type] |
| 525 | if Path(name).exists(): # path to model data directory |
| 526 | return load_model_from_path(Path(name), **kwargs) # type: ignore[arg-type] |
| 527 | elif hasattr(name, "exists"): # Path or Path-like to model data |
| 528 | return load_model_from_path(name, **kwargs) # type: ignore[arg-type] |
| 529 | if name in OLD_MODEL_SHORTCUTS: |
| 530 | raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name])) # type: ignore[index] |
| 531 | raise IOError(Errors.E050.format(name=name)) |
| 532 | |
| 533 | |
| 534 | def load_model_from_package( |
searching dependent graphs…