Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: dataclass_transform() got an unexpected keyword argument 'field_specifiers' #12200

Closed
gupta-alok opened this issue Jan 30, 2023 · 9 comments
Labels
duplicate Issues that have been reported before

Comments

@gupta-alok
Copy link

Using spaCy library for keyword extraction from documents however, ended up getting the following TypeError:

TypeError: dataclass_transform() got an unexpected keyword argument 'field_specifiers'

How to reproduce the behaviour

One can follow this blog from analyticsvidhya
https://www.analyticsvidhya.com/blog/2022/03/keyword-extraction-methods-from-documents-in-nlp/

  1. Installed spaCy
    pip3 install spacy
  2. Executed following code for extracting the keywords
import spacy
from collections import Counter
from string import punctuation
nlp = spacy.load("en_core_web_sm")
def get_hotwords(text):
    result = []
    pos_tag = ['PROPN', 'ADJ', 'NOUN'] 
    doc = nlp(text.lower()) 
    for token in doc:
        if(token.text in nlp.Defaults.stop_words or token.text in punctuation):
            continue
        if(token.pos_ in pos_tag):
            result.append(token.text)
    return result
new_text = """
When it comes to evaluating the performance of keyword extractors, you can use some of the standard metrics in machine learning: accuracy, precision, recall, and F1 score. However, these metrics don’t reflect partial matches. they only consider the perfect match between an extracted segment and the correct prediction for that tag.
Fortunately, there are some other metrics capable of capturing partial matches. An example of this is ROUGE.
"""
output = set(get_hotwords(new_text))
most_common_list = Counter(output).most_common(10)
for item in most_common_list:
  print(item[0])
  1. TypeError occurred with the following Traceback
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [26], in <cell line: 1>()
----> 1 import spacy
      2 from collections import Counter
      3 from string import punctuation

File ~\Anaconda3\lib\site-packages\spacy\__init__.py:6, in <module>
      3 import sys
      5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
      8 setup_default_warnings()  # noqa: E402
     10 # These are imported as part of the API

File ~\Anaconda3\lib\site-packages\spacy\errors.py:2, in <module>
      1 import warnings
----> 2 from .compat import Literal
      5 class ErrorsWithCodes(type):
      6     def __getattribute__(self, code):

File ~\Anaconda3\lib\site-packages\spacy\compat.py:3, in <module>
      1 """Helpers for Python and platform compatibility."""
      2 import sys
----> 3 from thinc.util import copy_array
      5 try:
      6     import cPickle as pickle

File ~\Anaconda3\lib\site-packages\thinc\__init__.py:5, in <module>
      2 import numpy
      4 from .about import __version__
----> 5 from .config import registry
      8 # fmt: off
      9 __all__ = [
     10     "registry",
     11     "__version__",
     12 ]

File ~\Anaconda3\lib\site-packages\thinc\config.py:2, in <module>
      1 import catalogue
----> 2 import confection
      3 from confection import Config, ConfigValidationError, Promise, VARIABLE_RE
      4 from .types import Decorator

File ~\Anaconda3\lib\site-packages\confection\__init__.py:10, in <module>
      8 from configparser import ParsingError
      9 from pathlib import Path
---> 10 from pydantic import BaseModel, create_model, ValidationError, Extra
     11 from pydantic.main import ModelMetaclass
     12 from pydantic.fields import ModelField

File ~\Anaconda3\lib\site-packages\pydantic\__init__.py:2, in init pydantic.__init__()

File ~\Anaconda3\lib\site-packages\pydantic\dataclasses.py:46, in init pydantic.dataclasses()

File ~\Anaconda3\lib\site-packages\pydantic\main.py:121, in init pydantic.main()

TypeError: dataclass_transform() got an unexpected keyword argument 'field_specifiers'

Your Environment

!python -m spacy info

============================== Info about spaCy ==============================

spaCy version    3.5.0                         
Location         C:\Users\xyz\Anaconda3\lib\site-packages\spacy
Platform         Windows-10-10.0.19044-SP0     
Python version   3.9.12                        
Pipelines    
@adrianeboyd
Copy link
Contributor

This is a duplicate of #12034, please see the solutions there.

@adrianeboyd adrianeboyd added duplicate Issues that have been reported before resolved The issue was addressed / answered labels Jan 30, 2023
@gupta-alok
Copy link
Author

Thanks, @adrianeboyd however, the #12034 issue was reported for Python ver. 3.7.15 and spaCy ver. 3.4.4
It seems like the issue still persists for Python ver. 3.9.12 and spaCy ver. 3.5.0. Do you know how to fix this issue for latest version?

@github-actions github-actions bot removed the resolved The issue was addressed / answered label Jan 30, 2023
@adrianeboyd
Copy link
Contributor

You can still run into this issue with other libraries and typing_extensions, but I don't think it's coming from any requirements in spacy for python 3.9.

See if you see a version conflict with pip check related to typing_extensions. If you have pydantic>=1.10.4 it should require typing_extensions>=4.2.0.

@gupta-alok
Copy link
Author

No, there's nothing related to typing_extensions.

!pip check
spyder 5.1.5 requires pyqt5, which is not installed.
spyder 5.1.5 requires pyqtwebengine, which is not installed.
daal4py 2021.5.0 requires daal, which is not installed.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.
jupyter-server 1.13.5 has requirement pywinpty<2; os_name == "nt", but you have pywinpty 2.0.2.
autopep8 1.6.0 has requirement pycodestyle>=2.8.0, but you have pycodestyle 2.7.0.

@adrianeboyd
Copy link
Contributor

If you're not sure double-check that pip and pip3 refer to the same python installation, then check the versions of pydantic and typing_extensions with pip list or pip freeze.

@gupta-alok
Copy link
Author

pip and pip3 has the same output. The version of pydantic and typing_extensions are 1.10.4 and 4.4.0 respectively.

!pip3 check
spyder 5.1.5 requires pyqt5, which is not installed.
spyder 5.1.5 requires pyqtwebengine, which is not installed.
daal4py 2021.5.0 requires daal, which is not installed.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.
jupyter-server 1.13.5 has requirement pywinpty<2; os_name == "nt", but you have pywinpty 2.0.2.
autopep8 1.6.0 has requirement pycodestyle>=2.8.0, but you have pycodestyle 2.7.0.
!pip check
spyder 5.1.5 requires pyqt5, which is not installed.
spyder 5.1.5 requires pyqtwebengine, which is not installed.
daal4py 2021.5.0 requires daal, which is not installed.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.
jupyter-server 1.13.5 has requirement pywinpty<2; os_name == "nt", but you have pywinpty 2.0.2.
autopep8 1.6.0 has requirement pycodestyle>=2.8.0, but you have pycodestyle 2.7.0.
!pip list
Package                       Version
----------------------------- --------------------
...
pydantic                      1.10.4
typing_extensions             4.4.0
...

@adrianeboyd
Copy link
Contributor

Sorry, then I don't really know what's going on. It's possible that a package didn't get installed or upgraded cleanly. Does it work if you install spacy with pip install spacy in a new virtual environment?

@gupta-alok
Copy link
Author

After un-installing and re-installing spacy have resolved the issue. Thanks @adrianeboyd for your support.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate Issues that have been reported before
Projects
None yet
Development

No branches or pull requests

2 participants