(self, sequence, sequence_length)
Hierarchically encodes the input sequences, returning a single embedding.

    Each sequence should be padded per-segment. For example, a sequence with
    three segments [1, 2, 3], [4, 5], [6, 7, 8 ,9] and a `max_seq_len` of 12
    should be input as `sequence = [1, 2, 3, 0, 4, 5, 0, 0, 6, 7, 8, 9]` with
    `sequence_length = [3, 2, 4]`.

    Args:
      sequence: A batch of (padded) sequences, sized
        `[batch_size, max_seq_len, input_depth]`.
      sequence_length: A batch of sequence lengths. May be sized
        `[batch_size, level_lengths[0]]` or `[batch_size]`. If the latter,
        each length must either equal `max_seq_len` or 0. In this case, the
        segment lengths are assumed to be constant and the total length will be
        evenly divided amongst the segments.

    Returns:
      embedding: A batch of embeddings, sized `[batch_size, N]`.
Hierarchically encodes the input sequences, returning a single embedding.
Hierarchically encodes the input sequences returning a single embedding .
def encode(self, sequence, sequence_length):
    """Hierarchically encodes the input sequences, returning a single embedding.

    Each sequence should be padded per-segment. For example, a sequence with
    three segments [1, 2, 3], [4, 5], [6, 7, 8 ,9] and a `max_seq_len` of 12
    should be input as `sequence = [1, 2, 3, 0, 4, 5, 0, 0, 6, 7, 8, 9]` with
    `sequence_length = [3, 2, 4]`.

    Args:
      sequence: A batch of (padded) sequences, sized
        `[batch_size, max_seq_len, input_depth]`.
      sequence_length: A batch of sequence lengths. May be sized
        `[batch_size, level_lengths[0]]` or `[batch_size]`. If the latter,
        each length must either equal `max_seq_len` or 0. In this case, the
        segment lengths are assumed to be constant and the total length will be
        evenly divided amongst the segments.

    Returns:
      embedding: A batch of embeddings, sized `[batch_size, N]`.
    """
    batch_size = int(sequence.shape[0])
    sequence_length = lstm_utils.maybe_split_sequence_lengths(
        sequence_length, np.prod(self._level_lengths[1:]),
        self._total_length)

    for level, (num_splits, h_encoder) in enumerate(
        self._hierarchical_encoders):
      split_seqs = tf.split(sequence, num_splits, axis=1)
      # In the first level, we use the input `sequence_length`. After that,
      # we use the full embedding sequences.
      if level:
        sequence_length = tf.fill(
            [batch_size, num_splits], split_seqs[0].shape[1])
      split_lengths = tf.unstack(sequence_length, axis=1)
      embeddings = [
          h_encoder.encode(s, l) for s, l in zip(split_seqs, split_lengths)]
      sequence = tf.stack(embeddings, axis=1)

    with tf.control_dependencies([tf.assert_equal(tf.shape(sequence)[1], 1)]):
      return sequence[:, 0]
def encode ( self , sequence , sequence_length ) : batch_size = int ( sequence . shape [ 0 ] ) sequence_length = lstm_utils . maybe_split_sequence_lengths ( sequence_length , np . prod ( self . _level_lengths [ 1 : ] ) , self . _total_length ) for level , ( num_splits , h_encoder ) in enumerate ( self . _hierarchical_encoders ) : split_seqs = tf . split ( sequence , num_splits , axis = 1 ) # In the first level, we use the input `sequence_length`. After that, # we use the full embedding sequences. if level : sequence_length = tf . fill ( [ batch_size , num_splits ] , split_seqs [ 0 ] . shape [ 1 ] ) split_lengths = tf . unstack ( sequence_length , axis = 1 ) embeddings = [ h_encoder . encode ( s , l ) for s , l in zip ( split_seqs , split_lengths ) ] sequence = tf . stack ( embeddings , axis = 1 ) with tf . control_dependencies ( [ tf . assert_equal ( tf . shape ( sequence ) [ 1 ] , 1 ) ] ) : return sequence [ : , 0 ]