1
This is my predictive array which i have calculated separately
model.predict(x_test) 
array([[0.53189766, 0.5206426 , 0.5028406 ],
      [0.49872813, 0.49236214, 0.46486002],
      [0.5356784 , 0.6017476 , 0.46934658],
       ...,
      [0.5134366 , 0.50351447, 0.5025247 ],
      [0.5107351 , 0.5409793 , 0.5059488 ],
      [0.47921842, 0.4638722 , 0.50206804]], dtype=float32) 

Now when I am trying to make a function where it will show the 'positive', 'negative', 'neutral' it is giving me more than one element is ambiguous error

def preprocess(text):
  review=re.sub('@\S+|https?:\S+|http?:\S|[^A-Za-z0-9]+',' ',text)
  review=review.lower()
  review=review.split()
  review=[word for word in review if not word in stop_words]
  print(review)
  review=pad_sequences(tokenizer.texts_to_sequences([review]), maxlen=300)
  return review 

def prediction(review):
  review=preprocess(review)
  score=model.predict(review)
  score=score[0]
  if score<0.4:
    print("Negative")
  elif score>0.4 and score<0.6:
    print("Neutral")
  else:
    print("Positive")
  print(score)

prediction("the food is not bad")


this is my error code-
['food', 'bad']
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-91-b47bdbfca359> in <module>()
----> 1 prediction("the food is not bad")

<ipython-input-90-1974b824c005> in prediction(review)
  3     score=model.predict(x_test)
  4     score=score[0]
----> 5     if score<0.4:
  6         print("Negative")
  7     elif score>0.4 and score<0.6:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

AMC
  • 2,642
  • 7
  • 13
  • 35
Parth Dhir
  • 21
  • 3

0 Answers0