0
我试图在培训期间最大化GPU占用率。我有可变长度的序列,我想密集包装成固定长度的批次。从本质上讲,我希望短序列跟随另一个序列,并且我想要分割长序列以使它们在下一批中继续。例如:连续,固定长度的可变长度序列批次
// Say batch size is 2 and desired sequence length is 4
s1 = [a, b, c, d, e, f]
s2 = [x, y, z]
s3 = [l, m, n, o]
// Resulting batches:
b1 = [[a, b, c, d]
[x, y, z, l]]
b2 = [[e, f, _, _]
[m, n, o, _]]
在Tensorflow中有一个简单的方法吗?我的序列来自tf.TextLineReader
:
file_queue = tf.train.string_input_producer('./example_text')
reader = tf.TextLineReader()
key, sentence = reader.read(file_queue)
// convert string to int32 vector
sequence_tensor = to_sequence(sentence)
// what I wish I had:
batch = tf.fixed_length_batch_from_variable_length_sequences(
sequence_tensor, batch_size, fixed_length)
非常感谢您的任何建议。