我试图最大限度地提高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)
提前谢谢你的建议。你知道吗
好吧,我有一个工作的例子,这几乎是我所希望的。下面的代码以我希望的方式生成批处理,但它需要使用占位符在TF会话中传入和传出数据。我希望能够完全从TF图中构建这些批处理。你知道吗
希望我是愚蠢的,有一些明显的解决办法,有人可以指出。也请原谅这个案子。你知道吗
结果:
请注意,每个句子在下一批中继续。使用的示例文本文件来自1-billion word benchmark dataset,每行包含一个句子。你知道吗
相关问题 更多 >
编程相关推荐