<commit_before>from unittest import TestCase

from teafacto.blocks.seq.memnn import BulkNN, SimpleBulkNN
import numpy as np


class BulkNNTest(TestCase):
    def test_init_mem_shape(self):
        inpvocsize = 5
        outvocsize = 7
        impembdim = 10
        memembdim = 12
        inpdim = 15
        memdim = 15
        memlen = 17
        coredims = [20, 30]

        batsize = 13
        seqlen = 11

        m = SimpleBulkNN(inpvocsize=inpvocsize, inpembdim=impembdim, inpencinnerdim=inpdim,
                         memvocsize=outvocsize, memembdim=memembdim, memencinnerdim=memdim,
                         memlen=memlen, coredims=coredims,
                         explicit_interface=True, write_value_dim=15)

        d = np.random.randint(0, inpvocsize, (batsize, seqlen))
        '''
        pred, extras = m.predict(d, _extra_outs=["mem_0", "h_0"])
        print extras["mem_0"].shape
        print pred.shape
        self.assertEqual(pred.shape, (batsize, memlen, outvocsize))
        self.assertEqual(extras["mem_0"].shape, (batsize, memlen, outvocsize))
        '''<commit_msg>* BulkNN initial implementation almost finished<commit_after>from unittest import TestCase

from teafacto.blocks.seq.memnn import BulkNN, SimpleBulkNN
import numpy as np


class BulkNNTest(TestCase):
    def test_init_mem_shape(self):
        inpvocsize = 5
        outvocsize = 7
        inpembdim = 10
        memembdim = 12
        inpdim = [15]
        memdim = [15]
        memlen = 17
        writedim = 19
        lastcoredim = inpdim[-1] + memdim[-1] + memdim[-1] \
                      + writedim + 1 + 1
        coredims = [40, lastcoredim]     # last dim must match interface when explicit interface

        batsize = 13
        seqlen = 11

        m = SimpleBulkNN(inpvocsize=inpvocsize,
                         inpembdim=inpembdim,
                         inpencinnerdim=inpdim,
                         memvocsize=outvocsize,
                         memembdim=memembdim,
                         memencinnerdim=memdim,
                         memlen=memlen,
                         coredims=coredims,
                         explicit_interface=True,
                         write_value_dim=writedim)

        d = np.random.randint(0, inpvocsize, (batsize, seqlen))
        '''
        pred, extras = m.predict(d, _extra_outs=["mem_0", "h_0"])
        print extras["mem_0"].shape
        print pred.shape
        self.assertEqual(pred.shape, (batsize, memlen, outvocsize))
        self.assertEqual(extras["mem_0"].shape, (batsize, memlen, outvocsize))
        '''
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.022050290135396517, 'mean_word_length': 1.8861607142857142, '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': '6772766', 'n_tokens_mistral': 860, 'n_tokens_neox': 807, 'n_words': 164}