{
  "id": 223466,
  "title": "Brief summary of \"How to calculate Levenshtein distance\"🔰",
  "url": "/competitions/bms-molecular-translation/discussion/223466",
  "author_name": "",
  "post_date": "2021-03-04T01:49:17.246407500Z",
  "votes": 36,
  "comment_count": 12,
  "views": 0,
  "content": "<p>In this competition, <strong><em>Levenshtein distance</em></strong> is used for evaluation.<br>\nSo, I briefly summarized it.</p>\n<p>The Levenshtein distance is one of the methods to calculate the similarity between two strings.<br>\nLevenshtein distance is calculated by the number of operations;</p>\n<ul>\n<li><strong><em>insert</em></strong></li>\n<li><strong><em>delete</em></strong></li>\n<li><strong><em>replace</em></strong></li>\n</ul>\n<p>when converting one string to the other.</p>\n<p>For example, Levenshtein distance between<br>\n<strong><em>'Rievenstein'</em></strong> and <strong><em>'Levenshtein'</em></strong> is <strong>3</strong>.</p>\n<table>\n<thead>\n<tr>\n<th>string</th>\n<th>operation</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>R</strong>ievenstein</td>\n<td></td>\n</tr>\n<tr>\n<td><strong>i</strong>evenstein</td>\n<td>delete <strong>R</strong></td>\n</tr>\n<tr>\n<td><strong>L</strong>evenstein</td>\n<td>replace <strong>i</strong> with <strong>L</strong></td>\n</tr>\n<tr>\n<td>Levens<strong>h</strong>tein</td>\n<td>insert <strong>h</strong> at position <strong>t</strong></td>\n</tr>\n</tbody>\n</table>\n<p>If you use <em>Python</em>, Levenshtein distance is calculated by just running like below!!<br>\n(<em>For the first time, Perhaps you should run</em> <code>!pip install python-Levenshtein</code>)</p>\n<pre><code>import Levenshtein\n\nstr1 = 'Rievenstein'\nstr2 = 'Levenshtein'\n\nprint(Levenshtein.distance(str1, str2))\n# 3\n</code></pre>\n<p>If you want to know the <em>operarions</em>(how to convert one to the other), use <code>editops</code>.</p>\n<pre><code>print(Levenshtein.editops(str1, str2))\n# [('delete', 0, 0), ('replace', 1, 0), ('insert', 7, 6)]\n</code></pre>\n<p>If you want to get the <em>similarity value</em>, you can use <code>ratio</code>.</p>\n<pre><code>print(Levenshtein.ratio(str1, str2))\n# 0.8181818181818182\nprint(Levenshtein.ratio(str1, str1))\n# 1.0\nprint(Levenshtein.ratio(str1, ''))\n# 0.0\n</code></pre>\n<p>If you want to select the <em>average string</em> in the list of several strings, you should use to <code>median</code>.</p>\n<pre><code>print(Levenshtein.median([\n                    'Rievenstein',\n                    'Levenshtein',\n                    'Revenshtein',\n                    'Lievenstein',\n                    'Levenshtain',\n                    'Levennshtein'\n                    ]))\n# Levenshtein\n</code></pre>\n<hr>\n<p>That's it!<br>\nPlease try your best and enjoy this competition😊</p>\n<p><em>If you want to know more detail, please refer to Wikipedia(described in the Overview of this competition)</em></p>",
  "messages": [
    {
      "id": "1225833",
      "postDate": "03/04/2021 01:49:17",
      "content": "<p>In this competition, <strong><em>Levenshtein distance</em></strong> is used for evaluation.<br>\nSo, I briefly summarized it.</p>\n<p>The Levenshtein distance is one of the methods to calculate the similarity between two strings.<br>\nLevenshtein distance is calculated by the number of operations;</p>\n<ul>\n<li><strong><em>insert</em></strong></li>\n<li><strong><em>delete</em></strong></li>\n<li><strong><em>replace</em></strong></li>\n</ul>\n<p>when converting one string to the other.</p>\n<p>For example, Levenshtein distance between<br>\n<strong><em>'Rievenstein'</em></strong> and <strong><em>'Levenshtein'</em></strong> is <strong>3</strong>.</p>\n<table>\n<thead>\n<tr>\n<th>string</th>\n<th>operation</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>R</strong>ievenstein</td>\n<td></td>\n</tr>\n<tr>\n<td><strong>i</strong>evenstein</td>\n<td>delete <strong>R</strong></td>\n</tr>\n<tr>\n<td><strong>L</strong>evenstein</td>\n<td>replace <strong>i</strong> with <strong>L</strong></td>\n</tr>\n<tr>\n<td>Levens<strong>h</strong>tein</td>\n<td>insert <strong>h</strong> at position <strong>t</strong></td>\n</tr>\n</tbody>\n</table>\n<p>If you use <em>Python</em>, Levenshtein distance is calculated by just running like below!!<br>\n(<em>For the first time, Perhaps you should run</em> <code>!pip install python-Levenshtein</code>)</p>\n<pre><code>import Levenshtein\n\nstr1 = 'Rievenstein'\nstr2 = 'Levenshtein'\n\nprint(Levenshtein.distance(str1, str2))\n# 3\n</code></pre>\n<p>If you want to know the <em>operarions</em>(how to convert one to the other), use <code>editops</code>.</p>\n<pre><code>print(Levenshtein.editops(str1, str2))\n# [('delete', 0, 0), ('replace', 1, 0), ('insert', 7, 6)]\n</code></pre>\n<p>If you want to get the <em>similarity value</em>, you can use <code>ratio</code>.</p>\n<pre><code>print(Levenshtein.ratio(str1, str2))\n# 0.8181818181818182\nprint(Levenshtein.ratio(str1, str1))\n# 1.0\nprint(Levenshtein.ratio(str1, ''))\n# 0.0\n</code></pre>\n<p>If you want to select the <em>average string</em> in the list of several strings, you should use to <code>median</code>.</p>\n<pre><code>print(Levenshtein.median([\n                    'Rievenstein',\n                    'Levenshtein',\n                    'Revenshtein',\n                    'Lievenstein',\n                    'Levenshtain',\n                    'Levennshtein'\n                    ]))\n# Levenshtein\n</code></pre>\n<hr>\n<p>That's it!<br>\nPlease try your best and enjoy this competition😊</p>\n<p><em>If you want to know more detail, please refer to Wikipedia(described in the Overview of this competition)</em></p>",
      "rawMarkdown": "In this competition, ***Levenshtein distance*** is used for evaluation.\nSo, I briefly summarized it.\n\nThe Levenshtein distance is one of the methods to calculate the similarity between two strings.\nLevenshtein distance is calculated by the number of operations;\n- ***insert***\n- ***delete***\n- ***replace***\n\nwhen converting one string to the other.\n\nFor example, Levenshtein distance between\n***'Rievenstein'*** and ***'Levenshtein'*** is **3**.\n\n|string|operation|\n|---|---|\n|**R**ievenstein||\n|**i**evenstein|delete **R**|\n|**L**evenstein|replace **i** with **L**|\n|Levens**h**tein|insert **h** at position **t**|\n\nIf you use *Python*, Levenshtein distance is calculated by just running like below!!\n(*For the first time, Perhaps you should run* `!pip install python-Levenshtein`)\n\n```\nimport Levenshtein\n\nstr1 = 'Rievenstein'\nstr2 = 'Levenshtein'\n\nprint(Levenshtein.distance(str1, str2))\n# 3\n```\n\nIf you want to know the *operarions*(how to convert one to the other), use `editops`.\n\n```\nprint(Levenshtein.editops(str1, str2))\n# [('delete', 0, 0), ('replace', 1, 0), ('insert', 7, 6)]\n```\n\nIf you want to get the *similarity value*, you can use `ratio`.\n\n```\nprint(Levenshtein.ratio(str1, str2))\n# 0.8181818181818182\nprint(Levenshtein.ratio(str1, str1))\n# 1.0\nprint(Levenshtein.ratio(str1, ''))\n# 0.0\n```\n\nIf you want to select the *average string* in the list of several strings, you should use to `median`.\n\n```\nprint(Levenshtein.median([\n                    'Rievenstein',\n                    'Levenshtein',\n                    'Revenshtein',\n                    'Lievenstein',\n                    'Levenshtain',\n                    'Levennshtein'\n                    ]))\n# Levenshtein\n```\n\n----\nThat's it!\nPlease try your best and enjoy this competition😊\n\n\n*If you want to know more detail, please refer to Wikipedia(described in the Overview of this competition)*",
      "votes": null
    },
    {
      "id": "1228051",
      "postDate": "03/06/2021 04:35:32",
      "content": "<p>Thank you very much. This is very helpful!</p>",
      "rawMarkdown": "Thank you very much. This is very helpful!",
      "votes": null
    },
    {
      "id": "1229594",
      "postDate": "03/07/2021 13:20:15",
      "content": "<p><a href=\"https://www.kaggle.com/matsumuranaoki\" target=\"_blank\">@matsumuranaoki</a> <br>\nThanks!<br>\nI hope it will help you somewhat.</p>",
      "rawMarkdown": "matsumuranaoki \nThanks!\nI hope it will help you somewhat.",
      "votes": null
    },
    {
      "id": "1230921",
      "postDate": "03/08/2021 14:44:03",
      "content": "<p><a href=\"https://pypi.org/project/edlib/\" target=\"_blank\">edlib</a> is a highly efficient implementation</p>\n<p>and is also as simple as:<br>\n<code>levenshtein_distance = edlib.align(str1, str2)['editDistance']</code></p>",
      "rawMarkdown": "[edlib](https://pypi.org/project/edlib/) is a highly efficient implementation\n\nand is also as simple as:\n`levenshtein_distance = edlib.align(str1, str2)['editDistance']`",
      "votes": null
    },
    {
      "id": "1232865",
      "postDate": "03/10/2021 03:02:32",
      "content": "<p><a href=\"https://www.kaggle.com/yhirakawa\" target=\"_blank\">@yhirakawa</a>  Good post on how to calculate levenshtein_distance  using Python . While many posts focusses on theory and sharing videos on what levenshtein_distance  is , its good you had also shared the implementation</p>",
      "rawMarkdown": "yhirakawa  Good post on how to calculate levenshtein_distance  using Python . While many posts focusses on theory and sharing videos on what levenshtein_distance  is , its good you had also shared the implementation",
      "votes": null
    },
    {
      "id": "1232868",
      "postDate": "03/10/2021 03:03:15",
      "content": "<p><a href=\"https://www.kaggle.com/nofreewill\" target=\"_blank\">@nofreewill</a> Thanks for sharing about edlib library . I am hearing about it for the first time</p>",
      "rawMarkdown": "nofreewill Thanks for sharing about edlib library . I am hearing about it for the first time",
      "votes": null
    },
    {
      "id": "1233086",
      "postDate": "03/10/2021 06:07:45",
      "content": "<p>You're welcome! :)</p>",
      "rawMarkdown": "You're welcome! :)",
      "votes": null
    },
    {
      "id": "1257787",
      "postDate": "03/31/2021 05:18:20",
      "content": "<p><a href=\"https://www.kaggle.com/usharengaraju\" target=\"_blank\">@usharengaraju</a> <br>\nThank you for your comment☺️</p>\n<p>If you want to know how to implement more in detail, please check the official page <a href=\"https://rawgit.com/ztane/python-Levenshtein/master/docs/Levenshtein.html\" target=\"_blank\">here</a>.<br>\nNot only many other usages in levenshtein but also hamming and jaro are shown there😊</p>",
      "rawMarkdown": "usharengaraju \nThank you for your comment☺️\n\nIf you want to know how to implement more in detail, please check the official page [here](https://rawgit.com/ztane/python-Levenshtein/master/docs/Levenshtein.html).\nNot only many other usages in levenshtein but also hamming and jaro are shown there😊",
      "votes": null
    },
    {
      "id": "1257791",
      "postDate": "03/31/2021 05:25:03",
      "content": "<p><a href=\"https://www.kaggle.com/nofreewill\" target=\"_blank\">@nofreewill</a> <br>\nThank you😊<br>\nI did not know <em>edlib</em> and I've found this is useful in calculating levenshtein distance.</p>",
      "rawMarkdown": "nofreewill \nThank you😊\nI did not know *edlib* and I've found this is useful in calculating levenshtein distance.",
      "votes": null
    },
    {
      "id": "1258246",
      "postDate": "03/31/2021 13:34:25",
      "content": "<p>if you understand Levenshtein distance, you may also want to check this:</p>\n<p>Levenshtein Transformer<br>\n<a href=\"https://arxiv.org/abs/1905.11006\" target=\"_blank\">https://arxiv.org/abs/1905.11006</a></p>\n<p><img src=\"https://paperswithcode.com/media/methods/Screen_Shot_2020-08-21_at_4.29.34_PM_gXAQWfx.png\" alt=\"\"></p>",
      "rawMarkdown": "if you understand Levenshtein distance, you may also want to check this:\n\nLevenshtein Transformer\nhttps://arxiv.org/abs/1905.11006\n\n![](https://paperswithcode.com/media/methods/Screen_Shot_2020-08-21_at_4.29.34_PM_gXAQWfx.png)",
      "votes": null
    },
    {
      "id": "1258885",
      "postDate": "04/01/2021 01:27:33",
      "content": "<p><a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> <br>\nThanks😍</p>\n<p>I've wanted to study Transformer, which is now indispensable in NLP.<br>\nI've not known that levenshtein is used with Levenshtein as well😲<br>\nI'll check it out!</p>",
      "rawMarkdown": "hengck23 \nThanks😍\n\nI've wanted to study Transformer, which is now indispensable in NLP.\nI've not known that levenshtein is used with Levenshtein as well😲\nI'll check it out!",
      "votes": null
    },
    {
      "id": "1264898",
      "postDate": "04/06/2021 13:45:55",
      "content": "<p>Thank you very much. This is very helpful!</p>",
      "rawMarkdown": "Thank you very much. This is very helpful!",
      "votes": null
    },
    {
      "id": "1265654",
      "postDate": "04/07/2021 05:13:30",
      "content": "<p>Thank you, too😊</p>",
      "rawMarkdown": "Thank you, too😊",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1228051,
      "author_name": "matsumuranaoki",
      "author_url": "",
      "post_date": "03/06/2021 04:35:32",
      "content": "<p>Thank you very much. This is very helpful!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1229594,
          "author_name": "yhirakawa",
          "author_url": "",
          "post_date": "03/07/2021 13:20:15",
          "content": "<p><a href=\"https://www.kaggle.com/matsumuranaoki\" target=\"_blank\">@matsumuranaoki</a> <br>\nThanks!<br>\nI hope it will help you somewhat.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1230921,
      "author_name": "nofreewill",
      "author_url": "",
      "post_date": "03/08/2021 14:44:03",
      "content": "<p><a href=\"https://pypi.org/project/edlib/\" target=\"_blank\">edlib</a> is a highly efficient implementation</p>\n<p>and is also as simple as:<br>\n<code>levenshtein_distance = edlib.align(str1, str2)['editDistance']</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 1232868,
          "author_name": "usharengaraju",
          "author_url": "",
          "post_date": "03/10/2021 03:03:15",
          "content": "<p><a href=\"https://www.kaggle.com/nofreewill\" target=\"_blank\">@nofreewill</a> Thanks for sharing about edlib library . I am hearing about it for the first time</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1233086,
          "author_name": "nofreewill",
          "author_url": "",
          "post_date": "03/10/2021 06:07:45",
          "content": "<p>You're welcome! :)</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1257791,
          "author_name": "yhirakawa",
          "author_url": "",
          "post_date": "03/31/2021 05:25:03",
          "content": "<p><a href=\"https://www.kaggle.com/nofreewill\" target=\"_blank\">@nofreewill</a> <br>\nThank you😊<br>\nI did not know <em>edlib</em> and I've found this is useful in calculating levenshtein distance.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1232865,
      "author_name": "usharengaraju",
      "author_url": "",
      "post_date": "03/10/2021 03:02:32",
      "content": "<p><a href=\"https://www.kaggle.com/yhirakawa\" target=\"_blank\">@yhirakawa</a>  Good post on how to calculate levenshtein_distance  using Python . While many posts focusses on theory and sharing videos on what levenshtein_distance  is , its good you had also shared the implementation</p>",
      "votes": null,
      "replies": [
        {
          "id": 1257787,
          "author_name": "yhirakawa",
          "author_url": "",
          "post_date": "03/31/2021 05:18:20",
          "content": "<p><a href=\"https://www.kaggle.com/usharengaraju\" target=\"_blank\">@usharengaraju</a> <br>\nThank you for your comment☺️</p>\n<p>If you want to know how to implement more in detail, please check the official page <a href=\"https://rawgit.com/ztane/python-Levenshtein/master/docs/Levenshtein.html\" target=\"_blank\">here</a>.<br>\nNot only many other usages in levenshtein but also hamming and jaro are shown there😊</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1258246,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "03/31/2021 13:34:25",
      "content": "<p>if you understand Levenshtein distance, you may also want to check this:</p>\n<p>Levenshtein Transformer<br>\n<a href=\"https://arxiv.org/abs/1905.11006\" target=\"_blank\">https://arxiv.org/abs/1905.11006</a></p>\n<p><img src=\"https://paperswithcode.com/media/methods/Screen_Shot_2020-08-21_at_4.29.34_PM_gXAQWfx.png\" alt=\"\"></p>",
      "votes": null,
      "replies": [
        {
          "id": 1258885,
          "author_name": "yhirakawa",
          "author_url": "",
          "post_date": "04/01/2021 01:27:33",
          "content": "<p><a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> <br>\nThanks😍</p>\n<p>I've wanted to study Transformer, which is now indispensable in NLP.<br>\nI've not known that levenshtein is used with Levenshtein as well😲<br>\nI'll check it out!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1264898,
      "author_name": "mohamedbakrey",
      "author_url": "",
      "post_date": "04/06/2021 13:45:55",
      "content": "<p>Thank you very much. This is very helpful!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1265654,
          "author_name": "yhirakawa",
          "author_url": "",
          "post_date": "04/07/2021 05:13:30",
          "content": "<p>Thank you, too😊</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1225833": "In this competition, ***Levenshtein distance*** is used for evaluation.\nSo, I briefly summarized it.\n\nThe Levenshtein distance is one of the methods to calculate the similarity between two strings.\nLevenshtein distance is calculated by the number of operations;\n- ***insert***\n- ***delete***\n- ***replace***\n\nwhen converting one string to the other.\n\nFor example, Levenshtein distance between\n***'Rievenstein'*** and ***'Levenshtein'*** is **3**.\n\n|string|operation|\n|---|---|\n|**R**ievenstein||\n|**i**evenstein|delete **R**|\n|**L**evenstein|replace **i** with **L**|\n|Levens**h**tein|insert **h** at position **t**|\n\nIf you use *Python*, Levenshtein distance is calculated by just running like below!!\n(*For the first time, Perhaps you should run* `!pip install python-Levenshtein`)\n\n```\nimport Levenshtein\n\nstr1 = 'Rievenstein'\nstr2 = 'Levenshtein'\n\nprint(Levenshtein.distance(str1, str2))\n# 3\n```\n\nIf you want to know the *operarions*(how to convert one to the other), use `editops`.\n\n```\nprint(Levenshtein.editops(str1, str2))\n# [('delete', 0, 0), ('replace', 1, 0), ('insert', 7, 6)]\n```\n\nIf you want to get the *similarity value*, you can use `ratio`.\n\n```\nprint(Levenshtein.ratio(str1, str2))\n# 0.8181818181818182\nprint(Levenshtein.ratio(str1, str1))\n# 1.0\nprint(Levenshtein.ratio(str1, ''))\n# 0.0\n```\n\nIf you want to select the *average string* in the list of several strings, you should use to `median`.\n\n```\nprint(Levenshtein.median([\n                    'Rievenstein',\n                    'Levenshtein',\n                    'Revenshtein',\n                    'Lievenstein',\n                    'Levenshtain',\n                    'Levennshtein'\n                    ]))\n# Levenshtein\n```\n\n----\nThat's it!\nPlease try your best and enjoy this competition😊\n\n\n*If you want to know more detail, please refer to Wikipedia(described in the Overview of this competition)*",
    "1228051": "Thank you very much. This is very helpful!",
    "1229594": "matsumuranaoki \nThanks!\nI hope it will help you somewhat.",
    "1230921": "[edlib](https://pypi.org/project/edlib/) is a highly efficient implementation\n\nand is also as simple as:\n`levenshtein_distance = edlib.align(str1, str2)['editDistance']`",
    "1232865": "yhirakawa  Good post on how to calculate levenshtein_distance  using Python . While many posts focusses on theory and sharing videos on what levenshtein_distance  is , its good you had also shared the implementation",
    "1232868": "nofreewill Thanks for sharing about edlib library . I am hearing about it for the first time",
    "1233086": "You're welcome! :)",
    "1257787": "usharengaraju \nThank you for your comment☺️\n\nIf you want to know how to implement more in detail, please check the official page [here](https://rawgit.com/ztane/python-Levenshtein/master/docs/Levenshtein.html).\nNot only many other usages in levenshtein but also hamming and jaro are shown there😊",
    "1257791": "nofreewill \nThank you😊\nI did not know *edlib* and I've found this is useful in calculating levenshtein distance.",
    "1258246": "if you understand Levenshtein distance, you may also want to check this:\n\nLevenshtein Transformer\nhttps://arxiv.org/abs/1905.11006\n\n![](https://paperswithcode.com/media/methods/Screen_Shot_2020-08-21_at_4.29.34_PM_gXAQWfx.png)",
    "1258885": "hengck23 \nThanks😍\n\nI've wanted to study Transformer, which is now indispensable in NLP.\nI've not known that levenshtein is used with Levenshtein as well😲\nI'll check it out!",
    "1264898": "Thank you very much. This is very helpful!",
    "1265654": "Thank you, too😊"
  },
  "source": "meta"
}