{
  "id": 258218,
  "title": "Label smoothing binary cross entropy",
  "url": "/competitions/seti-breakthrough-listen/discussion/258218",
  "author_name": "DeepUnderstanding",
  "post_date": "2021-08-03T07:46:42.388000",
  "votes": 5,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I have been thinking to apply label smoothing loss.<br>\nBut I couldn't found any code implemented on PyTorch.<br>\nRight now I am using BCEwith logits as my loss.<br>\ncan anyone give any resource/link where it has been implemented?<br>\nThanks</p>",
  "messages": [
    {
      "id": 1426675,
      "postDate": "2021-08-03T07:46:42.390Z",
      "content": "<p>I have been thinking to apply label smoothing loss.<br>\nBut I couldn't found any code implemented on PyTorch.<br>\nRight now I am using BCEwith logits as my loss.<br>\ncan anyone give any resource/link where it has been implemented?<br>\nThanks</p>",
      "rawMarkdown": "I have been thinking to apply label smoothing loss.\nBut I couldn't found any code implemented on PyTorch.\nRight now I am using BCEwith logits as my loss.\ncan anyone give any resource/link where it has been implemented?\nThanks",
      "votes": 5
    },
    {
      "id": 1441278,
      "postDate": "2021-08-03T20:02:01.423Z",
      "content": "<p>I think so you can use this.. </p>\n<pre><code>class LabelSmoothing(nn.Module):\n    def __init__(self, smoothing = 0.09):\n        super(LabelSmoothing, self).__init__()\n        self.smoothing = smoothing \n\n    def forward(self,logits, labels):\n        labels[labels == 1] = 1 - self.smoothing \n        labels[labels == 0] = self.smoothing \n        return F.binary_cross_entropy_with_logits(logits, labels)\n</code></pre>",
      "rawMarkdown": "I think so you can use this.. \n```\n\nclass LabelSmoothing(nn.Module):\n    def __init__(self, smoothing = 0.09):\n        super(LabelSmoothing, self).__init__()\n        self.smoothing = smoothing \n        \n    def forward(self,logits, labels):\n        labels[labels == 1] = 1 - self.smoothing \n        labels[labels == 0] = self.smoothing \n        return F.binary_cross_entropy_with_logits(logits, labels)\n\n\n```",
      "votes": 3,
      "replies": [
        {
          "id": 1441421,
          "postDate": "2021-08-03T20:19:54.567Z",
          "content": "<p>Thanks for this!!</p>",
          "rawMarkdown": "Thanks for this!!\n"
        }
      ]
    },
    {
      "id": 1427877,
      "postDate": "2021-08-03T08:52:48.793Z",
      "content": "<p>Just replace target 0 by epsilon, and target 1 by 1 - epsilon.  It is so simple that there is no need to store an implementation in a git repo.</p>",
      "rawMarkdown": "Just replace target 0 by epsilon, and target 1 by 1 - epsilon.  It is so simple that there is no need to store an implementation in a git repo.",
      "votes": 4,
      "replies": [
        {
          "id": 1428378,
          "postDate": "2021-08-03T09:24:42.177Z",
          "content": "<p>my bad, surely it was a simple thing to do<br>\nThanks</p>",
          "rawMarkdown": "my bad, surely it was a simple thing to do\nThanks"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1441278,
      "author_name": "Parth Dhameliya",
      "author_url": "",
      "post_date": "2021-08-03T20:02:01.423000",
      "content": "<p>I think so you can use this.. </p>\n<pre><code>class LabelSmoothing(nn.Module):\n    def __init__(self, smoothing = 0.09):\n        super(LabelSmoothing, self).__init__()\n        self.smoothing = smoothing \n\n    def forward(self,logits, labels):\n        labels[labels == 1] = 1 - self.smoothing \n        labels[labels == 0] = self.smoothing \n        return F.binary_cross_entropy_with_logits(logits, labels)\n</code></pre>",
      "votes": 3,
      "replies": [
        {
          "id": 1441421,
          "author_name": "DeepUnderstanding",
          "author_url": "",
          "post_date": "2021-08-03T20:19:54.567000",
          "content": "<p>Thanks for this!!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1427877,
      "author_name": "CPMP",
      "author_url": "",
      "post_date": "2021-08-03T08:52:48.793000",
      "content": "<p>Just replace target 0 by epsilon, and target 1 by 1 - epsilon.  It is so simple that there is no need to store an implementation in a git repo.</p>",
      "votes": 4,
      "replies": [
        {
          "id": 1428378,
          "author_name": "DeepUnderstanding",
          "author_url": "",
          "post_date": "2021-08-03T09:24:42.177000",
          "content": "<p>my bad, surely it was a simple thing to do<br>\nThanks</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1426675": "I have been thinking to apply label smoothing loss.\nBut I couldn't found any code implemented on PyTorch.\nRight now I am using BCEwith logits as my loss.\ncan anyone give any resource/link where it has been implemented?\nThanks",
    "1441278": "I think so you can use this.. \n```\n\nclass LabelSmoothing(nn.Module):\n    def __init__(self, smoothing = 0.09):\n        super(LabelSmoothing, self).__init__()\n        self.smoothing = smoothing \n        \n    def forward(self,logits, labels):\n        labels[labels == 1] = 1 - self.smoothing \n        labels[labels == 0] = self.smoothing \n        return F.binary_cross_entropy_with_logits(logits, labels)\n\n\n```",
    "1427877": "Just replace target 0 by epsilon, and target 1 by 1 - epsilon.  It is so simple that there is no need to store an implementation in a git repo."
  }
}