4

I have run into the following error while training a BERT classifier. The

type(b_input_mask) = type(b_labels) = torch.Tensor      

type(b_labels[i]) = tensor(1., dtype=torch.float64)

type(b_input_masks[i]) = class'torch.Tensor'

What could be the possible data type error here since I have not typecasted any variable to either long or double?

Thanks in advance! Error Stack Trace

2 Answers 2

2

In a classification task, the data type for input labels should be Long but you assigned them as float64

type(b_labels[i]) = tensor(1., dtype=torch.float64)

=>

type(b_labels[i]) = tensor(1., dtype=torch.long)
Sign up to request clarification or add additional context in comments.

1 Comment

where should I typecast the float type to long type? In the above-attached image, will labels = np.int_(b_input_mask) will do it for me? Note: np.int_ is for long type.
0

You can use torch.Tensor.long to convert tensor to expected long type.

# Here, you can pass parameter like this in your call
..., labels = b_labels.long())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.