<commit_before>from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()

from chainer import cuda
from chainer import function
from chainer.utils import type_check


class InvertGradients(function.Function):
    """Inverts gradients of values exceeding a given range.

    See: http://arxiv.org/abs/1511.04143
    """

    def __init__(self, range_min, range_max):
        self.range_min = range_min
        self.range_max = range_max
        self.range_width = self.range_max - self.range_min
        assert (self.range_width > 0).all()

    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1,)

    @property
    def label(self):
        return 'InvertGradients'

    def forward(self, inputs):
        return inputs

    def backward(self, inputs, grad_outputs):
        x, = inputs
        gy, = grad_outputs
        # In chainer, update will be like x.data -= lr * x.grad,
        # which means negative gradients will increase values.
        increasing = (gy < 0).astype(gy.dtype)
        gx = gy * ((self.range_max - x) / self.range_width * increasing +
                   (x - self.range_min) / self.range_width * (1 - increasing))<commit_msg>Fix for 0-dim array<commit_after>from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()

from chainer import cuda
from chainer import function
from chainer.utils import type_check


class InvertGradients(function.Function):
    """Inverts gradients of values exceeding a given range.

    See: http://arxiv.org/abs/1511.04143
    """

    def __init__(self, range_min, range_max):
        self.range_min = range_min
        self.range_max = range_max
        self.range_width = self.range_max - self.range_min
        assert (self.range_width > 0).all()

    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1,)

    @property
    def label(self):
        return 'InvertGradients'

    def forward(self, inputs):
        return inputs

    def backward(self, inputs, grad_outputs):
        x, = inputs
        gy, = grad_outputs
        # In chainer, update will be like x.data -= lr * x.grad,
        # which means negative gradients will increase values.
        increasing = (gy < 0).astype(gy.dtype)
        gx = gy.copy()
        gx *= ((self.range_max - x) / self.range_width * increasing +
               (x - self.range_min) / self.range_width * (1 - increasing))
{'fraction_non_alphanumeric': 0.09194097616345062, 'fraction_numerical': 0.01021566401816118, 'mean_word_length': 2.882525697503671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4894998', 'n_tokens_mistral': 813, 'n_tokens_neox': 770, 'n_words': 219}