Spaces:
Running
Running
Nathan Fradet
commited on
editing readme
Browse files
README.md
CHANGED
@@ -8,7 +8,7 @@ tags:
|
|
8 |
- metric
|
9 |
description: Levenshtein (edit) distance
|
10 |
sdk: gradio
|
11 |
-
sdk_version: 5.
|
12 |
app_file: app.py
|
13 |
pinned: false
|
14 |
---
|
@@ -17,7 +17,7 @@ pinned: false
|
|
17 |
|
18 |
## Metric Description
|
19 |
|
20 |
-
This metric computes the Levenshtein distance, also commonly called "edit distance". The Levenshtein distance measures the number of combined
|
21 |
This module directly calls the [Levenshtein package](https://github.com/rapidfuzz/Levenshtein) for fast execution speed.
|
22 |
|
23 |
## How to Use
|
@@ -35,6 +35,28 @@ Dictionary mapping to the average Levenshtein distance (lower is better) and the
|
|
35 |
|
36 |
### Examples
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
```Python
|
39 |
import evaluate
|
40 |
|
@@ -46,6 +68,7 @@ results = levenshtein.compute(
|
|
46 |
references=[
|
47 |
"foo", "bar"
|
48 |
],
|
|
|
49 |
)
|
50 |
print(results)
|
51 |
# {"levenshtein": 1, "levenshtein_ratio": 0.875}
|
|
|
8 |
- metric
|
9 |
description: Levenshtein (edit) distance
|
10 |
sdk: gradio
|
11 |
+
sdk_version: 5.24.0
|
12 |
app_file: app.py
|
13 |
pinned: false
|
14 |
---
|
|
|
17 |
|
18 |
## Metric Description
|
19 |
|
20 |
+
This metric computes the Levenshtein distance, also commonly called "edit distance". The Levenshtein distance measures the number of combined insertions, deletions and substitutions operations (one per character) to perform on a string so that it becomes identical to a second one. It is a popular metric for text similarity.
|
21 |
This module directly calls the [Levenshtein package](https://github.com/rapidfuzz/Levenshtein) for fast execution speed.
|
22 |
|
23 |
## How to Use
|
|
|
35 |
|
36 |
### Examples
|
37 |
|
38 |
+
#### Levenshtein distance
|
39 |
+
|
40 |
+
```Python
|
41 |
+
import evaluate
|
42 |
+
|
43 |
+
levenshtein = evaluate.load("Natooz/Levenshtein")
|
44 |
+
results = levenshtein.compute(
|
45 |
+
predictions=[
|
46 |
+
"foo", "baroo" # 0 and 2 edits
|
47 |
+
],
|
48 |
+
references=[
|
49 |
+
"foo", "bar"
|
50 |
+
],
|
51 |
+
)
|
52 |
+
print(results)
|
53 |
+
# {"levenshtein": 1, "levenshtein_ratio": 0.875}
|
54 |
+
```
|
55 |
+
|
56 |
+
#### Indel (insertion-deletion) distance
|
57 |
+
|
58 |
+
The weight of each operation can be provided in order to customize the score. For example, the substitution score can be set to 2 to compute the "indel" distance, so that each substitution is counted as two operations (deletion + insertion).
|
59 |
+
|
60 |
```Python
|
61 |
import evaluate
|
62 |
|
|
|
68 |
references=[
|
69 |
"foo", "bar"
|
70 |
],
|
71 |
+
weights=(1, 1, 2), # weight of 2 for substitutions
|
72 |
)
|
73 |
print(results)
|
74 |
# {"levenshtein": 1, "levenshtein_ratio": 0.875}
|