opennmt/data/dataset.py
def filter_irregular_batches(multiple):
    """Transformation that filters out batches based on their size.

    Example:

      >>> dataset = tf.data.Dataset.range(10).batch(3)
      >>> dataset = dataset.apply(opennmt.data.filter_irregular_batches(3))
      >>> len(list(iter(dataset)))
      3

    Args:
      multiple: The divisor of the batch size.

    Returns:
      A ``tf.data.Dataset`` transformation.
    """
    if multiple == 1:
        return lambda dataset: dataset

    def _predicate(*x):
        flat = tf.nest.flatten(x)
        batch_size = tf.shape(flat[0])[0]
        return tf.equal(batch_size % multiple, 0)

    return lambda dataset: dataset.filter(_predicate)
Transformation that filters out batches based on their size.

    Example:

      >>> dataset = tf.data.Dataset.range(10).batch(3)
      >>> dataset = dataset.apply(opennmt.data.filter_irregular_batches(3))
      >>> len(list(iter(dataset)))
      3

    Args:
      multiple: The divisor of the batch size.

    Returns:
      A ``tf.data.Dataset`` transformation.
    
Transformation that filters out batches based on their size.
Transformation that filters out batches based on their size .
def filter_irregular_batches(multiple):
    if multiple == 1:
        return lambda dataset: dataset
    def _predicate(*x):
        flat = tf.nest.flatten(x)
        batch_size = tf.shape(flat[0])[0]
        return tf.equal(batch_size % multiple, 0)
    return lambda dataset: dataset.filter(_predicate)
def filter_irregular_batches ( multiple ) : if multiple == 1 : return lambda dataset : dataset def _predicate ( * x ) : flat = tf . nest . flatten ( x ) batch_size = tf . shape ( flat [ 0 ] ) [ 0 ] return tf . equal ( batch_size % multiple , 0 ) return lambda dataset : dataset . filter ( _predicate )
Transformation that filters out batches based on their size.
Transformation that filters out batches based on their size .
"""Transformation that filters out batches based on their size.

    Example:

      >>> dataset = tf.data.Dataset.range(10).batch(3)
      >>> dataset = dataset.apply(opennmt.data.filter_irregular_batches(3))
      >>> len(list(iter(dataset)))
      3

    Args:
      multiple: The divisor of the batch size.

    Returns:
      A ``tf.data.Dataset`` transformation.
    """
A ``tf.data.Dataset`` transformation.
A ` ` tf . data . Dataset ` ` transformation .
multiple
The divisor of the batch size.
The divisor of the batch size .
examples
>>> dataset = tf.data.Dataset.range(10).batch(3)
>>> dataset = dataset.apply(opennmt.data.filter_irregular_batches(3))
>>> len(list(iter(dataset)))
3
>>> dataset = tf . data . Dataset . range ( 10 ) . batch ( 3 ) >>> dataset = dataset . apply ( opennmt . data . filter_irregular_batches ( 3 )) >>> len ( list ( iter ( dataset ))) 3