{
  "id": 343762,
  "title": "[Public 31st] CodeT5-base Encoder 1024",
  "url": "/competitions/AI4Code/writeups/vecxoz-public-31st-codet5-base-encoder-1024",
  "author_name": "",
  "post_date": "2023-05-01T08:36:44.827Z",
  "votes": 27,
  "comment_count": 11,
  "views": 0,
  "content": "<p>Many thanks to Kaggle and Google X for an exciting unique challenge. Congrats to all participants!</p>\n<p>I used a point-wise ranking approach. Context for each markdown cell is dynamic, aiming to get as many meaningful tokens as possible. Specifically we reserve a maximum 128 tokens for markdown cell (query) and the rest goes for context. Context pool contains all code cells followed by all markdown cells except the query. Code cells in the context pool are always ordered, markdown cells are shuffled for each example. Sampling from a context pool is based on evenly distributed amounts of tokens taken from each cell. Specifically we start from 1 token per cell. If the total amount of sampled tokens is less than max length we try to take 2 tokens from each cell, and so on. Eventually if we cannot collect enough tokens padding is applied.</p>\n<p>I tried several backbones and found GraphCodeBERT-base and CodeT5-base being the best ones. They have similar performance on 512 length while CodeT5 was slightly better in my experiments. CodeT5 with 1024 max length demonstrated significant improvement over 512 max length, about 0.014. Single checkpoint takes 4 hours for inference and gets the score around 0.8700. I got my final score with an ensemble of 2 checkpoints from different folds, but they still were undertrained so probably a single checkpoint can reach even higher.</p>\n<p>I did not use any additional data. I believe the official training set is already representative enough. I used a validation set of 27k notebooks obtained by group split. CV scores correlate very well, being systematically 0.003 higher than LB. Source cleaning is minimalistic. I just removed extra spaces including all indents from the code to make it more compact.</p>\n<p>Acknowledgment. Huge thanks to the <a href=\"https://sites.research.google/trc/about/\" target=\"_blank\">TRC</a> program for TPU resources.</p>\n<p>Best of luck to all in the 2nd phase rerun! <br>\nHopefully our models will not encounter spherical endless notebooks especially in vacuum.</p>\n<p>EDIT: <a href=\"https://github.com/vecxoz/ai4code\" target=\"_blank\">Solution code</a></p>",
  "messages": [
    {
      "id": "1895849",
      "postDate": "08/12/2022 12:03:05",
      "content": "<p>Many thanks to Kaggle and Google X for an exciting unique challenge. Congrats to all participants!</p>\n<p>I used a point-wise ranking approach. Context for each markdown cell is dynamic, aiming to get as many meaningful tokens as possible. Specifically we reserve a maximum 128 tokens for markdown cell (query) and the rest goes for context. Context pool contains all code cells followed by all markdown cells except the query. Code cells in the context pool are always ordered, markdown cells are shuffled for each example. Sampling from a context pool is based on evenly distributed amounts of tokens taken from each cell. Specifically we start from 1 token per cell. If the total amount of sampled tokens is less than max length we try to take 2 tokens from each cell, and so on. Eventually if we cannot collect enough tokens padding is applied.</p>\n<p>I tried several backbones and found GraphCodeBERT-base and CodeT5-base being the best ones. They have similar performance on 512 length while CodeT5 was slightly better in my experiments. CodeT5 with 1024 max length demonstrated significant improvement over 512 max length, about 0.014. Single checkpoint takes 4 hours for inference and gets the score around 0.8700. I got my final score with an ensemble of 2 checkpoints from different folds, but they still were undertrained so probably a single checkpoint can reach even higher.</p>\n<p>I did not use any additional data. I believe the official training set is already representative enough. I used a validation set of 27k notebooks obtained by group split. CV scores correlate very well, being systematically 0.003 higher than LB. Source cleaning is minimalistic. I just removed extra spaces including all indents from the code to make it more compact.</p>\n<p>Acknowledgment. Huge thanks to the <a href=\"https://sites.research.google/trc/about/\" target=\"_blank\">TRC</a> program for TPU resources.</p>\n<p>Best of luck to all in the 2nd phase rerun! <br>\nHopefully our models will not encounter spherical endless notebooks especially in vacuum.</p>\n<p>EDIT: <a href=\"https://github.com/vecxoz/ai4code\" target=\"_blank\">Solution code</a></p>",
      "rawMarkdown": "Many thanks to Kaggle and Google X for an exciting unique challenge. Congrats to all participants!\n\nI used a point-wise ranking approach. Context for each markdown cell is dynamic, aiming to get as many meaningful tokens as possible. Specifically we reserve a maximum 128 tokens for markdown cell (query) and the rest goes for context. Context pool contains all code cells followed by all markdown cells except the query. Code cells in the context pool are always ordered, markdown cells are shuffled for each example. Sampling from a context pool is based on evenly distributed amounts of tokens taken from each cell. Specifically we start from 1 token per cell. If the total amount of sampled tokens is less than max length we try to take 2 tokens from each cell, and so on. Eventually if we cannot collect enough tokens padding is applied.\n\nI tried several backbones and found GraphCodeBERT-base and CodeT5-base being the best ones. They have similar performance on 512 length while CodeT5 was slightly better in my experiments. CodeT5 with 1024 max length demonstrated significant improvement over 512 max length, about 0.014. Single checkpoint takes 4 hours for inference and gets the score around 0.8700. I got my final score with an ensemble of 2 checkpoints from different folds, but they still were undertrained so probably a single checkpoint can reach even higher.\n\nI did not use any additional data. I believe the official training set is already representative enough. I used a validation set of 27k notebooks obtained by group split. CV scores correlate very well, being systematically 0.003 higher than LB. Source cleaning is minimalistic. I just removed extra spaces including all indents from the code to make it more compact.\n\nAcknowledgment. Huge thanks to the [TRC](https://sites.research.google/trc/about/) program for TPU resources.\n\nBest of luck to all in the 2nd phase rerun! \nHopefully our models will not encounter spherical endless notebooks especially in vacuum.\n\nEDIT: [Solution code](https://github.com/vecxoz/ai4code)",
      "votes": null
    },
    {
      "id": "1896140",
      "postDate": "08/12/2022 16:03:11",
      "content": "<p>Good to see a CodeT5 model(encoder side). Congrats on your strong finish. Did you find any major benefits in putting the (unordered) markdowns in the context?</p>",
      "rawMarkdown": "Good to see a CodeT5 model(encoder side). Congrats on your strong finish. Did you find any major benefits in putting the (unordered) markdowns in the context?",
      "votes": null
    },
    {
      "id": "1896171",
      "postDate": "08/12/2022 16:19:15",
      "content": "<p>Thanks and congrats! Addition of markdown cells into context gave me a significant improvement (don't remember how much exactly). I shuffle them because during inference their order is unknown.</p>",
      "rawMarkdown": "Thanks and congrats! Addition of markdown cells into context gave me a significant improvement (don't remember how much exactly). I shuffle them because during inference their order is unknown.",
      "votes": null
    },
    {
      "id": "1896537",
      "postDate": "08/12/2022 22:19:02",
      "content": "<p>Congratulations (мої вітання)! Переходжу на англиську, щоб інші учасники змагання змогли зрозуміти. <br>\nWe also tried to train model with a higher max length (1024), but we don't have much time. It would probably improve us as you from your experiments by a lot. <br>\nThank you for the great solutions!</p>",
      "rawMarkdown": "Congratulations (мої вітання)! Переходжу на англиську, щоб інші учасники змагання змогли зрозуміти. \n\nWe also tried to train model with a higher max length (1024), but we don't have much time. It would probably improve us as you from your experiments by a lot. \n\nThank you for the great solutions!",
      "votes": null
    },
    {
      "id": "1896603",
      "postDate": "08/13/2022 00:59:22",
      "content": "<p>\"TPU\" then I guess your code is based on TensorFlow or Jax?</p>",
      "rawMarkdown": "\"TPU\" then I guess your code is based on TensorFlow or Jax?",
      "votes": null
    },
    {
      "id": "1896768",
      "postDate": "08/13/2022 06:22:11",
      "content": "<p>Thank you for your comment. I was wondering why this arrangement works till it finally stuck me just now. When we do a self-attention, every token attends to every other token and tries to build relationships. By putting the markdowns into the context, we give more information to model to build these relationships. Relationships are further \"strengthened\" by adding the positional embedding. Sure, these markdowns are unordered and so the strengthening does not happen but definitely the first part happens (building of relations). This leads to stronger score, I suspect. <br>\nVery strong innovation from your side!</p>",
      "rawMarkdown": "Thank you for your comment. I was wondering why this arrangement works till it finally stuck me just now. When we do a self-attention, every token attends to every other token and tries to build relationships. By putting the markdowns into the context, we give more information to model to build these relationships. Relationships are further \"strengthened\" by adding the positional embedding. Sure, these markdowns are unordered and so the strengthening does not happen but definitely the first part happens (building of relations). This leads to stronger score, I suspect. \nVery strong innovation from your side!",
      "votes": null
    },
    {
      "id": "1896907",
      "postDate": "08/13/2022 09:01:05",
      "content": "<p>Thanks! Yes, I had similar thoughts.</p>",
      "rawMarkdown": "Thanks! Yes, I had similar thoughts.",
      "votes": null
    },
    {
      "id": "1896908",
      "postDate": "08/13/2022 09:03:12",
      "content": "<p>Thanks a lot and congrats! Each competition is a great space for learning, especially when solving complicated tasks like this one. Good luck in the next competitions!</p>",
      "rawMarkdown": "Thanks a lot and congrats! Each competition is a great space for learning, especially when solving complicated tasks like this one. Good luck in the next competitions!",
      "votes": null
    },
    {
      "id": "1896913",
      "postDate": "08/13/2022 09:04:22",
      "content": "<p>Congrats on the high spot! Yes, 100% Tensorflow.</p>",
      "rawMarkdown": "Congrats on the high spot! Yes, 100% Tensorflow.",
      "votes": null
    },
    {
      "id": "1899080",
      "postDate": "08/15/2022 04:00:16",
      "content": "<p>Hi, amazing approach, and congrats on the strong finish!<br>\nI am not sure I understood exactly how you structured the problem at the end.<br>\nWhat exactly is the target of the model? Is it training on a single cell (indicated by the query) to predict a simple integer as the rank of that cell on the notebook? <br>\nAlso, do you plan to release the code? It is interesting to see how you actually implemented this.</p>\n<p>Thanks and congrats again.<br>\nThe Devastator.</p>",
      "rawMarkdown": "Hi, amazing approach, and congrats on the strong finish!\nI am not sure I understood exactly how you structured the problem at the end.\nWhat exactly is the target of the model? Is it training on a single cell (indicated by the query) to predict a simple integer as the rank of that cell on the notebook? \nAlso, do you plan to release the code? It is interesting to see how you actually implemented this.\n\nThanks and congrats again.\nThe Devastator.",
      "votes": null
    },
    {
      "id": "1899410",
      "postDate": "08/15/2022 08:46:34",
      "content": "<p>Thanks and congrats! Basically you are correct. I trained the model to predict the relative rank of each markdown cell within any given notebook. For example, say our notebook has 4 markdown cells and 4 code cells, and we want to create a training example for the very first markdown cell. In this case our training example would look like the following:</p>\n<p>[md1] + [sep] + [code1][code2][code3][code4][md4][md2][md3] and target rank is 0.0</p>\n<p>I plan to release the code, but not very soon. Need time for some cleaning. I will update this thread when it is ready.</p>",
      "rawMarkdown": "Thanks and congrats! Basically you are correct. I trained the model to predict the relative rank of each markdown cell within any given notebook. For example, say our notebook has 4 markdown cells and 4 code cells, and we want to create a training example for the very first markdown cell. In this case our training example would look like the following:\n\n[md1] + [sep] + [code1][code2][code3][code4][md4][md2][md3] and target rank is 0.0\n\nI plan to release the code, but not very soon. Need time for some cleaning. I will update this thread when it is ready.",
      "votes": null
    },
    {
      "id": "2241181",
      "postDate": "05/01/2023 09:06:29",
      "content": "<p>Recently returned to this project to run some experiments. Really great dataset.  <br>\nSorry, it’s a bit late, but still, here’s my <a href=\"https://github.com/vecxoz/ai4code\" target=\"_blank\">solution code</a>. It’s a minimalist TF/TPU pipeline. <a href=\"https://www.kaggle.com/thedevastator\" target=\"_blank\">@thedevastator</a></p>",
      "rawMarkdown": "Recently returned to this project to run some experiments. Really great dataset.  \nSorry, it’s a bit late, but still, here’s my [solution code](https://github.com/vecxoz/ai4code). It’s a minimalist TF/TPU pipeline. @thedevastator",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1896140,
      "author_name": "allohvk",
      "author_url": "",
      "post_date": "08/12/2022 16:03:11",
      "content": "<p>Good to see a CodeT5 model(encoder side). Congrats on your strong finish. Did you find any major benefits in putting the (unordered) markdowns in the context?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1896171,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "08/12/2022 16:19:15",
          "content": "<p>Thanks and congrats! Addition of markdown cells into context gave me a significant improvement (don't remember how much exactly). I shuffle them because during inference their order is unknown.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1896768,
          "author_name": "allohvk",
          "author_url": "",
          "post_date": "08/13/2022 06:22:11",
          "content": "<p>Thank you for your comment. I was wondering why this arrangement works till it finally stuck me just now. When we do a self-attention, every token attends to every other token and tries to build relationships. By putting the markdowns into the context, we give more information to model to build these relationships. Relationships are further \"strengthened\" by adding the positional embedding. Sure, these markdowns are unordered and so the strengthening does not happen but definitely the first part happens (building of relations). This leads to stronger score, I suspect. <br>\nVery strong innovation from your side!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1896907,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "08/13/2022 09:01:05",
          "content": "<p>Thanks! Yes, I had similar thoughts.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1896537,
      "author_name": "vad13irt",
      "author_url": "",
      "post_date": "08/12/2022 22:19:02",
      "content": "<p>Congratulations (мої вітання)! Переходжу на англиську, щоб інші учасники змагання змогли зрозуміти. <br>\nWe also tried to train model with a higher max length (1024), but we don't have much time. It would probably improve us as you from your experiments by a lot. <br>\nThank you for the great solutions!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1896908,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "08/13/2022 09:03:12",
          "content": "<p>Thanks a lot and congrats! Each competition is a great space for learning, especially when solving complicated tasks like this one. Good luck in the next competitions!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1896603,
      "author_name": "snaker",
      "author_url": "",
      "post_date": "08/13/2022 00:59:22",
      "content": "<p>\"TPU\" then I guess your code is based on TensorFlow or Jax?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1896913,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "08/13/2022 09:04:22",
          "content": "<p>Congrats on the high spot! Yes, 100% Tensorflow.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1899080,
      "author_name": "thedevastator",
      "author_url": "",
      "post_date": "08/15/2022 04:00:16",
      "content": "<p>Hi, amazing approach, and congrats on the strong finish!<br>\nI am not sure I understood exactly how you structured the problem at the end.<br>\nWhat exactly is the target of the model? Is it training on a single cell (indicated by the query) to predict a simple integer as the rank of that cell on the notebook? <br>\nAlso, do you plan to release the code? It is interesting to see how you actually implemented this.</p>\n<p>Thanks and congrats again.<br>\nThe Devastator.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1899410,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "08/15/2022 08:46:34",
          "content": "<p>Thanks and congrats! Basically you are correct. I trained the model to predict the relative rank of each markdown cell within any given notebook. For example, say our notebook has 4 markdown cells and 4 code cells, and we want to create a training example for the very first markdown cell. In this case our training example would look like the following:</p>\n<p>[md1] + [sep] + [code1][code2][code3][code4][md4][md2][md3] and target rank is 0.0</p>\n<p>I plan to release the code, but not very soon. Need time for some cleaning. I will update this thread when it is ready.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 2241181,
          "author_name": "vecxoz",
          "author_url": "",
          "post_date": "05/01/2023 09:06:29",
          "content": "<p>Recently returned to this project to run some experiments. Really great dataset.  <br>\nSorry, it’s a bit late, but still, here’s my <a href=\"https://github.com/vecxoz/ai4code\" target=\"_blank\">solution code</a>. It’s a minimalist TF/TPU pipeline. <a href=\"https://www.kaggle.com/thedevastator\" target=\"_blank\">@thedevastator</a></p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1895849": "Many thanks to Kaggle and Google X for an exciting unique challenge. Congrats to all participants!\n\nI used a point-wise ranking approach. Context for each markdown cell is dynamic, aiming to get as many meaningful tokens as possible. Specifically we reserve a maximum 128 tokens for markdown cell (query) and the rest goes for context. Context pool contains all code cells followed by all markdown cells except the query. Code cells in the context pool are always ordered, markdown cells are shuffled for each example. Sampling from a context pool is based on evenly distributed amounts of tokens taken from each cell. Specifically we start from 1 token per cell. If the total amount of sampled tokens is less than max length we try to take 2 tokens from each cell, and so on. Eventually if we cannot collect enough tokens padding is applied.\n\nI tried several backbones and found GraphCodeBERT-base and CodeT5-base being the best ones. They have similar performance on 512 length while CodeT5 was slightly better in my experiments. CodeT5 with 1024 max length demonstrated significant improvement over 512 max length, about 0.014. Single checkpoint takes 4 hours for inference and gets the score around 0.8700. I got my final score with an ensemble of 2 checkpoints from different folds, but they still were undertrained so probably a single checkpoint can reach even higher.\n\nI did not use any additional data. I believe the official training set is already representative enough. I used a validation set of 27k notebooks obtained by group split. CV scores correlate very well, being systematically 0.003 higher than LB. Source cleaning is minimalistic. I just removed extra spaces including all indents from the code to make it more compact.\n\nAcknowledgment. Huge thanks to the [TRC](https://sites.research.google/trc/about/) program for TPU resources.\n\nBest of luck to all in the 2nd phase rerun! \nHopefully our models will not encounter spherical endless notebooks especially in vacuum.\n\nEDIT: [Solution code](https://github.com/vecxoz/ai4code)",
    "1896140": "Good to see a CodeT5 model(encoder side). Congrats on your strong finish. Did you find any major benefits in putting the (unordered) markdowns in the context?",
    "1896171": "Thanks and congrats! Addition of markdown cells into context gave me a significant improvement (don't remember how much exactly). I shuffle them because during inference their order is unknown.",
    "1896537": "Congratulations (мої вітання)! Переходжу на англиську, щоб інші учасники змагання змогли зрозуміти. \n\nWe also tried to train model with a higher max length (1024), but we don't have much time. It would probably improve us as you from your experiments by a lot. \n\nThank you for the great solutions!",
    "1896603": "\"TPU\" then I guess your code is based on TensorFlow or Jax?",
    "1896768": "Thank you for your comment. I was wondering why this arrangement works till it finally stuck me just now. When we do a self-attention, every token attends to every other token and tries to build relationships. By putting the markdowns into the context, we give more information to model to build these relationships. Relationships are further \"strengthened\" by adding the positional embedding. Sure, these markdowns are unordered and so the strengthening does not happen but definitely the first part happens (building of relations). This leads to stronger score, I suspect. \nVery strong innovation from your side!",
    "1896907": "Thanks! Yes, I had similar thoughts.",
    "1896908": "Thanks a lot and congrats! Each competition is a great space for learning, especially when solving complicated tasks like this one. Good luck in the next competitions!",
    "1896913": "Congrats on the high spot! Yes, 100% Tensorflow.",
    "1899080": "Hi, amazing approach, and congrats on the strong finish!\nI am not sure I understood exactly how you structured the problem at the end.\nWhat exactly is the target of the model? Is it training on a single cell (indicated by the query) to predict a simple integer as the rank of that cell on the notebook? \nAlso, do you plan to release the code? It is interesting to see how you actually implemented this.\n\nThanks and congrats again.\nThe Devastator.",
    "1899410": "Thanks and congrats! Basically you are correct. I trained the model to predict the relative rank of each markdown cell within any given notebook. For example, say our notebook has 4 markdown cells and 4 code cells, and we want to create a training example for the very first markdown cell. In this case our training example would look like the following:\n\n[md1] + [sep] + [code1][code2][code3][code4][md4][md2][md3] and target rank is 0.0\n\nI plan to release the code, but not very soon. Need time for some cleaning. I will update this thread when it is ready.",
    "2241181": "Recently returned to this project to run some experiments. Really great dataset.  \nSorry, it’s a bit late, but still, here’s my [solution code](https://github.com/vecxoz/ai4code). It’s a minimalist TF/TPU pipeline. @thedevastator"
  },
  "source": "existing_discussion",
  "complete": true,
  "competition_id": 35887,
  "competition_slug": "AI4Code",
  "team_id": 8613915,
  "solution_url": "/competitions/AI4Code/writeups/vecxoz-public-31st-codet5-base-encoder-1024"
}