寻找一些指南来选择 Keras 词嵌入层的维度。例如在简化的电影评论分类代码中:
# NN layer params
MAX_LEN = 100 # Max length of a review text
VOCAB_SIZE = 10000 # Number of words in vocabulary
EMBEDDING_DIMS = 50 # Embedding dimension - number of components in word embedding vector
text_model = tf.keras.Sequential([
tf.keras.layers.Embedding(input_length=MAX_LEN,input_dim=VOCAB_SIZE,
output_dim=EMBEDDING_DIMS),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(6, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
text_model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
在这个例子中嵌入向量有 50 个分量。在 17500 上训练并在 5625 条评论上测试此模型报告:
precision recall f1-score support
0 0.87 0.86 0.87 2802
1 0.87 0.88 0.87 2823
accuracy 0.87 5625
macro avg 0.87 0.87 0.87 5625
weighted avg 0.87 0.87 0.87 5625
对于 10 甚至 2 维,我在分类报告中得到相似的值!
那么在选择词嵌入向量维度时,真正起作用的指导原则是什么?何时选择 50、10,100、200、...等尺寸?