mini-jstorch 1.1.6 → 1.1.9
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.
- package/CHANGELOG.md +32 -0
- package/README.md +130 -0
- package/index.js +1 -1
- package/package.json +5 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
## Changelog ##
|
|
2
|
+
|
|
3
|
+
**Official Release:** 2025-Monday-August-18
|
|
4
|
+
**Version:** 1.1.9
|
|
5
|
+
|
|
6
|
+
New Files that will All notable changes to *Mini-JSTorch* will be documented in this file.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [1.1.9] - 2025-Monday-August-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Complete overhaul of core engine for stability and full feature support.
|
|
14
|
+
- Adam optimizer fully integrated with batch gradient handling.
|
|
15
|
+
- NaN-safe operations for forward/backward passes and loss calculations.
|
|
16
|
+
- Sequential container with robust parameter tracking.
|
|
17
|
+
- Utility functions enhanced for numeric safety and matrix operations.
|
|
18
|
+
- Ready-to-use example scripts with multiple hidden layers for frontend experimentation.
|
|
19
|
+
- Full handling for lightweight devices, optimized for speed and low memory usage.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- bugs in ReLU and gradient propagation causing NaN loss values.
|
|
23
|
+
- Backward propagation errors for batch matrices corrected.
|
|
24
|
+
- Critical Error while startup Engine.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- Layer and activation API standardized for consistency.
|
|
28
|
+
- CrossEntropyLoss now safely handles edge cases in probability computations.
|
|
29
|
+
- Improvements systems for make experiences more stable and not heavy.
|
|
30
|
+
- Minor numeric stability improvements.
|
|
31
|
+
|
|
32
|
+
---
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
## Mini-JSTorch ##
|
|
2
|
+
|
|
3
|
+
# IMPORTANT! #
|
|
4
|
+
|
|
5
|
+
This Module will not gonna Run *Well* In at GPU or a Backend.
|
|
6
|
+
We're will gonna *Optimize* So all User can still use this Module.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Mini JSTorch** is a lightweight, high-performance JavaScript library designed for rapid prototyping of neural networks directly in the frontend environment and for low-end devices. Its core purpose is to enable experimentation and learning on devices with limited computing resources, without compromising stability or training reliability.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Vision
|
|
15
|
+
|
|
16
|
+
Our vision is to democratize AI experimentation by providing a tool that is:
|
|
17
|
+
|
|
18
|
+
- **Accessible**: Runs efficiently on *low-end* laptops or mobile devices.
|
|
19
|
+
- **Stable**: Handles gradient calculations and NaN values robustly.
|
|
20
|
+
- **Educational**: Clear abstractions for neural network layers, activations, and optimizers.
|
|
21
|
+
- **Fast**: Immediate output without lengthy training delays.
|
|
22
|
+
|
|
23
|
+
*Mini JSTorch* aims to bridge the gap between conceptual AI learning and hands-on experimentation, making it possible to explore neural network behavior interactively, even on minimal hardware.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **Core Layers**
|
|
30
|
+
- `Linear`: Fully connected layer with weight and bias support.
|
|
31
|
+
- **Activations**
|
|
32
|
+
- `ReLU`: Rectified Linear Unit activation.
|
|
33
|
+
- `Sigmoid`: Sigmoid activation function.
|
|
34
|
+
- **Loss Functions**
|
|
35
|
+
- `CrossEntropyLoss`: Combines softmax and cross-entropy for classification tasks.
|
|
36
|
+
- **Optimizers**
|
|
37
|
+
- `Adam`: Adaptive optimizer for stable and efficient training.
|
|
38
|
+
- **Utilities**
|
|
39
|
+
- `zeros(rows, cols)`: Generate a zero matrix.
|
|
40
|
+
- `randomMatrix(rows, cols, scale)`: Random initialization for weights.
|
|
41
|
+
- `softmax(x)`: Compute softmax probabilities.
|
|
42
|
+
- `crossEntropy(pred, target)`: Compute cross-entropy loss.
|
|
43
|
+
- `dot(a, b)`: Matrix multiplication.
|
|
44
|
+
- `addMatrices(a, b)`: Element-wise addition of matrices.
|
|
45
|
+
- **Model Container**
|
|
46
|
+
- `Sequential`: Container to stack layers sequentially with easy forward and backward passes.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install mini-jstorch
|
|
54
|
+
# Node.js v20+ recommended for a good experience while using module
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Example Scripts
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import { Sequential, Linear, ReLU, Sigmoid, CrossEntropy, Adam } from './engine/MainEngine.js'; // use import to import the modules
|
|
63
|
+
|
|
64
|
+
// Construct a model with two hidden layers
|
|
65
|
+
const model = new Sequential([
|
|
66
|
+
new Linear(2, 4),
|
|
67
|
+
new ReLU(),
|
|
68
|
+
new Linear(4, 4),
|
|
69
|
+
new ReLU(),
|
|
70
|
+
new Linear(4, 2),
|
|
71
|
+
new Sigmoid()
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
// Training data (XOR)
|
|
75
|
+
const inputs = [
|
|
76
|
+
[0,0], [0,1], [1,0], [1,1]
|
|
77
|
+
];
|
|
78
|
+
const targets = [
|
|
79
|
+
[1,0], [0,1], [0,1], [1,0]
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
// Optimizer and loss
|
|
83
|
+
const optimizer = new Adam(model.parameters(), 0.01);
|
|
84
|
+
const lossFunc = CrossEntropy;
|
|
85
|
+
|
|
86
|
+
// Training loop
|
|
87
|
+
for(let epoch = 1; epoch <= 5000; epoch++) {
|
|
88
|
+
let totalLoss = 0;
|
|
89
|
+
for(let i = 0; i < inputs.length; i++) {
|
|
90
|
+
const output = model.forward([inputs[i]]);
|
|
91
|
+
const loss = lossFunc(output, [targets[i]]);
|
|
92
|
+
totalLoss += loss;
|
|
93
|
+
model.zeroGrad();
|
|
94
|
+
model.backward(lossFunc.backward());
|
|
95
|
+
optimizer.step();
|
|
96
|
+
}
|
|
97
|
+
if(epoch % 500 === 0) console.log(`Epoch ${epoch}, Loss: ${totalLoss.toFixed(6)}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Predictions
|
|
101
|
+
inputs.forEach(inp => {
|
|
102
|
+
const pred = model.forward([inp]);
|
|
103
|
+
console.log(`${inp} -> ${pred.map(p => p.toFixed(4))}`);
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Intended Use Cases
|
|
109
|
+
|
|
110
|
+
- **Experimentation on low-end devices or mobile browsers.**
|
|
111
|
+
- **Learning and teaching foundational neural network concepts.**
|
|
112
|
+
- **Testing small to medium feedforward models in real-time.**
|
|
113
|
+
- **Quick prototyping without GPU dependency or complex setup.**
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Roadmap
|
|
118
|
+
|
|
119
|
+
- **Browser-based interactive playground.**
|
|
120
|
+
- **Additional activation functions and loss options.**
|
|
121
|
+
- **Visualization of training metrics and loss curves in real-time.**
|
|
122
|
+
- **Support for small convolutional networks in frontend environments.**
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Facts
|
|
127
|
+
|
|
128
|
+
- **This module is implemented entirely in pure JavaScript.**
|
|
129
|
+
- **The `Dummy` folder contains modules used for development, testing, and debugging before integration into the main engine.**
|
|
130
|
+
- **This module was created by a `single` developer.**
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Entry point of the library, export main classes and functions
|
|
1
|
+
// Entry point of the library, export main classes and functions [DEPRECATED]
|
|
2
2
|
export { Seq } from './models/seq.js';
|
|
3
3
|
export { Dense } from './layers/dense.js';
|
|
4
4
|
export * as act from './act/linear.js';
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini-jstorch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "A lightweight JavaScript neural network
|
|
5
|
+
"description": "A lightweight JavaScript neural network library for rapid frontend AI experimentation on low-resource devices Inspired by PyTorch.",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"neural-network",
|
|
9
9
|
"javascript",
|
|
10
10
|
"lightweight",
|
|
11
11
|
"ai",
|
|
12
|
+
"jstorch",
|
|
13
|
+
"pytorch",
|
|
14
|
+
"front-end",
|
|
12
15
|
"machine-learning",
|
|
13
|
-
"browser",
|
|
14
16
|
"mini"
|
|
15
17
|
],
|
|
16
18
|
"author": "Rizal",
|