MCPcopy
hub / github.com/explosion/spaCy / load_model

Function load_model

spacy/util.py:492–531  ·  view source on GitHub ↗

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(),
)

Source from the content-addressed store, hash-verified

490
491
492def 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
534def load_model_from_package(

Callers 10

test_issue4054Function · 0.90
test_issue4190Function · 0.90
test_issue4042Function · 0.90
applyFunction · 0.85
profileFunction · 0.85
copy_from_base_modelFunction · 0.85
load_vectors_into_modelFunction · 0.85
json_to_docsFunction · 0.85
conll_ner_to_docsFunction · 0.85
segment_sents_and_docsFunction · 0.85

Calls 5

SimpleFrozenDictClass · 0.85
get_lang_classFunction · 0.85
is_packageFunction · 0.85
load_model_from_packageFunction · 0.85
load_model_from_pathFunction · 0.85

Tested by 3

test_issue4054Function · 0.72
test_issue4190Function · 0.72
test_issue4042Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…