<commit_before>import numpy

from chainer import cuda
from chainer import cudnn
from chainer import function

if cudnn.available:
    from chainer.cudnn import libcudnn
    _algorithm = libcudnn.cudnnSoftmaxAlgorithm['CUDNN_SOFTMAX_ACCURATE']
    _mode = libcudnn.cudnnSoftmaxMode['CUDNN_SOFTMAX_MODE_INSTANCE']


class Softmax(function.Function):

    """Softmax activation function."""

    def __init__(self, use_cudnn=True):
        self.use_cudnn = use_cudnn

    def forward_cpu(self, x):
        assert x[0].ndim == 2
        self.y = x[0] - numpy.amax(x[0], axis=1, keepdims=True)
        numpy.exp(self.y, out=self.y)
        self.y /= self.y.sum(axis=1, keepdims=True)
        return self.y,
<commit_msg>Make type check for Softmax<commit_after>import numpy

from chainer import cuda
from chainer import cudnn
from chainer import function

if cudnn.available:
    from chainer.cudnn import libcudnn
    _algorithm = libcudnn.cudnnSoftmaxAlgorithm['CUDNN_SOFTMAX_ACCURATE']
    _mode = libcudnn.cudnnSoftmaxMode['CUDNN_SOFTMAX_MODE_INSTANCE']


class Softmax(function.Function):

    """Softmax activation function."""

    def __init__(self, use_cudnn=True):
        self.use_cudnn = use_cudnn

    def check_type_forward(self, in_types):
        in_types.size().should_be(1)
        x_type, = in_types
        x_type.dtype.should_be(numpy.float32)
        x_type.ndim.should_be(2)

    def check_type_backward(self, in_types, out_types):
        in_types.size().should_be(1)
        out_types.size().should_be(1)
        x_type, = in_types
        y_type, = out_types
        y_type.ndim.should_be(2)
        y_type.shape[0].should_be(x_type.shape[0])
        y_type.shape[1].should_be(x_type.shape[1])

    def forward_cpu(self, x):
        assert x[0].ndim == 2
        self.y = x[0] - numpy.amax(x[0], axis=1, keepdims=True)
        numpy.exp(self.y, out=self.y)
        self.y /= self.y.sum(axis=1, keepdims=True)
        return self.y,

{'fraction_non_alphanumeric': 0.11270491803278689, 'fraction_numerical': 0.0117827868852459, 'mean_word_length': 3.2456521739130433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2733460', 'n_tokens_mistral': 736, 'n_tokens_neox': 725, 'n_words': 129}