mbrs.selectors.base module#

class mbrs.selectors.base.Selector(cfg: Config)[source]#

Bases: ABC

Selector base class.

class Config[source]#

Bases: object

Configuration for the selector.

class Output(idx: list[int], sentence: list[str], score: list[float])[source]#

Bases: object

  • idx (list[int]): Index numbers of the n-best hypotheses.

  • sentence (list[str]): Sentences of the n-best hypotheses.

  • score (list[float]): Scores of the n-best hypotheses.

idx: list[int]#
score: list[float]#
sentence: list[str]#
argbest(x: Tensor, maximize: bool = True) Tensor[source]#

Return the index of the best element.

Parameters:
  • x (Tensor) – Input 1-D array.

  • maximize (bool) – Whether maximize the scores or not.

Returns:

A scalar tensor of the best index.

Return type:

Tensor

abstract select(hypotheses: list[str], expected_scores: Tensor, nbest: int = 1, source: str | None = None, maximize: bool = True, **kwargs) Output[source]#

Select the final output list.

Parameters:
  • hypotheses (list[str]) – Hypotheses.

  • expected_scores (Tensor) – The expected scores for each hypothesis.

  • nbest (int) – Return the n-best hypotheses based on the selection rule.

  • source (str, optional) – A source.

  • maximize (bool) – Whether maximize the scores or not.

Returns:

Selected hypotheses.

Return type:

Selector.Output

superior(a: float, b: float, maximize: bool = True) bool[source]#

Return whether the score a is superior to the score b.

Parameters:
  • a (float) – A score.

  • b (float) – A score.

  • maximize (bool) – Whether maximize the scores or not.

Returns:

Return True when a is superior to b.

Return type:

bool

topk(x: Tensor, k: int = 1, maximize: bool = True) tuple[list[float], list[int]][source]#

Return the top-k best elements and corresponding indices.

Parameters:
  • x (Tensor) – Input 1-D array.

  • k (int) – Return the top-k values and indices.

  • maximize (bool) – Whether maximize the scores or not.

Returns:

tuple[list[float], list[int]]
  • list[float]: The top-k values.

  • list[int]: The top-k indices.