gpt4 book ai didi

python - 如何从Tensorflow中的多个对齐数据集中随机选择数据?

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:35 25 4
gpt4 key购买 nike

假设我们有 6 个文本文件,分为 2 组,每组包含 3 个文件,例如,

  • 第 1 组:1.a、1.b、1.c
  • 第 2 组:2.a、2.b、2.c

给定一个固定阈值rand ,和random()来自random模块,我希望得到的是3个张量:

  • x 组:x_a、x_b、x_c

其中每个文件中的行数相同且对齐,x_a 的第 n 行将是:

  • 第 1 步:'<nth line from 1.a>' if rand < random() else '<nth line from 2.a>'

x_b 和 x_c 的第 n 行将是:

  • 第 2 步:<'nth line from 1.b>' if '<nth row of x_a from 1.a>' else '<nth line from 2.b>'
  • 第 3 步:<'nth line from 1.c>' if '<nth row of x_a from 1.a>' else '<nth line from 2.c>' (按照第 2 步操作,但适用于 x_c)

使 x_a、x_b 和 x_c 全部对齐。

我使用的工具是tf.data.TextLineDataset ,你能告诉我如何进行随机选择并保持选择轨迹吗?谢谢!

最佳答案

========================== 我的解决方案====================== ===

我提供了一个跟踪文件来引导这 3 个文件。仍然欢迎其他解决方案!

a1 = tf.data.TextLineDataset(afile1).map(...)
b1 = tf.data.TextLineDataset(bfile1).map(...)
c1 = tf.data.TextLineDataset(cfile1).map(...)
...
index = tf.data.TextLineDataset(track_file).map(lambda line: tf.string_to_number(line, tf.int32))
As = tf.data.Dataset.zip((index, a1, a2))
Bs = tf.data.Dataset.zip((index, b1, b2))
...
ax = As.map(lambda i, l, r: tf.where(i > 0, l, r))
bx = As.map(lambda i, l, r: tf.where(i > 0, l, r))
cx = As.map(lambda i, l, r: tf.where(i > 0, l, r))
...

关于python - 如何从Tensorflow中的多个对齐数据集中随机选择数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54566926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com