SpacyPOSTagger

#1
by mansoorhamidzadeh - opened

Hello
good to see new version of hazm base on deep learnning
there is little bug here
the last version installed but when i want user SpacyPOSTagger ,i got error "NameError: name 'SpacyPOSTagger' is not defined"
it seems like there is no "SpacyPOSTagger"
is this bug or new version not release yet?

There are missing imports at the top of the dedicated module.

This may work as a temporary solution:

  1. Fork the repository.

  2. In hazm/pos_tagger.py, move lines 206-214 into the top of the module.

        import spacy  # noqa: I001

        from spacy.tokens import Doc
        from spacy.tokens import DocBin
        from spacy.vocab import Vocab

        from sklearn.metrics import classification_report,f1_score,accuracy_score,precision_score,recall_score

        from tqdm import tqdm

Also add the following import into hazm/__init__.py.

from hazm.pos_tagger import SpacyPOSTagger
  1. In your project environment, install some dependencies that are originally missing in pyproject.toml.
# CPU-only local inference; preventing heavy installation of CUDA packages
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install spacy spacy-transformers tqdm
  1. Clone the forked repository and install modified Hazm package in an editable manner.
git clone <YOUR_FORKED_REPOSITORY_URL>
cd hazm
pip install -e .

Now, you can use SpacyPOSTagger.

from hazm import SpacyPOSTagger

Make sure that you are using an old Python version, aka 3.10, since there are lots of conflicting and deprecated dependencies in pyproject.toml for newer Python version.

Sign up or log in to comment