<jupyter_start><jupyter_text>Train and Validate<jupyter_code>import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Dropout, LSTM, Embedding, Activation, Lambda, Bidirectional
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split
import numpy as np
import gc
import pandas as pd
df = pd.read_csv("dna.csv")
def letter_to_index(letter):
    _alphabet = 'ATGC'
    return next((i for i, _letter in enumerate(_alphabet) if _letter == letter), None)
test_split = 0.1
maxlen = 150
df['sequence'] = df['sequence'].apply(lambda x: [int(letter_to_index(e)) for e in x])
df = df.reindex(np.random.permutation(df.index))
train_size = int(len(df) * (1 - test_split))
X_train = df['sequence'].values[:train_size]
y_train = np.array(df['target'].values[:train_size])
X_test = np.array(df['sequence'].values[train_size:])
y_test = np.array(df['target'].values[train_size:])
print('Average train sequence length: {}'.format(np.mean(list(map(len, X_train)), dtype=int)))
print('Average test sequence length: {}'.format(np.mean(list(map(len, X_test)), dtype=int)))
X_train, y_train, X_test, y_test = pad_sequences(X_train, maxlen=maxlen), y_train, pad_sequences(X_test, maxlen=maxlen), y_test
model = Sequential()
model.add(Embedding(input_dim = 4, output_dim = 50, input_length = X_train.shape[1], name='embedding_layer'))
model.add(Bidirectional(LSTM(62, return_sequences=True)))
model.add(Dropout(0.2))
model.add(Bidirectional(LSTM(62)))
model.add(Dropout(0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=100)
model.save("SAVED.h5")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14986072423398328, 'fraction_numerical': 0.012813370473537604, 'mean_word_length': 8.025125628140703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '514168', 'license': 'MIT', 'n_tokens_mistral': 658, 'n_tokens_neox': 632, 'n_words': 132, 'path': 'classify.ipynb', 'repo_name': 'Aishwarya-Prakash/BiDirectional-DNA-Classifier', 'size': '1795'}