bjascob / amrlib

A python library that makes AMR parsing, generation and visualization simple.
MIT License
219 stars 34 forks source link

amr_view : ImportError: cannot import name 'T5ForConditionalGeneration' from 'transformers' #30

Closed bjascob closed 2 years ago

bjascob commented 2 years ago

When running amr_view I am getting an import error, though I'm not sure exactly why. The full error is..

  File "/home/bjascob/.local/lib/python3.8/site-packages/amrlib/models/parse_t5/inference.py", line 7, in <module>
    from   transformers import T5ForConditionalGeneration, T5Tokenizer
ImportError: cannot import name 'T5ForConditionalGeneration' from 'transformers' (/home/bjascob/.local/lib/python3.8/site-packages/transformers/__init__.py)

The library is installed and loading the model from the command line (stog = amrlib.load_stog_model()) works fine. I'm guessing this version of transformers has some dynamic loading issue for that module.

The simple fix is to put import transformers on the line above the error. that extra import seems to fix the issue.

bjascob commented 2 years ago

The above commit looks like it fixes the issue. Note that this was happening when running amr_view with transformers 4.4.2.

Also note that model generate_t5 and generate_t5wtense have similar import structure but don't seem to cause this issue (note parse_t5 is imported first). If this problem comes up in those models, try putting the import transformers in the code as above.