python - 值错误: Cannot create a tensor proto whose content is larger than 2GB

标签 python tensorflow machine-learning nlp word2vec

我正在使用此代码来训练新闻文章数据集。

https://github.com/borislavmavrin/stance-detection/blob/master/model_matchingLSTM_wdev.py

当我加载 GoogleNews word2vec 文件时,出现错误。

ValueError: Cannot create a tensor proto whose content is larger than 2GB.

堆栈跟踪从行 https://github.com/borislavmavrin/stance-detection/blob/master/model_matchingLSTM_wdev.py#L614 开始,

然后转到https://github.com/borislavmavrin/stance-detection/blob/master/model_matchingLSTM_wdev.py#L154

如有任何帮助,我们将不胜感激。我现在不想改变这段代码的结构,我现在只是更关注结果,因为这只是我想在这个数据集上做的原型(prototype)。如果结果足够好,我可能会编写自己的模型或改进现有模型。

最佳答案

将计算放在 CPU 上不会有帮助。这里的问题是tf.constant的实现涉及使用 Protocol Buffer 序列化值。后者的大小限制最多为 2GB。

一种解决方法是用占位符替换常量并将值输入 sess.run() .

您可以尝试的另一个选项是将常量分解为几个常量(拆分 numpy 数组并为每个部分创建一个 tf.constant )并使用 tf.concat 连接它们。 。这可以在本地完成,无需稍后提供占位符。

关于python - 值错误: Cannot create a tensor proto whose content is larger than 2GB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51244489/

相关文章:

python - 读取海量图像数据来训练分类器

python - 在 Tensorflow 中使用迭代器时如何正确设置 is_training

python - 将任何其他列附加到前三列

当文件具有相同名称时,Python 代码覆盖率缺失

tensorflow - 来自 Tensorflow 中 4-D 张量的 tf.nn.top_k 索引的二进制掩码?

python - 不能使用 TensorFlow 变量两次

python - TensorFlow 神经网络的输出不会改变

python - 从 Python (ctypes) 调试 C 库

Python 如何列出 python 函数的导入

python - LSTM 自动编码器的可变长度输入 - Keras