dynamic_decode

opennmt.utils.dynamic_decode(symbols_to_logits_fn, start_ids, end_id=2, initial_state=None, decoding_strategy=None, sampler=None, maximum_iterations=None, minimum_iterations=0, attention_history=False, attention_size=None, tflite_output_size=None)[source]

Dynamic decoding.

Parameters
  • symbols_to_logits_fn – A callable taking (symbols, step, state) and returning (logits, state, attention) (attention is optional).

  • start_ids – Initial input IDs of shape \([B]\).

  • end_id – ID of the end of sequence token.

  • initial_state – Initial decoder state.

  • decoding_strategy – A opennmt.utils.DecodingStrategy instance that defines the decoding logic. Defaults to a greedy search.

  • sampler – A opennmt.utils.Sampler instance that samples predictions from the model output. Defaults to an argmax sampling.

  • maximum_iterations – The maximum number of iterations to decode for.

  • minimum_iterations – The minimum number of iterations to decode for.

  • attention_history – Gather attention history during the decoding.

  • attention_size – If known, the size of the attention vectors (i.e. the maximum source length).

  • tflite_output_size – If not None will run TFLite safe, is the size of 1D output tensor.

Returns

A opennmt.utils.DecodingResult instance.