Skip to content

Commit a3d719e

Browse files
authored
chore: fmt (#63)
* chore: fmt * chore: bump version
1 parent ee217d0 commit a3d719e

22 files changed

+121
-222
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
rustc --version
3333
cargo --version
3434
cargo build --release -p netsaur
35-
deno run -Ar jsr:@deno/[email protected].1 -p netsaur --out src/backends/wasm/lib
36-
deno run -Ar jsr:@deno/[email protected].1 -p netsaur-tokenizers --out tokenizers/lib
35+
deno run -Ar jsr:@deno/[email protected].2 -p netsaur --out src/backends/wasm/lib
36+
deno run -Ar jsr:@deno/[email protected].2 -p netsaur-tokenizers --out tokenizers/lib
3737
- name: Release
3838
uses: softprops/action-gh-release@master
3939
env:

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
package.version = "0.4.0"
2+
package.version = "0.4.1"
33
members = ["crates/*"]
44
resolver = "2"
55

deno.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@denosaurs/netsaur",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"exports": {
55
".": "./mod.ts",
66
"./web": "./web.ts",

deno.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/backends/cpu/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const options: FetchOptions = {
1515
name: "netsaur",
1616
url: new URL(import.meta.url).protocol !== "file:"
1717
? new URL(
18-
"https://github.com/denosaurs/netsaur/releases/download/0.4.0/",
18+
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/",
1919
import.meta.url,
2020
)
2121
: "./target/release/",

packages/core/src/backends/gpu/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const options: FetchOptions = {
1515
name: "netsaur_gpu",
1616
url: new URL(import.meta.url).protocol !== "file:"
1717
? new URL(
18-
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/",
18+
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/",
1919
import.meta.url,
2020
)
2121
: "./target/release/",

packages/core/src/backends/wasm/lib/netsaur.generated.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const imports = {
217217
__wbindgen_object_drop_ref: function (arg0) {
218218
takeObject(arg0);
219219
},
220-
__wbg_log_023d7669e382bddf: function (arg0, arg1) {
220+
__wbg_log_6f7dfa87fad40a57: function (arg0, arg1) {
221221
console.log(getStringFromWasm0(arg0, arg1));
222222
},
223223
__wbindgen_number_new: function (arg0) {
Binary file not shown.

packages/core/src/backends/wasm/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class WASMInstance {
2222
await instantiate({
2323
url: new URL(import.meta.url).protocol !== "file:"
2424
? new URL(
25-
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/netsaur_bg.wasm",
25+
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/netsaur_bg.wasm",
2626
import.meta.url,
2727
)
2828
: undefined,

packages/core/src/backends/wasm/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import type { Rank, Shape } from "../../core/api/shape.ts";
33
/**
44
* Train Options Interface.
55
*/
6-
export type TrainOptions = {
6+
export interface TrainOptions {
77
datasets: number;
88
inputShape: Shape<Rank>;
99
outputShape: Shape<Rank>;
1010
epochs: number;
1111
batches: number;
1212
rate: number;
13-
};
13+
}
1414

1515
/**
1616
* Predict Options Interface.
1717
*/
18-
export type PredictOptions = {
18+
export interface PredictOptions {
1919
inputShape: Shape<Rank>;
2020
outputShape: Shape<Rank>;
21-
};
21+
}

packages/core/src/core/api/layer.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type Layer =
2121
/**
2222
* The configuration for a dense layer.
2323
*/
24-
export type DenseLayerConfig = {
24+
export interface DenseLayerConfig {
2525
/**
2626
* The type of initialization to use.
2727
*/
@@ -46,7 +46,7 @@ export type DenseLayerConfig = {
4646
/**
4747
* The configuration for a dropout layer.
4848
*/
49-
export type DropoutLayerConfig = {
49+
export interface DropoutLayerConfig {
5050
/**
5151
* probability of dropping out a value.
5252
*/
@@ -61,7 +61,7 @@ export type DropoutLayerConfig = {
6161
/**
6262
* The configuration for an activation layer.
6363
*/
64-
export type ActivationLayerConfig = {
64+
export interface ActivationLayerConfig {
6565
/**
6666
* The activation function to use.
6767
*/
@@ -71,7 +71,7 @@ export type ActivationLayerConfig = {
7171
/**
7272
* The configuration for a convolutional layer.
7373
*/
74-
export type Conv2DLayerConfig = {
74+
export interface Conv2DLayerConfig {
7575
/**
7676
* The type of initialization to use.
7777
*/
@@ -111,7 +111,7 @@ export type Conv2DLayerConfig = {
111111
/**
112112
* The configuration for a convolutional transpose layer.
113113
*/
114-
export type ConvTranspose2DLayerConfig = {
114+
export interface ConvTranspose2DLayerConfig {
115115
/**
116116
* The type of initialization to use.
117117
*/
@@ -158,7 +158,7 @@ export enum PoolMode {
158158
/**
159159
* The configuration for a pooling layer.
160160
*/
161-
export type Pool2DLayerConfig = {
161+
export interface Pool2DLayerConfig {
162162
/**
163163
* The optional strides to use.
164164
*/
@@ -173,7 +173,7 @@ export type Pool2DLayerConfig = {
173173
/**
174174
* The configuration for a flatten layer.
175175
*/
176-
export type FlattenLayerConfig = {
176+
export interface FlattenLayerConfig {
177177
/**
178178
* The size of the layer.
179179
*/
@@ -183,7 +183,7 @@ export type FlattenLayerConfig = {
183183
/**
184184
* The configuration for a batch normalization layer.
185185
*/
186-
export type BatchNormLayerConfig = {
186+
export interface BatchNormLayerConfig {
187187
/**
188188
* The momentum to use for the batch normalization.
189189
* Defaults to 0.99.

packages/core/src/core/api/optimizer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ export type Optimizer =
66
| { type: OptimizerType.Nadam; config: AdamOptimizerConfig }
77
| { type: OptimizerType.RMSProp; config: RMSPropOptimizerConfig };
88

9-
export type AdamOptimizerConfig = {
9+
export interface AdamOptimizerConfig {
1010
beta1?: number;
1111
beta2?: number;
1212
epsilon?: number;
13-
};
13+
}
1414

15-
export type RMSPropOptimizerConfig = {
15+
export interface RMSPropOptimizerConfig {
1616
decayRate?: number;
1717
epsilon?: number;
18-
};
18+
}
1919

2020
export function SGDOptimizer(): Optimizer {
2121
return { type: OptimizerType.SGD };

packages/core/src/core/api/scheduler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ export type Scheduler =
88
}
99
| { type: SchedulerType.OneCycle; config: OneCycleSchedulerConfig };
1010

11-
export type DecaySchedulerConfig = {
11+
export interface DecaySchedulerConfig {
1212
rate?: number;
1313
step_size?: number;
14-
};
14+
}
1515

16-
export type OneCycleSchedulerConfig = {
16+
export interface OneCycleSchedulerConfig {
1717
max_rate?: number;
1818
step_size?: number;
19-
};
19+
}
2020

2121
export function NoScheduler(): Scheduler {
2222
return { type: SchedulerType.None };

packages/core/src/core/engine.ts

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export interface BackendInstance {
1515
export interface BackendLoader {
1616
/**
1717
* Whether the backend is supported.
18+
*
19+
* ```ts
20+
* import { WASM } from "https://deno.land/x/netsaur/mod.ts";
21+
*
22+
* console.log(WASM.isSupported());
23+
* ```
1824
*/
1925
isSupported(): boolean;
2026

packages/core/src/core/mod.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import { SGDOptimizer } from "./api/optimizer.ts";
1717
*/
1818
export class Sequential implements NeuralNetwork {
1919
backend!: Backend;
20+
config: NetworkConfig;
2021

2122
/**
2223
* Create a Sequential Neural Network.
2324
*/
24-
constructor(public config: NetworkConfig) {
25+
constructor(config: NetworkConfig) {
26+
this.config = config;
2527
this.config.cost = this.config.cost || Cost.MSE;
2628
this.config.optimizer = this.config.optimizer || SGDOptimizer();
2729
this.config.scheduler = this.config.scheduler || {

packages/core/src/core/tensor/tensor.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
} from "../api/shape.ts";
1717
import { inferShape, length } from "./util.ts";
1818

19-
export type TensorLike<R extends Rank> = {
19+
export interface TensorLike<R extends Rank> {
2020
shape: Shape<R>;
2121
data: Float32Array;
2222
};
@@ -35,13 +35,20 @@ export class Tensor<R extends Rank> {
3535

3636
/**
3737
* Creates an empty tensor.
38+
* ```ts
39+
* Tensor.zeros([2, 2]);
40+
* ```
3841
*/
3942
static zeroes<R extends Rank>(shape: Shape<R>): Tensor<R> {
4043
return new Tensor(new Float32Array(length(shape)), shape);
4144
}
4245

4346
/**
4447
* Serialise a tensor into JSON.
48+
*
49+
* ```ts
50+
* tensor([1, 2, 3, 4], [2, 2]).toJSON();
51+
* ```
4552
*/
4653
toJSON(): { data: number[]; shape: Shape<R> } {
4754
const data = new Array(this.data.length).fill(1);

packages/core/src/core/types.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export interface Backend {
1212
* The train method is a function that trains a neural network using a set of training data.
1313
* It takes in an array of DataSet objects, the number of epochs to train for, and the learning rate.
1414
* The method modifies the weights and biases of the network to minimize the cost function and improve its accuracy on the training data.
15+
*
16+
* ```ts
17+
* net.train(datasets, 100, 10, 0.01);
18+
* ```
1519
*/
1620
train(
1721
datasets: DataSet[],
@@ -24,6 +28,11 @@ export interface Backend {
2428
* The predict method is a function that takes in a Tensor object
2529
* representing the input to the neural network and returns a Promise that resolves to a Tensor object representing the output of the network.
2630
* This method is used to make predictions on new data after the network has been trained.
31+
*
32+
* ```ts
33+
* const input = new Tensor([1, 2, 3, 4]);
34+
* const output = await net.predict(input);
35+
* ```
2736
*/
2837
predict(
2938
input: Tensor<Rank>,
@@ -34,20 +43,28 @@ export interface Backend {
3443
/**
3544
* The save method is a function that saves the network to a Uint8Array.
3645
* This method is used to save the network after it has been trained.
46+
*
47+
* ```ts
48+
* const buffer = net.save();
49+
* ```
3750
*/
3851
save(): Uint8Array;
3952

4053
/**
4154
* The saveFile method is a function that takes in a string representing the path to a file and saves the network to that file.
4255
* This method is used to save the network after it has been trained.
56+
*
57+
* ```ts
58+
* net.saveFile("model.bin");
59+
* ```
4360
*/
4461
saveFile(path: string): void;
4562
}
4663

4764
/**
4865
* NetworkConfig represents the configuration of a neural network.
4966
*/
50-
export type NetworkConfig = {
67+
export interface NetworkConfig {
5168
/**
5269
* Input size of the neural network.
5370
*/
@@ -87,7 +104,7 @@ export type NetworkConfig = {
87104
* Number of disappointing iterations to allow before early stopping
88105
*/
89106
patience?: number;
90-
};
107+
}
91108

92109
/**
93110
* Activation functions are used to transform the output of a layer into a new output.
@@ -195,10 +212,10 @@ export enum SchedulerType {
195212
/**
196213
* DataSet is a container for training data.
197214
*/
198-
export type DataSet = {
215+
export interface DataSet {
199216
inputs: Tensor<Rank>;
200217
outputs: Tensor<Rank>;
201-
};
218+
}
202219

203220
export enum LayerType {
204221
Activation = "activation",
105 Bytes
Binary file not shown.

packages/tokenizers/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function init(): Promise<void> {
1616
await instantiate({
1717
url: new URL(import.meta.url).protocol !== "file:"
1818
? new URL(
19-
"https://github.com/denosaurs/netsaur/releases/download/0.3.2-patch/netsaur_tokenizers_bg.wasm",
19+
"https://github.com/denosaurs/netsaur/releases/download/0.4.1/netsaur_tokenizers_bg.wasm",
2020
import.meta.url,
2121
)
2222
: undefined,

0 commit comments

Comments
 (0)