mill-dl 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mill_dl-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 b0gd5n
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mill_dl-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: mill-dl
3
+ Version: 0.1.0
4
+ Summary: A simple deep learning framework in pure Python.
5
+ Author: Bohdan Karpenko
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 b0gd5n
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Dynamic: license-file
32
+
33
+ A simple deep learning framework in pure Python.
@@ -0,0 +1 @@
1
+ A simple deep learning framework in pure Python.
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mill-dl"
7
+ version = "0.1.0"
8
+ description = "A simple deep learning framework in pure Python."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [{ name = "Bohdan Karpenko" }]
12
+ requires-python = ">=3.8"
13
+ dependencies = []
14
+
15
+ [tool.setuptools.packages.find]
16
+ where = ["source"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ from .parameters import Parameter
2
+ from .blocks import Dense, RectifiedLinearUnit
3
+ from .distributions import Random
4
+ from .generators import LinearCongruentialGenerator
5
+ from .evaluators import MeanSquaredError
6
+ from .updaters import StochasticGradientDescent
7
+ from .pipeline import Sequential
8
+ from .schedulers import Cosine
9
+ from .stoppers import ValidationLossEarlyStopping
10
+
11
+ __version__ = '0.1.0'
12
+
13
+ __all__ = [
14
+ 'Parameter',
15
+ 'Dense',
16
+ 'RectifiedLinearUnit',
17
+ 'Random',
18
+ 'LinearCongruentialGenerator',
19
+ 'MeanSquaredError',
20
+ 'StochasticGradientDescent',
21
+ 'Sequential',
22
+ 'Cosine',
23
+ 'ValidationLossEarlyStopping',
24
+ ]
@@ -0,0 +1,98 @@
1
+ from .parameters import Parameter
2
+
3
+ class Dense:
4
+ def __init__(self, inputs, outputs, distributor):
5
+ self.inputs = inputs
6
+ self.outputs = outputs
7
+
8
+ self.weights = Parameter(values=distributor.generate(inputs=inputs, outputs=outputs))
9
+ self.biases = Parameter(values=[])
10
+
11
+ self.last_inputs = []
12
+
13
+ for bias in range(outputs):
14
+ self.biases.values.append(0)
15
+ self.biases.gradients.append(0)
16
+
17
+ def forward(self, tensor, mode='inference'):
18
+ if mode == 'training':
19
+ self.last_inputs.append(tensor)
20
+
21
+ output = []
22
+
23
+ for batch in range(len(tensor)):
24
+ output.append([])
25
+
26
+ for node in range(self.outputs):
27
+ summand = self.biases.values[node]
28
+
29
+ for value in range(self.inputs):
30
+ summand += tensor[batch][value] * self.weights.values[node * self.inputs + value]
31
+
32
+ output[batch].append(summand)
33
+
34
+ return output
35
+
36
+ def backward(self, tensor):
37
+ last_input = self.last_inputs.pop()
38
+
39
+ output = []
40
+
41
+ for batch in range(len(tensor)):
42
+ output.append([])
43
+
44
+ for node in range(self.outputs):
45
+ self.biases.gradients[node] += tensor[batch][node]
46
+
47
+ for value in range(self.inputs):
48
+ self.weights.gradients[node * self.inputs + value] += tensor[batch][node] * last_input[batch][value]
49
+
50
+ for value in range(self.inputs):
51
+ summand = 0
52
+
53
+ for node in range(self.outputs):
54
+ summand += tensor[batch][node] * self.weights.values[node * self.inputs + value]
55
+
56
+ output[batch].append(summand)
57
+
58
+ return output
59
+
60
+ def parameters(self):
61
+ return [self.weights, self.biases]
62
+
63
+ class RectifiedLinearUnit:
64
+ def __init__(self):
65
+ self.last_inputs = []
66
+
67
+ def forward(self, tensor, mode='inference'):
68
+ if mode == 'training':
69
+ self.last_inputs.append(tensor)
70
+
71
+ output = []
72
+
73
+ for batch in range(len(tensor)):
74
+ output.append([])
75
+
76
+ for value in range(len(tensor[batch])):
77
+ if tensor[batch][value] > 0:
78
+ output[batch].append(tensor[batch][value])
79
+ else:
80
+ output[batch].append(0)
81
+
82
+ return output
83
+
84
+ def backward(self, tensor):
85
+ last_input = self.last_inputs.pop()
86
+
87
+ output = []
88
+
89
+ for batch in range(len(tensor)):
90
+ output.append([])
91
+
92
+ for value in range(len(tensor[batch])):
93
+ if last_input[batch][value] > 0:
94
+ output[batch].append(tensor[batch][value])
95
+ else:
96
+ output[batch].append(0)
97
+
98
+ return output
@@ -0,0 +1,14 @@
1
+
2
+ class Random:
3
+ def __init__(self, generator, minimal_value=-0.5, maximal_value=0.5):
4
+ self.generator = generator
5
+ self.minimal_value = minimal_value
6
+ self.maximal_value = maximal_value
7
+
8
+ def generate(self, inputs, outputs):
9
+ weights = []
10
+
11
+ for weight in range(inputs * outputs):
12
+ weights.append(self.generator.generate(minimal_value=self.minimal_value, maximal_value=self.maximal_value))
13
+
14
+ return weights
@@ -0,0 +1,21 @@
1
+
2
+ class MeanSquaredError:
3
+ def evaluate(self, predictions, targets):
4
+ summand = 0
5
+
6
+ for batch in range(len(predictions)):
7
+ for value in range(len(predictions[batch])):
8
+ summand += (predictions[batch][value] - targets[batch][value]) ** 2
9
+
10
+ return summand / (len(predictions) * len(predictions[0]))
11
+
12
+ def backward(self, predictions, targets):
13
+ output = []
14
+
15
+ for batch in range(len(predictions)):
16
+ output.append([])
17
+
18
+ for value in range(len(predictions[batch])):
19
+ output[batch].append(2 * (predictions[batch][value] - targets[batch][value]) / (len(predictions) * len(predictions[0])))
20
+
21
+ return output
@@ -0,0 +1,14 @@
1
+
2
+ class LinearCongruentialGenerator:
3
+ def __init__(self, seed=42):
4
+ self.seed = seed
5
+ self.state = seed % 4294967296
6
+
7
+ self.usages = 0
8
+
9
+ def generate(self, minimal_value, maximal_value):
10
+ self.state = (1664525 * self.state + 1013904223) % 4294967296
11
+
12
+ self.usages += 1
13
+
14
+ return minimal_value + (maximal_value - minimal_value) * self.state / 4294967296
@@ -0,0 +1,12 @@
1
+
2
+ class Parameter:
3
+ def __init__(self, values):
4
+ self.values = values
5
+ self.gradients = []
6
+
7
+ for value in range(len(values)):
8
+ self.gradients.append(0)
9
+
10
+ def clear(self):
11
+ for gradient in range(len(self.gradients)):
12
+ self.gradients[gradient] = 0
@@ -0,0 +1,60 @@
1
+
2
+ class Sequential:
3
+ def __init__(self, *blocks):
4
+ self.blocks = blocks
5
+
6
+ def forward(self, tensor, mode='inference'):
7
+ current = tensor
8
+
9
+ for block in range(len(self.blocks)):
10
+ current = self.blocks[block].forward(current, mode=mode)
11
+
12
+ return current
13
+
14
+ def backward(self, tensor):
15
+ current = tensor
16
+
17
+ for block in reversed(range(len(self.blocks))):
18
+ current = self.blocks[block].backward(current)
19
+
20
+ return current
21
+
22
+ def parameters(self):
23
+ parameters = []
24
+
25
+ for block in range(len(self.blocks)):
26
+ if hasattr(self.blocks[block], 'parameters'):
27
+ block_parameters = self.blocks[block].parameters()
28
+
29
+ for parameter in range(len(block_parameters)):
30
+ if not any(block_parameters[parameter] is parameters[existing] for existing in range(len(parameters))):
31
+ parameters.append(block_parameters[parameter])
32
+
33
+ return parameters
34
+
35
+ def save(self, path='model.txt'):
36
+ parameters = self.parameters()
37
+
38
+ with open(path, 'w') as file:
39
+ for parameter in range(len(parameters)):
40
+ line = ''
41
+
42
+ for value in range(len(parameters[parameter].values)):
43
+ if value > 0:
44
+ line += ' '
45
+
46
+ line += repr(float(parameters[parameter].values[value]))
47
+
48
+ file.write(line + '\n')
49
+
50
+ def load(self, path='model.txt'):
51
+ with open(path, 'r') as file:
52
+ lines = file.read().split('\n')
53
+
54
+ parameters = self.parameters()
55
+
56
+ for parameter in range(len(parameters)):
57
+ numbers = lines[parameter].split()
58
+
59
+ for value in range(len(parameters[parameter].values)):
60
+ parameters[parameter].values[value] = float(numbers[value])
@@ -0,0 +1,26 @@
1
+
2
+ class Cosine:
3
+ def __init__(self, minimal_rate, maximal_rate, warming_steps, total_steps, iterations=16):
4
+ self.maximal_rate = maximal_rate
5
+ self.minimal_rate = minimal_rate
6
+ self.warming_steps = warming_steps
7
+ self.total_steps = total_steps
8
+ self.iterations = iterations
9
+
10
+ def cosine(self, angle):
11
+ summand = 1
12
+ term = 1
13
+
14
+ for index in range(1, self.iterations):
15
+ term *= -angle * angle / ((2 * index - 1) * (2 * index))
16
+ summand += term
17
+
18
+ return summand
19
+
20
+ def rate(self, step):
21
+ if step < self.warming_steps:
22
+ return self.maximal_rate * (step + 1) / self.warming_steps
23
+
24
+ progress = min(1, (step - self.warming_steps) / max(1, self.total_steps - self.warming_steps))
25
+
26
+ return self.minimal_rate + (self.maximal_rate - self.minimal_rate) * 0.5 * (1 + self.cosine(3.141592653589793 * progress))
@@ -0,0 +1,47 @@
1
+
2
+ class ValidationLossEarlyStopping:
3
+ def __init__(self, model, evaluator, patience=8, minimum_improvement=0):
4
+ self.model = model
5
+ self.evaluator = evaluator
6
+ self.patience = patience
7
+ self.minimum_improvement = minimum_improvement
8
+
9
+ self.best_loss = float('inf')
10
+ self.best_epoch = -1
11
+ self.best_parameters = []
12
+ self.epochs_without_improvement = 0
13
+ self.epoch = 0
14
+
15
+ def check(self, inputs, targets):
16
+ loss = self.evaluator.evaluate(predictions=self.model.forward(tensor=inputs), targets=targets)
17
+
18
+ if loss < self.best_loss - self.minimum_improvement:
19
+ self.best_loss = loss
20
+ self.best_epoch = self.epoch
21
+ self.epochs_without_improvement = 0
22
+
23
+ self.remember()
24
+ else:
25
+ self.epochs_without_improvement += 1
26
+
27
+ self.epoch += 1
28
+
29
+ return self.epochs_without_improvement >= self.patience
30
+
31
+ def remember(self):
32
+ parameters = self.model.parameters()
33
+
34
+ self.best_parameters = []
35
+
36
+ for parameter in range(len(parameters)):
37
+ self.best_parameters.append([])
38
+
39
+ for value in range(len(parameters[parameter].values)):
40
+ self.best_parameters[parameter].append(parameters[parameter].values[value])
41
+
42
+ def restore(self):
43
+ parameters = self.model.parameters()
44
+
45
+ for parameter in range(len(parameters)):
46
+ for value in range(len(parameters[parameter].values)):
47
+ parameters[parameter].values[value] = self.best_parameters[parameter][value]
@@ -0,0 +1,13 @@
1
+
2
+ class StochasticGradientDescent:
3
+ def __init__(self, parameters):
4
+ self.parameters = parameters
5
+
6
+ def step(self, rate):
7
+ for parameter in range(len(self.parameters)):
8
+ for value in range(len(self.parameters[parameter].values)):
9
+ self.parameters[parameter].values[value] -= rate * self.parameters[parameter].gradients[value]
10
+
11
+ def clear(self):
12
+ for parameter in range(len(self.parameters)):
13
+ self.parameters[parameter].clear()
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: mill-dl
3
+ Version: 0.1.0
4
+ Summary: A simple deep learning framework in pure Python.
5
+ Author: Bohdan Karpenko
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 b0gd5n
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Dynamic: license-file
32
+
33
+ A simple deep learning framework in pure Python.
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ source/mill/__init__.py
5
+ source/mill/blocks.py
6
+ source/mill/distributions.py
7
+ source/mill/evaluators.py
8
+ source/mill/generators.py
9
+ source/mill/parameters.py
10
+ source/mill/pipeline.py
11
+ source/mill/schedulers.py
12
+ source/mill/stoppers.py
13
+ source/mill/updaters.py
14
+ source/mill_dl.egg-info/PKG-INFO
15
+ source/mill_dl.egg-info/SOURCES.txt
16
+ source/mill_dl.egg-info/dependency_links.txt
17
+ source/mill_dl.egg-info/top_level.txt