uf-hobi-informatics-lab / ClinicalTransformerNER

a library for named entity recognition developed by UF HOBI NLP lab featuring SOTA algorithms
MIT License
145 stars 28 forks source link

ImportError for 'ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST' from 'transformers' #39

Open esther1262 opened 6 months ago

esther1262 commented 6 months ago

Hi, I followed this tutorial with the sample data. https://github.com/uf-hobi-informatics-lab/ClinicalTransformerNER/blob/master/tutorial/pipeline_preprocessing_model_training_prediction.ipynb

Everything worked well until I ran the command python ../src/run_transformer_ner.py. I use anaconda and I installed transformer v4.41 using conda forge. Pytorch was installed using conda too for linux and cuda 12.1. The ClinicalTransformerNER folder is stored in /home/user . I stored the training data in /home/user/language model/sample data/ddi_bio/merge.

This is the command I used:

python ClinicalTransformerNER/src/run_transformer_ner.py 
--model_type bert --pretrained_model bert-base-uncased 
--data_dir language model/sample data/ddi_bio/merge
 --new_model_dir language model/new_bert_ner_model --overwrite_model_dir 
--save_model_core --do_train --do_lower_case 
--log_file language model/log.txt --progress_bar --early_stop 3

Here is the error I got:

Traceback (most recent call last):
  File "/home/user/ClinicalTransformerNER/src/run_transformer_ner.py", line 12, in <module>
    from transformer_ner.task import run_task
  File "/home/user/ClinicalTransformerNER/src/transformer_ner/task.py", line 43, in <module>
    from transformer_ner.model import (AlbertNerModel, BartNerModel,
  File "/home/user/ClinicalTransformerNER/src/transformer_ner/model.py", line 11, in <module>
    from transformers import (ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
ImportError: cannot import name 'ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST' from 'transformers' (/home/user/anaconda3/lib/python3.11/site-packages/transformers/__init__.py)

Can someone please help how to fix the error? I restarted the computer already. In python, I can run commands like from transformers import TFBertModel, BertModel but there's nothing named ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST or any PRETRAINED_MODEL_ARCHIVE_LIST in transformers/__init__.py .

Thanks

bugface commented 6 months ago

@esther1262 I think the version of transformers we used is transformers==4.12.5, if you can create a virtual env and use this version, it should work.

Meanwhile, @chenaokun @cpenguf any of u can check the transformers package compatibility issue and we might need to update this repo for any break updates.

esther1262 commented 6 months ago

Hi, I couldn't install transformers earlier than version 4.34.0. It gave me the following errors:

ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

So I installed ver 4.34.0 which also contains ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST. It's just there were some warnings:

/home/user/anaconda3/envs/nlp/lib/python3.12/site-packages/transformers/utils/generic.py:311: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  torch.utils._pytree._register_pytree_node(
/home/user/anaconda3/envs/nlp/lib/python3.12/site-packages/transformers/utils/generic.py:311: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.

Otherwise, the code is working. Thanks.

bugface commented 6 months ago

Hi, I couldn't install transformers earlier than version 4.34.0. It gave me the following errors:

ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

So I installed ver 4.34.0 which also contains ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST. It's just there were some warnings:

/home/user/anaconda3/envs/nlp/lib/python3.12/site-packages/transformers/utils/generic.py:311: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  torch.utils._pytree._register_pytree_node(
/home/user/anaconda3/envs/nlp/lib/python3.12/site-packages/transformers/utils/generic.py:311: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.

Otherwise, the code is working. Thanks.

Great to know. Thanks.