<commit_before>import tensorflow as tf
import numpy as np
import utility

class Memory:

    def __init__(self, words_num=256, word_size=64, read_heads=4, batch_size=1):
        """
        constructs a memory matrix with read heads and a write head as described
        in the DNC paper
        http://www.nature.com/nature/journal/vaop/ncurrent/full/nature20101.html

        Parameters:
        ----------
        words_num: int
            the maximum number of words that can be stored in the memory at the
            same time
        word_size: int
            the size of the individual word in the memory
        read_heads: int
            the number of read heads that can read simultaneously from the memory
        batch_size: int
            the size of input data batch
        """

        self.words_num = words_num
        self.word_size = word_size
        self.read_heads = read_heads
        self.batch_size = batch_size

        with tf.variable_scope('external_memory'):

            self.memory_matrix = tf.Variable(tf.zeros([batch_size, words_num, word_size]), name='memory_matrix', trainable=False)
            self.usage_vector = tf.Variable(tf.zeros([batch_size, words_num, ]), name='usage_vector', trainable=False)
            self.precedence_vector = tf.Variable(tf.zeros([batch_size, words_num, ]), name='precedence_vector', trainable=False)
            self.link_matrix = tf.Variable(tf.zeros([batch_size, words_num, words_num]), name='link_matrix', trainable=False)

            self.write_weighting = tf.Variable(tf.zeros([batch_size, words_num, ]), name='write_weighting', trainable=False)
            self.read_weightings = tf.Variable(tf.zeros([batch_size, words_num, read_heads]), name='read_weightings', trainable=False)

            self.read_vectors = tf.Variable(tf.zeros([batch_size, word_size, read_heads]), name='read_vectors', trainable=False)

            # a words_num x words_num identity matrix
            self.I = tf.constant(np.identity(words_num, dtype=np.float32))

            # a variable used to bring the allocation weighting in order of memory words
            # after computing them using the sorted usage and free list
            self.ordered_allocation_weighting = tf.Variable(tf.zeros([batch_size * words_num]), trainable=False)

            # maps the indecies from the 2D array of free list per batch to
            # their corresponding values in the flat 1D array of ordered_allocation_weighting<commit_msg>used plain tensors instead of variables in memory<commit_after>import tensorflow as tf
import numpy as np
import utility

class Memory:

    def __init__(self, words_num=256, word_size=64, read_heads=4, batch_size=1):
        """
        constructs a memory matrix with read heads and a write head as described
        in the DNC paper
        http://www.nature.com/nature/journal/vaop/ncurrent/full/nature20101.html

        Parameters:
        ----------
        words_num: int
            the maximum number of words that can be stored in the memory at the
            same time
        word_size: int
            the size of the individual word in the memory
        read_heads: int
            the number of read heads that can read simultaneously from the memory
        batch_size: int
            the size of input data batch
        """

        self.words_num = words_num
        self.word_size = word_size
        self.read_heads = read_heads
        self.batch_size = batch_size

        with tf.name_scope('external_memory'):

            self.memory_matrix = tf.zeros([batch_size, words_num, word_size], name='memory_matrix')
            self.usage_vector = tf.zeros([batch_size, words_num, ], name='usage_vector')
            self.precedence_vector = tf.zeros([batch_size, words_num, ], name='precedence_vector')
            self.link_matrix = tf.zeros([batch_size, words_num, words_num], name='link_matrix')

            self.write_weighting = tf.zeros([batch_size, words_num, ], name='write_weighting')
            self.read_weightings = tf.zeros([batch_size, words_num, read_heads], name='read_weightings')

            self.read_vectors = tf.zeros([batch_size, word_size, read_heads])

            # a words_num x words_num identity matrix
            self.I = tf.constant(np.identity(words_num, dtype=np.float32))

            # a variable used to bring the allocation weighting in order of memory words
            # after computing them using the sorted usage and free list
            self.ordered_allocation_weighting = tf.Variable(tf.zeros([batch_size * words_num]), trainable=False)

            # maps the indecies from the 2D array of free list per batch to
            # their corresponding values in the flat 1D array of ordered_allocation_weighting
{'fraction_non_alphanumeric': 0.08303552659239016, 'fraction_numerical': 0.006726928736598697, 'mean_word_length': 2.7084957131722525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6559670', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1293, 'n_words': 390}