{
  "id": 325272,
  "title": "About loss function and better score",
  "url": "/competitions/AI4Code/discussion/325272",
  "author_name": "",
  "post_date": "2022-05-15T16:19:17.013763300Z",
  "votes": 38,
  "comment_count": 10,
  "views": 0,
  "content": "<p>I published here an inference notebook (<a href=\"http://www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777\" target=\"_blank\">www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777</a>) which is scored around 0.777. The improvement made in this notebook is that, I replaced the loss function MSELoss by L1Loss. I did this for the fact that, prediction made by model trained with MSE loss is always normally distributed, which is far from the distribution of our label. <br>\n The following are distribution of model trained by MSELoss. <br>\n<img src=\"https://i.imgur.com/bwSIsw6.jpg\" alt=\"distribution MSELoss\"></p>\n<p>Distribution of model trained by L1Loss. <br>\n<img src=\"https://i.imgur.com/DASKEJl.jpg\" alt=\"L1Loss\"></p>\n<p>Here is the training notebook for obtaining the 0.777 result, or even above 0.78 . changing the NUM_TRAIN to 1000000 should do the job.</p>\n<p><a href=\"http://www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777\" target=\"_blank\">www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777</a></p>",
  "messages": [
    {
      "id": "1791089",
      "postDate": "05/15/2022 16:19:17",
      "content": "<p>I published here an inference notebook (<a href=\"http://www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777\" target=\"_blank\">www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777</a>) which is scored around 0.777. The improvement made in this notebook is that, I replaced the loss function MSELoss by L1Loss. I did this for the fact that, prediction made by model trained with MSE loss is always normally distributed, which is far from the distribution of our label. <br>\n The following are distribution of model trained by MSELoss. <br>\n<img src=\"https://i.imgur.com/bwSIsw6.jpg\" alt=\"distribution MSELoss\"></p>\n<p>Distribution of model trained by L1Loss. <br>\n<img src=\"https://i.imgur.com/DASKEJl.jpg\" alt=\"L1Loss\"></p>\n<p>Here is the training notebook for obtaining the 0.777 result, or even above 0.78 . changing the NUM_TRAIN to 1000000 should do the job.</p>\n<p><a href=\"http://www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777\" target=\"_blank\">www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777</a></p>",
      "rawMarkdown": "I published here an inference notebook (www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777) which is scored around 0.777. The improvement made in this notebook is that, I replaced the loss function MSELoss by L1Loss. I did this for the fact that, prediction made by model trained with MSE loss is always normally distributed, which is far from the distribution of our label. \n The following are distribution of model trained by MSELoss. \n![distribution MSELoss](https://i.imgur.com/bwSIsw6.jpg)\n\n Distribution of model trained by L1Loss. \n![L1Loss](https://i.imgur.com/DASKEJl.jpg)\n\nHere is the training notebook for obtaining the 0.777 result, or even above 0.78 . changing the NUM_TRAIN to 1000000 should do the job.\n\nwww.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777",
      "votes": null
    },
    {
      "id": "1791340",
      "postDate": "05/15/2022 23:06:12",
      "content": "<p>Did you use a different framework to build your \"my_own_model_markdown_file_0_0.78169.bin\" file?</p>",
      "rawMarkdown": "Did you use a different framework to build your \"my_own_model_markdown_file_0_0.78169.bin\" file?",
      "votes": null
    },
    {
      "id": "1791356",
      "postDate": "05/15/2022 23:53:53",
      "content": "<p>I've already been there on yours awesome DistilBert.</p>",
      "rawMarkdown": "I've already been there on yours awesome DistilBert.",
      "votes": null
    },
    {
      "id": "1791381",
      "postDate": "05/16/2022 01:00:02",
      "content": "<p>For \"my_own_model_markdown_file_0_0.78169.bin\", I used the weights from huggingface and the code from baseline.</p>",
      "rawMarkdown": "For \"my_own_model_markdown_file_0_0.78169.bin\", I used the weights from huggingface and the code from baseline.",
      "votes": null
    },
    {
      "id": "1791388",
      "postDate": "05/16/2022 01:14:24",
      "content": "<p>Can you show me a link to information on how you produced this bin file?</p>",
      "rawMarkdown": "Can you show me a link to information on how you produced this bin file?",
      "votes": null
    },
    {
      "id": "1791394",
      "postDate": "05/16/2022 01:30:57",
      "content": "<p>to save a model, you need the following lines. </p>\n<blockquote>\n  <p>output_model_file = f\"./my_own_model_file_{e}_{np.round(score, 5)}.bin\"<br>\n  model_to_save = model.module if hasattr(model, 'module') else model<br>\n  torch.save(model_to_save.state_dict(), output_model_file)</p>\n</blockquote>",
      "rawMarkdown": "to save a model, you need the following lines. \n\n> output_model_file = f\"./my_own_model_file_{e}_{np.round(score, 5)}.bin\"\nmodel_to_save = model.module if hasattr(model, 'module') else model\ntorch.save(model_to_save.state_dict(), output_model_file)",
      "votes": null
    },
    {
      "id": "1791397",
      "postDate": "05/16/2022 01:36:10",
      "content": "<p>have fun 😏</p>",
      "rawMarkdown": "have fun 😏",
      "votes": null
    },
    {
      "id": "1791786",
      "postDate": "05/16/2022 11:11:41",
      "content": "<p>Thanks for sharing, may I ask about the validation metrics of your model? Like how much of them?</p>",
      "rawMarkdown": "Thanks for sharing, may I ask about the validation metrics of your model? Like how much of them?",
      "votes": null
    },
    {
      "id": "1791874",
      "postDate": "05/16/2022 12:43:10",
      "content": "<p>I used Kendall Tau Correlation to validate the dataset. As is shown in the checkpoint, it gets score ~0.78.</p>",
      "rawMarkdown": "I used Kendall Tau Correlation to validate the dataset. As is shown in the checkpoint, it gets score ~0.78.",
      "votes": null
    },
    {
      "id": "1791895",
      "postDate": "05/16/2022 13:07:55",
      "content": "<p>Ah, so this is the valid score, not your LB. I see, thank you!</p>",
      "rawMarkdown": "Ah, so this is the valid score, not your LB. I see, thank you!",
      "votes": null
    },
    {
      "id": "1792365",
      "postDate": "05/16/2022 22:38:30",
      "content": "<p>Thanks to sharing your insight. This is reasonable since the task metric (Kendall's tau) has a linear property with respect to the L1 distance.<br>\nIn precise, the true task loss (1-Kendall's tau) is proportional to the absolute difference between the correct position and the predicted position of the cell (=L1 loss) under some assumption.<br>\nI checked the property in the <a href=\"https://www.kaggle.com/code/yufuin/ai4code-linearity-of-kendall-s-tau-english\" target=\"_blank\">notebook</a></p>",
      "rawMarkdown": "Thanks to sharing your insight. This is reasonable since the task metric (Kendall's tau) has a linear property with respect to the L1 distance.\nIn precise, the true task loss (1-Kendall's tau) is proportional to the absolute difference between the correct position and the predicted position of the cell (=L1 loss) under some assumption.\nI checked the property in the [notebook](https://www.kaggle.com/code/yufuin/ai4code-linearity-of-kendall-s-tau-english)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1791340,
      "author_name": "",
      "author_url": "",
      "post_date": "05/15/2022 23:06:12",
      "content": "<p>Did you use a different framework to build your \"my_own_model_markdown_file_0_0.78169.bin\" file?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1791381,
          "author_name": "yuanzhezhou",
          "author_url": "",
          "post_date": "05/16/2022 01:00:02",
          "content": "<p>For \"my_own_model_markdown_file_0_0.78169.bin\", I used the weights from huggingface and the code from baseline.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1791388,
          "author_name": "",
          "author_url": "",
          "post_date": "05/16/2022 01:14:24",
          "content": "<p>Can you show me a link to information on how you produced this bin file?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1791394,
          "author_name": "yuanzhezhou",
          "author_url": "",
          "post_date": "05/16/2022 01:30:57",
          "content": "<p>to save a model, you need the following lines. </p>\n<blockquote>\n  <p>output_model_file = f\"./my_own_model_file_{e}_{np.round(score, 5)}.bin\"<br>\n  model_to_save = model.module if hasattr(model, 'module') else model<br>\n  torch.save(model_to_save.state_dict(), output_model_file)</p>\n</blockquote>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1791356,
      "author_name": "mpwolke",
      "author_url": "",
      "post_date": "05/15/2022 23:53:53",
      "content": "<p>I've already been there on yours awesome DistilBert.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1791397,
          "author_name": "yuanzhezhou",
          "author_url": "",
          "post_date": "05/16/2022 01:36:10",
          "content": "<p>have fun 😏</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1791786,
      "author_name": "shinomoriaoshi",
      "author_url": "",
      "post_date": "05/16/2022 11:11:41",
      "content": "<p>Thanks for sharing, may I ask about the validation metrics of your model? Like how much of them?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1791874,
          "author_name": "yuanzhezhou",
          "author_url": "",
          "post_date": "05/16/2022 12:43:10",
          "content": "<p>I used Kendall Tau Correlation to validate the dataset. As is shown in the checkpoint, it gets score ~0.78.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1791895,
          "author_name": "shinomoriaoshi",
          "author_url": "",
          "post_date": "05/16/2022 13:07:55",
          "content": "<p>Ah, so this is the valid score, not your LB. I see, thank you!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1792365,
      "author_name": "yufuin",
      "author_url": "",
      "post_date": "05/16/2022 22:38:30",
      "content": "<p>Thanks to sharing your insight. This is reasonable since the task metric (Kendall's tau) has a linear property with respect to the L1 distance.<br>\nIn precise, the true task loss (1-Kendall's tau) is proportional to the absolute difference between the correct position and the predicted position of the cell (=L1 loss) under some assumption.<br>\nI checked the property in the <a href=\"https://www.kaggle.com/code/yufuin/ai4code-linearity-of-kendall-s-tau-english\" target=\"_blank\">notebook</a></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1791089": "I published here an inference notebook (www.kaggle.com/code/yuanzhezhou/ai4code-distilbert-inference-777) which is scored around 0.777. The improvement made in this notebook is that, I replaced the loss function MSELoss by L1Loss. I did this for the fact that, prediction made by model trained with MSE loss is always normally distributed, which is far from the distribution of our label. \n The following are distribution of model trained by MSELoss. \n![distribution MSELoss](https://i.imgur.com/bwSIsw6.jpg)\n\n Distribution of model trained by L1Loss. \n![L1Loss](https://i.imgur.com/DASKEJl.jpg)\n\nHere is the training notebook for obtaining the 0.777 result, or even above 0.78 . changing the NUM_TRAIN to 1000000 should do the job.\n\nwww.kaggle.com/code/yuanzhezhou/ai4code-distilbert-training-777",
    "1791340": "Did you use a different framework to build your \"my_own_model_markdown_file_0_0.78169.bin\" file?",
    "1791356": "I've already been there on yours awesome DistilBert.",
    "1791381": "For \"my_own_model_markdown_file_0_0.78169.bin\", I used the weights from huggingface and the code from baseline.",
    "1791388": "Can you show me a link to information on how you produced this bin file?",
    "1791394": "to save a model, you need the following lines. \n\n> output_model_file = f\"./my_own_model_file_{e}_{np.round(score, 5)}.bin\"\nmodel_to_save = model.module if hasattr(model, 'module') else model\ntorch.save(model_to_save.state_dict(), output_model_file)",
    "1791397": "have fun 😏",
    "1791786": "Thanks for sharing, may I ask about the validation metrics of your model? Like how much of them?",
    "1791874": "I used Kendall Tau Correlation to validate the dataset. As is shown in the checkpoint, it gets score ~0.78.",
    "1791895": "Ah, so this is the valid score, not your LB. I see, thank you!",
    "1792365": "Thanks to sharing your insight. This is reasonable since the task metric (Kendall's tau) has a linear property with respect to the L1 distance.\nIn precise, the true task loss (1-Kendall's tau) is proportional to the absolute difference between the correct position and the predicted position of the cell (=L1 loss) under some assumption.\nI checked the property in the [notebook](https://www.kaggle.com/code/yufuin/ai4code-linearity-of-kendall-s-tau-english)"
  },
  "source": "meta"
}