1

我正在尝试将两层合并在一起。我的输入或我处理的数据如下所示:

[[2069 2297 3087 ...,    0    0    0]
 [2069 2297 3087 ...,    0    0    0]
 [2069 2297 3087 ...,    0    0    0]
 ..., 
 [2711 4215  875 ...,    0    0    0]
 [5324 1412 1301 ...,    0    0    0]
 [5065 3561 5002 ...,    0    0    0]]

每行代表一个单词序列,每个#,一个单词的特定索引。我有两个这样的数据,我试图将它们合并在一起,首先将它们嵌入到 16 维词向量中,然后使用点积。为此,我创建了两个分支来首先嵌入数据。然后我尝试合并它们。

当我尝试在 Keras 中使用此函数合并两者时:

model = Sequential()
model.add(Merge( [x1_branch, x2_branch], mode = 'dot'))

我收到以下错误:

ValueError: Error when checking target: expected merge_1 to have 3 dimensions, but got array with shape (162, 1)

我相信矩阵乘法已执行,如文档中所述:

"E.g. if applied to two tensors a and b of shape (batch_size, n), the output will be a tensor of shape  (batch_size, 1) where each entry i will be the dot product between a[i] and b[i]."

显然,我的这个样本的批量大小是 162。但是,这个错误仍然没有意义。如果合并层似乎已经完成了计算,它怎么能期望输入呢?

我将不胜感激任何帮助。谢谢!

4

0 回答 0