Create the nlp object from a loaded config. Will set up the tokenizer and language data, add pipeline components etc. If no config is provided, the default config of the given language is used. config (Dict[str, Any] / Config): The loaded config. vocab (Vocab): A Voc
(
cls,
config: Union[Dict[str, Any], Config] = {},
*,
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,
meta: Dict[str, Any] = SimpleFrozenDict(),
auto_fill: bool = True,
validate: bool = True,
)
| 1761 | |
| 1762 | @classmethod |
| 1763 | def from_config( |
| 1764 | cls, |
| 1765 | config: Union[Dict[str, Any], Config] = {}, |
| 1766 | *, |
| 1767 | vocab: Union[Vocab, bool] = True, |
| 1768 | disable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 1769 | enable: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 1770 | exclude: Union[str, Iterable[str]] = _DEFAULT_EMPTY_PIPES, |
| 1771 | meta: Dict[str, Any] = SimpleFrozenDict(), |
| 1772 | auto_fill: bool = True, |
| 1773 | validate: bool = True, |
| 1774 | ) -> "Language": |
| 1775 | """Create the nlp object from a loaded config. Will set up the tokenizer |
| 1776 | and language data, add pipeline components etc. If no config is provided, |
| 1777 | the default config of the given language is used. |
| 1778 | |
| 1779 | config (Dict[str, Any] / Config): The loaded config. |
| 1780 | vocab (Vocab): A Vocab object. If True, a vocab is created. |
| 1781 | disable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to disable. |
| 1782 | Disabled pipes will be loaded but they won't be run unless you |
| 1783 | explicitly enable them by calling nlp.enable_pipe. |
| 1784 | enable (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to enable. All other |
| 1785 | pipes will be disabled (and can be enabled using `nlp.enable_pipe`). |
| 1786 | exclude (Union[str, Iterable[str]]): Name(s) of pipeline component(s) to exclude. |
| 1787 | Excluded components won't be loaded. |
| 1788 | meta (Dict[str, Any]): Meta overrides for nlp.meta. |
| 1789 | auto_fill (bool): Automatically fill in missing values in config based |
| 1790 | on defaults and function argument annotations. |
| 1791 | validate (bool): Validate the component config and arguments against |
| 1792 | the types expected by the factory. |
| 1793 | RETURNS (Language): The initialized Language class. |
| 1794 | |
| 1795 | DOCS: https://spacy.io/api/language#from_config |
| 1796 | """ |
| 1797 | if auto_fill: |
| 1798 | config = Config( |
| 1799 | cls.default_config, section_order=CONFIG_SECTION_ORDER |
| 1800 | ).merge(config) |
| 1801 | if "nlp" not in config: |
| 1802 | raise ValueError(Errors.E985.format(config=config)) |
| 1803 | # fill in [nlp.vectors] if not present (as a narrower alternative to |
| 1804 | # auto-filling [nlp] from the default config) |
| 1805 | if "vectors" not in config["nlp"]: |
| 1806 | config["nlp"]["vectors"] = {"@vectors": "spacy.Vectors.v1"} |
| 1807 | config_lang = config["nlp"].get("lang") |
| 1808 | if config_lang is not None and config_lang != cls.lang: |
| 1809 | raise ValueError( |
| 1810 | Errors.E958.format( |
| 1811 | bad_lang_code=config["nlp"]["lang"], |
| 1812 | lang_code=cls.lang, |
| 1813 | lang=util.get_object_name(cls), |
| 1814 | ) |
| 1815 | ) |
| 1816 | config["nlp"]["lang"] = cls.lang |
| 1817 | # This isn't very elegant, but we remove the [components] block here to prevent |
| 1818 | # it from getting resolved (causes problems because we expect to pass in |
| 1819 | # the nlp and name args for each component). If we're auto-filling, we're |
| 1820 | # using the nlp.config with all defaults. |