{
  "id": 11018,
  "title": "Shuffling lines of big data files",
  "url": "/competitions/avazu-ctr-prediction/discussion/11018",
  "author_name": "",
  "post_date": "2014-11-22T16:26:20.563Z",
  "votes": 12,
  "comment_count": 13,
  "views": 5770,
  "content": "<p>Hi,</p>\n<p>To anyone who's interested in shuffled train data I would like to impudently promote my own opensource&nbsp;<a href=\"https://github.com/trufanov-nok/shuf-t\">tool</a> which is available here under LGPL.</p>\n<p>It's written in C++ with Qt framework and specially made for files bigger than available RAM size. More technical details could be found in readme file and&nbsp;<a href=\"http://www.kaggle.com/c/criteo-display-ad-challenge/forums/t/10429/congratulations-to-the-winners/54598#post54598\">this</a> discussion.</p>\n<p><a href=\"https://github.com/trufanov-nok/shuf-t/tree/master/binaries\">Binaries</a>&nbsp;are available for Linux (.deb, x64) and Win x32/x64.</p>\n<p>I have tried it on avazu's train file preliminary converted to VW format so it become 15.5 Gb (i used long prefixes for categorical values). It was shuffled for ~ 1h 40 min with 1Gb buffer (up to 2Gb total RAM used). And original ~6Gb train csv was shuffled in less than 20 min with following command:</p>\n<p>[code]$ shuf-t -t 1 train -o train_shuffled<br>random seed: 1416668999<br>searching line offsets: ...........<br>offsets found: 40428967<br>2 min 2.71 sec<br>shuffling line offsets: ..........<br>2.89 sec<br>writing lines to output: ..........<br>15 min 6.34 sec<br>[/code]</p>\n<p>The command line format is taken from GNU Shuf util.</p>\n<p>It's still a beta so feedback is highly appreciated.</p>",
  "messages": [
    {
      "id": "58689",
      "postDate": "11/22/2014 16:26:20",
      "content": "<p>Hi,</p>\n<p>To anyone who's interested in shuffled train data I would like to impudently promote my own opensource&nbsp;<a href=\"https://github.com/trufanov-nok/shuf-t\">tool</a> which is available here under LGPL.</p>\n<p>It's written in C++ with Qt framework and specially made for files bigger than available RAM size. More technical details could be found in readme file and&nbsp;<a href=\"http://www.kaggle.com/c/criteo-display-ad-challenge/forums/t/10429/congratulations-to-the-winners/54598#post54598\">this</a> discussion.</p>\n<p><a href=\"https://github.com/trufanov-nok/shuf-t/tree/master/binaries\">Binaries</a>&nbsp;are available for Linux (.deb, x64) and Win x32/x64.</p>\n<p>I have tried it on avazu's train file preliminary converted to VW format so it become 15.5 Gb (i used long prefixes for categorical values). It was shuffled for ~ 1h 40 min with 1Gb buffer (up to 2Gb total RAM used). And original ~6Gb train csv was shuffled in less than 20 min with following command:</p>\n<p>[code]$ shuf-t -t 1 train -o train_shuffled<br>random seed: 1416668999<br>searching line offsets: ...........<br>offsets found: 40428967<br>2 min 2.71 sec<br>shuffling line offsets: ..........<br>2.89 sec<br>writing lines to output: ..........<br>15 min 6.34 sec<br>[/code]</p>\n<p>The command line format is taken from GNU Shuf util.</p>\n<p>It's still a beta so feedback is highly appreciated.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "58699",
      "postDate": "11/22/2014 20:10:42",
      "content": "<p>Thanks a lot! Great tool.</p>\n<p>Shuffled in just over 4 min :D</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "58800",
      "postDate": "11/24/2014 18:10:47",
      "content": "<p>When using exe file for win64&#65292; where can I enter the command line (including input file for shuffling)&#65311;</p>\n<p>thanks a lot!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "58810",
      "postDate": "11/24/2014 19:56:04",
      "content": "<p>[quote=tung chne;58800]</p>\n<p>When using exe file for win64&#65292; where can I enter the command line (including input file for shuffling)&#65311;</p>\n<p>thanks a lot!</p>\n<p>[/quote]</p>\n<p>Well, it's a console tool without user interface. If you just launch it then it will expect that you type in opened console all your data and press ctrl+D. Shuffled lines will be outputted on screen. You can't specify more options as you already launched the app. To launch it with parameters you shall use windows console and if you need more details then this&nbsp;<a href=\"http://www.youtube.com/watch?v=4A13pN9_s7c\">videolesson</a> seems fine.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "58950",
      "postDate": "11/25/2014 20:15:01",
      "content": "<p>Quite curious for the shuffling idea working or not. Tried reversing the order but no luck. Probably time sequence matters. Any idea?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "58952",
      "postDate": "11/25/2014 21:38:50",
      "content": "<p>[quote=simeng;58950]</p>\n<p>Quite curious for the shuffling idea working or not. Tried reversing the order but no luck. Probably time sequence matters. Any idea?</p>\n<p>[/quote]</p>\n<p>I don't know if order matters for final model training, but in my opinion defining hyper-parameters and playing with features (making ngrams etc) is better while using shuffled data.&nbsp;</p>\n<p>For example, VW implements online learning algorithms and outputs average train / holdout losses every N learned examples, so you may realize that your last model tweak was a bad idea much earlier than its training ends just by comparing VW output with previous result. And this is easier to do if sequence of average loss values fits in some trend and has small variance. From this perspective shuffled data behave better. If I find good enough model with shuffled data, of course, I'll give it a try with original dataset too to choose better one.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59042",
      "postDate": "11/26/2014 20:11:03",
      "content": "<p>What kind of expected improvement on LB compare shuffle vs non-shuffle?&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59074",
      "postDate": "11/27/2014 08:27:20",
      "content": "<p>[quote=superfan123;59042]</p>\n<p>What kind of expected improvement on LB compare shuffle vs non-shuffle?&nbsp;</p>\n<p>[/quote]</p>\n\n<p>Ok, I've tried basic VW. Shuffled data was used to find its hyperparameters. Then I used shuffled and non-shuffled data to train 2 models. The model trained on non-shufled data gave -0.002 on public LB vs model trained on random data.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59088",
      "postDate": "11/27/2014 11:04:08",
      "content": "<p>does it have any option to keep header intact?</p>\n<p>EDIT: found it&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59089",
      "postDate": "11/27/2014 11:51:17",
      "content": "<p>shuffling did not give me a better score...</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59136",
      "postDate": "11/28/2014 04:39:57",
      "content": "<p>Think the vendor will also not favour strategies with&nbsp;shuffling as data will stream in according to time. &nbsp;One of the advantage of Online algo is in adapting to the time nature and user shifts in preference with the correct features. &nbsp;Guess more strategic hunting needed.... &nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62557",
      "postDate": "01/10/2015 12:42:02",
      "content": "<p>I attach here a script in pure python to shuffle big files. The algorithm creates temporary files to do the sorting, so depending on the number of lines you want to shuffle, you may need to increase your limit on open file descriptors. I used 15000 in my computer to shuffle the 40M lines of train.</p>\n<p>Usage:</p>\n<p>pypy/python shuffle_ooc.py file.txt [N] &gt; file_shuffled.txt</p>\n<p>where N is optional and it&#180;s the number of lines in the file, otherwise the scripts counts them</p>\n<p>Hope it helps!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "356587",
      "postDate": "07/13/2018 23:03:30",
      "content": "<p>You could also use the shuf command in a bash shell, which is very quick.</p>\n\n<p>Strip the header line from train.csv: tail -40428967 train.csv &gt; train.csv</p>\n\n<p>Then shuffle in place:</p>\n\n<p>shuf -o train.csv &lt; train.csv</p>",
      "rawMarkdown": "You could also use the shuf command in a bash shell, which is very quick.\n\nStrip the header line from train.csv: tail -40428967 train.csv &gt; train.csv\n\nThen shuffle in place:\n\nshuf -o train.csv &lt; train.csv",
      "votes": null
    },
    {
      "id": "928896",
      "postDate": "07/14/2020 10:05:29",
      "content": "<p>I downloaded the shuffle_ooc.py file. from Guillem Palou.\nbut I don't know how to run this script on my dataset.... how to introduce the file path and the file itself.\nany one can help me.</p>",
      "rawMarkdown": "I downloaded the shuffle_ooc.py file. from Guillem Palou.\nbut I don't know how to run this script on my dataset.... how to introduce the file path and the file itself.\nany one can help me.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 58699,
      "author_name": "lukemetz",
      "author_url": "",
      "post_date": "11/22/2014 20:10:42",
      "content": "<p>Thanks a lot! Great tool.</p>\n<p>Shuffled in just over 4 min :D</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 58800,
      "author_name": "tungchne",
      "author_url": "",
      "post_date": "11/24/2014 18:10:47",
      "content": "<p>When using exe file for win64&#65292; where can I enter the command line (including input file for shuffling)&#65311;</p>\n<p>thanks a lot!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 58810,
      "author_name": "trufanov",
      "author_url": "",
      "post_date": "11/24/2014 19:56:04",
      "content": "<p>[quote=tung chne;58800]</p>\n<p>When using exe file for win64&#65292; where can I enter the command line (including input file for shuffling)&#65311;</p>\n<p>thanks a lot!</p>\n<p>[/quote]</p>\n<p>Well, it's a console tool without user interface. If you just launch it then it will expect that you type in opened console all your data and press ctrl+D. Shuffled lines will be outputted on screen. You can't specify more options as you already launched the app. To launch it with parameters you shall use windows console and if you need more details then this&nbsp;<a href=\"http://www.youtube.com/watch?v=4A13pN9_s7c\">videolesson</a> seems fine.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 58950,
      "author_name": "simengy82",
      "author_url": "",
      "post_date": "11/25/2014 20:15:01",
      "content": "<p>Quite curious for the shuffling idea working or not. Tried reversing the order but no luck. Probably time sequence matters. Any idea?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 58952,
      "author_name": "trufanov",
      "author_url": "",
      "post_date": "11/25/2014 21:38:50",
      "content": "<p>[quote=simeng;58950]</p>\n<p>Quite curious for the shuffling idea working or not. Tried reversing the order but no luck. Probably time sequence matters. Any idea?</p>\n<p>[/quote]</p>\n<p>I don't know if order matters for final model training, but in my opinion defining hyper-parameters and playing with features (making ngrams etc) is better while using shuffled data.&nbsp;</p>\n<p>For example, VW implements online learning algorithms and outputs average train / holdout losses every N learned examples, so you may realize that your last model tweak was a bad idea much earlier than its training ends just by comparing VW output with previous result. And this is easier to do if sequence of average loss values fits in some trend and has small variance. From this perspective shuffled data behave better. If I find good enough model with shuffled data, of course, I'll give it a try with original dataset too to choose better one.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59042,
      "author_name": "superfan123",
      "author_url": "",
      "post_date": "11/26/2014 20:11:03",
      "content": "<p>What kind of expected improvement on LB compare shuffle vs non-shuffle?&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59074,
      "author_name": "trufanov",
      "author_url": "",
      "post_date": "11/27/2014 08:27:20",
      "content": "<p>[quote=superfan123;59042]</p>\n<p>What kind of expected improvement on LB compare shuffle vs non-shuffle?&nbsp;</p>\n<p>[/quote]</p>\n\n<p>Ok, I've tried basic VW. Shuffled data was used to find its hyperparameters. Then I used shuffled and non-shuffled data to train 2 models. The model trained on non-shufled data gave -0.002 on public LB vs model trained on random data.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59088,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "11/27/2014 11:04:08",
      "content": "<p>does it have any option to keep header intact?</p>\n<p>EDIT: found it&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59089,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "11/27/2014 11:51:17",
      "content": "<p>shuffling did not give me a better score...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59136,
      "author_name": "drpatrickchan",
      "author_url": "",
      "post_date": "11/28/2014 04:39:57",
      "content": "<p>Think the vendor will also not favour strategies with&nbsp;shuffling as data will stream in according to time. &nbsp;One of the advantage of Online algo is in adapting to the time nature and user shifts in preference with the correct features. &nbsp;Guess more strategic hunting needed.... &nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62557,
      "author_name": "guillempalou",
      "author_url": "",
      "post_date": "01/10/2015 12:42:02",
      "content": "<p>I attach here a script in pure python to shuffle big files. The algorithm creates temporary files to do the sorting, so depending on the number of lines you want to shuffle, you may need to increase your limit on open file descriptors. I used 15000 in my computer to shuffle the 40M lines of train.</p>\n<p>Usage:</p>\n<p>pypy/python shuffle_ooc.py file.txt [N] &gt; file_shuffled.txt</p>\n<p>where N is optional and it&#180;s the number of lines in the file, otherwise the scripts counts them</p>\n<p>Hope it helps!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 356587,
      "author_name": "jcatanza",
      "author_url": "",
      "post_date": "07/13/2018 23:03:30",
      "content": "<p>You could also use the shuf command in a bash shell, which is very quick.</p>\n\n<p>Strip the header line from train.csv: tail -40428967 train.csv &gt; train.csv</p>\n\n<p>Then shuffle in place:</p>\n\n<p>shuf -o train.csv &lt; train.csv</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 928896,
      "author_name": "samirafotuhi",
      "author_url": "",
      "post_date": "07/14/2020 10:05:29",
      "content": "<p>I downloaded the shuffle_ooc.py file. from Guillem Palou.\nbut I don't know how to run this script on my dataset.... how to introduce the file path and the file itself.\nany one can help me.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "58689": "",
    "58699": "",
    "58800": "",
    "58810": "",
    "58950": "",
    "58952": "",
    "59042": "",
    "59074": "",
    "59088": "",
    "59089": "",
    "59136": "",
    "62557": "",
    "356587": "You could also use the shuf command in a bash shell, which is very quick.\n\nStrip the header line from train.csv: tail -40428967 train.csv &gt; train.csv\n\nThen shuffle in place:\n\nshuf -o train.csv &lt; train.csv",
    "928896": "I downloaded the shuffle_ooc.py file. from Guillem Palou.\nbut I don't know how to run this script on my dataset.... how to introduce the file path and the file itself.\nany one can help me."
  },
  "source": "meta"
}