---
title: Translation Edit Rate (TER)
description: >-
  Calculate Translation edit rate (TER)  of machine translated text with one or
  more references.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/text/translation_edit_rate'
---
# Translation Edit Rate (TER) {#translation-edit-rate-ter}

## Module Interface {#module-interface}

### `class torchmetrics.text.TranslationEditRate(normalize=False, no_punctuation=False, lowercase=True, asian_support=False, return_sentence_level_score=False, **kwargs)` {#torchmetrics.text.TranslationEditRate}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/text/ter.py#L30-L161)

Calculate Translation edit rate ([TER](https://aclanthology.org/2006.amta-papers.25)) of machine translated text with one or more references.

This implementation follows the one from [SacreBleu\_ter](https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/metrics/ter.py), which is a near-exact reimplementation of the Tercom algorithm, produces identical results on all “sane” outputs.

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:

*   `ter` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): if `return_sentence_level_score=True` return a corpus-level translation edit rate with a list of sentence-level translation\_edit\_rate, else return a corpus-level translation edit rate
    

Parameters:

*   **normalize** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether a general tokenization to be applied.
    
*   **no\_punctuation** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whteher a punctuation to be removed from the sentences.
    
*   **lowercase** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether to enable case-insensitivity.
    
*   **asian\_support** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether asian characters to be processed.
    
*   **return\_sentence\_level\_score** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether a sentence-level TER to be returned.
    
*   **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 TranslationEditRate
>>> preds = ['the cat is on the mat']
>>> target = [['there is a cat on the mat', 'a cat is on the mat']]
>>> ter = TranslationEditRate()
>>> ter(preds, target)
tensor(0.1538)
```

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

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/text/ter.py#L119-L161)

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 TranslationEditRate
>>> metric = TranslationEditRate()
>>> preds = ['the cat is on the mat']
>>> target = [['there is a cat on the mat', 'a cat is on the mat']]
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/translation\_edit\_rate-1.png](/docs/torchmetrics/1.9.0/static/_images/translation_edit_rate-1.png)](/docs/torchmetrics/1.9.0/static/_images/translation_edit_rate-1.png)

```python
>>> # Example plotting multiple values
>>> from torchmetrics.text import TranslationEditRate
>>> metric = TranslationEditRate()
>>> preds = ['the cat is on the mat']
>>> target = [['there is a cat on the mat', 'a cat is on the mat']]
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(preds, target))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/translation\_edit\_rate-2.png](/docs/torchmetrics/1.9.0/static/_images/translation_edit_rate-2.png)](/docs/torchmetrics/1.9.0/static/_images/translation_edit_rate-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.text.translation_edit_rate(preds, target, normalize=False, no_punctuation=False, lowercase=True, asian_support=False, return_sentence_level_score=False)` {#torchmetrics.functional.text.translation_edit_rate}

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

Calculate Translation edit rate ([TER](https://aclanthology.org/2006.amta-papers.25)) of machine translated text with one or more references.

This implementation follows the implementations from [https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/metrics/ter.py](https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/metrics/ter.py). The sacrebleu implementation is a near-exact reimplementation of the Tercom algorithm, produces identical results on all “sane” outputs.

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.
    
*   **normalize** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether a general tokenization to be applied.
    
*   **no\_punctuation** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whteher a punctuation to be removed from the sentences.
    
*   **lowercase** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether to enable case-insensitivity.
    
*   **asian\_support** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether asian characters to be processed.
    
*   **return\_sentence\_level\_score** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – An indication whether a sentence-level TER to be returned.
    

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)"), [`List`](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]\]\]

Returns:

A corpus-level translation edit rate (TER). (Optionally) A list of sentence-level translation\_edit\_rate (TER) if return\_sentence\_level\_score=True.

Example

```python
>>> preds = ['the cat is on the mat']
>>> target = [['there is a cat on the mat', 'a cat is on the mat']]
>>> translation_edit_rate(preds, target)
tensor(0.1538)
```

References

\[1\] A Study of Translation Edit Rate with Targeted Human Annotation by Mathew Snover, Bonnie Dorr, Richard Schwartz, Linnea Micciulla and John Makhoul [TER](https://aclanthology.org/2006.amta-papers.25)

---

**Navigation**

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