{
  "id": 221236,
  "title": "Publish my multi-task-mlp pipline code",
  "url": "/competitions/indoor-location-navigation/discussion/221236",
  "author_name": "Daniels",
  "post_date": "2021-02-22T02:48:12.718000",
  "votes": 11,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Publish my pytorch version multi-task-mlp code as follows:<br>\nTraining part: <a href=\"https://www.kaggle.com/a763337092/multi-task-mlp-training\" target=\"_blank\">https://www.kaggle.com/a763337092/multi-task-mlp-training</a><br>\nInference part: <a href=\"https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425\" target=\"_blank\">https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425</a></p>\n<p>I defined a MeanPositionError Loss in my code:</p>\n<pre><code>class MeanPositionLoss(nn.Module):\n    def __init__(self):\n        super(MeanPositionLoss, self).__init__()\n    def forward(self, output_way_x, output_way_y, output_floor, way_x, way_y, floor):\n        diff_x = output_way_x - way_x\n        diff_y = output_way_y - way_y\n        diff_f = output_floor - floor\n\n        error = torch.sqrt(diff_x * diff_x + diff_y * diff_y) + 15 * torch.sqrt(diff_f * diff_f)\n        return torch.mean(error)\n</code></pre>\n<p>According to my experiment results, multi-task model is better than 3 single-task model. But my mlp model still can't acheive the same score as LightGBM model. Maybe it’s because the sample size is too small.</p>\n<p>Hope the whole code flow can be helpful, good luck to every kagglers!</p>",
  "messages": [
    {
      "id": 1213270,
      "postDate": "2021-02-22T02:48:12.720Z",
      "content": "<p>Publish my pytorch version multi-task-mlp code as follows:<br>\nTraining part: <a href=\"https://www.kaggle.com/a763337092/multi-task-mlp-training\" target=\"_blank\">https://www.kaggle.com/a763337092/multi-task-mlp-training</a><br>\nInference part: <a href=\"https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425\" target=\"_blank\">https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425</a></p>\n<p>I defined a MeanPositionError Loss in my code:</p>\n<pre><code>class MeanPositionLoss(nn.Module):\n    def __init__(self):\n        super(MeanPositionLoss, self).__init__()\n    def forward(self, output_way_x, output_way_y, output_floor, way_x, way_y, floor):\n        diff_x = output_way_x - way_x\n        diff_y = output_way_y - way_y\n        diff_f = output_floor - floor\n\n        error = torch.sqrt(diff_x * diff_x + diff_y * diff_y) + 15 * torch.sqrt(diff_f * diff_f)\n        return torch.mean(error)\n</code></pre>\n<p>According to my experiment results, multi-task model is better than 3 single-task model. But my mlp model still can't acheive the same score as LightGBM model. Maybe it’s because the sample size is too small.</p>\n<p>Hope the whole code flow can be helpful, good luck to every kagglers!</p>",
      "rawMarkdown": "Publish my pytorch version multi-task-mlp code as follows:\nTraining part: https://www.kaggle.com/a763337092/multi-task-mlp-training\nInference part: https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425\n\nI defined a MeanPositionError Loss in my code:\n```\nclass MeanPositionLoss(nn.Module):\n    def __init__(self):\n        super(MeanPositionLoss, self).__init__()\n    def forward(self, output_way_x, output_way_y, output_floor, way_x, way_y, floor):\n        diff_x = output_way_x - way_x\n        diff_y = output_way_y - way_y\n        diff_f = output_floor - floor\n\n        error = torch.sqrt(diff_x * diff_x + diff_y * diff_y) + 15 * torch.sqrt(diff_f * diff_f)\n        return torch.mean(error)\n```\n\nAccording to my experiment results, multi-task model is better than 3 single-task model. But my mlp model still can't acheive the same score as LightGBM model. Maybe it’s because the sample size is too small.\n\nHope the whole code flow can be helpful, good luck to every kagglers!\n",
      "votes": 11
    },
    {
      "id": 1213428,
      "postDate": "2021-02-22T05:40:59.553Z",
      "content": "<p>Thank you for sharing. it is critical to use the multi-classification objective for predicting the floor. That alone will give a handsome boost to the score.</p>",
      "rawMarkdown": "Thank you for sharing. it is critical to use the multi-classification objective for predicting the floor. That alone will give a handsome boost to the score.",
      "votes": 3,
      "replies": [
        {
          "id": 1213470,
          "postDate": "2021-02-22T06:15:38.933Z",
          "content": "<p>Thanks Jiwei! I'll try it😄</p>",
          "rawMarkdown": "Thanks Jiwei! I'll try it😄"
        },
        {
          "id": 1245322,
          "postDate": "2021-03-19T17:12:53.013Z",
          "content": "<p>Why not regression? The loss will be more related to the comp metric</p>",
          "rawMarkdown": "Why not regression? The loss will be more related to the comp metric"
        }
      ]
    },
    {
      "id": 1213451,
      "postDate": "2021-02-22T05:57:18.433Z",
      "content": "<p>I agree with <a href=\"https://www.kaggle.com/jiweiliu\" target=\"_blank\">@jiweiliu</a> <br>\nYou will need 2 objectives : multi_class for floor and regression  for locations<br>\nMy first attempt with multi-task NN gave me 10.287 on LB (edit now 9.261 on LB)</p>",
      "rawMarkdown": "I agree with @jiweiliu \nYou will need 2 objectives : multi_class for floor and regression  for locations\nMy first attempt with multi-task NN gave me 10.287 on LB (edit now 9.261 on LB)",
      "votes": 2,
      "replies": [
        {
          "id": 1213472,
          "postDate": "2021-02-22T06:16:12.873Z",
          "content": "<p>Awesome score！</p>",
          "rawMarkdown": "Awesome score！"
        },
        {
          "id": 1213482,
          "postDate": "2021-02-22T06:27:59.560Z",
          "content": "<p>Thanks!  <br>\nI use the same features as you and 2 objectives.</p>\n<p>But I think an even better approach should be single NN for all sites and all tasks. </p>",
          "rawMarkdown": "Thanks!  \nI use the same features as you and 2 objectives.\n\nBut I think an even better approach should be single NN for all sites and all tasks. ",
          "votes": 1
        }
      ]
    },
    {
      "id": 1244207,
      "postDate": "2021-03-18T19:10:39.400Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 1213428,
      "author_name": "Jiwei Liu",
      "author_url": "",
      "post_date": "2021-02-22T05:40:59.553000",
      "content": "<p>Thank you for sharing. it is critical to use the multi-classification objective for predicting the floor. That alone will give a handsome boost to the score.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 1213470,
          "author_name": "Daniels",
          "author_url": "",
          "post_date": "2021-02-22T06:15:38.933000",
          "content": "<p>Thanks Jiwei! I'll try it😄</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1245322,
          "author_name": "EnricRovira",
          "author_url": "",
          "post_date": "2021-03-19T17:12:53.013000",
          "content": "<p>Why not regression? The loss will be more related to the comp metric</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1213451,
      "author_name": "Serigne ",
      "author_url": "",
      "post_date": "2021-02-22T05:57:18.433000",
      "content": "<p>I agree with <a href=\"https://www.kaggle.com/jiweiliu\" target=\"_blank\">@jiweiliu</a> <br>\nYou will need 2 objectives : multi_class for floor and regression  for locations<br>\nMy first attempt with multi-task NN gave me 10.287 on LB (edit now 9.261 on LB)</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1213472,
          "author_name": "Daniels",
          "author_url": "",
          "post_date": "2021-02-22T06:16:12.873000",
          "content": "<p>Awesome score！</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1213482,
          "author_name": "Serigne ",
          "author_url": "",
          "post_date": "2021-02-22T06:27:59.560000",
          "content": "<p>Thanks!  <br>\nI use the same features as you and 2 objectives.</p>\n<p>But I think an even better approach should be single NN for all sites and all tasks. </p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1244207,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-03-18T19:10:39.400000",
      "content": "",
      "votes": 1,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1213270": "Publish my pytorch version multi-task-mlp code as follows:\nTraining part: https://www.kaggle.com/a763337092/multi-task-mlp-training\nInference part: https://www.kaggle.com/a763337092/multi-task-mlp-inference/notebook?scriptVersionId=54919425\n\nI defined a MeanPositionError Loss in my code:\n```\nclass MeanPositionLoss(nn.Module):\n    def __init__(self):\n        super(MeanPositionLoss, self).__init__()\n    def forward(self, output_way_x, output_way_y, output_floor, way_x, way_y, floor):\n        diff_x = output_way_x - way_x\n        diff_y = output_way_y - way_y\n        diff_f = output_floor - floor\n\n        error = torch.sqrt(diff_x * diff_x + diff_y * diff_y) + 15 * torch.sqrt(diff_f * diff_f)\n        return torch.mean(error)\n```\n\nAccording to my experiment results, multi-task model is better than 3 single-task model. But my mlp model still can't acheive the same score as LightGBM model. Maybe it’s because the sample size is too small.\n\nHope the whole code flow can be helpful, good luck to every kagglers!\n",
    "1213428": "Thank you for sharing. it is critical to use the multi-classification objective for predicting the floor. That alone will give a handsome boost to the score.",
    "1213451": "I agree with @jiweiliu \nYou will need 2 objectives : multi_class for floor and regression  for locations\nMy first attempt with multi-task NN gave me 10.287 on LB (edit now 9.261 on LB)",
    "1244207": ""
  }
}