Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'ATEPCConfigManager' object has no attribute 'hidden_dim' #397

Open
sqs17 opened this issue Apr 5, 2024 · 8 comments
Open
Labels
bug Something isn't working

Comments

@sqs17
Copy link

sqs17 commented Apr 5, 2024

Version
See the console output for PyABSA, Torch, Transformers Version
2.4.1.post1

Describe the bug
A clear and concise description of what the bug is.
Traceback (most recent call last):
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\configuration_class\configuration_template.py", line 45, in getattribute
value = super().getattribute("args")[arg_name]
KeyError: 'hidden_dim'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\PyABSA-2\yelp\test.py", line 56, in
trainer = ATEPC.ATEPCTrainer(
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\trainer\atepc_trainer.py", line 69, in init
self._run()
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\trainer_class\trainer_template.py", line 240, in _run
model_path.append(self.training_instructor(self.config).run())
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\instructor\atepc_instructor.py", line 40, in init
self._load_dataset_and_prepare_dataloader()
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\instructor\atepc_instructor.py", line 252, in load_dataset_and_prepare_dataloader
self.model = self.config.model(self.bert_base_model, config=self.config)
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\models_lcf
\fast_lcf_atepc.py", line 31, in init
self.linear_double = nn.Linear(config.hidden_dim * 2, config.hidden_dim)
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\configuration_class\configuration_template.py", line 52, in getattribute
return super().getattribute(arg_name)
AttributeError: 'ATEPCConfigManager' object has no attribute 'hidden_dim'

Code To Reproduce
Paste buggy code here
from pyabsa import DatasetItem
my_dataset = DatasetItem("atepc_datasets", ["428.test"])

my_dataset1 and my_dataset2 are the dataset folders. In there folders, the train dataset is necessary

dataset = my_dataset
print(dataset)

from pyabsa import *
config = (
ATEPC.ATEPCConfigManager.get_atepc_config_english()
) # this config contains 'pretrained_bert', it is based on pretrained models
config.model = ATEPC.ATEPCModelList.FAST_LCF_ATEPC # improved version of LCF-ATEPC

from pyabsa import ModelSaveOption, DeviceTypeOption
import warnings

warnings.filterwarnings("ignore")

config.batch_size = 16
config.patience = 2
config.log_step = -1
config.seed = [1]
config.verbose = False # If verbose == True, PyABSA will output the model strcture and seversal processed data examples
config.notice = (
"This is an training example for aspect term extraction" # for memos usage
)

trainer = ATEPC.ATEPCTrainer(
config=config,
dataset=dataset,
from_checkpoint="English",# 不想基于预训练模型的话,删掉这行(还是建议用)
auto_device=DeviceTypeOption.AUTO, # use cuda if available
checkpoint_save_mode=ModelSaveOption.SAVE_MODEL_STATE_DICT, # save state dict only instead of the whole model
load_aug=False, # there are some augmentation dataset for integrated datasets, you use them by setting load_aug=True to improve performance
)

aspect_extractor = trainer.load_trained_model()
assert isinstance(aspect_extractor, ATEPC.AspectExtractor)

Expected behavior
I want to make small adjustments based on your own data
Thank you for your answering!

@sqs17 sqs17 added the bug Something isn't working label Apr 5, 2024
@sqs17
Copy link
Author

sqs17 commented Apr 5, 2024

and when i add "config.hidden_dim = 768"
error is :
Traceback (most recent call last):
File "c:\PyABSA-2\yelp\test.py", line 57, in
trainer = ATEPC.ATEPCTrainer(
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\trainer\atepc_trainer.py", line 69, in init
self._run()
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\trainer_class\trainer_template.py", line 240, in _run
model_path.append(self.training_instructor(self.config).run())
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\tasks\AspectTermExtraction\instructor\atepc_instructor.py", line 799, in run
return self._train(criterion=None)
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\instructor_class\instructor_template.py", line 353, in _train
self._resume_from_checkpoint()
File "D:\anaconda\envs\pyabsa2\lib\site-packages\pyabsa\framework\instructor_class\instructor_template.py", line 451, in _resume_from_checkpoint
self.model.load_state_dict(
File "D:\anaconda\envs\pyabsa2\lib\site-packages\torch\nn\modules\module.py", line 2153, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for FAST_LCF_ATEPC:
size mismatch for dense.weight: copying a param with shape torch.Size([3, 768]) from checkpoint, the shape in current model is torch.Size([2, 768]).
size mismatch for dense.bias: copying a param with shape torch.Size([3]) from checkpoint, the shape in current model is torch.Size([2]).

@sqs17
Copy link
Author

sqs17 commented Apr 5, 2024

image
I downloaded the model locally, using microsoft\deberta-v3-base

@sqs17
Copy link
Author

sqs17 commented Apr 5, 2024

Its my checkpoints.
image

@sqs17
Copy link
Author

sqs17 commented Apr 6, 2024

This seems to have something to do with the training data set. I successfully fine-tuned the training data when I used 119.Yelp and 133.finNews, but I reported errors when I used my own data set and 99.PoliticalData. 99.PoliticalData has dimension 4, and my dataset has dimension 1
image

@yangheng95
Copy link
Owner

Please make sure that your datasets contains the same number of the labels as the pretrained model you are going to use. If the number of labels are not equal, please try fine-tuning the model based on merely your own dataset.

@sqs17
Copy link
Author

sqs17 commented Apr 6, 2024

Hello, thank you very much for your answer.
The task I want to do now is to extract the aspect level of each sentence and conduct sentiment analysis. A sentence corresponds to multiple aspect levels. I don't quite understand the meaning of the number of labels, doesn't every sentence correspond to one aspect? If it corresponds to multiple aspects, repeat the sentence. Thanks again for your help.

@sqs17
Copy link
Author

sqs17 commented Apr 6, 2024

image
是指这里的output_dim吗

@sqs17
Copy link
Author

sqs17 commented Apr 6, 2024

Thanks for your suggestion, after modifying self.output_dim, my code runs well. Is this because the result of the pre-trained model is a triplet of this type? But my data is consistent with the data structure of the pre-trained model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants