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

memoryview: a bytes-like object is required, not 'dict' when loading spaCy model #340

Open
ghominejad opened this issue May 31, 2024 · 2 comments

Comments

@ghominejad
Copy link

Description:

I'm encountering an issue when trying to load a spaCy model using the SpacyPOSTagger or even with spacy.load method. The error message I receive is:

memoryview: a bytes-like object is required, not 'dict'

Steps to Reproduce

  1. Clone the repository from spacy_pos_tagger_parsbertpostagger using:

    git clone --depth 1 https://huggingface.co/roshan-research/spacy_pos_tagger_parsbertpostagger
  2. Install dependencies:

    pip install --no-cache-dir scipy==1.11.4 spacy==3.6.0 srsly==2.4.5 Cython spacy-transformers==1.1.7 transformers==4.27.4 gensim hazm
  3. Run the following test script:

    import spacy
    from pathlib import Path
    
    def test_load_model(model_path):
        try:
            nlp = spacy.load(model_path)
            print("Model loaded successfully.")
        except Exception as e:
            print(f"Failed to load model: {e}")
    
    if __name__ == "__main__":
        model_path = "./models/spacy_pos_tagger_parsbertpostagger"  # Adjust the path accordingly
        test_load_model(model_path)

Expected Behavior

The model should load successfully without any errors.

Actual Behavior

The following error is encountered:

memoryview: a bytes-like object is required, not 'dict'

Environment

  • Python Version: 3.10
  • Installed Packages:
    • scipy==1.11.4
    • spacy==3.6.0
    • srsly==2.4.5
    • Cython
    • spacy-transformers==1.1.7
    • transformers==4.27.4
    • gensim
    • hazm

Additional Information

The error seems to occur when the spacy.load function is called. This suggests there might be an issue with the model files or the compatibility between the installed packages and the model.

Any guidance on resolving this issue would be greatly appreciated.

@MortezaMahdaviMortazavi
Copy link
Collaborator

Hi Mr.Ghominejad.Sorry for being late.Im looking into it and try to find the problem.Thanks for feedback.

@MortezaMahdaviMortazavi
Copy link
Collaborator

import spacy
from pathlib import Path

def test_load_model(model_path):
try:
nlp = spacy.load(model_path)
print("Model loaded successfully.")
except Exception as e:
print(f"Failed to load model: {e}")

if name == "main":
model_path = "spacy_pos_tagger_parsbertpostagger" # Adjust the path accordingly
test_load_model(model_path)

I run your code exactly and pass the spacy_pos_tagger_parsbertpostagger to spacy.load function.It work correct and printed me Model loaded successfully.I think your packages version are wrong.my spacy version is 3.6.0 same as you.My packages version listed below:
spacy==3.6.0
scipy==1.10.1
srsly==2.4.6
Cython==0.29.32
spacy-transformers==1.3.2
transformers==4.38.1
gensim==4.3.1
hazm
try to install these packages with version of mine.I hope your problem will be solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants