python - 在 Python 中使用预训练嵌入层时的高精度测量
问题描述
我正在尝试使用 GloVe 在我的生成模型中实现一个预训练的嵌入层。
在模型中,我输入从文本中提取的 50 (X) 个项目的序列,并预测文本中的 51. 单词 (y)。
当模型只训练了 1/100 次迭代时,我已经达到了 0.99 的准确度。可能是什么问题?
# create a weight matrix for words in training docs
embedding_matrix = zeros((vocab_size, 100))
for word, i in tokenizer.word_index.items():
embedding_vector = embeddings_index.get(word)
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
# define model
model = Sequential() #assigning the sequential function to a model
model.add(Embedding(vocab_size, 100, weights=[embedding_matrix], input_length=seq_length, trainable = False)) #defining embedding layer size
model.add(LSTM(100, return_sequences=True)) #adding layer of nodes
model.add(LSTM(100)) #adding layer of nodes
model.add(Dense(100, activation='relu')) #specifying the structure of the hidden layer, recu is an argument of a rectified linear unit.
model.add(Dense(vocab_size, activation='softmax')) #using the softmax function to creating probabilities
print(model.summary())
# compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# fit the model
model.fit(X, y, batch_size=128, epochs=100, verbose=1)
链接到 github:https ://github.com/KiriKoppelgaard/Generative_model 从 2018 年 11 月 14 日提交
解决方案
推荐阅读
- python - 将 Keras 模型导出为 TF Estimator:找不到经过训练的模型
- macos - 在 macOS 上重定向端口和 ip
- javascript - 如何在 html 5 画布上使用 FontAwesome 图标
- javascript - Req.Body 未定义 NODE.JS POST 请求
- node.js - 如果阻塞操作被异步处理并导致阻塞进程队列,那么异步编程如何加快速度?
- visual-studio - 如何在不卸载的情况下将 Visual Studio 2017 更新 15.9 降级到 15.5
- lockbox-3 - 使用 TurboPower LickBox 从 p7m 文件中提取内容
- c# - 填充模型中的角色
- angular - 我应该以什么格式将购物车数据存储在本地存储中
- yii2 - Git 实验室准备 CI 脚本以自动部署到 yii2 中的服务器?