<commit_before>from typing import Optional, List, Callable, Tuple, Sequence, Union

from ..types import (
    Xp,
    Array,
    Shape,
    DTypes,
    DTypesInt,
    DTypesFloat,
    Floats1d,
    Floats2d,
    Floats3d,
    Floats4d,
    FloatsNd,
    Ints1d,
    Ints2d,
    Ints3d,
    Ints4d,
    IntsNd,
    ArrayTypes,
    ArrayTypesInt,
    ArrayTypesFloat,
    ArrayT,
)
from ..util import copy_array, get_array_module


class Ops:
    device: str = "cpu"
    xp: Xp = None

    def __init__(self, xp: Optional[Xp] = None) -> None:
        if xp is not None:
            self.xp = xp

    def seq2col(self, seq: ArrayT, nW: int) -> ArrayT:
        """Given an (M, N) sequence of vectors, return an (M, N*(nW*2+1))
        sequence. The new sequence is constructed by concatenating nW preceding
        and succeeding vectors onto each column in the sequence, to extract a
        window of features.
        """
        # This is a test implementation that only supports nW=1
        assert nW == 1
        B = seq.shape[0]
        I = seq.shape[1]
        cols: Floats3d = self.alloc_f3d(B, (nW * 2 + 1), I)
        # Copy left contexts. The last words aren't the left-context for anything.
        cols[nW:, :nW] = seq[:-nW].reshape((-1, nW, I))
        cols[:, nW] = seq
        cols[:-nW, nW + 1 :] = seq[nW:].reshape((-1, nW, I))
        return cols.reshape((B, I * (2 * nW + 1)))

    def backprop_seq2col(self, dY: ArrayT, nW: int) -> Array:
        # This is a test implementation that only supports nW=1<commit_msg>Update imports<commit_after>from typing import Optional, List, Callable, Tuple, Sequence, Union

from ..types import Xp, Array, Shape, DTypes, DTypesInt, DTypesFloat
from ..types import Floats1d, Floats2d, Floats3d, Floats4d, FloatsNd
from ..types import Ints1d, Ints2d, Ints3d, Ints4d, IntsNd
from ..types import ArrayTypesInt, ArrayTypesFloat, ArrayT,
from ..util import copy_array, get_array_module


class Ops:
    device: str = "cpu"
    xp: Xp = None

    def __init__(self, xp: Optional[Xp] = None) -> None:
        if xp is not None:
            self.xp = xp

    def seq2col(self, seq: ArrayT, nW: int) -> ArrayT:
        """Given an (M, N) sequence of vectors, return an (M, N*(nW*2+1))
        sequence. The new sequence is constructed by concatenating nW preceding
        and succeeding vectors onto each column in the sequence, to extract a
        window of features.
        """
        # This is a test implementation that only supports nW=1
        assert nW == 1
        B = seq.shape[0]
        I = seq.shape[1]
        cols: Floats3d = self.alloc_f3d(B, (nW * 2 + 1), I)
        # Copy left contexts. The last words aren't the left-context for anything.
        cols[nW:, :nW] = seq[:-nW].reshape((-1, nW, I))
        cols[:, nW] = seq
        cols[:-nW, nW + 1 :] = seq[nW:].reshape((-1, nW, I))
        return cols.reshape((B, I * (2 * nW + 1)))

    def backprop_seq2col(self, dY: ArrayT, nW: int) -> Array:
        # This is a test implementation that only supports nW=1
{'fraction_non_alphanumeric': 0.11690885072655217, 'fraction_numerical': 0.017173051519154558, 'mean_word_length': 2.4342403628117912, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4634417', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1058, 'n_words': 350}