FineTuneBERT icon indicating copy to clipboard operation
FineTuneBERT copied to clipboard

TypeError: string indices must be integers

Open M-Amrollahi opened this issue 3 years ago • 0 comments

Hello I get this error when I try to run this line:

 #Converting these to cuda tensors
 seq, attn_masks, labels = seq.cpu(), attn_masks.cpu(), labels.cpu()

 #Obtaining the logits from the model
 logits = net(seq, attn_masks)
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_3563350/327820057.py in <module>
     37     print("Let the training begin")
     38     st = time.time()
---> 39     train(net, criterion, opti, train_loader, val_loader, args)
     40     print("Done in {} seconds".format(time.time() - st))

/tmp/ipykernel_3563350/2996746533.py in train(net, criterion, opti, train_loader, val_loader, args)
     49 
     50             #Obtaining the logits from the model
---> 51             logits = net(seq, attn_masks)
     52 
     53             #Computing loss

~/anaconda3/envs/trans/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

~/Tests/FineTuneBERT/src/model.py in forward(self, seq, attn_masks)
     29 
     30         #Obtaining the representation of [CLS] head
---> 31         cls_rep = cont_reps[:, 0]
     32 
     33         #Feeding cls_rep to the classifier layer

TypeError: string indices must be integers

How can I solve this?

M-Amrollahi avatar Oct 04 '21 15:10 M-Amrollahi