Hacker Public Radio

HPR4026: Using NLP to get better answer options for language learning


Listen Later

Code snippets
Install the Levenshtein package.
>>> pip install levenshtein
Use the Levenshtein package to calculate the edit distance.
>>> import Levenshtein
>>> Levenshtein.distance("cat", "dog")
3
>>> Levenshtein.distance("cat", "can")
1
Install the TheFuzz package.
>>> pip install thefuzz
Use TheFuzz to calculate the similarity ratio.
>>> from thefuzz import fuzz
>>> fuzz.ratio("cat", "dog")
0
>>> fuzz.ratio("cat", "can")
67
Use TheFuzz to calculate the similarity ratio for each item in a
list.
>>> from thefuzz import process
>>> options = ["dog", "can"]
>>> process.extract("cat", options, limit=2)
[('can', 67), ('dog', 0)]
>>> process.extract("cat", options, limit=1)
[('can', 67)]
>>> process.extract("cat", options, limit=2, scorer=fuzz.ratio)
[('can', 67), ('dog', 0)]
Other resources
Ethan Nam's Understanding
the Levenshtein Distance Equation for Beginners
Levenstein
package
TheFuzz
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Infinite Monkey Cage by BBC Radio 4

The Infinite Monkey Cage

1,952 Listeners

Click Here by Recorded Future News

Click Here

418 Listeners

Hacker And The Fed by Chris Tarbell & Hector Monsegur

Hacker And The Fed

168 Listeners