Advertisement
Guest User

Untitled

a guest
May 25th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import nltk
  2.  
  3. def decode_review(review):
  4.     tokens = ['<START>'] + nltk.tokenize.wordpunct_tokenize(review)
  5.     indices = np.array([word_index[word] if (word in word_index and word_index[word] < 10000) else word_index['<UNK>'] for word in tokens])
  6.     return indices
  7.    
  8.  
  9. review = "This isn't just a beautifully crafted gangster film. Or an outstanding family portrait, for that matter. An amazing period piece. A character study. A lesson in filmmaking and an inspiration to generations of actors, directors, screenwriters and producers. For me, this is more: this is the definitive film. 10 stars out of 10."
  10.  
  11. indices = decode_review(review)
  12.  
  13. sequence = keras.preprocessing.sequence.pad_sequences([indices],
  14.                                                       value=word_index["<PAD>"],
  15.                                                       padding='post',
  16.                                                       maxlen=256)
  17.  
  18. model.predict_proba(sequence)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement