---
title: Extended Edit Distance
description: >-
  Compute extended edit distance score (ExtendedEditDistance) for strings or
  list of strings.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/text/extended_edit_distance'
---
# Extended Edit Distance {#extended-edit-distance}

## Module Interface {#module-interface}

### `class torchmetrics.text.ExtendedEditDistance(language='en', return_sentence_level_score=False, alpha=2.0, rho=0.3, deletion=0.2, insertion=1.0, **kwargs)` {#torchmetrics.text.ExtendedEditDistance}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/text/eed.py#L29-L166)

Compute extended edit distance score ([ExtendedEditDistance](https://aclanthology.org/W19-5359)) for strings or list of strings.

The metric utilises the Levenshtein distance and extends it by adding a jump operation.

As input to `forward` and `update` the metric accepts the following input:

*   `preds` (`Sequence`): An iterable of hypothesis corpus
    
*   `target` (`Sequence`): An iterable of iterables of reference corpus
    

As output of `forward` and `compute` the metric returns the following output:

*   `eed` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A tensor with the extended edit distance score
    

Parameters:

*   **language** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'en'`, `'ja'`\]) – Language used in sentences. Only supports English (en) and Japanese (ja) for now.
    
*   **return\_sentence\_level\_score** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication of whether sentence-level EED score is to be returned
    
*   **alpha** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – optimal jump penalty, penalty for jumps between characters
    
*   **rho** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – coverage cost, penalty for repetition of characters
    
*   **deletion** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – penalty for deletion of character
    
*   **insertion** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – penalty for insertion or substitution of character
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Example

```python
>>> from torchmetrics.text import ExtendedEditDistance
>>> preds = ["this is the prediction", "here is an other sample"]
>>> target = ["this is the reference", "here is another one"]
>>> eed = ExtendedEditDistance()
>>> eed(preds=preds, target=target)
tensor(0.3078)
```

#### `plot(val=None, ax=None)` {#torchmetrics.text.ExtendedEditDistance.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/text/eed.py#L124-L166)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> from torchmetrics.text import ExtendedEditDistance
>>> metric = ExtendedEditDistance()
>>> preds = ["this is the prediction", "there is an other sample"]
>>> target = ["this is the reference", "there is another one"]
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/extended\_edit\_distance-1.png](/docs/torchmetrics/1.9.0/static/_images/extended_edit_distance-1.png)](/docs/torchmetrics/1.9.0/static/_images/extended_edit_distance-1.png)

```python
>>> # Example plotting multiple values
>>> from torchmetrics.text import ExtendedEditDistance
>>> metric = ExtendedEditDistance()
>>> preds = ["this is the prediction", "there is an other sample"]
>>> target = ["this is the reference", "there is another one"]
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(preds, target))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/extended\_edit\_distance-2.png](/docs/torchmetrics/1.9.0/static/_images/extended_edit_distance-2.png)](/docs/torchmetrics/1.9.0/static/_images/extended_edit_distance-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.text.extended_edit_distance(preds, target, language='en', return_sentence_level_score=False, alpha=2.0, rho=0.3, deletion=0.2, insertion=1.0)` {#torchmetrics.functional.text.extended_edit_distance}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/text/eed.py#L365-L415)

Compute extended edit distance score ([ExtendedEditDistance](https://aclanthology.org/W19-5359)) \[1\] for strings or list of strings.

The metric utilises the Levenshtein distance and extends it by adding a jump operation.

Parameters:

*   **preds** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]\]) – An iterable of hypothesis corpus.
    
*   **target** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]\]\]) – An iterable of iterables of reference corpus.
    
*   **language** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'en'`, `'ja'`\]) – Language used in sentences. Only supports English (en) and Japanese (ja) for now. Defaults to en
    
*   **return\_sentence\_level\_score** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication of whether sentence-level EED score is to be returned.
    
*   **alpha** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – optimal jump penalty, penalty for jumps between characters
    
*   **rho** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – coverage cost, penalty for repetition of characters
    
*   **deletion** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – penalty for deletion of character
    
*   **insertion** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – penalty for insertion or substitution of character
    

Return type:

`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]\]

Returns:

Extended edit distance score as a tensor

Example

```python
>>> from torchmetrics.functional.text import extended_edit_distance
>>> preds = ["this is the prediction", "here is an other sample"]
>>> target = ["this is the reference", "here is another one"]
>>> extended_edit_distance(preds=preds, target=target)
tensor(0.3078)
```

References

\[1\] P. Stanchev, W. Wang, and H. Ney, “EED: Extended Edit Distance Measure for Machine Translation”, submitted to WMT 2019. [ExtendedEditDistance](https://aclanthology.org/W19-5359)

---

**Navigation**

- Parent: [Text](/docs/torchmetrics/1.9.0/text.md)
