Exception Value: only integer tensors of a single element can be converted to an index

I am trying to predict the sentiment of a sentence by using learn.predict(message). But I am getting the following error -

  1.     result_test = learn.predict(message)
    

File “/usr/local/lib/python3.7/site-packages/fastai/basic_train.py” in predict
382. y = ds.y.reconstruct(pred, x) if has_arg(ds.y.reconstruct, ‘x’) else ds.y.reconstruct(pred)

File “/usr/local/lib/python3.7/site-packages/fastai/text/data.py” in reconstruct
341. return Text(t[idx_min:idx_max+1], self.vocab.textify(t[idx_min:idx_max+1]))

File “/usr/local/lib/python3.7/site-packages/fastai/text/transform.py” in textify
134. return sep.join([self.itos[i] for i in nums]) if sep is not None else [self.itos[i] for i in nums]

File “/usr/local/lib/python3.7/site-packages/fastai/text/transform.py” in
134. return sep.join([self.itos[i] for i in nums]) if sep is not None else [self.itos[i] for i in nums]

Exception Type: TypeError at /test_sent/
Exception Value: only integer tensors of a single element can be converted to an index

Can someone please help me with this?

@muellerzr @sgugger Can you please help me with this?

I’m running into this same issue, running through lesson7-human-numbers (unchanged) in course-v3 and add learn.predict("three").

1 Like

Please let me know if you have found a way to fix this.

I tried pred_batch(). It works but the results are not the same.

@sgugger @muellerzr Any inputs on this please?

Were you able to solve this error??