Model Pipeline - Edit distance (Levenshtein)
This pipeline calculates the edit distance between two words. It shows how many changes are needed to turn one word into another. This helps computers understand how similar two words are.
Jump into concepts and practice - no test required
This pipeline calculates the edit distance between two words. It shows how many changes are needed to turn one word into another. This helps computers understand how similar two words are.
N/A
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | N/A | N/A | Edit distance calculation is not a training process but a deterministic algorithm. |
s1 and s2 of lengths m and n?"kitten" and "sitting"?def edit_distance(s1, s2):
m, n = len(s1), len(s2)
table = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(m + 1):
table[i][0] = i
for j in range(n + 1):
table[0][j] = j
for i in range(1, m + 1):
for j in range(1, n + 1):
if s1[i] == s2[j]:
cost = 0
else:
cost = 1
table[i][j] = min(table[i-1][j] + 1, table[i][j-1] + 1, table[i-1][j-1] + cost)
return table[m][n]"flame" from the list ["frame", "flan", "flame", "blame"] using edit distance. Which word will the algorithm select as closest?