Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save saimadhu-polamuri/1847e7d63eb75d2cf6df760597039764 to your computer and use it in GitHub Desktop.

Select an option

Save saimadhu-polamuri/1847e7d63eb75d2cf6df760597039764 to your computer and use it in GitHub Desktop.
# Tokenize text and create word-to-index mapping
tokenizer = tf.keras.preprocessing.text.Tokenizer()
tokenizer.fit_on_texts(data["preprocessed_text"])
sequences = tokenizer.texts_to_sequences(data["preprocessed_text"])
padded_sequences = tf.keras.preprocessing.sequence.pad_sequences(sequences, maxlen=max_length)
# Create training data
X_train, X_val, y_train, y_val = train_test_split(padded_sequences, padded_sequences, test_size=0.2, random_state=42)
# Train the model
history = model.fit(X_train, y_train, epochs=10, batch_size=32, validation_data=(X_val, y_val))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment