'Computes the state of the RNN-NADE (NADE bias parameters and RNN state).
Args:
inputs: A batch of sequences to compute the state from, sized
`[batch_size, max(lengths), num_dims]` or `[batch_size, num_dims]`.
lengths: The length of each sequence, sized `[batch_size]`.
initial_state: An RnnNadeStateTuple, the initial state of the RNN-NADE, or
None if the zero state should be used.
Returns:
final_state: An RnnNadeStateTuple, the final state of the RNN-NADE.'

def _get_state(self, inputs, lengths=None, initial_state=None):

    batch_size = inputs.shape[0].value
    lengths = (tf.tile(tf.shape(inputs)[1:2], [batch_size]) if (lengths is None) else lengths)
    initial_rnn_state = (self._get_rnn_zero_state(batch_size) if (initial_state is None) else initial_state.rnn_state)
    helper = tf.contrib.seq2seq.TrainingHelper(inputs=inputs, sequence_length=lengths)
    decoder = tf.contrib.seq2seq.BasicDecoder(cell=self._rnn_cell, helper=helper, initial_state=initial_rnn_state, output_layer=self._fc_layer)
    (final_outputs, final_rnn_state) = tf.contrib.seq2seq.dynamic_decode(decoder)[0:2]
    final_outputs_flat = magenta.common.flatten_maybe_padded_sequences(final_outputs.rnn_output, lengths)
    (b_enc, b_dec) = tf.split(final_outputs_flat, [self._nade.num_hidden, self._nade.num_dims], axis=1)
    return RnnNadeStateTuple(b_enc, b_dec, final_rnn_state)
