Unsupport operand types(s) for +=: TensorCategory and TensorText

Hello -

I’ve run the following code below on a Mac and in Google Colab without issue, but on a different machine I’m running into a weird TypeError. I’m running anaconda 3.7 python, 2.1.6 fastai and 1.7.0 pytorch on a Mac, using a Jupyter Notebook. I run the following code, but the last line gives me an error:

dls_clas = TextDataLoaders.from_df(messages, path=data_path, text_col='message', label_col='is_happy', valid_pct=0.2, text_vocab=dls.vocab)
classify = text_classifier_learner(dls_clas, AWD_LSTM, drop_mult=0.5, metrics=accuracy)
classify.load_encoder('messages-awd.pkl')
classify.fit_one_cycle(1, 1e-2)
/anaconda3/lib/python3.7/site-packages/fastai/callback/rnn.py in after_loss(self)
     31 def after_loss(self):
     32    if not self.training: return
---> 33    if self.alpha != 0.: self.learn.loss += self.alpha * self.out.float().pow(2).mean()
     34    if self.beta != 0.:
     35        h = self.raw_out
TypeError: unsupported operand type(s) for +=: 'TensoryCategory' and 'TensorText'

Any hints what might be causing this and/or how to fix it?

I would recommend a quick forum search before asking if possible :slight_smile: This has been asked:

Also this has now been fixed, please update your fastai version :slight_smile:

1 Like

Ah, looks like it might have been resolved 13 minutes ago!

The error message “unsupported operand types(s) for +=: TensorCategory and TensorText” indicates that you are trying to add a TensorCategory object and a TensorText object using the += operator, which is not supported.

TensorCategory and TensorText are both data types used in machine learning frameworks such as PyTorch and TensorFlow. TensorCategory represents a categorical variable, while TensorText represents a text variable. The += operator is used to perform addition and assignment operations on numerical data types, such as integers and floating-point numbers. It cannot be used to add two different data types such as TensorCategory and TensorText.

Machine Learning Classes in Pune

To resolve this error, you need to ensure that you are only using the += operator on compatible data types. If you want to combine TensorCategory and TensorText objects, you may need to use a different operator or function that is specifically designed to work with those data types. Alternatively, you may need to convert one or both of the data types to a compatible format before performing the operation.