While training the model in text classification task, it kept saying this error, but since I ran this code few days ago , i am not understanding why it’s not working anymore
Epoch: 0%| | 0/10 [00:02<?, ?it/s]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-cdf49a404347> in <cell line: 1>()
----> 1 train(model=model,
2 criterion=criterion,
3 optimizer=optimizer,
4 train_loader=train_loader,
5 val_loader=valid_loader,
3 frames
<ipython-input-30-e26e65f9e3c5> in train(model, criterion, optimizer, train_loader, val_loader, epochs, device)
9 input_ids, attention_mask, labels = input_ids.to(device), attention_mask.to(device), labels.to(device)
10
---> 11 logits = model(input_ids=input_ids, attention_mask=attention_mask)
12
13 loss = criterion(logits, labels)
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in _wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
1519
1520 def _call_impl(self, *args, **kwargs):
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in _call_impl(self, *args, **kwargs)
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1528
1529 try:
<ipython-input-26-ca436c0e67a1> in forward(self, input_ids, attention_mask)
10 reps, _ = self.bert(input_ids=input_ids, attention_mask=attention_mask)
11 #Obtain the representations of [CLS] heads
---> 12 cls_reps = reps[:, 0]
13 logits = self.cls_layer(cls_reps)
14 return logits
TypeError: string indices must be integers
thanks in advance