Experiment 3 (D, E) (Embedding) (Plotting) PDF
Experiment 3 (D, E) (Embedding) (Plotting) PDF
PROGRAM:
import tensorflow as tf
# Parameters
maxlen = 500 # Only consider the first 500 words of each review
model = Sequential()
model.add(Embedding(input_dim=vocab_size, output_dim=embedding_dim,
input_length=maxlen))
model.summary()
/usr/local/lib/python3.10/dist-packages/keras/src/layers/core/embedding.py:90:
UserWarning: Argument `input_length` is deprecated. Just remove it.
warnings.warn(
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━
━━━━┓
┃ Layer (type) ┃ Output Shape ┃
Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━
━━━━┩
│ embedding (Embedding) │ ? │ 0
(unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────
────┤
│ simple_rnn (SimpleRNN) │ ? │ 0
(unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────
────┤
│ dense (Dense) │ ? │ 0
(unbuilt) │
└──────────────────────────────────────┴─────────────────────────────┴─────────────
────┘
Total params: 0 (0.00 B)
Epoch 1/3
Epoch 2/3
Epoch 3/3
PROGRAM:
import tensorflow as tf
# Parameters
maxlen = 500 # Only consider the first 500 words of each review
model = Sequential()
model.add(Embedding(input_dim=vocab_size, output_dim=embedding_dim,
input_length=maxlen))
model.add(Dense(1, activation='sigmoid'))
model.summary()
plt.figure(figsize=(12, 4))
plt.title('Model Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend(loc='upper left')
plt.subplot(1, 2, 2)
plt.title('Model Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()
OUTPUT:
/usr/local/lib/python3.10/dist-packages/keras/src/layers/core/embedding.py:90:
UserWarning: Argument `input_length` is deprecated. Just remove it warnings.warn(
Model: "sequential"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━
━━━━┓
┃ Layer (type) ┃ Output Shape ┃
Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━
━━━━┩
│ embedding (Embedding) │ ? │ 0
(unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────
────┤
│ simple_rnn (SimpleRNN) │ ? │ 0
(unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────
────┤
│ dense (Dense) │ ? │ 0
(unbuilt) │
└──────────────────────────────────────┴─────────────────────────────┴─────────────
────┘
Total params: 0 (0.00 B)
Epoch 1/3
Epoch 2/3
Epoch 3/3
313/313 ━━━━━━━━━━━━━━━━━━━━ 82s 208ms/step - accuracy: 0.7773 - loss:
0.4860 - val_accuracy: 0.8114 - val_loss: 0.4508