@huggingface/transformers 3.0.0-alpha.20 → 3.0.0-alpha.21
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/README.md +3 -2
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +129 -467
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +526 -861
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.cjs +11 -11
- package/dist/transformers.min.cjs.map +1 -1
- package/dist/transformers.min.js +10 -10
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.min.mjs +5 -5
- package/dist/transformers.min.mjs.map +1 -1
- package/dist/transformers.mjs +133 -468
- package/dist/transformers.mjs.map +1 -1
- package/package.json +2 -2
- package/src/configs.js +1 -0
- package/src/env.js +1 -1
- package/src/models.js +84 -453
- package/src/utils/tensor.js +37 -13
- package/types/configs.d.ts.map +1 -1
- package/types/models.d.ts +15 -294
- package/types/models.d.ts.map +1 -1
- package/types/pipelines.d.ts +1 -2
- package/types/pipelines.d.ts.map +1 -1
- package/types/utils/tensor.d.ts +14 -0
- package/types/utils/tensor.d.ts.map +1 -1
package/src/utils/tensor.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Helper module for `Tensor` processing.
|
|
3
|
-
*
|
|
4
|
-
* These functions and classes are only used internally,
|
|
3
|
+
*
|
|
4
|
+
* These functions and classes are only used internally,
|
|
5
5
|
* meaning an end-user shouldn't need to access anything here.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @module utils/tensor
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -169,9 +169,9 @@ export class Tensor {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
* @param {number} index
|
|
173
|
-
* @param {number} iterSize
|
|
174
|
-
* @param {any} iterDims
|
|
172
|
+
* @param {number} index
|
|
173
|
+
* @param {number} iterSize
|
|
174
|
+
* @param {any} iterDims
|
|
175
175
|
* @returns {Tensor}
|
|
176
176
|
*/
|
|
177
177
|
_subarray(index, iterSize, iterDims) {
|
|
@@ -228,6 +228,30 @@ export class Tensor {
|
|
|
228
228
|
return this;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Return a new Tensor with a callback function applied to each element.
|
|
233
|
+
* @param {Function} callback - The function to apply to each element. It should take three arguments:
|
|
234
|
+
* the current element, its index, and the tensor's data array.
|
|
235
|
+
* @returns {Tensor} A new Tensor with the callback function applied to each element.
|
|
236
|
+
*/
|
|
237
|
+
map(callback) {
|
|
238
|
+
return this.clone().map_(callback);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Apply a callback function to each element of the tensor in place.
|
|
243
|
+
* @param {Function} callback - The function to apply to each element. It should take three arguments:
|
|
244
|
+
* the current element, its index, and the tensor's data array.
|
|
245
|
+
* @returns {Tensor} Returns `this`.
|
|
246
|
+
*/
|
|
247
|
+
map_(callback) {
|
|
248
|
+
const this_data = this.data;
|
|
249
|
+
for (let i = 0; i < this_data.length; ++i) {
|
|
250
|
+
this_data[i] = callback(this_data[i], i, this_data);
|
|
251
|
+
}
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
231
255
|
/**
|
|
232
256
|
* Return a new Tensor with every element multiplied by a constant.
|
|
233
257
|
* @param {number} val The value to multiply by.
|
|
@@ -410,7 +434,7 @@ export class Tensor {
|
|
|
410
434
|
|
|
411
435
|
/**
|
|
412
436
|
* Returns the sum of each row of the input tensor in the given dimension dim.
|
|
413
|
-
*
|
|
437
|
+
*
|
|
414
438
|
* @param {number} [dim=null] The dimension or dimensions to reduce. If `null`, all dimensions are reduced.
|
|
415
439
|
* @param {boolean} keepdim Whether the output tensor has `dim` retained or not.
|
|
416
440
|
* @returns The summed tensor
|
|
@@ -543,10 +567,10 @@ export class Tensor {
|
|
|
543
567
|
|
|
544
568
|
/**
|
|
545
569
|
* Returns a tensor with all specified dimensions of input of size 1 removed.
|
|
546
|
-
*
|
|
570
|
+
*
|
|
547
571
|
* NOTE: The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other.
|
|
548
572
|
* If you would like a copy, use `tensor.clone()` before squeezing.
|
|
549
|
-
*
|
|
573
|
+
*
|
|
550
574
|
* @param {number} [dim=null] If given, the input will be squeezed only in the specified dimensions.
|
|
551
575
|
* @returns {Tensor} The squeezed tensor
|
|
552
576
|
*/
|
|
@@ -568,9 +592,9 @@ export class Tensor {
|
|
|
568
592
|
|
|
569
593
|
/**
|
|
570
594
|
* Returns a new tensor with a dimension of size one inserted at the specified position.
|
|
571
|
-
*
|
|
595
|
+
*
|
|
572
596
|
* NOTE: The returned tensor shares the same underlying data with this tensor.
|
|
573
|
-
*
|
|
597
|
+
*
|
|
574
598
|
* @param {number} dim The index at which to insert the singleton dimension
|
|
575
599
|
* @returns {Tensor} The unsqueezed tensor
|
|
576
600
|
*/
|
|
@@ -721,7 +745,7 @@ export class Tensor {
|
|
|
721
745
|
|
|
722
746
|
/**
|
|
723
747
|
* This creates a nested array of a given type and depth (see examples).
|
|
724
|
-
*
|
|
748
|
+
*
|
|
725
749
|
* @example
|
|
726
750
|
* NestArray<string, 1>; // string[]
|
|
727
751
|
* @example
|
|
@@ -1048,7 +1072,7 @@ function calc_unsqueeze_dims(dims, dim) {
|
|
|
1048
1072
|
* @param {number} size The size of the array.
|
|
1049
1073
|
* @param {number} [dimension=null] The dimension that the index is for (optional).
|
|
1050
1074
|
* @returns {number} The index, guaranteed to be non-negative and less than `arrayLength`.
|
|
1051
|
-
*
|
|
1075
|
+
*
|
|
1052
1076
|
* @throws {Error} If the index is out of range.
|
|
1053
1077
|
* @private
|
|
1054
1078
|
*/
|
package/types/configs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.js"],"names":[],"mappings":"AAmNA;;;;GAIG;AACH,0CAHW,gBAAgB;;IACd,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,CA6EpC;AACD;;;GAGG;AACH;IAwBI;;;;;;;;OAQG;IACH,sDANW,MAAM,0EACN,iBAAiB,GAGf,QAAQ,gBAAgB,CAAC,CAqBrC;IArCD;;;OAGG;IACH,6BAGC;IAnBD,0BAA0B;IAC1B,YADW,MAAM,GAAC,IAAI,CACJ;IAElB,sBAAsB;IACtB,oBADW,OAAO,CACS;IAE3B,qBAAqB;IACrB,yBADW,MAAM,CACO;IAExB,mCAAmC;IACnC,0BADW,oBAAoB,CACN;IAQrB,uBAAkD;CAgCzD;AAED;;;;;GAKG;AACH;IArCI;;;;;;;;OAQG;IACH,6MAmBC;CAcJ;gCAvUY,OAAO,gBAAgB,EAAE,iBAAiB;;;;;;;;qBA4UzC,OAAO,mBAAmB,EAAE,QAAQ;;;;;;+BACpC,OAAO,MAAM,EAAE,MAAM,CAAC;;;;aAGtB,OAAO,oBAAoB,EAAE,UAAU;;;;YACvC,OAAO,mBAAmB,EAAE,QAAQ;;;;+BACpC,OAAO,GAAC,OAAO,MAAM,EAAE,OAAO,CAAC"}
|