<jupyter_start><jupyter_text>LSTM<jupyter_code>model_lstm = models.Sequential()
model_lstm.add(layers.Input(shape=max_len))
model_lstm.add(layers.Embedding(vocab_size, max_len))
model_lstm.add(layers.LSTM(256))
model_lstm.add(layers.Dense(outdim_size, activation='softmax'))
model_lstm.compile(loss=loss, optimizer=optimizer, metrics=metric)
model_lstm.summary()
train_model(model_lstm, 25)<jupyter_output>Epoch 1/25
1424/1425 [============================>.] - ETA: 0s - loss: 3.1720 - accuracy: 0.0999 - lr: 1.0000e-04 - sparse_top_k_categorical_accuracy: 0.2245
Epoch 00001: val_loss improved from inf to 2.89137, saving model to temp_weights.h5
1425/1425 [==============================] - 38s 27ms/step - loss: 3.1719 - accuracy: 0.1000 - lr: 1.0000e-04 - sparse_top_k_categorical_accuracy: 0.2246 - val_loss: 2.8914 - val_accuracy: 0.1645 - val_lr: 1.0000e-04 - val_sparse_top_k_categorical_accuracy: 0.3250
Epoch 2/25
1423/1425 [============================>.] - ETA: 0s - loss: 2.7221 - accuracy: 0.1967 - lr: 1.0000e-04 - sparse_top_k_categorical_accuracy: 0.3974
Epoch 00002: val_loss improved from 2.89137 to 2.63068, saving model to temp_weights.h5
1425/1425 [==============================] - 37s 26ms/step - loss: 2.7219 - accuracy: 0.1967 - lr: 1.0000e-04 - sparse_top_k_categorical_accuracy: 0.3975 - val_loss: 2.6307 - val_accuracy: 0.2216 - val_lr: 1.0000e-04 - val_sparse_top_k_categoric[...]<jupyter_text>Universal Sentence Decoder<jupyter_code>from tensorflow.keras import layers, applications, models, optimizers, losses, metrics, regularizers, callbacks
import tensorflow_hub as hub

# constant for model compile
loss_fn = losses.sparse_categorical_crossentropy
optimizer_fn = optimizers.RMSprop(learning_rate=0.0001)
metric_ls = ["accuracy", tf.keras.metrics.SparseTopKCategoricalAccuracy(3)]

def build_hubnet_text(text_base, trainable=False):
    model = models.Sequential()
    model.add(hub.KerasLayer(text_base, input_shape=[], dtype=tf.string, trainable=trainable))
    model.add(layers.Dense(outdim_size, activation="softmax"))

    model.compile(loss=loss_fn, optimizer=optimizer_fn, metrics=metric_ls)

    return model


model = build_hubnet_text("https://tfhub.dev/google/universal-sentence-encoder-large/5", False)
train_model(model, 25)<jupyter_output>Epoch 1/25
1425/1425 [==============================] - ETA: 0s - loss: 3.3291 - accuracy: 0.2011 - sparse_top_k_categorical_accuracy: 0.3731
Epoch 00001: val_loss improved from inf to 3.25353, saving model to temp_weights.h5
1425/1425 [==============================] - 69s 48ms/step - loss: 3.3291 - accuracy: 0.2011 - sparse_top_k_categorical_accuracy: 0.3731 - val_loss: 3.2535 - val_accuracy: 0.3418 - val_sparse_top_k_categorical_accuracy: 0.5567
Epoch 2/25
1425/1425 [==============================] - ETA: 0s - loss: 3.1846 - accuracy: 0.3906 - sparse_top_k_categorical_accuracy: 0.6107
Epoch 00002: val_loss improved from 3.25353 to 3.11438, saving model to temp_weights.h5
1425/1425 [==============================] - 63s 44ms/step - loss: 3.1846 - accuracy: 0.3906 - sparse_top_k_categorical_accuracy: 0.6107 - val_loss: 3.1144 - val_accuracy: 0.4189 - val_sparse_top_k_categorical_accuracy: 0.6419
Epoch 3/25
1425/1425 [==============================] - ETA: 0s - loss: 3.0506 - accuracy:[...]
{'fraction_non_alphanumeric': 0.19247115968427445, 'fraction_numerical': 0.12264723740133576, 'mean_word_length': 5.629778672032193, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '311568', 'license': 'MIT', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1212, 'n_words': 231, 'path': 'baseline only text.ipynb', 'repo_name': 'chandrakundu/BOOK-GENRE-CLASSIFICATION-BY-ITS-COVER-USING-MULTI-VIEW-LEARNING-APPROACH', 'size': '3294'}