- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写 this 的实现我在 TensorFlow 的论文中遇到了一些障碍。在我的池化层中,我必须将所有内容连接在一起。这是我使用的代码:
pooled_outputs = []
for i, filter_size in enumerate(filter_sizes):
with tf.name_scope("conv-maxpool-%s" % filter_size):
# Conv layer
filter_shape = [filter_size, embedding_size, 1, num_filters]
# W is the filter matrix
W = tf.Variable(tf.truncated_normal(filter_shape, stddev=0.1), name="W")
b = tf.Variable(tf.constant(0.1, shape=[num_filters]), name="b")
conv = tf.nn.conv2d(
self.embedded_chars_expanded,
W,
strides=[1, 1, 1, 1],
padding="VALID",
name="conv"
)
# Apply nonlinearity
h = tf.nn.relu(tf.nn.bias_add(conv, b), name="relu")
# Max-pooling layer over the outputs
pooled = tf.nn.max_pool(
h,
ksize=[1, sequence_lengths[i] - filter_size + 1, 1, 1],
strides=[1, 1, 1, 1],
padding="VALID",
name="pool"
)
pooled_outputs.append(pooled)
# Combine all of the pooled features
num_filters_total = num_filters * len(filter_sizes)
print(pooled_outputs)
pooled_outputs = [tf.reshape(out, ["?", 94, 1, self.max_length]) for out in pooled_outputs] # The problem line
self.h_pool = tf.concat(3, pooled_outputs)
当我运行此代码时,它会为 pooled_outputs
打印出以下内容:
[<tf.Tensor 'conv-maxpool-3/pool:0' shape=(?, 94, 1, 128) dtype=float32>, <tf.Tensor 'conv-maxpool-4/pool:0' shape=(?, 51, 1, 128) dtype=float32>, <tf.Tensor 'conv-maxpool-5/pool:0' shape=(?, 237, 1, 128) dtype=float32>]
我最初尝试这段代码时没有使用 pooled_outputs = [tf.reshape(out, ["?", 94, 1, self.max_length]) for out in pooled_outputs]
行,我收到此错误:
ValueError: Dimension 1 in both shapes must be equal, but are 51 and 237
当我添加 reshape 线时,出现此错误:
TypeError: Expected binary or unicode string, got 94
我知道的第二个错误是因为我传递了一个“?”对于新的大小,我认为第一个错误是因为张量大小不同。 我怎样才能正确地填充这些张量,以便我可以毫无问题地连接它们?
最佳答案
您可以将 -1
作为形状的组成部分之一传递给 tf.reshape
方法;它将根据张量的形状自动推断,因此总大小将相同。
所以,尝试将问题行更改为
pooled_outputs = [tf.reshape(out, [-1, 94, 1, self.max_length]) for out in pooled_outputs]
请参阅documentation了解详情
关于python - 如何连接 "Jagged"张量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41797136/
每次我使用 jags() 函数运行我的 JAGS 模型时,我都会得到非常不同的拟合参数值。但是,我希望其他人重现我的结果。 我尝试添加 set.seed(123),但没有帮助。 This link描述
是否有颜色突出显示锯齿和错误模型文件的软件包?我安装了 ESS,但它似乎无法识别开箱即用的 .bug 文件或 jags/bugs 语法。 最佳答案 语法高亮 我正在使用 ESS 5.14(来自 ELP
我正在尝试在 JAGS 中运行一个二项式-beta 模型(参见下面的示例代码)。我不断收到错误:错误:尝试运行 JAGS 模型时遇到以下错误: Error in node a0 Slicer stuc
我正在尝试在 JAGS 中运行一个二项式-beta 模型(参见下面的示例代码)。我不断收到错误:错误:尝试运行 JAGS 模型时遇到以下错误: Error in node a0 Slicer stuc
我正在尝试在 JAGS 中执行此操作: z[l] ~ dbeta(0.5,0.5) y[i,l] ~ z[l]*dnorm(0,10000) + inprod(1-z[l],dnegbin(exp(e
我正在尝试使用 Mark the Ballot 的一段 jags 代码复制模拟,但是 jags 向我发送了一条错误消息.. 如果我理解正确,它应该在为某个地方的每一方索引房屋效应时出现问题,但我无法找
我正在尝试使用指数作为响应 (D47)、温度作为预测变量 (Temp) 并考虑离散变量( Material )的随机效应来对贝叶斯回归建模。我找到了关于非层次回归的非常好的信息,一些帖子甚至包括这些模
考虑以下数据框: set.seed(5678) sub_df% select(-1) %>% mutate(clustersize = as.integer(clustersize),
我正在使用 rJAGS 构建多级贝叶斯模型,并且我想为我的几个参数指定柯西先验。有没有办法在 JAGS 中做到这一点,或者我需要切换到 STAN 吗?我的 JAGS 模型如下。我想用柯西分布替换 dn
我正在尝试在使用 GPFS 作为其文件系统的集群上构建和安装 JAGS。我遇到了配置脚本的问题: ./configure --prefix=$HOME/JAGS/ --with-lapack=/cm/
想象一个基础过程,它从概率为 $\alpha$ 的正态分布和概率为 $1 -\alpha$ 的均匀分布中抽取数字。因此,观察到的由该过程生成的数字序列遵循 $f$ 分布,它是 2 个分量 的混合 和
我正在使用 dirlichet 分布在 JAGS 中拟合多变量模型。我有一个包含 3 个物种比例丰度的矩阵 y。 #generate 3 columns of species proprotional
完整数据集包含约 11,000 行。我一直在使用 K=400 运行代码,同时检查代码是否运行。 所有行都与 map 上的特定单元格相关,并包含从 Sentinel-2 图像和数字高程图中提取的信息。
我是 JAGS 的新手,我正在尝试运行一个简单的逻辑回归。我的数据文件非常简单:响应是二进制的,我使用的一个预测器具有三个级别。像这样: col1: 1 2 2 2 1 1 1 2 1 2 ... c
我正在尝试在 JAGS 中拟合逻辑回归模型,但我的数据形式为(#success y,#尝试 n),而不是二进制变量。在 R 中,可以通过使用带有“权重”参数的 glm(y/n ~) 将模型拟合到诸如此
假设我们使用 JAGS(或 WinBUGS)拟合贝叶斯线性混合模型,输出对象是否包括模型残差?我们怎样才能找到残差? 谢谢! 最佳答案 JAGS (BUGS) 模型只是输出您让它监控的模型中的节点值。
我正在使用 Kruschke 描述的分层建模框架在 JAGS 中建立两个模型之间的比较。该框架的想法是通过将每个版本指定为分类变量的一个级别来运行和比较模型的多个版本。该分类变量的后验分布可以解释为各
我正在使用 zeros-ones 技巧将计数数据拟合到 JAGS 中的广义泊松分布。我遵循“使用 WinBUGS 进行贝叶斯建模”一书中的代码(第 286 页)。这是我的代码: GPoisson.mo
我试图在 R 中调用以下 jags 模型: model{ # Main model level 1 for (i in 1:N){ ficon[i] ~ dnorm(mu[i], ta
这是对 SE 早期帖子的一种跟进:https://stats.stackexchange.com/questions/70858/right-censored-survival-fit-with-ja
我是一名优秀的程序员,十分优秀!