<commit_before>import numpy as np
from .base import Base


class SGD(Base):
    def __init__(self, cost, params, lr=0.1, momentum=0.9):
        super().__init__(cost, params, lr)
        self.momentum = momentum
        self.velocity = self._init_velocity_vec(params)

    def step(self, feed_dict):
        exe_output = self.executor.run(feed_dict)
        for i in range(len(self.params)):
            self.velocity[i] = self.momentum * self.velocity[i] - self.lr * exe_output[1 + i]
            self.params[i].const += self.velocity[i]
        return exe_output[0]

    @staticmethod
    def _init_velocity_vec(params):
        vector = []
        for param in params:
            vector.append(np.zeros_like(param.const))
        return vector
<commit_msg>Improve velocity list initialisation in SGD<commit_after>import numpy as np
from .base import Base


class SGD(Base):
    def __init__(self, cost, params, lr=0.1, momentum=0.9):
        super().__init__(cost, params, lr)
        self.momentum = momentum
        self.velocity = [np.zeros_like(param.const)for param in params]

    def step(self, feed_dict):
        exe_output = self.executor.run(feed_dict)
        for i in range(len(self.params)):
            self.velocity[i] = self.momentum * self.velocity[i] - self.lr * exe_output[1 + i]
            self.params[i].const += self.velocity[i]
        return exe_output[0]


{'fraction_non_alphanumeric': 0.11824080749819754, 'fraction_numerical': 0.008651766402307137, 'mean_word_length': 2.6914893617021276, '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': '4183405', 'n_tokens_mistral': 467, 'n_tokens_neox': 443, 'n_words': 103}