Create an nlp object from a config. Expects the full config file including a section "nlp" containing the settings for the nlp object. name (str): Package name or model path. meta (Dict[str, Any]): Optional model meta. vocab (Vocab / True): Optional vocab to pass in on initializatio
(
config: Union[Dict[str, Any], Config],
*,
meta: Dict[str, Any] = SimpleFrozenDict(),
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,
auto_fill: bool = False,
validate: bool = True,
)
| 609 | |
| 610 | |
| 611 | def load_model_from_config( |
| 612 | config: Union[Dict[str, Any], Config], |
| 613 | *, |
| 614 | meta: Dict[str, Any] = SimpleFrozenDict(), |
| 615 | vocab: Union["Vocab", bool] = True, |
| 616 | disable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 617 | enable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 618 | exclude: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 619 | auto_fill: bool = False, |
| 620 | validate: bool = True, |
| 621 | ) -> "Language": |
| 622 | """Create an nlp object from a config. Expects the full config file including |
| 623 | a section "nlp" containing the settings for the nlp object. |
| 624 | |
| 625 | name (str): Package name or model path. |
| 626 | meta (Dict[str, Any]): Optional model meta. |
| 627 | vocab (Vocab / True): Optional vocab to pass in on initialization. If True, |
| 628 | a new Vocab object will be created. |
| 629 | disable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to disable. Disabled |
| 630 | pipes will be loaded but they won't be run unless you explicitly |
| 631 | enable them by calling nlp.enable_pipe. |
| 632 | enable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to enable. All other |
| 633 | pipes will be disabled (and can be enabled using `nlp.enable_pipe`). |
| 634 | exclude (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to exclude. Excluded |
| 635 | components won't be loaded. |
| 636 | auto_fill (bool): Whether to auto-fill config with missing defaults. |
| 637 | validate (bool): Whether to show config validation errors. |
| 638 | RETURNS (Language): The loaded nlp object. |
| 639 | """ |
| 640 | if "nlp" not in config: |
| 641 | raise ValueError(Errors.E985.format(config=config)) |
| 642 | nlp_config = config["nlp"] |
| 643 | if "lang" not in nlp_config or nlp_config["lang"] is None: |
| 644 | raise ValueError(Errors.E993.format(config=nlp_config)) |
| 645 | # This will automatically handle all codes registered via the languages |
| 646 | # registry, including custom subclasses provided via entry points |
| 647 | lang_cls = get_lang_class(nlp_config["lang"]) |
| 648 | nlp = lang_cls.from_config( |
| 649 | config, |
| 650 | vocab=vocab, |
| 651 | disable=disable, |
| 652 | enable=enable, |
| 653 | exclude=exclude, |
| 654 | auto_fill=auto_fill, |
| 655 | validate=validate, |
| 656 | meta=meta, |
| 657 | ) |
| 658 | return nlp |
| 659 | |
| 660 | |
| 661 | def get_sourced_components( |
searching dependent graphs…