【问题标题】:Converting sparse IndexedSlices to a dense Tensor将稀疏 IndexedSlices 转换为密集张量
【发布时间】:2018-01-31 05:13:03
【问题描述】:

我收到以下警告:

94: UserWarning: Converting sparse IndexedSlices to a dense Tensor with 1200012120 elements. This may consume a large amount of memory.

对于以下代码:

from wordbatch.extractors import WordSeq
import wordbatch
from keras.layers import Input,Embedding
...
wb = wordbatch.WordBatch(normalize_text, extractor=(WordSeq, {"seq_maxlen": MAX_NAME_SEQ}), procs=NUM_PROCESSOR)
wb.dictionary_freeze = True
full_df["ws_name"] = wb.fit_transform(full_df["name"])
...
name = Input(shape=[full_df["name"].shape[1]], name="name")
emb_name = Embedding(MAX_TEXT, 50)(name)
...

也就是说,我使用了 GRU 网络嵌入层的 WordSeq(来自 WordBatch)输出。我应该如何修改代码以使其在不转换为密集张量的情况下工作?

【问题讨论】:

  • 你修过吗?

标签: tensorflow keras word-embedding gated-recurrent-unit


【解决方案1】:

我在 Keras 中的嵌入层遇到了同样的问题。 The solution 是显式使用 TensorFlow 优化器,如下所示:

model.compile(loss='mse', optimizer=TFOptimizer(tf.train.GradientDescentOptimizer(0.1)))

【讨论】:

  • 在我的测试中没有解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 2018-06-20
  • 2018-11-12
  • 2017-05-10
  • 1970-01-01
  • 2017-02-11
  • 2017-07-29
相关资源
最近更新 更多