{
  "id": 330503,
  "title": "Tricks From Winning Solutions Of Other Code Competitions",
  "url": "/competitions/AI4Code/discussion/330503",
  "author_name": "",
  "post_date": "2022-06-12T19:38:12.315377900Z",
  "votes": 36,
  "comment_count": 2,
  "views": 0,
  "content": "<h1>Tricks From Winning Solutions Of Other Code Competitions</h1>\n<p>Hi guys, <br>\nI just finished going through all the winning solutions of 4 different code competitions (not all from Kaggle). </p>\n<p>Here are all the tricks they used.<br>\nEnjoy yourself!</p>\n<h3><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/overview\" target=\"_blank\">Where there's code, there's bug</a> - Last week</h3>\n<blockquote>\n  <p>Classification: Line by line, some lines have bugs</p>\n</blockquote>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738\" target=\"_blank\">4th solution</a></h5>\n<p><strong>2 Stage Pipeline</strong></p>\n<ul>\n<li><strong>Backbone</strong> - CodeBERTa-small-v1 - applied to each code line - chose one fold (out of the 4)</li>\n<li><strong>Linear classifier</strong> runs on concatenation of the backbone pooler outputs</li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/code/karthickp6/giba-s-approach-tfidf-logistic-reg-lb-0-86538\" target=\"_blank\">4th solution - Giba's approach</a></h5>\n<p><img src=\"https://i.ibb.co/pRgRJ8Y/Selection-898.png\" alt=\"\"></p>\n<p><strong>Super simple pipeline</strong></p>\n<ul>\n<li><p>TFIDF (ngrams=(1,2))</p></li>\n<li><p>LogisticRegression </p></li>\n<li><p>Blended with the rest of the team </p></li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738\" target=\"_blank\">6th solution</a></h5>\n<p><strong>Models</strong></p>\n<ul>\n<li>\"microsoft/codebert-base\" (2 folds)</li>\n<li>\"huggingface/CodeBERTa-small-v1\" (2x 1 fold + 1x 2 folds)</li>\n<li>\"flax-sentence-embeddings/st-codesearch-distilroberta-base\" (1 fold)</li>\n</ul>\n<p><strong>Input &amp; output</strong></p>\n<ul>\n<li>Model Input : [CLS] line 1 [SEP] line 2 [SEP] line 3 [SEP] line 4 [SEP] line 5 [SEP]</li>\n<li>Average pooling on the last features + dense + tanh + dense</li>\n</ul>\n<p><strong>Training</strong></p>\n<ul>\n<li>bs=32, max_len=200</li>\n<li>lr: 4e-5, apart for some CodeBERTa exps (tried 2e-5 and 5e-5)</li>\n<li>5 epochs for codebert, 4 for 3 or 4 were enough for the other smaller models</li>\n</ul>\n<p><strong>Post-processing</strong></p>\n<ul>\n<li>Noticed that there were duplicates in the training data, and codes that were present twice had different labels</li>\n<li>Gave a 0.5 score to duplicated texts</li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328731\" target=\"_blank\">7th solution</a></h5>\n<p><strong>Injected Special Token</strong></p>\n<p><strong>Many Models Ensemble</strong></p>\n<blockquote>\n  <p>Note: always select a single fold.</p>\n</blockquote>\n<ul>\n<li>codebert-base(only 3line)</li>\n<li>roberta-base(all sentences)</li>\n<li>electra-base-discriminator(all sentences, epoch3)</li>\n<li>destilbert-base-uncased(all sentences, epoch3)</li>\n<li>codeberta-small-v1(all sentences, epoch 3)</li>\n<li>codebert_base(all sentences, epoch7)</li>\n<li>codebert-base(all sentences, epoch3)</li>\n<li>codebert-base-mlm(all sentences, epoch3)</li>\n<li>codebert-base-mlm(all sentences, epoch3)</li>\n<li>muppet-roberta-base(all sentences, epoch4)</li>\n<li>graphcodebert-base(all sentences, epoch3)</li>\n</ul>\n<h3>NLC2CMD - NuerIPS 2020</h3>\n<blockquote>\n  <p>Task: Translate english to bash syntax</p>\n</blockquote>\n<h5>1st place</h5>\n<p><a href=\"https://github.com/magnumresearchgroup/Magnum-NLC2CMD\" target=\"_blank\">github</a> | <a href=\"https://www.dre.vanderbilt.edu/~schmidt/PDF/A_Transformer_based_Approach_for_TranslatingNatural_Language_to_Bash_Commands.pdf\" target=\"_blank\">paper</a></p>\n<p><strong>Transformer + Architecture Improvements</strong></p>\n<p><strong>Custom Tokenizer</strong> </p>\n<ul>\n<li><p>Found by hyperparam search that they can shrink the vocabulary size by 90% and it even improves the results </p></li>\n<li><p><strong>Heuristic improved beam search</strong></p></li>\n</ul>\n<h5>2nd place</h5>\n<p><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris\" target=\"_blank\">github</a></p>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/trainer.py\" target=\"_blank\">Custom HF Trainer</a></strong></p>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/notebooks/data_preprocess.ipynb\" target=\"_blank\">Heavy preprocessing</a></strong></p>\n<blockquote>\n  <p>why didnt they just summarize thisssssss???? @#$@#%</p>\n</blockquote>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/diverse_beam_search.py\" target=\"_blank\">Custom diverse_beam_search</a></strong></p>\n<h5>3rd place</h5>\n<p><a href=\"https://github.com/JetBrains/nlc2cmd\" target=\"_blank\">github</a> | <a href=\"https://github.com/JetBrains/nlc2cmd/blob/master/report.pdf\" target=\"_blank\">paper</a></p>\n<p><strong>Augmentations</strong></p>\n<p>Backtranslated (only the english prompt) using fairseq pretrained models, used only predictions with BLEU higher then a threshold (to avoid training their model with the mistakes of the fairseq model)</p>\n<p><strong>Data Generation</strong></p>\n<p>Generated more data from the manpage: Commands were created by concatenating cmd name &amp; some random flags, <br>\nChanged some common pipline endings that were \"too easy\" such as \"wc\" &amp; \"how many\"</p>\n<p><strong>Preprocessing</strong></p>\n<ul>\n<li><strong>English prompt:</strong> Removed stopwords using nltk and stemmed using Snowballstemmer</li>\n<li><strong>Bash cmd:</strong> changed all arguments to \"ARG\"</li>\n</ul>\n<p><strong>Postprocessing</strong></p>\n<ul>\n<li>**Used two models, one for </li>\n</ul>\n<h5>4th place</h5>\n<p><a href=\"https://github.com/Samsung/NLC2CMD\" target=\"_blank\">github</a></p>\n<blockquote>\n  <p>Again, reversing their code</p>\n</blockquote>\n<p><strong>Fairseq Model</strong> </p>\n<ul>\n<li>can by seed by their trainer <a href=\"https://github.com/Samsung/NLC2CMD/blob/main/train/3.train_template_predictor.sh\" target=\"_blank\">script</a></li>\n</ul>\n<p><strong>Two models</strong></p>\n<ul>\n<li>One for detecting templates </li>\n<li>Other for detecting arguments</li>\n</ul>\n<h5>6th place</h5>\n<p><a href=\"https://github.com/DNGros/clai\" target=\"_blank\">github</a> | <a href=\"https://clai-home.mybluemix.net/\" target=\"_blank\">demo</a> | <a href=\"https://arxiv.org/abs/2002.00762\" target=\"_blank\">paper</a></p>\n<h5>9th place</h5>\n<p><a href=\"https://github.com/greenmonn/nlc2cmd-competition\" target=\"_blank\">github</a> | <a href=\"https://ibm.box.com/s/3nb9oypu2iuiq3ow0m849o44ycd8jdbw\" target=\"_blank\">paper</a></p>\n<p><strong>Tree RNN Tensorflow Model</strong></p>\n<ul>\n<li><p>Right <a href=\"https://github.com/greenmonn/nlc2cmd-competition/blob/dfb28149deee16043b604dda4ea8a45ce4413938/nl2bash/encoder_decoder/seq2tree/tree_rnn_cell.py\" target=\"_blank\">here</a></p></li>\n<li><p>They also have many variations in the code with multiple heads and so on. They probably didn't delete the past experiments they tried.</p></li>\n</ul>\n<h3>CodRep-2019</h3>\n<blockquote>\n  <p>Task: predict formatting errors in source code</p>\n</blockquote>\n<h5><a href=\"https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05\" target=\"_blank\">2nd place</a></h5>\n<p><strong>Preprocessing</strong></p>\n<ul>\n<li><p><strong>Manually defined</strong> <a href=\"https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05\" target=\"_blank\">22 regex</a> expressions for automaticlly detect common source code errors.</p></li>\n<li><p><strong>Used the regex to clean manually a high quality dataset by hand</strong> then trained a generative language model only on those samples.</p></li>\n</ul>\n<p>[this is a really cool idea..]</p>\n<ul>\n<li><p><strong>Added common meaningful words</strong> to the tokenizer such as \"True\" \"False\" \"if\"..</p></li>\n<li><p>Optimized n-grams size (7 was optimal) so the distribution of tokens for \"broken/not broken\" would by as close as possible to 50%/50% then they used these token to train a balanced XGBoost classifier and an 1-class SVM for outlier detection.</p></li>\n<li><p><strong>Ensemble:</strong> prediction char by char (mean) with all models, then activate the regex on the \"most problematic\" parts of the text as post processing. </p></li>\n</ul>\n<h3><a href=\"https://github.com/KTH/CodRep-competition\" target=\"_blank\">CodRep-2018</a></h3>\n<blockquote>\n  <p>Task: replace lines in a given code: On a pair (code line, code file) predict for each line in \"code file\" the probability so that this is the line that needs to be replaced by \"code line\" [sort of \"similarity\" to code line]</p>\n</blockquote>\n<h5><a href=\"https://github.com/KTH/CodRep-competition/issues/29\" target=\"_blank\">1st place</a></h5>\n<p><strong>Treated as a search/ranking</strong> </p>\n<ul>\n<li>Extracted features and then used \"learning to rank\" model. </li>\n</ul>\n<p><strong>Post-processing</strong></p>\n<ul>\n<li>Ruled out the highest ranked prediction if applying the repair at that location yields a syntax error (they were allowed to do that? 😂)</li>\n</ul>\n<p>Here's a table that summarizes our results:</p>\n<h5><a href=\"https://github.com/KTH/CodRep-competition/issues/16\" target=\"_blank\">2nd place</a></h5>\n<blockquote>\n  <p>This was a bit messy to follow since they didn't have a full writeup. This is what I managed to extract from conversation over the pull request.</p>\n</blockquote>\n<ul>\n<li><p><strong>Had simple string similarity</strong> version that turned out to be a really strong baseline</p></li>\n<li><p><strong>Hand crafted features for a tree based model</strong>: High-level AST of each line (basically the type of each code element, VARIABLE, CLASS, STRING, COMMENT, NUMBER, TOKEN, KEYWORD)</p></li>\n<li><p><strong>Cool Trick</strong> One idea: because code tends to be added to the end of the file, and new code tend to be more buggy than old code.</p></li>\n</ul>\n<h5><a href=\"https://github.com/jjhenkel/instauro\" target=\"_blank\">3rd place</a></h5>\n<ul>\n<li><p><strong>LambdaMART using RankLib</strong></p></li>\n<li><p><strong>Used standard text similarity metrics</strong></p></li>\n</ul>\n<h5><a href=\"https://github.com/agb94/coldbrew/\" target=\"_blank\">4th place</a></h5>\n<blockquote>\n  <p>No writeup, reversed the code</p>\n</blockquote>\n<ul>\n<li><strong>Trained GP</strong> on the features: The Sum of Matching Blocks' Size, Edit Distance, Lexical Similarity, Keyword Similarity</li>\n</ul>\n<h5><a href=\"https://github.com/cesarsotovalero/CodRep-submission\" target=\"_blank\">5th place</a></h5>\n<p>Used:</p>\n<ul>\n<li><p>string matching</p></li>\n<li><p>parse checking</p></li>\n<li><p>decision rules</p></li>\n<li><p>heuristics</p></li>\n</ul>\n<p><a href=\"https://link.springer.com/article/10.1007/s10664-017-9564-7\" target=\"_blank\">related paper</a></p>\n<h5><a href=\"https://github.com/egor-bogomolov/CodRep-competition/blob/master/Solutions/prefSufMatch.py\" target=\"_blank\">6th place</a></h5>\n<ul>\n<li>Submitted a naive (handcrafted, hardcoded) baseline</li>\n</ul>",
  "messages": [
    {
      "id": "1818521",
      "postDate": "06/12/2022 19:38:12",
      "content": "<h1>Tricks From Winning Solutions Of Other Code Competitions</h1>\n<p>Hi guys, <br>\nI just finished going through all the winning solutions of 4 different code competitions (not all from Kaggle). </p>\n<p>Here are all the tricks they used.<br>\nEnjoy yourself!</p>\n<h3><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/overview\" target=\"_blank\">Where there's code, there's bug</a> - Last week</h3>\n<blockquote>\n  <p>Classification: Line by line, some lines have bugs</p>\n</blockquote>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738\" target=\"_blank\">4th solution</a></h5>\n<p><strong>2 Stage Pipeline</strong></p>\n<ul>\n<li><strong>Backbone</strong> - CodeBERTa-small-v1 - applied to each code line - chose one fold (out of the 4)</li>\n<li><strong>Linear classifier</strong> runs on concatenation of the backbone pooler outputs</li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/code/karthickp6/giba-s-approach-tfidf-logistic-reg-lb-0-86538\" target=\"_blank\">4th solution - Giba's approach</a></h5>\n<p><img src=\"https://i.ibb.co/pRgRJ8Y/Selection-898.png\" alt=\"\"></p>\n<p><strong>Super simple pipeline</strong></p>\n<ul>\n<li><p>TFIDF (ngrams=(1,2))</p></li>\n<li><p>LogisticRegression </p></li>\n<li><p>Blended with the rest of the team </p></li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738\" target=\"_blank\">6th solution</a></h5>\n<p><strong>Models</strong></p>\n<ul>\n<li>\"microsoft/codebert-base\" (2 folds)</li>\n<li>\"huggingface/CodeBERTa-small-v1\" (2x 1 fold + 1x 2 folds)</li>\n<li>\"flax-sentence-embeddings/st-codesearch-distilroberta-base\" (1 fold)</li>\n</ul>\n<p><strong>Input &amp; output</strong></p>\n<ul>\n<li>Model Input : [CLS] line 1 [SEP] line 2 [SEP] line 3 [SEP] line 4 [SEP] line 5 [SEP]</li>\n<li>Average pooling on the last features + dense + tanh + dense</li>\n</ul>\n<p><strong>Training</strong></p>\n<ul>\n<li>bs=32, max_len=200</li>\n<li>lr: 4e-5, apart for some CodeBERTa exps (tried 2e-5 and 5e-5)</li>\n<li>5 epochs for codebert, 4 for 3 or 4 were enough for the other smaller models</li>\n</ul>\n<p><strong>Post-processing</strong></p>\n<ul>\n<li>Noticed that there were duplicates in the training data, and codes that were present twice had different labels</li>\n<li>Gave a 0.5 score to duplicated texts</li>\n</ul>\n<h5><a href=\"https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328731\" target=\"_blank\">7th solution</a></h5>\n<p><strong>Injected Special Token</strong></p>\n<p><strong>Many Models Ensemble</strong></p>\n<blockquote>\n  <p>Note: always select a single fold.</p>\n</blockquote>\n<ul>\n<li>codebert-base(only 3line)</li>\n<li>roberta-base(all sentences)</li>\n<li>electra-base-discriminator(all sentences, epoch3)</li>\n<li>destilbert-base-uncased(all sentences, epoch3)</li>\n<li>codeberta-small-v1(all sentences, epoch 3)</li>\n<li>codebert_base(all sentences, epoch7)</li>\n<li>codebert-base(all sentences, epoch3)</li>\n<li>codebert-base-mlm(all sentences, epoch3)</li>\n<li>codebert-base-mlm(all sentences, epoch3)</li>\n<li>muppet-roberta-base(all sentences, epoch4)</li>\n<li>graphcodebert-base(all sentences, epoch3)</li>\n</ul>\n<h3>NLC2CMD - NuerIPS 2020</h3>\n<blockquote>\n  <p>Task: Translate english to bash syntax</p>\n</blockquote>\n<h5>1st place</h5>\n<p><a href=\"https://github.com/magnumresearchgroup/Magnum-NLC2CMD\" target=\"_blank\">github</a> | <a href=\"https://www.dre.vanderbilt.edu/~schmidt/PDF/A_Transformer_based_Approach_for_TranslatingNatural_Language_to_Bash_Commands.pdf\" target=\"_blank\">paper</a></p>\n<p><strong>Transformer + Architecture Improvements</strong></p>\n<p><strong>Custom Tokenizer</strong> </p>\n<ul>\n<li><p>Found by hyperparam search that they can shrink the vocabulary size by 90% and it even improves the results </p></li>\n<li><p><strong>Heuristic improved beam search</strong></p></li>\n</ul>\n<h5>2nd place</h5>\n<p><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris\" target=\"_blank\">github</a></p>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/trainer.py\" target=\"_blank\">Custom HF Trainer</a></strong></p>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/notebooks/data_preprocess.ipynb\" target=\"_blank\">Heavy preprocessing</a></strong></p>\n<blockquote>\n  <p>why didnt they just summarize thisssssss???? @#$@#%</p>\n</blockquote>\n<p><strong><a href=\"https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/diverse_beam_search.py\" target=\"_blank\">Custom diverse_beam_search</a></strong></p>\n<h5>3rd place</h5>\n<p><a href=\"https://github.com/JetBrains/nlc2cmd\" target=\"_blank\">github</a> | <a href=\"https://github.com/JetBrains/nlc2cmd/blob/master/report.pdf\" target=\"_blank\">paper</a></p>\n<p><strong>Augmentations</strong></p>\n<p>Backtranslated (only the english prompt) using fairseq pretrained models, used only predictions with BLEU higher then a threshold (to avoid training their model with the mistakes of the fairseq model)</p>\n<p><strong>Data Generation</strong></p>\n<p>Generated more data from the manpage: Commands were created by concatenating cmd name &amp; some random flags, <br>\nChanged some common pipline endings that were \"too easy\" such as \"wc\" &amp; \"how many\"</p>\n<p><strong>Preprocessing</strong></p>\n<ul>\n<li><strong>English prompt:</strong> Removed stopwords using nltk and stemmed using Snowballstemmer</li>\n<li><strong>Bash cmd:</strong> changed all arguments to \"ARG\"</li>\n</ul>\n<p><strong>Postprocessing</strong></p>\n<ul>\n<li>**Used two models, one for </li>\n</ul>\n<h5>4th place</h5>\n<p><a href=\"https://github.com/Samsung/NLC2CMD\" target=\"_blank\">github</a></p>\n<blockquote>\n  <p>Again, reversing their code</p>\n</blockquote>\n<p><strong>Fairseq Model</strong> </p>\n<ul>\n<li>can by seed by their trainer <a href=\"https://github.com/Samsung/NLC2CMD/blob/main/train/3.train_template_predictor.sh\" target=\"_blank\">script</a></li>\n</ul>\n<p><strong>Two models</strong></p>\n<ul>\n<li>One for detecting templates </li>\n<li>Other for detecting arguments</li>\n</ul>\n<h5>6th place</h5>\n<p><a href=\"https://github.com/DNGros/clai\" target=\"_blank\">github</a> | <a href=\"https://clai-home.mybluemix.net/\" target=\"_blank\">demo</a> | <a href=\"https://arxiv.org/abs/2002.00762\" target=\"_blank\">paper</a></p>\n<h5>9th place</h5>\n<p><a href=\"https://github.com/greenmonn/nlc2cmd-competition\" target=\"_blank\">github</a> | <a href=\"https://ibm.box.com/s/3nb9oypu2iuiq3ow0m849o44ycd8jdbw\" target=\"_blank\">paper</a></p>\n<p><strong>Tree RNN Tensorflow Model</strong></p>\n<ul>\n<li><p>Right <a href=\"https://github.com/greenmonn/nlc2cmd-competition/blob/dfb28149deee16043b604dda4ea8a45ce4413938/nl2bash/encoder_decoder/seq2tree/tree_rnn_cell.py\" target=\"_blank\">here</a></p></li>\n<li><p>They also have many variations in the code with multiple heads and so on. They probably didn't delete the past experiments they tried.</p></li>\n</ul>\n<h3>CodRep-2019</h3>\n<blockquote>\n  <p>Task: predict formatting errors in source code</p>\n</blockquote>\n<h5><a href=\"https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05\" target=\"_blank\">2nd place</a></h5>\n<p><strong>Preprocessing</strong></p>\n<ul>\n<li><p><strong>Manually defined</strong> <a href=\"https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05\" target=\"_blank\">22 regex</a> expressions for automaticlly detect common source code errors.</p></li>\n<li><p><strong>Used the regex to clean manually a high quality dataset by hand</strong> then trained a generative language model only on those samples.</p></li>\n</ul>\n<p>[this is a really cool idea..]</p>\n<ul>\n<li><p><strong>Added common meaningful words</strong> to the tokenizer such as \"True\" \"False\" \"if\"..</p></li>\n<li><p>Optimized n-grams size (7 was optimal) so the distribution of tokens for \"broken/not broken\" would by as close as possible to 50%/50% then they used these token to train a balanced XGBoost classifier and an 1-class SVM for outlier detection.</p></li>\n<li><p><strong>Ensemble:</strong> prediction char by char (mean) with all models, then activate the regex on the \"most problematic\" parts of the text as post processing. </p></li>\n</ul>\n<h3><a href=\"https://github.com/KTH/CodRep-competition\" target=\"_blank\">CodRep-2018</a></h3>\n<blockquote>\n  <p>Task: replace lines in a given code: On a pair (code line, code file) predict for each line in \"code file\" the probability so that this is the line that needs to be replaced by \"code line\" [sort of \"similarity\" to code line]</p>\n</blockquote>\n<h5><a href=\"https://github.com/KTH/CodRep-competition/issues/29\" target=\"_blank\">1st place</a></h5>\n<p><strong>Treated as a search/ranking</strong> </p>\n<ul>\n<li>Extracted features and then used \"learning to rank\" model. </li>\n</ul>\n<p><strong>Post-processing</strong></p>\n<ul>\n<li>Ruled out the highest ranked prediction if applying the repair at that location yields a syntax error (they were allowed to do that? 😂)</li>\n</ul>\n<p>Here's a table that summarizes our results:</p>\n<h5><a href=\"https://github.com/KTH/CodRep-competition/issues/16\" target=\"_blank\">2nd place</a></h5>\n<blockquote>\n  <p>This was a bit messy to follow since they didn't have a full writeup. This is what I managed to extract from conversation over the pull request.</p>\n</blockquote>\n<ul>\n<li><p><strong>Had simple string similarity</strong> version that turned out to be a really strong baseline</p></li>\n<li><p><strong>Hand crafted features for a tree based model</strong>: High-level AST of each line (basically the type of each code element, VARIABLE, CLASS, STRING, COMMENT, NUMBER, TOKEN, KEYWORD)</p></li>\n<li><p><strong>Cool Trick</strong> One idea: because code tends to be added to the end of the file, and new code tend to be more buggy than old code.</p></li>\n</ul>\n<h5><a href=\"https://github.com/jjhenkel/instauro\" target=\"_blank\">3rd place</a></h5>\n<ul>\n<li><p><strong>LambdaMART using RankLib</strong></p></li>\n<li><p><strong>Used standard text similarity metrics</strong></p></li>\n</ul>\n<h5><a href=\"https://github.com/agb94/coldbrew/\" target=\"_blank\">4th place</a></h5>\n<blockquote>\n  <p>No writeup, reversed the code</p>\n</blockquote>\n<ul>\n<li><strong>Trained GP</strong> on the features: The Sum of Matching Blocks' Size, Edit Distance, Lexical Similarity, Keyword Similarity</li>\n</ul>\n<h5><a href=\"https://github.com/cesarsotovalero/CodRep-submission\" target=\"_blank\">5th place</a></h5>\n<p>Used:</p>\n<ul>\n<li><p>string matching</p></li>\n<li><p>parse checking</p></li>\n<li><p>decision rules</p></li>\n<li><p>heuristics</p></li>\n</ul>\n<p><a href=\"https://link.springer.com/article/10.1007/s10664-017-9564-7\" target=\"_blank\">related paper</a></p>\n<h5><a href=\"https://github.com/egor-bogomolov/CodRep-competition/blob/master/Solutions/prefSufMatch.py\" target=\"_blank\">6th place</a></h5>\n<ul>\n<li>Submitted a naive (handcrafted, hardcoded) baseline</li>\n</ul>",
      "rawMarkdown": "# Tricks From Winning Solutions Of Other Code Competitions\n\n\nHi guys, \nI just finished going through all the winning solutions of 4 different code competitions (not all from Kaggle). \n\nHere are all the tricks they used.\nEnjoy yourself!\n\n\n### [Where there's code, there's bug](https://www.kaggle.com/competitions/wherethereiscodethereisbug/overview) - Last week\n\n> Classification: Line by line, some lines have bugs\n\n\n##### [4th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738)\n\n**2 Stage Pipeline**\n- **Backbone** - CodeBERTa-small-v1 - applied to each code line - chose one fold (out of the 4)\n- **Linear classifier** runs on concatenation of the backbone pooler outputs\n\n\n##### [4th solution - Giba's approach](https://www.kaggle.com/code/karthickp6/giba-s-approach-tfidf-logistic-reg-lb-0-86538)\n\n![](https://i.ibb.co/pRgRJ8Y/Selection-898.png)\n\n**Super simple pipeline**\n\n- TFIDF (ngrams=(1,2))\n\n- LogisticRegression \n\n- Blended with the rest of the team \n\n\n##### [6th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738)\n\n**Models**\n\n- \"microsoft/codebert-base\" (2 folds)\n- \"huggingface/CodeBERTa-small-v1\" (2x 1 fold + 1x 2 folds)\n- \"flax-sentence-embeddings/st-codesearch-distilroberta-base\" (1 fold)\n\n\n**Input & output**\n\n- Model Input : [CLS] line 1 [SEP] line 2 [SEP] line 3 [SEP] line 4 [SEP] line 5 [SEP]\n- Average pooling on the last features + dense + tanh + dense\n\n\n**Training**\n- bs=32, max_len=200\n- lr: 4e-5, apart for some CodeBERTa exps (tried 2e-5 and 5e-5)\n- 5 epochs for codebert, 4 for 3 or 4 were enough for the other smaller models\n\n**Post-processing**\n- Noticed that there were duplicates in the training data, and codes that were present twice had different labels\n- Gave a 0.5 score to duplicated texts\n\n##### [7th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328731)\n\n\n**Injected Special Token**\n\n**Many Models Ensemble**\n\n> Note: always select a single fold.\n\n- codebert-base(only 3line)\n- roberta-base(all sentences)\n- electra-base-discriminator(all sentences, epoch3)\n- destilbert-base-uncased(all sentences, epoch3)\n- codeberta-small-v1(all sentences, epoch 3)\n- codebert_base(all sentences, epoch7)\n- codebert-base(all sentences, epoch3)\n- codebert-base-mlm(all sentences, epoch3)\n- codebert-base-mlm(all sentences, epoch3)\n- muppet-roberta-base(all sentences, epoch4)\n- graphcodebert-base(all sentences, epoch3)\n\n### NLC2CMD - NuerIPS 2020\n\n> Task: Translate english to bash syntax\n\n\n##### 1st place\n\n[github](https://github.com/magnumresearchgroup/Magnum-NLC2CMD) | [paper](https://www.dre.vanderbilt.edu/~schmidt/PDF/A_Transformer_based_Approach_for_TranslatingNatural_Language_to_Bash_Commands.pdf)\n\n**Transformer + Architecture Improvements**\n\n**Custom Tokenizer** \n\n- Found by hyperparam search that they can shrink the vocabulary size by 90% and it even improves the results \n\n- **Heuristic improved beam search**\n\n\n##### 2nd place\n\n[github](https://github.com/nokia/nlc2cmd-submission-hubris)\n\n**[Custom HF Trainer](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/trainer.py)**\n\n**[Heavy preprocessing](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/notebooks/data_preprocess.ipynb)**\n\n> why didnt they just summarize thisssssss???? @#$@#%\n\n**[Custom diverse_beam_search](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/diverse_beam_search.py)**\n\n\n\n##### 3rd place\n\n[github](https://github.com/JetBrains/nlc2cmd) | [paper](https://github.com/JetBrains/nlc2cmd/blob/master/report.pdf)\n\n**Augmentations**\n\nBacktranslated (only the english prompt) using fairseq pretrained models, used only predictions with BLEU higher then a threshold (to avoid training their model with the mistakes of the fairseq model)\n\n**Data Generation**\n\nGenerated more data from the manpage: Commands were created by concatenating cmd name & some random flags, \nChanged some common pipline endings that were \"too easy\" such as \"wc\" & \"how many\"\n\n**Preprocessing**\n\n- **English prompt:** Removed stopwords using nltk and stemmed using Snowballstemmer\n- **Bash cmd:** changed all arguments to \"ARG\"\n\n**Postprocessing**\n\n- **Used two models, one for \n\n\n##### 4th place\n\n[github](https://github.com/Samsung/NLC2CMD)\n\n\n> Again, reversing their code\n\n**Fairseq Model** \n\n- can by seed by their trainer [script](https://github.com/Samsung/NLC2CMD/blob/main/train/3.train_template_predictor.sh)\n\n**Two models**\n\n- One for detecting templates \n- Other for detecting arguments\n\n\n##### 6th place\n\n[github](https://github.com/DNGros/clai) | [demo](https://clai-home.mybluemix.net/) | [paper](https://arxiv.org/abs/2002.00762)\n\n##### 9th place\n\n[github](https://github.com/greenmonn/nlc2cmd-competition) | [paper](https://ibm.box.com/s/3nb9oypu2iuiq3ow0m849o44ycd8jdbw)\n\n**Tree RNN Tensorflow Model**\n\n- Right [here](https://github.com/greenmonn/nlc2cmd-competition/blob/dfb28149deee16043b604dda4ea8a45ce4413938/nl2bash/encoder_decoder/seq2tree/tree_rnn_cell.py)\n\n- They also have many variations in the code with multiple heads and so on. They probably didn't delete the past experiments they tried.\n\n\n\n### CodRep-2019\n\n> Task: predict formatting errors in source code\n\n##### [2nd place](https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05)\n\n**Preprocessing**\n\n- **Manually defined** [22 regex](https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05) expressions for automaticlly detect common source code errors.\n\n- **Used the regex to clean manually a high quality dataset by hand** then trained a generative language model only on those samples.\n\n[this is a really cool idea..]\n\n- **Added common meaningful words** to the tokenizer such as \"True\" \"False\" \"if\"..\n\n- Optimized n-grams size (7 was optimal) so the distribution of tokens for \"broken/not broken\" would by as close as possible to 50%/50% then they used these token to train a balanced XGBoost classifier and an 1-class SVM for outlier detection.\n\n- **Ensemble:** prediction char by char (mean) with all models, then activate the regex on the \"most problematic\" parts of the text as post processing. \n\n\n### [CodRep-2018](https://github.com/KTH/CodRep-competition)\n\n> Task: replace lines in a given code: On a pair (code line, code file) predict for each line in \"code file\" the probability so that this is the line that needs to be replaced by \"code line\" [sort of \"similarity\" to code line]\n\n\n##### [1st place](https://github.com/KTH/CodRep-competition/issues/29)\n\n**Treated as a search/ranking** \n\n- Extracted features and then used \"learning to rank\" model. \n\n\n**Post-processing**\n- Ruled out the highest ranked prediction if applying the repair at that location yields a syntax error (they were allowed to do that? 😂)\n\nHere's a table that summarizes our results:\n\n##### [2nd place](https://github.com/KTH/CodRep-competition/issues/16)\n\n> This was a bit messy to follow since they didn't have a full writeup. This is what I managed to extract from conversation over the pull request.\n\n- **Had simple string similarity** version that turned out to be a really strong baseline\n\n- **Hand crafted features for a tree based model**: High-level AST of each line (basically the type of each code element, VARIABLE, CLASS, STRING, COMMENT, NUMBER, TOKEN, KEYWORD)\n\n- **Cool Trick** One idea: because code tends to be added to the end of the file, and new code tend to be more buggy than old code.\n\n##### [3rd place](https://github.com/jjhenkel/instauro)\n\n- **LambdaMART using RankLib**\n\n- **Used standard text similarity metrics**\n\n\n##### [4th place](https://github.com/agb94/coldbrew/)\n\n> No writeup, reversed the code\n\n- **Trained GP** on the features: The Sum of Matching Blocks' Size, Edit Distance, Lexical Similarity, Keyword Similarity\n\n\n##### [5th place](https://github.com/cesarsotovalero/CodRep-submission)\n\nUsed:\n\n- string matching\n\n- parse checking\n\n- decision rules\n\n- heuristics\n\n[related paper](https://link.springer.com/article/10.1007/s10664-017-9564-7)\n\n##### [6th place](https://github.com/egor-bogomolov/CodRep-competition/blob/master/Solutions/prefSufMatch.py)\n\n- Submitted a naive (handcrafted, hardcoded) baseline",
      "votes": null
    },
    {
      "id": "1818622",
      "postDate": "06/13/2022 01:36:40",
      "content": "<p>Thanks for putting this out! Just one quick question, why should you only select a single fold? Isn't using multiple per model just like a big pasting ensemble for the model?</p>",
      "rawMarkdown": "Thanks for putting this out! Just one quick question, why should you only select a single fold? Isn't using multiple per model just like a big pasting ensemble for the model?",
      "votes": null
    },
    {
      "id": "1820868",
      "postDate": "06/15/2022 04:25:32",
      "content": "<p>Thank you so much for looking into so many references. I think it will be a lot of study. Thank you. <a href=\"https://www.kaggle.com/thedevastator\" target=\"_blank\">@thedevastator</a> 👍👍</p>",
      "rawMarkdown": "Thank you so much for looking into so many references. I think it will be a lot of study. Thank you. @thedevastator 👍👍",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1818622,
      "author_name": "leoxu1243876",
      "author_url": "",
      "post_date": "06/13/2022 01:36:40",
      "content": "<p>Thanks for putting this out! Just one quick question, why should you only select a single fold? Isn't using multiple per model just like a big pasting ensemble for the model?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1820868,
      "author_name": "heuingttiang",
      "author_url": "",
      "post_date": "06/15/2022 04:25:32",
      "content": "<p>Thank you so much for looking into so many references. I think it will be a lot of study. Thank you. <a href=\"https://www.kaggle.com/thedevastator\" target=\"_blank\">@thedevastator</a> 👍👍</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1818521": "# Tricks From Winning Solutions Of Other Code Competitions\n\n\nHi guys, \nI just finished going through all the winning solutions of 4 different code competitions (not all from Kaggle). \n\nHere are all the tricks they used.\nEnjoy yourself!\n\n\n### [Where there's code, there's bug](https://www.kaggle.com/competitions/wherethereiscodethereisbug/overview) - Last week\n\n> Classification: Line by line, some lines have bugs\n\n\n##### [4th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738)\n\n**2 Stage Pipeline**\n- **Backbone** - CodeBERTa-small-v1 - applied to each code line - chose one fold (out of the 4)\n- **Linear classifier** runs on concatenation of the backbone pooler outputs\n\n\n##### [4th solution - Giba's approach](https://www.kaggle.com/code/karthickp6/giba-s-approach-tfidf-logistic-reg-lb-0-86538)\n\n![](https://i.ibb.co/pRgRJ8Y/Selection-898.png)\n\n**Super simple pipeline**\n\n- TFIDF (ngrams=(1,2))\n\n- LogisticRegression \n\n- Blended with the rest of the team \n\n\n##### [6th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328738)\n\n**Models**\n\n- \"microsoft/codebert-base\" (2 folds)\n- \"huggingface/CodeBERTa-small-v1\" (2x 1 fold + 1x 2 folds)\n- \"flax-sentence-embeddings/st-codesearch-distilroberta-base\" (1 fold)\n\n\n**Input & output**\n\n- Model Input : [CLS] line 1 [SEP] line 2 [SEP] line 3 [SEP] line 4 [SEP] line 5 [SEP]\n- Average pooling on the last features + dense + tanh + dense\n\n\n**Training**\n- bs=32, max_len=200\n- lr: 4e-5, apart for some CodeBERTa exps (tried 2e-5 and 5e-5)\n- 5 epochs for codebert, 4 for 3 or 4 were enough for the other smaller models\n\n**Post-processing**\n- Noticed that there were duplicates in the training data, and codes that were present twice had different labels\n- Gave a 0.5 score to duplicated texts\n\n##### [7th solution](https://www.kaggle.com/competitions/wherethereiscodethereisbug/discussion/328731)\n\n\n**Injected Special Token**\n\n**Many Models Ensemble**\n\n> Note: always select a single fold.\n\n- codebert-base(only 3line)\n- roberta-base(all sentences)\n- electra-base-discriminator(all sentences, epoch3)\n- destilbert-base-uncased(all sentences, epoch3)\n- codeberta-small-v1(all sentences, epoch 3)\n- codebert_base(all sentences, epoch7)\n- codebert-base(all sentences, epoch3)\n- codebert-base-mlm(all sentences, epoch3)\n- codebert-base-mlm(all sentences, epoch3)\n- muppet-roberta-base(all sentences, epoch4)\n- graphcodebert-base(all sentences, epoch3)\n\n### NLC2CMD - NuerIPS 2020\n\n> Task: Translate english to bash syntax\n\n\n##### 1st place\n\n[github](https://github.com/magnumresearchgroup/Magnum-NLC2CMD) | [paper](https://www.dre.vanderbilt.edu/~schmidt/PDF/A_Transformer_based_Approach_for_TranslatingNatural_Language_to_Bash_Commands.pdf)\n\n**Transformer + Architecture Improvements**\n\n**Custom Tokenizer** \n\n- Found by hyperparam search that they can shrink the vocabulary size by 90% and it even improves the results \n\n- **Heuristic improved beam search**\n\n\n##### 2nd place\n\n[github](https://github.com/nokia/nlc2cmd-submission-hubris)\n\n**[Custom HF Trainer](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/trainer.py)**\n\n**[Heavy preprocessing](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/notebooks/data_preprocess.ipynb)**\n\n> why didnt they just summarize thisssssss???? @#$@#%\n\n**[Custom diverse_beam_search](https://github.com/nokia/nlc2cmd-submission-hubris/blob/main/src/diverse_beam_search.py)**\n\n\n\n##### 3rd place\n\n[github](https://github.com/JetBrains/nlc2cmd) | [paper](https://github.com/JetBrains/nlc2cmd/blob/master/report.pdf)\n\n**Augmentations**\n\nBacktranslated (only the english prompt) using fairseq pretrained models, used only predictions with BLEU higher then a threshold (to avoid training their model with the mistakes of the fairseq model)\n\n**Data Generation**\n\nGenerated more data from the manpage: Commands were created by concatenating cmd name & some random flags, \nChanged some common pipline endings that were \"too easy\" such as \"wc\" & \"how many\"\n\n**Preprocessing**\n\n- **English prompt:** Removed stopwords using nltk and stemmed using Snowballstemmer\n- **Bash cmd:** changed all arguments to \"ARG\"\n\n**Postprocessing**\n\n- **Used two models, one for \n\n\n##### 4th place\n\n[github](https://github.com/Samsung/NLC2CMD)\n\n\n> Again, reversing their code\n\n**Fairseq Model** \n\n- can by seed by their trainer [script](https://github.com/Samsung/NLC2CMD/blob/main/train/3.train_template_predictor.sh)\n\n**Two models**\n\n- One for detecting templates \n- Other for detecting arguments\n\n\n##### 6th place\n\n[github](https://github.com/DNGros/clai) | [demo](https://clai-home.mybluemix.net/) | [paper](https://arxiv.org/abs/2002.00762)\n\n##### 9th place\n\n[github](https://github.com/greenmonn/nlc2cmd-competition) | [paper](https://ibm.box.com/s/3nb9oypu2iuiq3ow0m849o44ycd8jdbw)\n\n**Tree RNN Tensorflow Model**\n\n- Right [here](https://github.com/greenmonn/nlc2cmd-competition/blob/dfb28149deee16043b604dda4ea8a45ce4413938/nl2bash/encoder_decoder/seq2tree/tree_rnn_cell.py)\n\n- They also have many variations in the code with multiple heads and so on. They probably didn't delete the past experiments they tried.\n\n\n\n### CodRep-2019\n\n> Task: predict formatting errors in source code\n\n##### [2nd place](https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05)\n\n**Preprocessing**\n\n- **Manually defined** [22 regex](https://gist.github.com/kyrcha/4d4ebf960051ccfc8764d1f0f7ca6a05) expressions for automaticlly detect common source code errors.\n\n- **Used the regex to clean manually a high quality dataset by hand** then trained a generative language model only on those samples.\n\n[this is a really cool idea..]\n\n- **Added common meaningful words** to the tokenizer such as \"True\" \"False\" \"if\"..\n\n- Optimized n-grams size (7 was optimal) so the distribution of tokens for \"broken/not broken\" would by as close as possible to 50%/50% then they used these token to train a balanced XGBoost classifier and an 1-class SVM for outlier detection.\n\n- **Ensemble:** prediction char by char (mean) with all models, then activate the regex on the \"most problematic\" parts of the text as post processing. \n\n\n### [CodRep-2018](https://github.com/KTH/CodRep-competition)\n\n> Task: replace lines in a given code: On a pair (code line, code file) predict for each line in \"code file\" the probability so that this is the line that needs to be replaced by \"code line\" [sort of \"similarity\" to code line]\n\n\n##### [1st place](https://github.com/KTH/CodRep-competition/issues/29)\n\n**Treated as a search/ranking** \n\n- Extracted features and then used \"learning to rank\" model. \n\n\n**Post-processing**\n- Ruled out the highest ranked prediction if applying the repair at that location yields a syntax error (they were allowed to do that? 😂)\n\nHere's a table that summarizes our results:\n\n##### [2nd place](https://github.com/KTH/CodRep-competition/issues/16)\n\n> This was a bit messy to follow since they didn't have a full writeup. This is what I managed to extract from conversation over the pull request.\n\n- **Had simple string similarity** version that turned out to be a really strong baseline\n\n- **Hand crafted features for a tree based model**: High-level AST of each line (basically the type of each code element, VARIABLE, CLASS, STRING, COMMENT, NUMBER, TOKEN, KEYWORD)\n\n- **Cool Trick** One idea: because code tends to be added to the end of the file, and new code tend to be more buggy than old code.\n\n##### [3rd place](https://github.com/jjhenkel/instauro)\n\n- **LambdaMART using RankLib**\n\n- **Used standard text similarity metrics**\n\n\n##### [4th place](https://github.com/agb94/coldbrew/)\n\n> No writeup, reversed the code\n\n- **Trained GP** on the features: The Sum of Matching Blocks' Size, Edit Distance, Lexical Similarity, Keyword Similarity\n\n\n##### [5th place](https://github.com/cesarsotovalero/CodRep-submission)\n\nUsed:\n\n- string matching\n\n- parse checking\n\n- decision rules\n\n- heuristics\n\n[related paper](https://link.springer.com/article/10.1007/s10664-017-9564-7)\n\n##### [6th place](https://github.com/egor-bogomolov/CodRep-competition/blob/master/Solutions/prefSufMatch.py)\n\n- Submitted a naive (handcrafted, hardcoded) baseline",
    "1818622": "Thanks for putting this out! Just one quick question, why should you only select a single fold? Isn't using multiple per model just like a big pasting ensemble for the model?",
    "1820868": "Thank you so much for looking into so many references. I think it will be a lot of study. Thank you. @thedevastator 👍👍"
  },
  "source": "meta"
}