inference_pipeline

opennmt.data.inference_pipeline(batch_size, batch_type='examples', process_fn=None, transform_fns=None, length_bucket_width=None, length_fn=None, num_threads=None, prefetch_buffer_size=None)[source]

Transformation that applies dataset operations for inference.

Example

>>> dataset = dataset.apply(opennmt.data.inference_pipeline(...))
Parameters
  • batch_size – The batch size to use.

  • batch_type – The batching strategy to use: can be “examples” or “tokens”.

  • process_fn – The processing function to apply on each element.

  • transform_fns – List of dataset transformation functions (applied after process_fn if defined).

  • length_bucket_width – The width of the length buckets to select batch candidates from. If set, this means the inference pipeline will be reordered based on the examples length, the application is then responsible to restore the predictions in order. An “index” key will be inserted in the examples dictionary.

  • length_fn – A function mapping features to a sequence length.

  • num_threads – The number of elements processed in parallel.

  • prefetch_buffer_size – The number of batches to prefetch asynchronously. If None, use an automatically tuned value.

Returns

A tf.data.Dataset transformation.

Raises
  • ValueError – if length_bucket_width is set but not length_fn.

  • ValueError – if length_bucket_width is set but the dataset does not output a dictionary structure.