<commit_before>import collections
import json
import os

import numpy
import six

import chainer
from chainer import cuda
import chainer.functions as F
from chainer import initializers
import chainer.links as L

import babi


def bow_encode(embed, sentences):
    """BoW sentence encoder.

    It is defined as:

    .. math::

       m = \sum_j A x_j,

    where :math:`A` is an embed matrix, and :math:`x_j` is :math:`j`-th word
    ID.

    """

    e = embed(sentences)
    s = F.sum(e, axis=-2)
    return s


def position_encode(embed, sentences):
    """Position encoding.

    It is defined as:

    .. math::

       m = \sum_j l_j A x_j,

    where :math:`A` is an embed matrix, :math:`x_j` is :math:`j`-th word ID and

    .. math::

       l_{kj} = (1 - j / J) - (k / d)(1 - 2j / J).

    :math:`J` is length of a sentence and :math:`d` is the dimension of the
    embedding.

    """
<commit_msg>fix invalid escape sequence in examples<commit_after>import collections
import json
import os

import numpy
import six

import chainer
from chainer import cuda
import chainer.functions as F
from chainer import initializers
import chainer.links as L

import babi


def bow_encode(embed, sentences):
    """BoW sentence encoder.

    It is defined as:

    .. math::

       m = \\sum_j A x_j,

    where :math:`A` is an embed matrix, and :math:`x_j` is :math:`j`-th word
    ID.

    """

    e = embed(sentences)
    s = F.sum(e, axis=-2)
    return s


def position_encode(embed, sentences):
    """Position encoding.

    It is defined as:

    .. math::

       m = \sum_j l_j A x_j,

    where :math:`A` is an embed matrix, :math:`x_j` is :math:`j`-th word ID and

    .. math::

       l_{kj} = (1 - j / J) - (k / d)(1 - 2j / J).

    :math:`J` is length of a sentence and :math:`d` is the dimension of the
    embedding.

    """

{'fraction_non_alphanumeric': 0.12086720867208672, 'fraction_numerical': 0.004336043360433604, 'mean_word_length': 2.4376163873370578, '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': '3707132', 'n_tokens_mistral': 664, 'n_tokens_neox': 627, 'n_words': 233}