【问题标题】:Shuffling pairs of lines in two text files洗牌两个文本文件中的行对
【发布时间】:2019-05-12 23:09:35
【问题描述】:

我正在从事一个机器翻译项目,其中有 450 万行文本,有两种语言,EnglishGerman。在将数据划分为我将在其上训练我的模型的碎片之前,我想对这些行进行洗牌。我知道shuf 描述的shuf 命令允许一个文件中的行洗牌,但我怎样才能确保第二个文件中的相应行也洗牌成相同的顺序?是否有命令可以将两个文件中的行打乱?

【问题讨论】:

    标签: nlp shuffle training-data


    【解决方案1】:

    TL;DR

    • paste 将两个文件的单独列创建到一个文件中
    • shuf 在单个文件上
    • cut 拆分列

    粘贴

    $ cat test.en 
    a b c
    d e f
    g h i
    
    $ cat test.de 
    1 2 3
    4 5 6
    7 8 9
    
    $ paste test.en test.de > test.en-de
    
    $ cat test.en-de
    a b c   1 2 3
    d e f   4 5 6
    g h i   7 8 9
    

    随机播放

    $ shuf test.en-de > test.en-de.shuf
    
    $ cat test.en-de.shuf
    d e f   4 5 6
    a b c   1 2 3
    g h i   7 8 9
    

    剪切

    $ cut -f1 test.en-de.shuf> test.en-de.shuf.en
    $ cut -f2 test.en-de.shuf> test.en-de.shuf.de
    
    $ cat test.en-de.shuf.en 
    d e f
    a b c
    g h i
    
    $ cat test.en-de.shuf.de
    4 5 6
    1 2 3
    7 8 9
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多