File size: 1,478 Bytes
3ac838d
 
 
 
 
 
 
 
9bed1f8
3ac838d
 
d866e28
9bed1f8
d866e28
 
728c06a
 
 
 
 
d866e28
728c06a
 
 
d866e28
9bed1f8
 
 
 
 
 
 
 
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
---
title: Token Edit Distance
emoji: 🐠
colorFrom: pink
colorTo: yellow
sdk: gradio
sdk_version: 3.42.0
app_file: app.py
pinned: true
---

# Token Edit Distance 
This is an NLP evaluation metric that records the minimum number of token edits (insertions, deletions, and replacements, all weighted equally) to the prediction string in order to make it exactly match the reference string. Uses identical logic to Levenshtein Edit Distance, except applied to tokens (i.e. individual ints in a list) as opposed to individual characters in a string.

## Args:  
* predictions:  ```List[List[Int]]```, list of predictions to score.  
  * Each prediction should be tokenized into a list of tokens.  
* references:  ```List[List[Int]]```, list of references/ground truth output to score against.  
  * Each reference should be tokenized into a list of tokens.  

## Returns:
* "avg_token_edit_distance":  ```Float```, average Token Edit Distance for all inputted predictions and references  
* "token_edit_distances":  ```List[Int]```, the Token Edit Distance for each inputted prediction and reference  

## Examples:  
```
>>> token_edit_distance_metric = datasets.load_metric('Token Edit Distance')
>>> references = [[15, 4243], [100, 10008]]
>>> predictions = [[15, 4243], [100, 10009]]
>>> results = token_edit_distance_metric.compute(predictions=predictions, references=references)
>>> print(results)
{'avg_token_edit_distance': 0.5, 'token_edit_distances': array([0. 1.])}
```