Kyubyong / name2nat

name2nat: a Python package for nationality prediction from a name
Apache License 2.0
100 stars 8 forks source link

Error from 'my_nanat = Name2nat()' #5

Open spearmint4 opened 1 year ago

spearmint4 commented 1 year ago

I receive the following error when after running 'my_nanat = Name2nat()'

Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32 from name2nat import Name2nat my_nanat = Name2nat() Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() File "", line 2, in File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\name2nat\name2nat.py", line 11, in init self.classifier = TextClassifier.load(ckpt) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\flair\models\text_classification_model.py", line 137, in load return cast("TextClassifier", super().load(model_path=model_path)) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\flair\nn\model.py", line 944, in load return cast("DefaultClassifier", super().load(model_path=model_path)) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\flair\nn\model.py", line 559, in load return cast("Classifier", super().load(model_path=model_path)) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\flair\nn\model.py", line 191, in load state = load_torch_state(model_file) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\flair\file_utils.py", line 359, in load_torch_state return torch.load(f, map_location="cpu") File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\serialization.py", line 815, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\serialization.py", line 1043, in _legacy_load result = unpickler.load() File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\nn\modules\rnn.py", line 325, in setstate for w in self._flat_weights] File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\nn\modules\module.py", line 1614, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'GRU' object has no attribute '_flat_weights'

AnaKuzina commented 11 months ago

Hey @spearmint4, did you manage to bypass this error?

I get the same one with a little bit different message: AttributeError: 'GRU' object has no attribute '_flat_weights'. Did you mean: '_all_weights'?

SinaOzdemir commented 10 months ago

I have the same problem. Quick googling indicates Name2nat has a problem with initiating GRU. Some other package suggests that it might be related to pytorch version. It might also be that one of the dependencies of the Name2nat got updated and made this package useless.

haojoeyzhang commented 9 months ago

I successfully got the package to function.

The problem arises because the package depends on flair but does not specify a specific version of it. Additionally, flair itself does not clearly specify the required PyTorch version. This oversight leads to further complications as the necessary version of PyTorch is not available through pip. As a result, the system defaults to installing the latest versions of these dependencies, potentially leading to compatibility issues.

To resolve this, please follow these steps:

  1. Create a new environment using Conda. Ensure that the Python version is either 3.6 or 3.7.
  2. Install PyTorch version 1.7.1. Use this command: conda install pytorch==1.7.1 cpuonly -c pytorch.
  3. Install a specific version of Flair, version 0.6, with the following command: pip install flair==0.6.
  4. Finally, install the name2nat package, but bypass its dependencies by using: pip install --no-deps name2nat. image
sh0416 commented 6 months ago

For someone who might encounter ModuleNotFoundError: No module named 'torch.utils._pytree', install transformers with 4.28.0.