songyouwei / ABSA-PyTorch

Aspect Based Sentiment Analysis, PyTorch Implementations. 基于方面的情感分析,使用PyTorch实现。
MIT License
2.02k stars 525 forks source link

Infer_example for LCF_BERT #184

Open vahidsj opened 3 years ago

vahidsj commented 3 years ago

When running the Infer_example.py I got this error:

Traceback (most recent call last):
  File "infer_example.py", line 162, in <module>
    inf = Inferer(opt)
  File "infer_example.py", line 27, in __init__
    self.model = opt.model_class(bert, opt).to(opt.device)
  File "/ukp-storage-1/sadiri/ABSA-PyTorch/models/lcf_bert.py", line 40, in __init__
    self.dropout = nn.Dropout(opt.dropout)

Solution: You should add this: opt.dropout = 0.1 in Infer_example.py after setting your trained model, i.e.:

class Option(object): pass
    opt = Option()
    opt.model_name = 'lcf_bert'
    opt.model_class = model_classes[opt.model_name]
    opt.dataset = 'laptop'
    opt.dataset_file = dataset_files[opt.dataset]
    opt.inputs_cols = input_colses[opt.model_name]
    # set your trained models here
    opt.state_dict_path = 'state_dict/lcf_bert_laptop_val_acc_0.7806'
    **opt.dropout = 0.1**
    opt.embed_dim = 300
    opt.hidden_dim = 300
    opt.max_seq_len = 85
    opt.bert_dim = 768
yangheng95 commented 3 years ago

BTW, if anyone demands, PyABSA provides the training & inference scripts for LCF-BERT as well as other BERT-based and GloVe-based models.