<commit_before>import numpy as np
import theano

def sigmoid_numpy(x):
    assert not isinstance(x, theano.gof.Variable)
    return 1. / (1. + np.exp(-x))

def inverse_sigmoid_numpy(x):
    return np.log(x / (1. - x))<commit_msg>added expression for ratio of softmaxes<commit_after>"""
Useful expressions common to many neural network applications.
"""
__authors__ = "<NAME>"
__copyright__ = "Copyright 2010-2013, Universite de Montreal"
__credits__ = ["<NAME>"]
__license__ = "3-clause BSD"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"

import numpy as np
import theano
from theano.printing import Print
from theano import tensor as T

def sigmoid_numpy(x):
    assert not isinstance(x, theano.gof.Variable)
    return 1. / (1. + np.exp(-x))

def inverse_sigmoid_numpy(x):
    return np.log(x / (1. - x))

def arg_of_softmax(Y_hat):
    assert hasattr(Y_hat, 'owner')
    owner = Y_hat.owner
    assert owner is not None
    op = owner.op
    if isinstance(op, Print):
        assert len(owner.inputs) == 1
        Y_hat, = owner.inputs
        owner = Y_hat.owner
        op = owner.op
    assert isinstance(op, T.nnet.Softmax)
    z ,= owner.inputs
    assert z.ndim == 2
    return z

def softmax_ratio(numer, denom):

    numer_Z = arg_of_softmax(numer)
    denom_Z = arg_of_softmax(denom)
    numer_Z -= numer_Z.max(axis=1).dimshuffle(0, 'x')
    denom_Z -= denom_Z.min(axis=1).dimshuffle(0, 'x')

    new_num = T.exp(numer_Z - denom_Z) * (T.exp(denom_Z).sum(axis=1).dimshuffle(0, 'x'))
    new_den = (T.exp(numer_Z).sum(axis=1).dimshuffle(0, 'x'))

    return new_num / new_den
{'fraction_non_alphanumeric': 0.1348456206679269, 'fraction_numerical': 0.01575299306868305, 'mean_word_length': 3.4481792717086837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1739714', 'n_tokens_mistral': 609, 'n_tokens_neox': 597, 'n_words': 144}