Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niranjanneeru/0070fd6e8092301bd9f49be3a3c2f836 to your computer and use it in GitHub Desktop.
Save niranjanneeru/0070fd6e8092301bd9f49be3a3c2f836 to your computer and use it in GitHub Desktop.
sentences = df['review']
labels = np.array(df['sentiment'].map(lambda x: 1 if x == 'positive' else 0))
@niranjanneeru
Copy link
Author

training_sentences, testing_sentences, training_labels, testing_labels = train_test_split(sentences, labels, test_size=test_size, shuffle=False, random_state=42)

@niranjanneeru
Copy link
Author

tokenizer = Tokenizer(num_words=vocab_size, oov_token=oov_tok)
tokenizer.fit_on_texts(training_sentences)

word_index = tokenizer.word_index

@niranjanneeru
Copy link
Author

training_sequences = tokenizer.texts_to_sequences(training_sentences)
training_padded = pad_sequences(training_sequences, maxlen=max_length, padding=padding_type, truncating=trunc_type)

testing_sequences = tokenizer.texts_to_sequences(testing_sentences)
testing_padded = pad_sequences(testing_sequences, maxlen=max_length, padding=padding_type, truncating=trunc_type)

@niranjanneeru
Copy link
Author

model = tf.keras.Sequential([
tf.keras.layers.Embedding(input_dim=vocab_size, output_dim=embedding_dim, input_length=max_length),
tf.keras.layers.GlobalAveragePooling1D(),
tf.keras.layers.Dense(1, activation='sigmoid')
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment