MLDZ

Untitled

May 15th, 2021
563
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def predict(text):
  2.     model = TestNeuroConfig.loaded_model
  3.     d = keras.datasets.imdb.get_word_index()
  4.     words = text.split()
  5.     review = []
  6.     for word in words:
  7.         if word not in d:
  8.             review.append(2)
  9.         else:
  10.             review.append(d[word] + 3)
  11.  
  12.     review = keras.preprocessing.sequence.pad_sequences([review],
  13.                                                         truncating='pre', padding='pre', maxlen=10000)
  14.     prediction = model.predict(review)
  15.     print("Prediction (0 = negative, 1 = positive) = ", end="")
  16.     print("%0.4f" % prediction[0][0])
  17.     return prediction[0][0]
RAW Paste Data