(self, t)
return tf.transpose(hier_t, perm)
Reshapes `t` so that its initial dimensions match the hierarchy.
Reshapes `t` so that its initial dimensions match the hierarchy.
Reshapes t so that its initial dimensions match the hierarchy .
def _reshape_to_hierarchy(self, t):
    """Reshapes `t` so that its initial dimensions match the hierarchy."""
    # Exclude the final, core decoder length.
    level_lengths = self._level_lengths[:-1]
    t_shape = t.shape.as_list()
    t_rank = len(t_shape)
    batch_size = t_shape[0]
    hier_shape = [batch_size] + level_lengths
    if t_rank == 3:
      hier_shape += [-1] + t_shape[2:]
    elif t_rank != 2:
      # We only expect rank-2 for lengths and rank-3 for sequences.
      raise ValueError('Unexpected shape for tensor: %s' % t)
    hier_t = tf.reshape(t, hier_shape)
    # Move the batch dimension to after the hierarchical dimensions.
    num_levels = len(level_lengths)
    perm = list(range(len(hier_shape)))
    perm.insert(num_levels, perm.pop(0))
    return tf.transpose(hier_t, perm)
def _reshape_to_hierarchy ( self , t ) : # Exclude the final, core decoder length. level_lengths = self . _level_lengths [ : - 1 ] t_shape = t . shape . as_list ( ) t_rank = len ( t_shape ) batch_size = t_shape [ 0 ] hier_shape = [ batch_size ] + level_lengths if t_rank == 3 : hier_shape += [ - 1 ] + t_shape [ 2 : ] elif t_rank != 2 : # We only expect rank-2 for lengths and rank-3 for sequences. raise ValueError ( 'Unexpected shape for tensor: %s' % t ) hier_t = tf . reshape ( t , hier_shape ) # Move the batch dimension to after the hierarchical dimensions. num_levels = len ( level_lengths ) perm = list ( range ( len ( hier_shape ) ) ) perm . insert ( num_levels , perm . pop ( 0 ) ) return tf . transpose ( hier_t , perm )