Shortcuts

Extended Edit Distance

Module Interface

class torchmetrics.ExtendedEditDistance(language='en', return_sentence_level_score=False, alpha=2.0, rho=0.3, deletion=0.2, insertion=1.0, compute_on_step=None, **kwargs)[source]

Computes extended edit distance score (ExtendedEditDistance) [1] for strings or list of strings.

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

Parameters
  • language (Literal[‘en’, ‘ja’]) – Language used in sentences. Only supports English (en) and Japanese (ja) for now.

  • return_sentence_level_score (bool) – An indication of whether sentence-level EED score is to be returned

  • alpha (float) – optimal jump penalty, penalty for jumps between characters

  • rho (float) – coverage cost, penalty for repetition of characters

  • deletion (float) – penalty for deletion of character

  • insertion (float) – penalty for insertion or substitution of character

  • compute_on_step (Optional[bool]) –

    Forward only calls update() and returns None if this is set to False.

    Deprecated since version v0.8: Argument has no use anymore and will be removed v0.9.

  • kwargs (Dict[str, Any]) – Additional keyword arguments, see Advanced metric settings for more info.

Returns

Extended edit distance score as a tensor

Example

>>> from torchmetrics import ExtendedEditDistance
>>> preds = ["this is the prediction", "here is an other sample"]
>>> target = ["this is the reference", "here is another one"]
>>> metric = ExtendedEditDistance()
>>> metric(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

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Calculate extended edit distance score.

Return type

Union[Tensor, Tuple[Tensor, Tensor]]

Returns

Extended edit distance score as tensor

update(preds, target)[source]

Update ExtendedEditDistance statistics.

Parameters
Return type

None

Functional Interface

torchmetrics.functional.extended_edit_distance(preds, target, language='en', return_sentence_level_score=False, alpha=2.0, rho=0.3, deletion=0.2, insertion=1.0)[source]

Computes extended edit distance score (ExtendedEditDistance) [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, Sequence[str]]) – An iterable of hypothesis corpus.

  • target (Sequence[Union[str, Sequence[str]]]) – An iterable of iterables of reference corpus.

  • language (Literal[‘en’, ‘ja’]) – Language used in sentences. Only supports English (en) and Japanese (ja) for now. Defaults to en

  • return_sentence_level_score (bool) – An indication of whether sentence-level EED score is to be returned.

  • alpha (float) – optimal jump penalty, penalty for jumps between characters

  • rho (float) – coverage cost, penalty for repetition of characters

  • deletion (float) – penalty for deletion of character

  • insertion (float) – penalty for insertion or substitution of character

Return type

Union[Tensor, Tuple[Tensor, Tensor]]

Returns

Extended edit distance score as a tensor

Example

>>> from torchmetrics.functional 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

Read the Docs v: v0.8.2
Versions
latest
stable
v0.8.2
v0.8.1
v0.8.0
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.2
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.1
v0.4.0
v0.3.2
v0.3.1
v0.3.0
v0.2.0
v0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.