I am trying to use the Spacy library again for my NPL task. somedays back it was working totally fine with spacy.load("en_core_web_sm"). I thought of using medium instead of small, but now nothing is working. I play around with spacy versions from the latest (3.6.1) to older (3.2.0). I am able to install SpaCy 3.2.0 and can download (!python -m spacy download en_core_web_md) medium pipeline too, however getting the "TypeError" error while loading. ( I tried for both small & medium, and got the same error). I will appreciate your help. Thanks in Advance!!
!pip install spacy==3.2.0
!python -m spacy download en_core_web_md
import spacy
from pydantic import BaseModel
import spacy
nlp = spacy.load("en_core_web_md")
TypeError Traceback (most recent call last)
<ipython-input-2-8bdf9ac04f54> in <module>
1 # Initialize SpaCy model
----> 2 nlp = spacy.load("en_core_web_md")
~\Anaconda3\lib\site-packages\spacy\__init__.py in load(name, vocab, disable, exclude, config)
49 RETURNS (Language): The loaded nlp object.
50 """
---> 51 return util.load_model(
52 name, vocab=vocab, disable=disable, exclude=exclude, config=config
53 )
~\Anaconda3\lib\site-packages\spacy\util.py in load_model(name, vocab, disable, exclude, config)
418 return get_lang_class(name.replace("blank:", ""))()
419 if is_package(name): # installed as package
--> 420 return load_model_from_package(name, **kwargs) # type: ignore[arg-type]
421 if Path(name).exists(): # path to model data directory
422 return load_model_from_path(Path(name), **kwargs) # type: ignore[arg-type]
~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_package(name, vocab, disable, exclude, config)
451 """
452 cls = importlib.import_module(name)
--> 453 return cls.load(vocab=vocab, disable=disable, exclude=exclude, config=config) # type: ignore[attr-defined]
454
455
~\Anaconda3\lib\site-packages\en_core_web_md\__init__.py in load(**overrides)
8
9 def load(**overrides):
---> 10 return load_model_from_init_py(__file__, **overrides)
~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_init_py(init_file, vocab, disable, exclude, config)
613 if not model_path.exists():
614 raise IOError(Errors.E052.format(path=data_path))
--> 615 return load_model_from_path(
616 data_path,
617 vocab=vocab,
~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_path(model_path, meta, vocab, disable, exclude, config)
486 overrides = dict_to_dot(config)
487 config = load_config(config_path, overrides=overrides)
--> 488 nlp = load_model_from_config(config, vocab=vocab, disable=disable, exclude=exclude)
489 return nlp.from_disk(model_path, exclude=exclude, overrides=overrides)
490
~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_config(config, vocab, disable, exclude, auto_fill, validate)
523 # registry, including custom subclasses provided via entry points
524 lang_cls = get_lang_class(nlp_config["lang"])
--> 525 nlp = lang_cls.from_config(
526 config,
527 vocab=vocab,
~\Anaconda3\lib\site-packages\spacy\language.py in from_config(cls, config, vocab, disable, exclude, meta, auto_fill, validate)
1783 # The pipe name (key in the config) here is the unique name
1784 # of the component, not necessarily the factory
-> 1785 nlp.add_pipe(
1786 factory,
1787 name=pipe_name,
~\Anaconda3\lib\site-packages\spacy\language.py in add_pipe(self, factory_name, name, before, after, first, last, source, config, raw_config, validate)
786 lang_code=self.lang,
787 )
--> 788 pipe_component = self.create_pipe(
789 factory_name,
790 name=name,
~\Anaconda3\lib\site-packages\spacy\language.py in create_pipe(self, factory_name, name, config, raw_config, validate)
669 # We're calling the internal _fill here to avoid constructing the
670 # registered functions twice
--> 671 resolved = registry.resolve(cfg, validate=validate)
672 filled = registry.fill({"cfg": cfg[factory_name]}, validate=validate)["cfg"]
673 filled = Config(filled)
~\Anaconda3\lib\site-packages\thinc\config.py in resolve(cls, config, schema, overrides, validate)
744 validate: bool = True,
745 ) -> Dict[str, Any]:
--> 746 resolved, _ = cls._make(
747 config, schema=schema, overrides=overrides, validate=validate, resolve=True
748 )
~\Anaconda3\lib\site-packages\thinc\config.py in _make(cls, config, schema, overrides, resolve, validate)
793 if not is_interpolated:
794 config = Config(orig_config).interpolate()
--> 795 filled, _, resolved = cls._fill(
796 config, schema, validate=validate, overrides=overrides, resolve=resolve
797 )
~\Anaconda3\lib\site-packages\thinc\config.py in _fill(cls, config, schema, validate, resolve, parent, overrides)
848 schema.__fields__[key] = copy_model_field(field, Any)
849 promise_schema = cls.make_promise_schema(value, resolve=resolve)
--> 850 filled[key], validation[v_key], final[key] = cls._fill(
851 value,
852 promise_schema,
~\Anaconda3\lib\site-packages\thinc\config.py in _fill(cls, config, schema, validate, resolve, parent, overrides)
847 field = schema.__fields__[key]
848 schema.__fields__[key] = copy_model_field(field, Any)
--> 849 promise_schema = cls.make_promise_schema(value, resolve=resolve)
850 filled[key], validation[v_key], final[key] = cls._fill(
851 value,
~\Anaconda3\lib\site-packages\thinc\config.py in make_promise_schema(cls, obj, resolve)
1055 sig_args[name] = (annotation, default)
1056 sig_args["__config__"] = _PromiseSchemaConfig
-> 1057 return create_model("ArgModel", **sig_args)
1058
1059
~\Anaconda3\lib\site-packages\pydantic\main.cp38-win_amd64.pyd in pydantic.main.create_model()
~\Anaconda3\lib\site-packages\pydantic\main.cp38-win_amd64.pyd in pydantic.main.ModelMetaclass.__new__()
~\Anaconda3\lib\site-packages\pydantic\fields.cp38-win_amd64.pyd in pydantic.fields.ModelField.infer()
~\Anaconda3\lib\site-packages\pydantic\fields.cp38-win_amd64.pyd in pydantic.fields.ModelField.__init__()
~\Anaconda3\lib\site-packages\pydantic\fields.cp38-win_amd64.pyd in pydantic.fields.ModelField.prepare()
~\Anaconda3\lib\site-packages\pydantic\fields.cp38-win_amd64.pyd in pydantic.fields.ModelField._type_analysis()
~\Anaconda3\lib\typing.py in __subclasscheck__(self, cls)
772 if self._special:
773 if not isinstance(cls, _GenericAlias):
--> 774 return issubclass(cls, self.__origin__)
775 if cls._special:
776 return issubclass(cls.__origin__, self.__origin__)
**TypeError: issubclass() arg 1 must be a class**
You can add below to your requirements:
typing-inspect==0.8.0
typing_extensions==4.5.0
There appears to be a bug in Pydantic v1.10.7 and earlier related to the recent release of typing_extensions v4.6.0 that causes errors for import spacy and any other spacy commands for python 3.8 and python 3.9
For spacy v3.2 and v3.3, we have published patch releases with fixes for the typing_extension requirement. Upgrade to spacy v3.2.6+ or v3.3.3
python -m pip install 'spacy~=3.2.6'
Pydantic should be v1.10.8 or higher
Here is the complete solution in this link: