[QUESTION] Chapter 16 - NLP - Sentiment Analysis - TensorFlow Hub
marcelorromano opened this issue · 0 comments
marcelorromano commented
Hello,
My question refers to chapter 16 (NLP - Sentiment Analysis - TensorFlow Hub)
I didn't get why the authors changed the network architeture, using a dense layer after the embedding, instead of using a GRU:
import tensorflow_hub as hub
model = keras.Sequential([
hub.KerasLayer("https://tfhub.dev/google/tf2-preview/nnlm-en-dim50/1",
dtype=tf.string, input_shape=[], output_shape=[50]),
keras.layers.Dense(128, activation="relu"),
keras.layers.Dense(1, activation="sigmoid")
])
model.compile(loss="binary_crossentropy", optimizer="adam",
metrics=["accuracy"])
The accuracy was lower (0.7560) compared to the previous model.
So I tried to keep the architecture (see below), but the accuracy did not improve. Am I missing something? I thought the accuracy should be better than the previous model, because the embedding has been trained with many more words than the previous model.
import tensorflow_hub as hub
model = keras.Sequential([
hub.KerasLayer("https://tfhub.dev/google/tf2-preview/nnlm-en-dim50/1",
dtype=tf.string, input_shape=[], output_shape=[50]),
keras.layers.Reshape((-1, 50)),
keras.layers.GRU(128, return_sequences=True),
keras.layers.GRU(128),
keras.layers.Dense(1, activation="sigmoid")
])
model.compile(loss="binary_crossentropy", optimizer="adam",
metrics=["accuracy"])