小编vvz*_*vzh的帖子

tensorflow, tf.while_loop: 这两个结构没有相同的嵌套结构

我试图构建一个嵌套循环,用于创建一个二维零矩阵来解决 LCS 问题(动态规划)。这稍后用于计算 Rouge-L 分数(输入是张量,而不是字符串),但它总是出错ValueError: The two structures don't have the same nested structure.

我查了一些类似的问题并修改了一些代码,但它仍然不起作用(我放在这里的代码是最终代码):

  1. 我改变了 shape_invariants。我现在使用 len(inner) 来动态获取内部的形状。
  2. 还是shape_invariants,我现在把1改成0(shape_invariants的第一个参数)。我认为标量的形状是 1,但我在 github 上查看了一些源代码,发现它全部使用 0。

# the origin code is below, in which sub and string are both string(type), len_sub and len_string are both int:

lengths = [[0 for i in range(0,len_sub+1)] for j in range(0,len_string+1)]

# but in the new code that I need, the sub and string are both tensor, so I code like this:

len_string = tf.shape(string)[0] …
Run Code Online (Sandbox Code Playgroud)

python deep-learning tensorflow

5
推荐指数
1
解决办法
2572
查看次数

标签 统计

deep-learning ×1

python ×1

tensorflow ×1