我试图构建一个嵌套循环,用于创建一个二维零矩阵来解决 LCS 问题(动态规划)。这稍后用于计算 Rouge-L 分数(输入是张量,而不是字符串),但它总是出错ValueError: The two structures don't have the same nested structure.
我查了一些类似的问题并修改了一些代码,但它仍然不起作用(我放在这里的代码是最终代码):
# 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)