{
  "id": 368997,
  "title": "10th place solution",
  "url": "/competitions/AI4Code/writeups/guanshuo-xu-10th-place-solution",
  "author_name": "",
  "post_date": "2022-11-28T16:39:20.330291300Z",
  "votes": 13,
  "comment_count": 1,
  "views": 0,
  "content": "<h4>Overview</h4>\n<p>First, I would like to thank Kaggle and Google and X for hosting this interesting competition. <br>\nIn my approach, all the markdown and code cells in a notebook are tokenized and concatenated to form a long input sequence, with all the markdown cells go first followed by all the code cells, and they are separated with a [SEP] token. There are also special separator tokens added for markdown (MKDS) and code (CDS) respectively. Once the input goes through the transformer, tokens of each cell is aggregated by meanpooling and a linear layer to map to a single value. During training, the output of each cell is penalized with a pairwise ranking loss which considers all the combinations of cells within a notebook. For inference we can simply sort the output of each cell for correct order. </p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F478989%2Ff7de356d26ff88204073ee34d459e7b5%2FUntitled%20Diagram.drawio.png?generation=1669608703048539&amp;alt=media\" alt=\"\"></p>\n<h4>Source Code</h4>\n<p><a href=\"https://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks\" target=\"_blank\">https://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks</a></p>\n<h4>What Worked</h4>\n<ul>\n<li>torch.nn.MarginRankingLoss works better than BCE and MSE loss</li>\n<li>deberta-v3-large is the best transformer in Huggingface for this task</li>\n<li>longer training sequence (2048) and even longer inference (4096 for validation and 4352 for submission). </li>\n<li>compress markdown cells with <a href=\"https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe\" target=\"_blank\">https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe</a></li>\n<li>compress code cells with <a href=\"https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook\" target=\"_blank\">https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook</a></li>\n</ul>\n<h4>What didn't Work</h4>\n<ul>\n<li>seq-to-seq model like T5</li>\n<li>multilingual models</li>\n</ul>",
  "messages": [
    {
      "id": "2047147",
      "postDate": "11/28/2022 16:39:20",
      "content": "<h4>Overview</h4>\n<p>First, I would like to thank Kaggle and Google and X for hosting this interesting competition. <br>\nIn my approach, all the markdown and code cells in a notebook are tokenized and concatenated to form a long input sequence, with all the markdown cells go first followed by all the code cells, and they are separated with a [SEP] token. There are also special separator tokens added for markdown (MKDS) and code (CDS) respectively. Once the input goes through the transformer, tokens of each cell is aggregated by meanpooling and a linear layer to map to a single value. During training, the output of each cell is penalized with a pairwise ranking loss which considers all the combinations of cells within a notebook. For inference we can simply sort the output of each cell for correct order. </p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F478989%2Ff7de356d26ff88204073ee34d459e7b5%2FUntitled%20Diagram.drawio.png?generation=1669608703048539&amp;alt=media\" alt=\"\"></p>\n<h4>Source Code</h4>\n<p><a href=\"https://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks\" target=\"_blank\">https://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks</a></p>\n<h4>What Worked</h4>\n<ul>\n<li>torch.nn.MarginRankingLoss works better than BCE and MSE loss</li>\n<li>deberta-v3-large is the best transformer in Huggingface for this task</li>\n<li>longer training sequence (2048) and even longer inference (4096 for validation and 4352 for submission). </li>\n<li>compress markdown cells with <a href=\"https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe\" target=\"_blank\">https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe</a></li>\n<li>compress code cells with <a href=\"https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook\" target=\"_blank\">https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook</a></li>\n</ul>\n<h4>What didn't Work</h4>\n<ul>\n<li>seq-to-seq model like T5</li>\n<li>multilingual models</li>\n</ul>",
      "rawMarkdown": "#### Overview\nFirst, I would like to thank Kaggle and Google and X for hosting this interesting competition. \nIn my approach, all the markdown and code cells in a notebook are tokenized and concatenated to form a long input sequence, with all the markdown cells go first followed by all the code cells, and they are separated with a [SEP] token. There are also special separator tokens added for markdown (MKDS) and code (CDS) respectively. Once the input goes through the transformer, tokens of each cell is aggregated by meanpooling and a linear layer to map to a single value. During training, the output of each cell is penalized with a pairwise ranking loss which considers all the combinations of cells within a notebook. For inference we can simply sort the output of each cell for correct order. \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F478989%2Ff7de356d26ff88204073ee34d459e7b5%2FUntitled%20Diagram.drawio.png?generation=1669608703048539&alt=media)\n\n#### Source Code\nhttps://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks\n\n#### What Worked\n- torch.nn.MarginRankingLoss works better than BCE and MSE loss\n- deberta-v3-large is the best transformer in Huggingface for this task\n- longer training sequence (2048) and even longer inference (4096 for validation and 4352 for submission). \n- compress markdown cells with https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe\n- compress code cells with https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook\n\n#### What didn't Work\n- seq-to-seq model like T5\n- multilingual models",
      "votes": null
    },
    {
      "id": "2047174",
      "postDate": "11/28/2022 17:00:30",
      "content": "<p>Many people don't realize that not only your code wins Kaggle competitions. </p>\n<p><strong>In terms of code quality: You are on a different level than nearly everyone else on Kaggle.</strong></p>\n<p>You get to these results with 10% of the amount of code in comparison to other \"High scoring\" solutions, your solution to Jigsaw had been unbelievably useful for me simply because it is minimalistic: <br>\nOnly what is actually needed is included. No huge configs you can not replicate. Everything is encapsulated in its own function / simple-file.</p>\n<p>Didn't go through this repository yet but I am sure it is 10/10. </p>\n<p>Keep humiliating us all and thank you for sharing! <a href=\"https://www.kaggle.com/wowfattie\" target=\"_blank\">@wowfattie</a> </p>",
      "rawMarkdown": "Many people don't realize that not only your code wins Kaggle competitions. \n\n**In terms of code quality: You are on a different level than nearly everyone else on Kaggle.**\n\nYou get to these results with 10% of the amount of code in comparison to other \"High scoring\" solutions, your solution to Jigsaw had been unbelievably useful for me simply because it is minimalistic: \nOnly what is actually needed is included. No huge configs you can not replicate. Everything is encapsulated in its own function / simple-file.\n\nDidn't go through this repository yet but I am sure it is 10/10. \n\nKeep humiliating us all and thank you for sharing! @wowfattie",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2047174,
      "author_name": "thedevastator",
      "author_url": "",
      "post_date": "11/28/2022 17:00:30",
      "content": "<p>Many people don't realize that not only your code wins Kaggle competitions. </p>\n<p><strong>In terms of code quality: You are on a different level than nearly everyone else on Kaggle.</strong></p>\n<p>You get to these results with 10% of the amount of code in comparison to other \"High scoring\" solutions, your solution to Jigsaw had been unbelievably useful for me simply because it is minimalistic: <br>\nOnly what is actually needed is included. No huge configs you can not replicate. Everything is encapsulated in its own function / simple-file.</p>\n<p>Didn't go through this repository yet but I am sure it is 10/10. </p>\n<p>Keep humiliating us all and thank you for sharing! <a href=\"https://www.kaggle.com/wowfattie\" target=\"_blank\">@wowfattie</a> </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2047147": "#### Overview\nFirst, I would like to thank Kaggle and Google and X for hosting this interesting competition. \nIn my approach, all the markdown and code cells in a notebook are tokenized and concatenated to form a long input sequence, with all the markdown cells go first followed by all the code cells, and they are separated with a [SEP] token. There are also special separator tokens added for markdown (MKDS) and code (CDS) respectively. Once the input goes through the transformer, tokens of each cell is aggregated by meanpooling and a linear layer to map to a single value. During training, the output of each cell is penalized with a pairwise ranking loss which considers all the combinations of cells within a notebook. For inference we can simply sort the output of each cell for correct order. \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F478989%2Ff7de356d26ff88204073ee34d459e7b5%2FUntitled%20Diagram.drawio.png?generation=1669608703048539&alt=media)\n\n#### Source Code\nhttps://github.com/GuanshuoXu/Google-AI4Code-Understand-Code-in-Python-Notebooks\n\n#### What Worked\n- torch.nn.MarginRankingLoss works better than BCE and MSE loss\n- deberta-v3-large is the best transformer in Huggingface for this task\n- longer training sequence (2048) and even longer inference (4096 for validation and 4352 for submission). \n- compress markdown cells with https://gist.github.com/lorey/eb15a7f3338f959a78cc3661fbc255fe\n- compress code cells with https://www.kaggle.com/code/haithamaliryan/ai4code-extract-all-functions-variables-names/notebook\n\n#### What didn't Work\n- seq-to-seq model like T5\n- multilingual models",
    "2047174": "Many people don't realize that not only your code wins Kaggle competitions. \n\n**In terms of code quality: You are on a different level than nearly everyone else on Kaggle.**\n\nYou get to these results with 10% of the amount of code in comparison to other \"High scoring\" solutions, your solution to Jigsaw had been unbelievably useful for me simply because it is minimalistic: \nOnly what is actually needed is included. No huge configs you can not replicate. Everything is encapsulated in its own function / simple-file.\n\nDidn't go through this repository yet but I am sure it is 10/10. \n\nKeep humiliating us all and thank you for sharing! @wowfattie"
  },
  "source": "meta"
}