paddlespeech.s2t.decoders.scorers.scorer_interface module

Scorer interface module.

class paddlespeech.s2t.decoders.scorers.scorer_interface.BatchPartialScorerInterface[source]

Bases: BatchScorerInterface, PartialScorerInterface

Batch partial scorer interface for beam search.

Methods

batch_init_state(x)

Get an initial state for decoding (optional).

batch_score(ys, states, xs)

Score new token batch (required).

batch_score_partial(ys, next_tokens, states, xs)

Score new token (required).

final_score(state)

Score eos (optional).

init_state(x)

Get an initial state for decoding (optional).

score(y, state, x)

Score new token (required).

score_partial(y, next_tokens, state, x)

Score new token (required).

select_state(state, i[, new_id])

Select state with relative ids in the main beam search.

batch_score_partial(ys: Tensor, next_tokens: Tensor, states: List[Any], xs: Tensor) Tuple[Tensor, Any][source]

Score new token (required).

Args:

ys (paddle.Tensor): paddle.int64 prefix tokens (n_batch, ylen). next_tokens (paddle.Tensor): paddle.int64 tokens to score (n_batch, n_token). states (List[Any]): Scorer states for prefix tokens. xs (paddle.Tensor):

The encoder feature that generates ys (n_batch, xlen, n_feat).

Returns:
tuple[paddle.Tensor, Any]:

Tuple of a score tensor for ys that has a shape (n_batch, n_vocab) and next states for ys

class paddlespeech.s2t.decoders.scorers.scorer_interface.BatchScorerInterface[source]

Bases: ScorerInterface

Batch scorer interface.

Methods

batch_init_state(x)

Get an initial state for decoding (optional).

batch_score(ys, states, xs)

Score new token batch (required).

final_score(state)

Score eos (optional).

init_state(x)

Get an initial state for decoding (optional).

score(y, state, x)

Score new token (required).

select_state(state, i[, new_id])

Select state with relative ids in the main beam search.

batch_init_state(x: Tensor) Any[source]

Get an initial state for decoding (optional).

Args:

x (paddle.Tensor): The encoded feature tensor

Returns: initial state

batch_score(ys: Tensor, states: List[Any], xs: Tensor) Tuple[Tensor, List[Any]][source]

Score new token batch (required).

Args:

ys (paddle.Tensor): paddle.int64 prefix tokens (n_batch, ylen). states (List[Any]): Scorer states for prefix tokens. xs (paddle.Tensor):

The encoder feature that generates ys (n_batch, xlen, n_feat).

Returns:
tuple[paddle.Tensor, List[Any]]: Tuple of

batchfied scores for next token with shape of (n_batch, n_vocab) and next state list for ys.

class paddlespeech.s2t.decoders.scorers.scorer_interface.PartialScorerInterface[source]

Bases: ScorerInterface

Partial scorer interface for beam search.

The partial scorer performs scoring when non-partial scorer finished scoring, and receives pre-pruned next tokens to score because it is too heavy to score all the tokens.

Score sub-set of tokens, not all.

Examples:
  • Prefix search for connectionist-temporal-classification models
    • decoders.scorers.ctc.CTCPrefixScorer

Methods

final_score(state)

Score eos (optional).

init_state(x)

Get an initial state for decoding (optional).

score(y, state, x)

Score new token (required).

score_partial(y, next_tokens, state, x)

Score new token (required).

select_state(state, i[, new_id])

Select state with relative ids in the main beam search.

score_partial(y: Tensor, next_tokens: Tensor, state: Any, x: Tensor) Tuple[Tensor, Any][source]

Score new token (required).

Args:

y (paddle.Tensor): 1D prefix token next_tokens (paddle.Tensor): paddle.int64 next token to score state: decoder state for prefix tokens x (paddle.Tensor): The encoder feature that generates ys

Returns:
tuple[paddle.Tensor, Any]:

Tuple of a score tensor for y that has a shape (len(next_tokens),) and next state for ys

class paddlespeech.s2t.decoders.scorers.scorer_interface.ScorerInterface[source]

Bases: object

Scorer interface for beam search.

The scorer performs scoring of the all tokens in vocabulary.

Examples:
  • Search heuristics
    • scorers.length_bonus.LengthBonus

  • Decoder networks of the sequence-to-sequence models
    • transformer.decoder.Decoder

    • rnn.decoders.Decoder

  • Neural language models
    • lm.transformer.TransformerLM

    • lm.default.DefaultRNNLM

    • lm.seq_rnn.SequentialRNNLM

Methods

final_score(state)

Score eos (optional).

init_state(x)

Get an initial state for decoding (optional).

score(y, state, x)

Score new token (required).

select_state(state, i[, new_id])

Select state with relative ids in the main beam search.

final_score(state: Any) float[source]

Score eos (optional).

Args:

state: Scorer state for prefix tokens

Returns:

float: final score

init_state(x: Tensor) Any[source]

Get an initial state for decoding (optional).

Args:

x (paddle.Tensor): The encoded feature tensor

Returns: initial state

score(y: Tensor, state: Any, x: Tensor) Tuple[Tensor, Any][source]

Score new token (required).

Args:

y (paddle.Tensor): 1D paddle.int64 prefix tokens. state: Scorer state for prefix tokens x (paddle.Tensor): The encoder feature that generates ys.

Returns:
tuple[paddle.Tensor, Any]: Tuple of

scores for next token that has a shape of (n_vocab) and next state for ys

select_state(state: Any, i: int, new_id: Optional[int] = None) Any[source]

Select state with relative ids in the main beam search.

Args:

state: Decoder state for prefix tokens i (int): Index to select a state in the main beam search new_id (int): New label index to select a state if necessary

Returns:

state: pruned state