dataset-types 3.3.3 → 3.3.4
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/attention2.d.ts +210 -0
- package/attention2.js +2 -0
- package/index.d.ts +2 -2
- package/package.json +4 -1
package/attention2.d.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { MathType, Matrix } from "mathjs";
|
|
2
|
+
import { IVector } from './valuedata';
|
|
3
|
+
export type INamedEmbedding = {
|
|
4
|
+
key: string;
|
|
5
|
+
vector?: IVector;
|
|
6
|
+
row?: IVector;
|
|
7
|
+
probability?: number;
|
|
8
|
+
};
|
|
9
|
+
export type IEmbedding = {
|
|
10
|
+
[key: string]: IVector;
|
|
11
|
+
};
|
|
12
|
+
export type IEmbeddingRecord = {
|
|
13
|
+
[key: string]: IVector[];
|
|
14
|
+
};
|
|
15
|
+
export type INamedPrediction = {
|
|
16
|
+
[key: string]: number;
|
|
17
|
+
};
|
|
18
|
+
export type ISequenceEmbeddings = {
|
|
19
|
+
names: () => string[];
|
|
20
|
+
vectors: () => IVector[];
|
|
21
|
+
seqmatrix: () => ISequenceMatrix;
|
|
22
|
+
setColumn: (i: number, name: string, v: number[]) => void;
|
|
23
|
+
getColumn: (i: number) => INamedEmbedding;
|
|
24
|
+
describe: () => string;
|
|
25
|
+
};
|
|
26
|
+
export interface ISequenceMatrix {
|
|
27
|
+
columns: () => number[][];
|
|
28
|
+
setRow: (i: number, v: number[]) => void;
|
|
29
|
+
setColumn: (i: number, v: number[]) => void;
|
|
30
|
+
getColumn: (i: number) => number[];
|
|
31
|
+
getRow: (i: number) => number[];
|
|
32
|
+
getLastColumn: () => ISequenceMatrix;
|
|
33
|
+
getColumnString: (i: number) => string;
|
|
34
|
+
getRowString: (i: number) => string;
|
|
35
|
+
getColumnMatrix: (i: number) => Matrix;
|
|
36
|
+
getRowMatrix: (i: number) => Matrix;
|
|
37
|
+
matrix: () => Matrix;
|
|
38
|
+
rawmatrix: () => number[][];
|
|
39
|
+
mask: () => ISequenceMatrix;
|
|
40
|
+
dropout: () => ISequenceMatrix;
|
|
41
|
+
layerNorm: () => ISequenceMatrix;
|
|
42
|
+
softmax: () => ISequenceMatrix;
|
|
43
|
+
transpose: () => ISequenceMatrix;
|
|
44
|
+
dot: (other: ISequenceMatrix) => ISequenceMatrix;
|
|
45
|
+
add: (other: ISequenceMatrix) => ISequenceMatrix;
|
|
46
|
+
addColToColumns: (vector: ISequenceMatrix) => ISequenceMatrix;
|
|
47
|
+
size: () => string;
|
|
48
|
+
toString: () => string;
|
|
49
|
+
getValue: (index: number[]) => number;
|
|
50
|
+
asFocus: () => any[];
|
|
51
|
+
}
|
|
52
|
+
export interface IDenseLayer {
|
|
53
|
+
forward: (x: MathType) => Matrix;
|
|
54
|
+
backward: (loss: any) => MathType;
|
|
55
|
+
inputs: () => number;
|
|
56
|
+
neurons: () => number;
|
|
57
|
+
weights: () => MathType;
|
|
58
|
+
biases: () => MathType;
|
|
59
|
+
activationFnName: () => string;
|
|
60
|
+
dWeights: () => MathType;
|
|
61
|
+
dBiases: () => MathType;
|
|
62
|
+
setWeights: (w: MathType) => void;
|
|
63
|
+
setBiases: (w: MathType) => void;
|
|
64
|
+
}
|
|
65
|
+
export interface IMLP {
|
|
66
|
+
addLayer: (l: IDenseLayer) => void;
|
|
67
|
+
layers: () => IDenseLayer[];
|
|
68
|
+
forward: (x: Matrix) => Matrix;
|
|
69
|
+
backward: (loss: any) => void;
|
|
70
|
+
toString: () => string;
|
|
71
|
+
}
|
|
72
|
+
export interface ISGD {
|
|
73
|
+
update: (layer: IDenseLayer) => void;
|
|
74
|
+
learningRate: () => number;
|
|
75
|
+
}
|
|
76
|
+
export interface ITrainer {
|
|
77
|
+
train: (eventcollector: any) => void;
|
|
78
|
+
show: () => void;
|
|
79
|
+
}
|
|
80
|
+
export interface ITrainData {
|
|
81
|
+
X_train: any;
|
|
82
|
+
y_train: any;
|
|
83
|
+
nSamples: number;
|
|
84
|
+
nFeatures: number;
|
|
85
|
+
}
|
|
86
|
+
export interface ITransformerTraining {
|
|
87
|
+
data: ITransformerExample[];
|
|
88
|
+
}
|
|
89
|
+
export interface ITransformerExample {
|
|
90
|
+
context: string[];
|
|
91
|
+
target: string;
|
|
92
|
+
}
|
|
93
|
+
export interface ITransformerSpecification {
|
|
94
|
+
VOCAB_LENGTH: number;
|
|
95
|
+
EMBEDDING_LENGTH: number;
|
|
96
|
+
CONTEXT_LENGTH: number;
|
|
97
|
+
KQ_LENGTH: number;
|
|
98
|
+
V_UP_DOWN_LENGTH: number;
|
|
99
|
+
OUTPUT_UP_LENGTH: number;
|
|
100
|
+
OUTPUT_DOWN_LENGTH: number;
|
|
101
|
+
ATTENTION_HEADS_SIZE: number;
|
|
102
|
+
}
|
|
103
|
+
export interface ITransformerModel {
|
|
104
|
+
parameters: ITransformerSpecification;
|
|
105
|
+
matrix_tokens: ISequenceMatrix;
|
|
106
|
+
embeddings?: INamedEmbedding[];
|
|
107
|
+
queries?: INamedEmbedding[];
|
|
108
|
+
keys?: INamedEmbedding[];
|
|
109
|
+
value_up?: INamedEmbedding[];
|
|
110
|
+
value_down?: INamedEmbedding[];
|
|
111
|
+
outputs_up?: INamedEmbedding[];
|
|
112
|
+
outputs_bias?: INamedEmbedding[];
|
|
113
|
+
outputs_down?: INamedEmbedding[];
|
|
114
|
+
weights_prediction?: INamedEmbedding[];
|
|
115
|
+
}
|
|
116
|
+
export interface IModelSpecification {
|
|
117
|
+
CONTEXT_SHAPE: number[];
|
|
118
|
+
CONTEXT_SIZE: string;
|
|
119
|
+
wQ_wK_SHAPE: number[];
|
|
120
|
+
wQ_wK_SIZE: string;
|
|
121
|
+
Q_SHAPE: number[];
|
|
122
|
+
Q_SIZE: string;
|
|
123
|
+
K_SHAPE: number[];
|
|
124
|
+
K_SIZE: string;
|
|
125
|
+
wVDown_SHAPE: number[];
|
|
126
|
+
wVDown_SIZE: string;
|
|
127
|
+
wVUp_SHAPE: number[];
|
|
128
|
+
wVUp_SIZE: string;
|
|
129
|
+
FOCUS_SHAPE: number[];
|
|
130
|
+
FOCUS_SIZE: string;
|
|
131
|
+
VDOWN_SHAPE: number[];
|
|
132
|
+
VDOWN_SIZE: string;
|
|
133
|
+
VUP_SHAPE: number[];
|
|
134
|
+
VUP_SIZE: string;
|
|
135
|
+
CHANGES_SHAPE: number[];
|
|
136
|
+
CHANGES_SIZE: string;
|
|
137
|
+
WOUTPUT_UP_SHAPE: number[];
|
|
138
|
+
WOUTPUT_UP_SIZE: string;
|
|
139
|
+
OUTPUT_UP_SHAPE: number[];
|
|
140
|
+
OUTPUT_UP_SIZE: string;
|
|
141
|
+
BIAS_SHAPE: number[];
|
|
142
|
+
BIAS_SIZE: string;
|
|
143
|
+
WOUTPUT_DOWN_SHAPE: number[];
|
|
144
|
+
WOUTPUT_DOWN_SIZE: string;
|
|
145
|
+
ENRICHED_SHAPE: number[];
|
|
146
|
+
ENRICHED_SIZE: string;
|
|
147
|
+
WPREDICTION_SHAPE: number[];
|
|
148
|
+
WPREDICTION_SIZE: string;
|
|
149
|
+
PREDICTION_SHAPE: number[];
|
|
150
|
+
PREDICTION_SIZE: string;
|
|
151
|
+
ATTENTION_HEADS_SIZE: string;
|
|
152
|
+
PARAMETERS: {
|
|
153
|
+
pQ: number;
|
|
154
|
+
pK: number;
|
|
155
|
+
pVUp: number;
|
|
156
|
+
pVDown: number;
|
|
157
|
+
pWUp: number;
|
|
158
|
+
pWBias: number;
|
|
159
|
+
pWDown: number;
|
|
160
|
+
pWPrediction: number;
|
|
161
|
+
total: number;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export interface IAttention2Model {
|
|
165
|
+
transformerModel: ITransformerModel;
|
|
166
|
+
specifications: IModelSpecification;
|
|
167
|
+
getMatrix_Tokens: () => ISequenceMatrix;
|
|
168
|
+
getMatrix_Query: () => ISequenceMatrix;
|
|
169
|
+
getMatrix_Key: () => ISequenceMatrix;
|
|
170
|
+
getMatrix_ValueUp: () => ISequenceMatrix;
|
|
171
|
+
getMatrix_ValueDown: () => ISequenceMatrix;
|
|
172
|
+
getMatrix_OutputUp: () => ISequenceMatrix;
|
|
173
|
+
getMatrix_OutputDown: () => ISequenceMatrix;
|
|
174
|
+
validateInputs: (td: ITransformerExample) => void;
|
|
175
|
+
forward: (context: string[], target: string) => IForwardResult;
|
|
176
|
+
prediction: (context: string[], target: string, forwardresult: IForwardResult) => IForwardResult;
|
|
177
|
+
}
|
|
178
|
+
export type IAttention2ModelFactory = (transformerModel: ITransformerModel) => IAttention2Model;
|
|
179
|
+
export interface IForwardResult {
|
|
180
|
+
context: string[];
|
|
181
|
+
target: string;
|
|
182
|
+
wQ_m: ISequenceMatrix;
|
|
183
|
+
wK_m: ISequenceMatrix;
|
|
184
|
+
wVDown_m: ISequenceMatrix;
|
|
185
|
+
wVUp_m: ISequenceMatrix;
|
|
186
|
+
wOUp_m: ISequenceMatrix;
|
|
187
|
+
wOBias_m: ISequenceMatrix;
|
|
188
|
+
wODown_m: ISequenceMatrix;
|
|
189
|
+
wPrediction_m: ISequenceMatrix;
|
|
190
|
+
X_m: ISequenceMatrix;
|
|
191
|
+
Q_m: ISequenceMatrix;
|
|
192
|
+
K_m: ISequenceMatrix;
|
|
193
|
+
Qt_m: ISequenceMatrix;
|
|
194
|
+
scores_m: ISequenceMatrix;
|
|
195
|
+
scoresmasked_m: ISequenceMatrix;
|
|
196
|
+
weights_m: ISequenceMatrix;
|
|
197
|
+
XScaled_m: ISequenceMatrix;
|
|
198
|
+
VDown_m: ISequenceMatrix;
|
|
199
|
+
VUp_m: ISequenceMatrix;
|
|
200
|
+
XContextualized_m: ISequenceMatrix;
|
|
201
|
+
XContextualizedLayerNorm_m: ISequenceMatrix;
|
|
202
|
+
O_Up_m: ISequenceMatrix;
|
|
203
|
+
O_Bias_m: ISequenceMatrix;
|
|
204
|
+
O_Down_m: ISequenceMatrix;
|
|
205
|
+
O_Down_LayerNorm_m: ISequenceMatrix;
|
|
206
|
+
LastColumn_m?: ISequenceMatrix;
|
|
207
|
+
Prediction_m?: ISequenceMatrix;
|
|
208
|
+
PredictionProb_m?: ISequenceMatrix;
|
|
209
|
+
predictions?: INamedEmbedding[];
|
|
210
|
+
}
|
package/attention2.js
ADDED
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IExpression, IValueMetadata, IValueData, IValueMatrix, INeuron, INetwork, INNValue, INNLayer, IValueNetworkDisplayOption, INNMatrix, INNSpecification, IMatrixSpecification, INNTrainable, ITrainingExample, IOptimizer, ILearningConfig, ILearnable, IEventCollector, ITrainingDataSet, ITransformerSpecification, IValueTransformer, IValueTransformerInstance } from './valuedata';
|
|
2
|
-
export { IExpression, IValueMetadata, IValueData, IValueMatrix, INeuron, INetwork, INNValue, INNLayer, IValueNetworkDisplayOption, INNMatrix, INNSpecification, IMatrixSpecification, INNTrainable, ITrainingExample, IOptimizer, ILearningConfig, ILearnable, IEventCollector, ITrainingDataSet, ITransformerSpecification, IValueTransformer, IValueTransformerInstance };
|
|
1
|
+
import { IVector, IMatrix, IExpression, IValueMetadata, IValueData, IValueMatrix, INeuron, INetwork, INNValue, INNLayer, IValueNetworkDisplayOption, INNMatrix, INNSpecification, IMatrixSpecification, INNTrainable, ITrainingExample, IOptimizer, ILearningConfig, ILearnable, IEventCollector, ITrainingDataSet, ITransformerSpecification, IValueTransformer, IValueTransformerInstance } from './valuedata';
|
|
2
|
+
export { IVector, IMatrix, IExpression, IValueMetadata, IValueData, IValueMatrix, INeuron, INetwork, INNValue, INNLayer, IValueNetworkDisplayOption, INNMatrix, INNSpecification, IMatrixSpecification, INNTrainable, ITrainingExample, IOptimizer, ILearningConfig, ILearnable, IEventCollector, ITrainingDataSet, ITransformerSpecification, IValueTransformer, IValueTransformerInstance };
|
|
3
3
|
type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
|
|
4
4
|
export interface ICommandResult {
|
|
5
5
|
status: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataset-types",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "npm run build && npm run package",
|
|
6
6
|
"build": "tsc --rootDir 'src/types' --outDir './dist'",
|
|
@@ -29,5 +29,8 @@
|
|
|
29
29
|
"nodemon": "^3.1.9",
|
|
30
30
|
"prettier": "^3.4.2",
|
|
31
31
|
"typescript": "^5.7.2"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"mathjs": "^15.2.0"
|
|
32
35
|
}
|
|
33
36
|
}
|