{
  "id": 434351,
  "title": "A simple function to visualize your diffs! ",
  "url": "/competitions/bengaliai-speech/discussion/434351",
  "author_name": "",
  "post_date": "2023-08-24T23:41:48.727771700Z",
  "votes": 5,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi everyone,</p>\n<p>I would like to share a simple yet efficient function to visualize the differences between your predicted and a ground truth sentence. It utilises the <a href=\"https://docs.python.org/3/library/difflib.html\" target=\"_blank\">difflib</a> module in Python. It is colorful in the scripts or notebooks but hard to do it here with the markdown. So I only made it bold.</p>\n<pre><code> difflib\n\n ():\n    differ = difflib.Differ()\n    diff = (differ.compare(ground_truth, prediction))\n    highlighted_diff = [( + item[-] + )  item.startswith()  item[-]  item  diff]\n     .join(highlighted_diff)\n</code></pre>\n<p><strong>Some examples:</strong></p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বাড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বা<strong>ড়</strong>ড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<hr>\n<p>কৃত্তিবাস রামায়ণ-বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>\n<p>কৃত্তিবাস রামা<strong>য়</strong>য়ণ- বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>",
  "messages": [
    {
      "id": "2407191",
      "postDate": "08/24/2023 23:41:48",
      "content": "<p>Hi everyone,</p>\n<p>I would like to share a simple yet efficient function to visualize the differences between your predicted and a ground truth sentence. It utilises the <a href=\"https://docs.python.org/3/library/difflib.html\" target=\"_blank\">difflib</a> module in Python. It is colorful in the scripts or notebooks but hard to do it here with the markdown. So I only made it bold.</p>\n<pre><code> difflib\n\n ():\n    differ = difflib.Differ()\n    diff = (differ.compare(ground_truth, prediction))\n    highlighted_diff = [( + item[-] + )  item.startswith()  item[-]  item  diff]\n     .join(highlighted_diff)\n</code></pre>\n<p><strong>Some examples:</strong></p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বাড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বা<strong>ড়</strong>ড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<hr>\n<p>কৃত্তিবাস রামায়ণ-বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>\n<p>কৃত্তিবাস রামা<strong>য়</strong>য়ণ- বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>",
      "rawMarkdown": "Hi everyone,\n\nI would like to share a simple yet efficient function to visualize the differences between your predicted and a ground truth sentence. It utilises the [difflib](https://docs.python.org/3/library/difflib.html) module in Python. It is colorful in the scripts or notebooks but hard to do it here with the markdown. So I only made it bold.\n\n```python\nimport difflib\n\ndef highlight_differences(ground_truth, prediction):\n    differ = difflib.Differ()\n    diff = list(differ.compare(ground_truth, prediction))\n    highlighted_diff = [('\\033[91m' + item[-1] + '\\033[0m') if item.startswith('+') else item[-1] for item in diff]\n    return ''.join(highlighted_diff)\n```\n**Some examples:**\n\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বাড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বা<strong>ড়</strong>ড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n\n---\n\n<p>কৃত্তিবাস রামায়ণ-বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>\n<p>কৃত্তিবাস রামা<strong>য়</strong>য়ণ- বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>",
      "votes": null
    },
    {
      "id": "2407328",
      "postDate": "08/25/2023 03:13:16",
      "content": "<p>I'm really struggling to find the differences between those two lines 🤣 Even the bold font is hard to spot.<br>\nThanks for sharing this </p>",
      "rawMarkdown": "I'm really struggling to find the differences between those two lines 🤣 Even the bold font is hard to spot.\nThanks for sharing this",
      "votes": null
    },
    {
      "id": "2410082",
      "postDate": "08/26/2023 16:11:33",
      "content": "<p>Ahahaha.. yeah, apparently it was not the best idea 🤣</p>",
      "rawMarkdown": "Ahahaha.. yeah, apparently it was not the best idea 🤣",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2407328,
      "author_name": "nyleve",
      "author_url": "",
      "post_date": "08/25/2023 03:13:16",
      "content": "<p>I'm really struggling to find the differences between those two lines 🤣 Even the bold font is hard to spot.<br>\nThanks for sharing this </p>",
      "votes": null,
      "replies": [
        {
          "id": 2410082,
          "author_name": "snnclsr",
          "author_url": "",
          "post_date": "08/26/2023 16:11:33",
          "content": "<p>Ahahaha.. yeah, apparently it was not the best idea 🤣</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2407191": "Hi everyone,\n\nI would like to share a simple yet efficient function to visualize the differences between your predicted and a ground truth sentence. It utilises the [difflib](https://docs.python.org/3/library/difflib.html) module in Python. It is colorful in the scripts or notebooks but hard to do it here with the markdown. So I only made it bold.\n\n```python\nimport difflib\n\ndef highlight_differences(ground_truth, prediction):\n    differ = difflib.Differ()\n    diff = list(differ.compare(ground_truth, prediction))\n    highlighted_diff = [('\\033[91m' + item[-1] + '\\033[0m') if item.startswith('+') else item[-1] for item in diff]\n    return ''.join(highlighted_diff)\n```\n**Some examples:**\n\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বাড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n<p>তিনি এবং তাঁর মা তাদের পৈতৃক বা<strong>ড়</strong>ড়িতে থেকে প্রতিবেশীদের দ্বারা অনেক তিরস্কার সহ্য করেন।</p>\n\n---\n\n<p>কৃত্তিবাস রামায়ণ-বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>\n<p>কৃত্তিবাস রামা<strong>য়</strong>য়ণ- বহির্ভূত অনেক গল্প এই অনুবাদে গ্রহণ করেছিলেন।</p>",
    "2407328": "I'm really struggling to find the differences between those two lines 🤣 Even the bold font is hard to spot.\nThanks for sharing this",
    "2410082": "Ahahaha.. yeah, apparently it was not the best idea 🤣"
  },
  "source": "meta"
}