- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用tensorflow实现了一个语言模型。训练数据只是 feed_dict
中的很多句子,如下所示:
feed_dict = {
model.inputs: x,
model.seqlen:seqlen
}
x
看起来像:
[[127713, 68665, 211766, 2698, 138657, 36122, 138963, 198149, 4975, 104939, 205505], [81512, 161790, 4191, 131922, 38206, 123973, 102593, 147631, 117256, 153046, 190414], [213013, 159996, 9461, 131922, 175230, 191825, 102593, 201242, 6535, 160687, 15960], [39155, 160687, 2236, 117259, 200449, 120265, 214117, 102593, 117198, 138657, 159996], [9959, 136465, 121296, 96619, 184509, 10843, 117256, 102593, 187463, 213648, 102593], [11370, 189417, 127691, 43487, 109775, 19315, 102593, 130793, 36122, 160023, 138657], [221903, 102593, 76854, 215208, 146459, 172190, 99562, 54144, 141328, 134798, 176905], [102593, 29004, 189417, 77559, 11370, 102593, 201121, 436, 127713, 85797, 71369], [67515, 90422, 141328, 102593, 222023, 107914, 155883, 102593, 148221, 169199, 36122], [205336, 11191, 127713, 115425, 147700, 152270, 80276, 143317, 4190, 2373, 24519], [61049, 144035, 219863, 54144, 111851, 104926, 117256, 182871, 10033, 188890, 102593], [97804, 95468, 72416, 178512, 56040, 190225, 169304, 214785, 127713, 106900, 32960], [220409, 11370, 117249, 213607, 89611, 34385, 117256, 198815, 49674, 94546, 37171], [179753, 176347, 160687, 32912, 72416, 189281, 203515, 44526, 190225, 160687, 189417], [49035, 165055, 100531, 102593, 187465, 6535, 174629, 175940, 208552, 124145, 42418], [136713, 67575, 193443, 24519, 0, 67515, 71905, 36122, 78050, 36122, 117492], [67575, 201558, 169304, 25531, 102593, 152308, 124145, 129101, 75544, 117256, 102593], [127713, 58045, 7814, 90422, 36130, 26354, 11370, 169304, 71048, 196602, 133966], [223954, 127713, 135835, 111851, 36122, 102593, 16398, 24622, 11370, 102593, 90879], [34539, 46136, 72416, 79125, 214125, 31507, 117256, 127713, 21687, 150290, 102593], [172081, 117256, 127713, 148704, 193249, 189417, 57754, 204591, 117256, 127713, 217441], [156885, 213648, 102593, 137549, 24519, 102593, 81722, 159996, 92404, 102593, 158063], [117256, 102593, 1481, 36122, 102593, 188983, 117249, 189417, 2698, 4190, 198149], [146627, 188890, 102593, 220327, 36122, 26266, 11370, 32603, 67575, 136465, 102593], [117249, 189417, 179882, 190414, 115744, 138657, 117249, 189417, 190225, 215006, 51726], [70710, 152185, 129802, 137980, 95640, 119899, 102593, 203527, 4191, 131922, 57303], [138657, 189417, 75401, 117256, 102593, 39587, 131922, 110117, 138657, 138963, 42664], [35145, 15678, 65575, 11370, 131922, 202552, 190414, 102593, 195413, 209716, 61049], [213218, 158064, 190414, 72416, 99562, 145256, 68055, 190414, 112808, 102593, 94655], [36117, 45024, 170008, 158664, 201179, 162247, 36117, 72039, 436, 63876, 210529], [121778, 11370, 169304, 51713, 72416, 160980, 100531, 102593, 187465, 127691, 160687], [196602, 190414, 115744, 152185, 117249, 211349, 190414, 198056, 152386, 219761, 212195], [106606, 127713, 34109, 154924, 119235, 36122, 127713, 133841, 114413, 102593, 195413], [161791, 163058, 49084, 99562, 98981, 160687, 11191, 127713, 116409, 117256, 102593], [49674, 144174, 189417, 127689, 222397, 36122, 161717, 436, 107573, 11370, 186602], [102593, 76854, 14223, 180403, 150708, 196787, 36117, 186602, 8374, 102593, 148453], [189417, 53675, 58648, 11370, 102593, 130984, 141328, 157511, 190414, 102593, 137453], [190786, 213013, 99562, 54144, 25531, 101525, 127222, 11370, 144108, 11370, 149922], [76179, 107914, 43486, 174088, 161609, 38367, 166913, 160687, 4188, 40566, 190414], [111186, 176905, 188890, 182871, 100952, 11370, 221875, 182871, 199204, 36117, 127713], [216479, 11370, 196787, 123973, 58648, 138657, 164316, 117256, 102593, 214093, 118878], [127689, 190225, 141334, 67575, 89207, 189281, 36166, 36122, 35179, 102593, 173841], [73827, 45780, 140996, 61049, 35145, 134798, 190414, 102593, 210662, 36122, 102593], [220833, 181338, 138657, 102593, 131688, 36122, 22599, 11370, 102593, 203636, 28886], [77513, 189417, 190414, 72416, 189281, 146384, 190414, 83835, 102593, 141940, 36122], [159996, 43486, 72416, 190414, 177756, 159391, 213648, 102593, 123641, 36122, 82016], [145098, 117249, 117247, 87334, 11370, 126458, 37923, 140495, 102593, 113303, 11370], [102593, 69762, 70104, 67575, 180545, 214125, 53255, 190414, 102593, 198785, 117249], [116408, 138657, 138963, 36122, 102593, 20362, 76179, 35145, 136290, 214125, 102593], [35406, 160687, 121032, 136465, 102593, 181712, 169923, 58974, 36117, 92968, 102593]]
我的模型代码:
import numpy as np
import tensorflow as tf
from tensorflow.python.ops import array_ops
class Model(object):
def __init__(
self,
batch_size,
vocab_size,
hidden_size,
learning_rate):
self.inputs = tf.placeholder(tf.int32, [batch_size, None])
self.seqlen = tf.placeholder(tf.float32)
with tf.device('/cpu:0'), tf.name_scope("embedding"):
# embed = tf.get_variable(name="Embedding", shape=[vocab_size, hidden_size])
embed = tf.Variable(
tf.random_uniform([vocab_size, hidden_size], -1.0, 1.0))
self.embedded_chars = tf.nn.embedding_lookup(embed, self.inputs)
self.rev_input = tf.reverse(self.inputs, [False,True])
self.embedded_chars_rev = tf.nn.embedding_lookup(embed, self.rev_input)
with tf.variable_scope('forward'):
forward_lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(hidden_size)
forward_outputs, _ = tf.nn.dynamic_rnn(forward_lstm_cell, self.embedded_chars,
sequence_length=self.seqlen,
dtype=tf.float32)
with tf.variable_scope('backward'):
backward_lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(hidden_size)
backward_outputs, _ = tf.nn.dynamic_rnn(backward_lstm_cell,
self.embedded_chars_rev,
sequence_length=self.seqlen,
dtype=tf.float32)
lstm_outputs = tf.add(forward_outputs, backward_outputs, name="lstm_outputs")
self.outputs = tf.nn.relu(lstm_outputs)
# W = tf.Variable(tf.truncated_normal([hidden_size,vocab_size, 1], -0.1, 0.1))
W = tf.get_variable('Weights', shape=[hidden_size, 1])
b = tf.get_variable('Bias', shape=[1])
outputs = self.outputs[:,1,:]
y_pred = tf.squeeze(tf.matmul(outputs, W)) + b
inputs_0 = tf.cast(self.inputs[:,0], tf.float32)
self.loss = tf.nn.sigmoid_cross_entropy_with_logits(y_pred, inputs_0)
self.train_op = tf.train.AdamOptimizer(0.0002).minimize(self.loss)
当我输入数据并运行时,发生错误:
Traceback (most recent call last):
File "h1_mscc/train_model.py", line 156, in <module>
tf.app.run()
File "/usr/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv))
File "h1_mscc/train_model.py", line 153, in main
train()
File "h1_mscc/train_model.py", line 143, in train
train_step(batch,seqlen)
File "h1_mscc/train_model.py", line 134, in train_step
feed_dict)
File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 372, in run
run_metadata_ptr)
File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 636, in _run
feed_dict_string, options, run_metadata)
File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 708, in _do_run
target_list, options, run_metadata)
File "/usr/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 728, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.InvalidArgumentError: indices[0,0] = 205505 is not in [0, 50000)
[[Node: embedding/embedding_lookup_1 = Gather[Tindices=DT_INT32, Tparams=DT_FLOAT, _class=["loc:@embedding/Variable"], validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](embedding/Variable/read, embedding/Reverse)]]
Caused by op u'embedding/embedding_lookup_1', defined at:
File "h1_mscc/train_model.py", line 156, in <module>
tf.app.run()
File "/usr/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv))
File "h1_mscc/train_model.py", line 153, in main
train()
File "h1_mscc/train_model.py", line 81, in train
model = create_model(sess)
File "h1_mscc/train_model.py", line 59, in create_model
learning_rate=FLAGS.learning_rate)
File "/home/liac/code/Project3-preprocess-master/h1_mscc/model1.py", line 24, in __init__
self.embedded_chars_rev = tf.nn.embedding_lookup(embed, self.rev_input)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 86, in embedding_lookup
validate_indices=validate_indices)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 780, in gather
validate_indices=validate_indices, name=name)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 704, in apply_op
op_def=op_def)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2260, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1230, in __init__
self._traceback = _extract_stack()
这让我很困惑,希望能得到一些回应!输入
最佳答案
嘿,你会不会把 vocab_size 定义错了? https://github.com/tensorflow/tensorflow/issues/2734
看起来可能是这样的问题。
多说一点,了解如何使用参数执行模型可能会有所帮助。
关于python - tensorflow.python.framework.errors.InvalidArgumentError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089598/
reqwest v0.9 将 serde v1.0 作为依赖项,因此实现 converting serde_json errors into reqwest error . 在我的代码中,我使用 se
我有这个代码: let file = FileStorage { // ... }; file.write("Test", bytes.as_ref()) .map_err(|e| Mu
我只是尝试用angular-cli创建一个新项目,然后运行服务器,但是它停止并显示一条有趣的消息:Error: No errors。 我以这种方式更新了(希望有帮助):npm uninstall -g
我从我的 javascript 发送交易 Metamask 打开传输对话框 我确定 i get an error message in metamask (inpage.js:1 MetaMask -
这个问题在这里已经有了答案: How do you define custom `Error` types in Rust? (3 个答案) How to get a reference to a
我想知道两者之间有什么大的区别 if let error = error{} vs if error != nil?或者只是人们的不同之处,比如他们如何用代码表达自己? 例如,如果我使用这段代码: u
当我尝试发送超过 50KB 的图像时,我在 Blazor 服务器应用程序上收到以下错误消息 Error: Connection disconnected with error 'Error: Serv
我有一个error-page指令,它将所有异常重定向到错误显示页面 我的web.xml: [...] java.lang.Exception /vi
我有这样的对象: address: { "phone" : 888, "value" : 12 } 在 WHERE 中我需要通过 address.value 查找对象,但是在 SQL 中有函数
每次我尝试编译我的代码时,我都会遇到大量错误。这不是我的代码的问题,因为它在另一台计算机上工作得很好。我尝试重新安装和修复,但这没有帮助。这是整个错误消息: 1>------ Build starte
在我的代码的类部分,如果我写一个错误,则在不应该的情况下,将有几行报告为错误。我将'| error'放在可以从错误中恢复的良好/安全位置,但是我认为它没有使用它。也许它试图在某个地方恢复中间表情? 有
我遇到了 csv 输入文件整体读取故障的问题,我可以通过在 read_csv 函数中添加 "error_bad_lines=False" 来删除这些问题来解决这个问题。 但是我需要报告这些造成问题的文
在 Spring 中,验证后我们在 controller 中得到一个 BindingResult 对象。 很简单,如果我收到验证错误,我想重新显示我的表单,并在每个受影响的字段上方显示错误消息。 因此
我不知道出了什么问题,因为我用 Java 编程了大约一年,从来没有遇到过这个错误。在一分钟前在 Eclipse 中编译和运行工作,现在我得到这个错误: #A fatal error has been
SELECT to_char(messages. TIME, 'YYYY/MM/DD') AS FullDate, to_char(messages. TIME, 'MM/DD
我收到这些错误: AnonymousPath\Anonymized.vb : error BC30037: Character is not valid. AnonymousPath\Anonymiz
我刚刚安装了 gridengine 并在执行 qstat 时出现错误: error: commlib error: got select error (Connection refused) erro
嗨,我正在学习 PHP,我从 CRUD 系统开始,我在 Windows 上安装了 WAMP 服务器,当我运行它时,我收到以下错误消息。 SCREAM: Error suppression ignore
我刚刚开始一个新项目,我正在学习核心数据教程,可以找到:https://www.youtube.com/watch?v=zZJpsszfTHM 我似乎无法弄清楚为什么会抛出此错误。我有一个名为“Exp
当我使用 Jenkins 运行新构建时,出现以下错误: "FilePathY\XXX.cpp : fatal error C1853: 'FilePathZ\XXX.pch' precompiled
我是一名优秀的程序员,十分优秀!