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

TypeError: string indices must be integers #7

Open
M-Amrollahi opened this issue Oct 4, 2021 · 0 comments
Open

TypeError: string indices must be integers #7

M-Amrollahi opened this issue Oct 4, 2021 · 0 comments

Comments

@M-Amrollahi
Copy link

M-Amrollahi commented Oct 4, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant