def pad_up_to(vector, size):
rank = vector.get_shape().ndims - 1
length_diff = tf.reshape(size - tf.shape(vector)[1], shape=(1,))
with tf.control_dependencies([tf.assert_non_negative(length_diff, data=(vector, size, tf.shape(vector)))]):
padding = tf.reshape(tf.concat([[0, 0, 0], length_diff, [0,0]*(rank-1)], axis=0), shape=((rank+1), 2))
return tf.pad(vector, padding, mode='constant')
seq2seq_aligner.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录