-
Notifications
You must be signed in to change notification settings - Fork 160
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
IndexError: Target 2 is out of bounds. #375
Comments
What are the labels in your dataset? Please paste the full console output here |
[2023-12-26 04:41:19] (2.3.4) Set Model Device: cpu 2023-12-26 04:41:24,192 INFO: Load dataset from datasets/apc_datasets/100.pro/pro.test.dat.apc 2023-12-26 04:41:24,931 INFO: Load dataset from datasets/apc_datasets/100.pro/pro.valid.dat.apc 2023-12-26 04:41:25,180 INFO: Model Architecture:
|
Epoch:0 | Loss:0: 0%| | 0/4 [00:03<?, ?it/s]
IndexError Traceback (most recent call last)
Cell In[21], line 7
5 config.num_epoch = 1
6 config.model = APC.APCModelList.FAST_LSA_T_V2
----> 7 trainer = APC.APCTrainer(
8 config=config,
9 dataset=my_dataset,
10 #from_checkpoint="english",
11 # if you want to resume training from our pretrained checkpoints, you can pass the checkpoint name here
12 auto_device=DeviceTypeOption.AUTO,
13 path_to_save=None, # set a path to save checkpoints, if it is None, save checkpoints at 'checkpoints' folder
14 checkpoint_save_mode=ModelSaveOption.SAVE_MODEL_STATE_DICT,
15 load_aug=False,
16 # there are some augmentation dataset for integrated datasets, you use them by setting load_aug=True to improve performance
17 )
File /opt/conda/lib/python3.10/site-packages/pyabsa/tasks/AspectPolarityClassification/trainer/apc_trainer.py:69, in APCTrainer.init(self, config, dataset, from_checkpoint, checkpoint_save_mode, auto_device, path_to_save, load_aug)
64 self.config.task_code = TaskCodeOption.Aspect_Polarity_Classification
65 self.config.task_name = TaskNameOption().get(
66 TaskCodeOption.Aspect_Polarity_Classification
67 )
---> 69 self._run()
File /opt/conda/lib/python3.10/site-packages/pyabsa/framework/trainer_class/trainer_template.py:241, in Trainer._run(self)
239 self.config.seed = s
240 if self.config.checkpoint_save_mode:
--> 241 model_path.append(self.training_instructor(self.config).run())
242 else:
243 # always return the last trained model if you don't save trained model
244 model = self.inference_model_class(
245 checkpoint=self.training_instructor(self.config).run()
246 )
File /opt/conda/lib/python3.10/site-packages/pyabsa/tasks/AspectPolarityClassification/instructor/apc_instructor.py:702, in APCTrainingInstructor.run(self)
699 def run(self):
700 # Loss and Optimizer
701 criterion = nn.CrossEntropyLoss()
--> 702 return self._train(criterion)
File /opt/conda/lib/python3.10/site-packages/pyabsa/framework/instructor_class/instructor_template.py:372, in BaseTrainingInstructor._train(self, criterion)
369 return self._k_fold_train_and_evaluate(criterion)
370 # Train and evaluate the model if there is only one validation dataloader
371 else:
--> 372 return self._train_and_evaluate(criterion)
File /opt/conda/lib/python3.10/site-packages/pyabsa/tasks/AspectPolarityClassification/instructor/apc_instructor.py:135, in APCTrainingInstructor._train_and_evaluate(self, criterion)
133 loss = outputs["loss"]
134 else:
--> 135 loss = criterion(outputs["logits"], targets)
137 if self.config.auto_device == DeviceTypeOption.ALL_CUDA:
138 loss = loss.mean()
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)
1496 # If we don't have any hooks, we want to skip the rest of the logic in
1497 # this function, and just call forward.
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(*args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/loss.py:1174, in CrossEntropyLoss.forward(self, input, target)
1173 def forward(self, input: Tensor, target: Tensor) -> Tensor:
-> 1174 return F.cross_entropy(input, target, weight=self.weight,
1175 ignore_index=self.ignore_index, reduction=self.reduction,
1176 label_smoothing=self.label_smoothing)
File /opt/conda/lib/python3.10/site-packages/torch/nn/functional.py:3029, in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
3027 if size_average is not None or reduce is not None:
3028 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 3029 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
IndexError: Target 2 is out of bounds.
This is the error I am getting while using custom dataset
this is my training snippet
from pyabsa import AspectPolarityClassification as APC
from pyabsa import ModelSaveOption, DeviceTypeOption
import random
config = APC.APCConfigManager.get_apc_config_english()
config.model = APC.APCModelList.FAST_LSA_T_V2
config.model = APC.APCModelList.FAST_LSA_S_V2
config.model = APC.APCModelList.BERT_SPC_V2
config.pretrained_bert = "microsoft/deberta-v3-large"
#config.evaluate_begin = 2
config.max_seq_len = 80
config.num_epoch = 1
config.log_step = 5
config.dropout = 0
config.cache_dataset = False
#config.l2reg = 1e-8
config.lsa = True
config.seed = [random.randint(0, 10000) for _ in range(3)]
trainer = APC.APCTrainer(
config=config,
dataset=my_dataset,
#from_checkpoint="/kaggle/working/fast_lcf_bert_English_acc_84.65_f1_82.39",
# if you want to resume training from our pretrained checkpoints, you can pass the checkpoint name here
auto_device=DeviceTypeOption.AUTO,
path_to_save=None, # set a path to save checkpoints, if it is None, save checkpoints at 'checkpoints' folder
checkpoint_save_mode=ModelSaveOption.SAVE_MODEL_STATE_DICT,
load_aug=False,
# there are some augmentation dataset for integrated datasets, you use them by setting load_aug=True to improve performance
)
The text was updated successfully, but these errors were encountered: