evaluatio.alignment¶
Functions¶
optimal_alignment¶
optimal_alignment(references: Iterable[object], hypotheses: Iterable[object]) -> List[_bindings.Alignment]Compute an optimal alignment between a reference and hypothesis sequence.
Aligns each element in references to a span in hypotheses using
dynamic programming, minimising the total edit distance between the two
sequences. The result describes, for each reference index, which range of
hypothesis indices it aligns to.
Parameters
references:Iterable[object]
Reference token sequence.hypotheses:Iterable[object]
Hypothesis token sequence.
Returns
List[Alignment]
OneAlignmentper reference token, sorted by reference index. EachAlignmenthas three fields:index: int — index of the token inreferences.start: int — start index of the aligned span inhypotheses(inclusive).end: int — end index of the aligned span inhypotheses(exclusive).
Note
Tokens are compared using the same underlying mechanism as universal_edit_distance.
Multiple optimal alignments might exist, one is returned arbitrarily, but deterministically.