'Creates a new Swivel model.'

def __init__(self, input_base_path, hparams):

    (self.row_ix_to_word, self.row_word_to_ix) = self._read_vocab(os.path.join(input_base_path, 'row_vocab.txt'))
    (self.col_ix_to_word, self.col_word_to_ix) = self._read_vocab(os.path.join(input_base_path, 'col_vocab.txt'))
    row_sums = self._read_marginals_file(os.path.join(input_base_path, 'row_sums.txt'))
    col_sums = self._read_marginals_file(os.path.join(input_base_path, 'col_sums.txt'))
    count_matrix_files = glob.glob(os.path.join(input_base_path, 'shard-*.pb'))
    (global_rows, global_cols, counts) = self._count_matrix_input(count_matrix_files, hparams.submatrix_rows, hparams.submatrix_cols)
    sigma = (1.0 / np.sqrt(hparams.dim))
    self.row_embedding = tf.get_variable('row_embedding', shape=[len(row_sums), hparams.dim], initializer=tf.random_normal_initializer(0, sigma), dtype=tf.float32)
    self.col_embedding = tf.get_variable('col_embedding', shape=[len(col_sums), hparams.dim], initializer=tf.random_normal_initializer(0, sigma), dtype=tf.float32)
    matrix_log_sum = np.log((np.sum(row_sums) + 1))
    row_bias = tf.constant([np.log((x + 1)) for x in row_sums], dtype=tf.float32)
    col_bias = tf.constant([np.log((x + 1)) for x in col_sums], dtype=tf.float32)
    selected_rows = tf.nn.embedding_lookup(self.row_embedding, global_rows)
    selected_cols = tf.nn.embedding_lookup(self.col_embedding, global_cols)
    selected_row_bias = tf.gather(row_bias, global_rows)
    selected_col_bias = tf.gather(col_bias, global_cols)
    predictions = tf.matmul(selected_rows, selected_cols, transpose_b=True)
    count_is_nonzero = tf.to_float(tf.cast(counts, tf.bool))
    count_is_zero = (1 - count_is_nonzero)
    objectives = (count_is_nonzero * tf.log((counts + 1e-30)))
    objectives -= tf.reshape(selected_row_bias, [(-1), 1])
    objectives -= selected_col_bias
    objectives += matrix_log_sum
    err = (predictions - objectives)
    l2_confidence = (hparams.confidence_base + (hparams.confidence_scale * tf.pow(counts, hparams.confidence_exponent)))
    loss_multiplier = (1 / np.sqrt((hparams.submatrix_rows * hparams.submatrix_cols)))
    l2_loss = (loss_multiplier * tf.reduce_sum(((0.5 * l2_confidence) * tf.square(err))))
    sigmoid_loss = (loss_multiplier * tf.reduce_sum((tf.nn.softplus(err) * count_is_zero)))
    self.loss_op = (l2_loss + sigmoid_loss)
    if (hparams.optimizer == 'adagrad'):
        opt = tf.train.AdagradOptimizer(hparams.learning_rate)
    elif (hparams.optimizer == 'rmsprop'):
        opt = tf.train.RMSPropOptimizer(hparams.learning_rate, hparams.momentum)
    else:
        raise ValueError(('unknown    optimizer    "%s"' % hparams.optimizer))
    self.global_step = tf.get_variable('global_step', initializer=0, trainable=False)
    self.train_op = opt.minimize(self.loss_op, global_step=self.global_step)
    self.steps_per_epoch = ((len(row_sums) / hparams.submatrix_rows) * (len(col_sums) / hparams.submatrix_cols))
