roshan-research / hazm

Persian NLP Toolkit
https://www.roshan-ai.ir/hazm/
MIT License
1.19k stars 180 forks source link

name 'spacy' is not defined when using SpacyPOSTagger #339

Closed ghominejad closed 3 months ago

ghominejad commented 3 months ago

Description

Encountering name 'spacy' is not defined when trying to call spacy_posTagger.tag from the Hazm library.

Steps to Reproduce

  1. Set up a new Python environment and install Hazm via pip.
  2. Attempt to call spacy_posTagger.tag as per the documentation/examples provided:
    
    from hazm import SpacyPOSTagger
    spacy_posTagger = SpacyPOSTagger(model_path = 'models/spacy_pos_tagger_parsbertpostagger')
    print(spacy_posTagger.tag(tokens = ['من', 'به', 'مدرسه', 'ایران', 'رفته_بودم', '.']))
  3. The following error occurs
------------- You Prefer to use CPU --------------
Traceback (most recent call last):
  File "/usr/src/app/main.py", line 8, in <module>
    print(spacy_posTagger.tag(tokens = Ä'من', 'به', 'مدرسه', 'ایران', 'رفته_بودم', '.'Ü))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/hazm/pos_tagger.py", line 380, in tag
    self._setup_model(ÄtokensÜ)
  File "/usr/local/lib/python3.11/site-packages/hazm/pos_tagger.py", line 260, in _setup_model
    self.tagger = spacy.load(self.model_path)  # Load the spaCy model
                  ^^^^^
NameError: name 'spacy' is not defined

Environment

Hazm version: 0.10.0 Python version: 3.11 Operating System: Docker image python:3.11-slim scipy: 1.11.4 numpy: 1.24.3