- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我当时正在 Tensor Flow 中实现词袋,并获得了
TypeError: 'Mul' Op 的输入 'y' 的 float32 类型与参数 'x' 的 int32 类型不匹配。
在 tf.nn.nce_loss 中。我尝试查看进入 tf.nn.nce_loss 的类型并尝试强制它们无济于事。任何帮助,将不胜感激。我在 jupyter notebook 中使用 python 工作。
包含数据拉取的完整代码可在 https://gist.github.com/gammaguy/683a1357fdb044d0abbd897a7179d525 获得。
graph = tf.Graph()
with graph.as_default():
# Input data.
train_inputs = tf.placeholder(tf.int32,shape=[batch_size, skip_window * 2],name="train_inputs")
train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1],name="train_labels")
valid_dataset = tf.constant(valid_examples, dtype=tf.int32,name="valid_dataset")
# train_inputs = tf.placeholder(tf.int32,shape=[batch_size, skip_window * 2],name="train_inputs")
# train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1],name="train_labels")
# valid_dataset = tf.constant(valid_examples, dtype=tf.int32,name="valid_dataset")
with tf.device('/cpu:0'):
# Look up embeddings for inputs.
embeddings = tf.Variable(
tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0),name="embeddings")
# Embedding size is calculated as shape(train_inputs) + shape(embeddings)[1:]
embed = tf.nn.embedding_lookup(embeddings, train_inputs,name="embed")
reduced_embed = tf.div(tf.reduce_sum(embed, 1), skip_window*2,name="reduced_embed")
# Construct the variables for the NCE loss
nce_weights = tf.Variable(
tf.truncated_normal([vocabulary_size, embedding_size],
stddev=1.0 / math.sqrt(embedding_size)),name="nce_weights")
nce_biases = tf.Variable(tf.zeros([vocabulary_size]),name="nce_biases")
print(train_inputs)
print(train_labels)
print(valid_dataset)
print(embeddings)
print(embed)
print(reduced_embed)
print(nce_weights)
print(nce_biases)
print(num_sampled)
print(vocabulary_size)
# Compute the average NCE loss for the batch.
# tf.nce_loss automatically draws a new sample of the negative labels each
# time we evaluate the loss.
loss = tf.reduce_mean(
tf.nn.nce_loss(nce_weights, nce_biases, reduced_embed, train_labels,
num_sampled, vocabulary_size))
Tensor("train_inputs:0", shape=(128, 2), dtype=int32)
Tensor("train_labels:0", shape=(128, 1), dtype=int32)
Tensor("valid_dataset:0", shape=(16,), dtype=int32)
<tf.Variable 'embeddings:0' shape=(82297, 128) dtype=float32_ref>
Tensor("embed:0", shape=(128, 2, 128), dtype=float32, device=/device:CPU:0)
Tensor("reduced_embed:0", shape=(128, 128), dtype=float32, device=/device:CPU:0)
<tf.Variable 'nce_weights:0' shape=(82297, 128) dtype=float32_ref>
<tf.Variable 'nce_biases:0' shape=(82297,) dtype=float32_ref>
64
82297
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
490 as_ref=input_arg.is_ref,
--> 491 preferred_dtype=default_dtype)
492 except TypeError as err:
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype)
703 if ret is None:
--> 704 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
705
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in _TensorTensorConversionFunction(t, dtype, name, as_ref)
576 "Tensor conversion requested dtype %s for Tensor with dtype %s: %r"
--> 577 % (dtype.name, t.dtype.name, str(t)))
578 return t
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("nce_loss/Reshape_1:0", shape=(?, 1, ?), dtype=float32)'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-7-55d5813d0e24> in <module>()
42 loss = tf.reduce_mean(
43 tf.nn.nce_loss(nce_weights, nce_biases, reduced_embed, train_labels,
---> 44 num_sampled, vocabulary_size))
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/ops/nn_impl.py in nce_loss(weights, biases, labels, inputs, num_sampled, num_classes, num_true, sampled_values, remove_accidental_hits, partition_strategy, name)
1164 remove_accidental_hits=remove_accidental_hits,
1165 partition_strategy=partition_strategy,
-> 1166 name=name)
1167 sampled_losses = sigmoid_cross_entropy_with_logits(
1168 labels=labels, logits=logits, name="sampled_losses")
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/ops/nn_impl.py in _compute_sampled_logits(weights, biases, labels, inputs, num_sampled, num_classes, num_true, sampled_values, subtract_log_q, remove_accidental_hits, partition_strategy, name)
999 row_wise_dots = math_ops.multiply(
1000 array_ops.expand_dims(inputs, 1),
-> 1001 array_ops.reshape(true_w, new_true_w_shape))
1002 # We want the row-wise dot plus biases which yields a
1003 # [batch_size, num_true] tensor of true_logits.
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py in multiply(x, y, name)
276
277 def multiply(x, y, name=None):
--> 278 return gen_math_ops._mul(x, y, name)
279
280
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py in _mul(x, y, name)
1432 A `Tensor`. Has the same type as `x`.
1433 """
-> 1434 result = _op_def_lib.apply_op("Mul", x=x, y=y, name=name)
1435 return result
1436
/home/paul/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
525 "%s type %s of argument '%s'." %
526 (prefix, dtypes.as_dtype(attrs[input_arg.type_attr]).name,
--> 527 inferred_from[input_arg.type_attr]))
528
529 types = [values.dtype]
TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'.
最佳答案
nce_loss(
weights,
biases,
labels,
inputs,
num_sampled,
num_classes,
num_true=1,
sampled_values=None,
remove_accidental_hits=False,
partition_strategy='mod',
name='nce_loss'
)
用 train_labels
交换 reduced_embed
。
关于python - 在 Tensorflow tf.nn.nce_loss 中得到 TypeError : Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43786994/
我正在使用 React Native 构建移动应用程序。我面临 Nativ Base Toast 问题。当我第一次加载应用程序然后导航到工单状态时,如果我返回带有 android 后退按钮的主页,则会
我正在尝试创建一个“完美的滚动条”,它是这样的:。Https://github.com/noraesae/perfect-scrollbar-bower。使用尽可能简单的代码:。我犯了以下错误:。当然
我正在尝试在简单的 Draftjs 编辑器上应用自定义装饰器: import React from 'react'; import {Editor, EditorState, RichUtils} f
读取以钟形字符作为分隔符的CSV文件时,出现类型错误。我不想使用熊猫,我需要使用CSV库来解决这个问题。。示例标题:。数据类型。样本数据:。示例代码。我明白这个错误-。铃声字符参考-https://w
我正在处理 useSelector的 react-redux在我的 React Native 应用程序中,我收到以下错误: TypeError: TypeError: (0, _reactRedux.
当我用 Node 运行以下代码时: var command = "/home/myScript.sh"; fs.exists(command, function(exists){ if(exi
我正在为我的一个组件编写测试用例,该组件具有路由器(使用 withrouter)。我收到错误 wrapper.find is not a function。基本要求是需要检查我的渲染中是否存在标签,还
我一直在研究一个简单的表单提交。首先,我想在提交表单之前创建一个模式警报。于是,我使用了bootstrap的modal函数,反复得到 TypeError: $(...).modal is not a
这个问题在这里已经有了答案: Flask-Login raises TypeError: 'bool' object is not callable when trying to override
这是我在leetcode中遇到的问题。您将看到两个非空链接表,表示两个非负整数。数字以相反的顺序存储,并且它们的每个节点都包含一个数字。将这两个数字相加,然后以链表的形式返回总和。。你可以假设这两个数
我正在尝试学习Python,并试图将GitHub问题变成一种可读的形式。根据关于如何将JSON转换为CSV的建议,我得出了以下结论:。其中“Issues.json”是包含GitHub问题的JSON文件
我在使用 Proxy 类时遇到了这个有趣的错误: TypeError: 'set' on proxy: trap returned truish for property 'users' which
在研究Jupyter笔记本电脑时,我遇到了这个问题:。这是代码开始的地方:。下面的代码是在jupyter笔记本的另一个单元上运行的。我怎么才能解决它呢?。尝试更改参数和一系列其他内容,但所有这些都弹出
Working on jupyter notebooks, I came across this problem:在研究Jupyter笔记本电脑时,我遇到了这个问题: TypeError:un
我对此很陌生(对于 Jasmine 测试、ExtJs 和 JS 来说确实很陌生),我必须修复这个错误/错误。我正在运行一些单元测试,但不断收到以下错误: TypeError: object is no
在下面的文档中,我们可以不使用JupyterDash在笔记本中运行应用程序,而只需运行app.run(jupyter_mode=“外部”)。。Https://dash.plotly.com/dash-
导入地理位置时: import { Geolocation } from '@ionic-native/geolocation/ngx'; 获取错误: ionic Geolocation :Ionic
我定义了以下函数: def eigval(matrix): a = matrix[0, 0] b = matrix[0, 1] c = matrix[1, 0] d =
刚刚获得了SDXL模型的访问权限,希望为即将发布的版本进行测试...不幸的是,我们当前用于我们服务的代码似乎不能与稳定ai/稳定-扩散-xl-base-0.9一起工作,我不完全确定SDXL有什么不同,
这是我的全部代码。我试图通过/insta/:id在我的page.ejs页面上查找,但它显示错误:。无法读取未定义的属性(正在读取‘UserName’)。。我希望获得uuidv4()将提供的id,但它返
我是一名优秀的程序员,十分优秀!