使用预训练词嵌入训练 CNN 非常慢 (TensorFlow)

Training a CNN with pre-trained word embeddings is very slow (TensorFlow)

我正在使用 TensorFlow (0.6) 在文本数据上训练 CNN。我使用的方法类似于 (with the exception that the embeddings are trainable). My dataset is pretty small and the vocabulary is around 12,000 words. When I train using random word embeddings everything works nicely. However, when I switch to the pre-trained embeddings from the word2vec site 中指定的第二个选项,词汇量增长到超过 3,000,000 个单词,训练迭代速度变慢 100 多倍。我也看到了这个警告:

UserWarning: Converting sparse IndexedSlices to a dense Tensor with 900482700 elements

我看到了关于 this TensorFlow issue 的讨论,但我仍然不确定我遇到的减速是否是预料之中的,或者这是一个错误。我正在使用 Adam 优化器,但它与 Adagrad 几乎相同。

我想我可以尝试的一种解决方法是使用数据集中只有约 12,000 个单词的最小嵌入矩阵进行训练,序列化生成的嵌入,并在运行时将它们与预训练嵌入中的剩余单词合并。我认为这应该可行,但听起来很老套。

这是目前最好的解决方案还是我遗漏了什么?

所以这里有两个问题:

  1. 正如 mrry 在他对问题的评论中指出的那样,警告不是更新期间转换的结果。相反,我正在计算嵌入梯度的汇总统计数据(稀疏性和直方图),这导致了转换。
  2. 有趣的是,删除摘要使消息消失,但代码仍然很慢。根据 the TensorFlow issue referenced in the question,我还必须将 AdamOptimizer 替换为 AdagradOptimizer,一旦我这样做,运行时间就回到了从小词汇量获得的运行时间。