Spaces:
Sleeping
Sleeping
File size: 1,959 Bytes
175cd1f 814113b 175cd1f 814113b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
---
title: Levenshtein distance
emoji: ✍️
colorFrom: blue
colorTo: green
tags:
- evaluate
- metric
description: Levenshtein (edit) distance
sdk: gradio
sdk_version: 5.6.0
app_file: app.py
pinned: false
---
# Metric Card for the Levenshtein (edit) distance
## Metric Description
This metric computes the Levenshtein distance, also commonly called "edit distance". The Levenshtein distance measures the number of combined editions, deletions and additions to perform on a string so that it becomes identical to a second one. It is a popular metric for text similarity.
This module directly calls the [Levenshtein package](https://github.com/rapidfuzz/Levenshtein) for fast execution speed.
## How to Use
### Inputs
*List all input arguments in the format below*
- **predictions** *(string): sequence of prediction strings*
- **references** *(string): sequence of reference string;*
- **kwargs** *keyword arguments to pass to the [Levenshtein.distance](https://rapidfuzz.github.io/Levenshtein/levenshtein.html#Levenshtein.distance) method.*
### Output Values
Dictionary mapping to the average Levenshtein distance (lower is better) and the ratio ([0, 1]) distance (higher is better).
### Examples
```Python
import evaluate
levenshtein = evaluate.load("Natooz/Levenshtein")
results = levenshtein.compute(
predictions=[
"foo", "baroo" # 0 and 2 edits
],
references=[
"foo", "bar"
],
)
print(results)
# {"levenshtein": 1, "levenshtein_ratio": 0.875}
```
## Citation
```bibtex
@ARTICLE{1966SPhD...10..707L,
author = {{Levenshtein}, V.~I.},
title = "{Binary Codes Capable of Correcting Deletions, Insertions and Reversals}",
journal = {Soviet Physics Doklady},
year = 1966,
month = feb,
volume = {10},
pages = {707},
adsurl = {https://ui.adsabs.harvard.edu/abs/1966SPhD...10..707L},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
```
|