thunlp / PELT

Source code for "A Simple but Effective Pluggable Entity Lookup Table for Pre-trained Language Models"
43 stars 8 forks source link

no attribute 'TFRobertaEntForMarkerSequenceClassification' #9

Closed eurkaaaa closed 1 year ago

eurkaaaa commented 1 year ago

hello, AttributeError: module 'transformers' has no attribute 'TFRobertaEntForMarkerSequenceClassification' In wiki_80.py, I have meet this problem

YeDeming commented 1 year ago

Can you show the detailed log?

eurkaaaa commented 1 year ago

Traceback (most recent call last): File "run_wiki80.py", line 715, in main() File "run_wiki80.py", line 613, in main model = model_class.from_pretrained(args.model_name_or_path, from_tf=True, config=config) File "/home/lihao/桌面/PELT/transformers/src/transformers/modeling_utils.py", line 488, in from_pretrained model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True) File "/home/lihao/桌面/PELT/transformers/src/transformers/modeling_tf_pytorch_utils.py", line 225, in load_tf2_checkpoint_in_pytorch_model tf_model_class = getattr(transformers, tf_model_class_name) AttributeError: module 'transformers' has no attribute 'TFRobertaEntForMarkerSequenceClassification'

YeDeming commented 1 year ago

https://github.com/thunlp/PELT/blob/7f5097fc69de45d6ac125ce6f9f19f4a06c46eff/RE/run_wiki80.py#L611

I set from_tf=False and use a huggface's BERT pytorch checkpoint

eurkaaaa commented 1 year ago

是的,但是如果这样的话,就会出现下面这个报错。

Traceback (most recent call last): File "run_wiki80.py", line 713, in main() File "run_wiki80.py", line 611, in main model = model_class.from_pretrained(args.model_name_or_path, from_tf=bool('.ckpt' in args.model_name_or_path), config=config) File "/home/lihao/桌面/PELT/transformers/src/transformers/modeling_utils.py", line 473, in from_pretrained raise OSError( OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

eurkaaaa commented 1 year ago

需要提前clone huaggface的代码吗

YeDeming commented 1 year ago

下相应的模型https://huggingface.co/ 比如bert是

mkdir -p bert_models/bert-base-uncased
wget -P bert_models/bert-base-uncased https://huggingface.co/bert-base-uncased/resolve/main/pytorch_model.bin
wget -P bert_models/bert-base-uncased https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt
wget -P bert_models/bert-base-uncased https://huggingface.co/bert-base-uncased/resolve/main/config.json

然后我这里用的是roberta不是bert