import tensorflow as tf


    # Make a matrix where each row contains [0, 1, ..., max_sequence_len]
    r = tf.range(0, max_sequence_len, 1)
    range_row = tf.expand_dims(r, 0)
    range_tiled = tf.tile(range_row, [batch_size, 1])

    self.lengths_transposed = lengths_transposed
    self.lengths_tiled = lengths_tiled
    self.range_row = range_row
    self.range_tiled = range_tiled

    # Use the logical operations to create a mask
    indicator = tf.less(range_tiled, lengths_tiled+1) #i.e. where seq len is less than index
    trim = np.ones(indicator.get_shape())
    trim[:,0] = 0 #ignore start symbol
    indicator = tf.logical_and(indicator, trim.astype(bool))
    self.indicator = indicator

    sz = [batch_size, max_sequence_len]
    self._mask = tf.select(indicator, tf.ones(sz), tf.zeros(sz))

    #-------------------------------#

    self.weights = tf.constant(weights, dtype=tf.float32, name='class_weights')
