@huggingface/inference 2.3.3 → 2.4.0
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 +26 -6
- package/dist/index.d.ts +41 -2
- package/dist/index.js +23 -15
- package/dist/index.mjs +22 -15
- package/package.json +1 -1
- package/src/tasks/index.ts +1 -0
- package/src/tasks/nlp/featureExtraction.ts +14 -20
- package/src/tasks/tabular/tabularClassification.ts +34 -0
package/README.md
CHANGED
|
@@ -211,12 +211,31 @@ await hf.tabularRegression({
|
|
|
211
211
|
model: "scikit-learn/Fish-Weight",
|
|
212
212
|
inputs: {
|
|
213
213
|
data: {
|
|
214
|
-
"Height":["11.52", "12.48", "12.3778"],
|
|
215
|
-
"Length1":["23.2", "24", "23.9"],
|
|
216
|
-
"Length2":["25.4", "26.3", "26.5"],
|
|
217
|
-
"Length3":["30", "31.2", "31.1"],
|
|
218
|
-
"Species":["Bream", "Bream", "Bream"],
|
|
219
|
-
"Width":["4.02", "4.3056", "4.6961"]
|
|
214
|
+
"Height": ["11.52", "12.48", "12.3778"],
|
|
215
|
+
"Length1": ["23.2", "24", "23.9"],
|
|
216
|
+
"Length2": ["25.4", "26.3", "26.5"],
|
|
217
|
+
"Length3": ["30", "31.2", "31.1"],
|
|
218
|
+
"Species": ["Bream", "Bream", "Bream"],
|
|
219
|
+
"Width": ["4.02", "4.3056", "4.6961"]
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
await hf.tabularClassification({
|
|
225
|
+
model: "vvmnnnkv/wine-quality",
|
|
226
|
+
inputs: {
|
|
227
|
+
data: {
|
|
228
|
+
"fixed_acidity": ["7.4", "7.8", "10.3"],
|
|
229
|
+
"volatile_acidity": ["0.7", "0.88", "0.32"],
|
|
230
|
+
"citric_acid": ["0", "0", "0.45"],
|
|
231
|
+
"residual_sugar": ["1.9", "2.6", "6.4"],
|
|
232
|
+
"chlorides": ["0.076", "0.098", "0.073"],
|
|
233
|
+
"free_sulfur_dioxide": ["11", "25", "5"],
|
|
234
|
+
"total_sulfur_dioxide": ["34", "67", "13"],
|
|
235
|
+
"density": ["0.9978", "0.9968", "0.9976"],
|
|
236
|
+
"pH": ["3.51", "3.2", "3.23"],
|
|
237
|
+
"sulphates": ["0.56", "0.68", "0.82"],
|
|
238
|
+
"alcohol": ["9.4", "9.8", "12.6"]
|
|
220
239
|
},
|
|
221
240
|
},
|
|
222
241
|
})
|
|
@@ -287,6 +306,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
|
|
|
287
306
|
### Tabular
|
|
288
307
|
|
|
289
308
|
- [x] Tabular regression
|
|
309
|
+
- [x] Tabular classification
|
|
290
310
|
|
|
291
311
|
## Tree-shaking
|
|
292
312
|
|
package/dist/index.d.ts
CHANGED
|
@@ -448,9 +448,9 @@ export type FeatureExtractionArgs = BaseArgs & {
|
|
|
448
448
|
inputs: string | string[];
|
|
449
449
|
};
|
|
450
450
|
/**
|
|
451
|
-
* Returned values are a list of floats, or a list of list of floats (depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README.
|
|
451
|
+
* Returned values are a list of floats, or a list of list of floats, or a list of list of list of floats (depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README.
|
|
452
452
|
*/
|
|
453
|
-
export type FeatureExtractionOutput = (number | number[])[];
|
|
453
|
+
export type FeatureExtractionOutput = (number | number[] | number[][])[];
|
|
454
454
|
/**
|
|
455
455
|
* This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
|
|
456
456
|
*/
|
|
@@ -875,6 +875,27 @@ export function zeroShotClassification(
|
|
|
875
875
|
args: ZeroShotClassificationArgs,
|
|
876
876
|
options?: Options
|
|
877
877
|
): Promise<ZeroShotClassificationOutput>;
|
|
878
|
+
export type TabularClassificationArgs = BaseArgs & {
|
|
879
|
+
inputs: {
|
|
880
|
+
/**
|
|
881
|
+
* A table of data represented as a dict of list where entries are headers and the lists are all the values, all lists must have the same size.
|
|
882
|
+
*/
|
|
883
|
+
data: Record<string, string[]>;
|
|
884
|
+
};
|
|
885
|
+
};
|
|
886
|
+
/**
|
|
887
|
+
* A list of predicted labels for each row
|
|
888
|
+
*/
|
|
889
|
+
export type TabularClassificationOutput = number[];
|
|
890
|
+
/**
|
|
891
|
+
* Predicts target label for a given set of features in tabular form.
|
|
892
|
+
* Typically, you will want to train a classification model on your training data and use it with your new data of the same format.
|
|
893
|
+
* Example model: vvmnnnkv/wine-quality
|
|
894
|
+
*/
|
|
895
|
+
export function tabularClassification(
|
|
896
|
+
args: TabularClassificationArgs,
|
|
897
|
+
options?: Options
|
|
898
|
+
): Promise<TabularClassificationOutput>;
|
|
878
899
|
export type TabularRegressionArgs = BaseArgs & {
|
|
879
900
|
inputs: {
|
|
880
901
|
/**
|
|
@@ -1069,6 +1090,15 @@ export class HfInference {
|
|
|
1069
1090
|
args: Omit<ZeroShotClassificationArgs, 'accessToken'>,
|
|
1070
1091
|
options?: Options
|
|
1071
1092
|
): Promise<ZeroShotClassificationOutput>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Predicts target label for a given set of features in tabular form.
|
|
1095
|
+
* Typically, you will want to train a classification model on your training data and use it with your new data of the same format.
|
|
1096
|
+
* Example model: vvmnnnkv/wine-quality
|
|
1097
|
+
*/
|
|
1098
|
+
tabularClassification(
|
|
1099
|
+
args: Omit<TabularClassificationArgs, 'accessToken'>,
|
|
1100
|
+
options?: Options
|
|
1101
|
+
): Promise<TabularClassificationOutput>;
|
|
1072
1102
|
/**
|
|
1073
1103
|
* Predicts target value for a given set of features in tabular form.
|
|
1074
1104
|
* Typically, you will want to train a regression model on your training data and use it with your new data of the same format.
|
|
@@ -1248,6 +1278,15 @@ export class HfInferenceEndpoint {
|
|
|
1248
1278
|
args: Omit<ZeroShotClassificationArgs, 'accessToken' | 'model'>,
|
|
1249
1279
|
options?: Options
|
|
1250
1280
|
): Promise<ZeroShotClassificationOutput>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Predicts target label for a given set of features in tabular form.
|
|
1283
|
+
* Typically, you will want to train a classification model on your training data and use it with your new data of the same format.
|
|
1284
|
+
* Example model: vvmnnnkv/wine-quality
|
|
1285
|
+
*/
|
|
1286
|
+
tabularClassification(
|
|
1287
|
+
args: Omit<TabularClassificationArgs, 'accessToken' | 'model'>,
|
|
1288
|
+
options?: Options
|
|
1289
|
+
): Promise<TabularClassificationOutput>;
|
|
1251
1290
|
/**
|
|
1252
1291
|
* Predicts target value for a given set of features in tabular form.
|
|
1253
1292
|
* Typically, you will want to train a regression model on your training data and use it with your new data of the same format.
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
streamingRequest: () => streamingRequest,
|
|
42
42
|
summarization: () => summarization,
|
|
43
43
|
tableQuestionAnswering: () => tableQuestionAnswering,
|
|
44
|
+
tabularClassification: () => tabularClassification,
|
|
44
45
|
tabularRegression: () => tabularRegression,
|
|
45
46
|
textClassification: () => textClassification,
|
|
46
47
|
textGeneration: () => textGeneration,
|
|
@@ -74,6 +75,7 @@ __export(tasks_exports, {
|
|
|
74
75
|
streamingRequest: () => streamingRequest,
|
|
75
76
|
summarization: () => summarization,
|
|
76
77
|
tableQuestionAnswering: () => tableQuestionAnswering,
|
|
78
|
+
tabularClassification: () => tabularClassification,
|
|
77
79
|
tabularRegression: () => tabularRegression,
|
|
78
80
|
textClassification: () => textClassification,
|
|
79
81
|
textGeneration: () => textGeneration,
|
|
@@ -459,23 +461,18 @@ async function conversational(args, options) {
|
|
|
459
461
|
async function featureExtraction(args, options) {
|
|
460
462
|
const res = await request(args, options);
|
|
461
463
|
let isValidOutput = true;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
} else if (typeof e !== "number") {
|
|
470
|
-
isValidOutput = false;
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
464
|
+
const isNumArrayRec = (arr, maxDepth, curDepth = 0) => {
|
|
465
|
+
if (curDepth > maxDepth)
|
|
466
|
+
return false;
|
|
467
|
+
if (arr.every((x) => Array.isArray(x))) {
|
|
468
|
+
return arr.every((x) => isNumArrayRec(x, maxDepth, curDepth + 1));
|
|
469
|
+
} else {
|
|
470
|
+
return arr.every((x) => typeof x === "number");
|
|
473
471
|
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
}
|
|
472
|
+
};
|
|
473
|
+
isValidOutput = Array.isArray(res) && isNumArrayRec(res, 2, 0);
|
|
477
474
|
if (!isValidOutput) {
|
|
478
|
-
throw new InferenceOutputError("Expected Array<number[] | number>");
|
|
475
|
+
throw new InferenceOutputError("Expected Array<number[][] | number[] | number>");
|
|
479
476
|
}
|
|
480
477
|
return res;
|
|
481
478
|
}
|
|
@@ -663,6 +660,16 @@ async function tabularRegression(args, options) {
|
|
|
663
660
|
return res;
|
|
664
661
|
}
|
|
665
662
|
|
|
663
|
+
// src/tasks/tabular/tabularClassification.ts
|
|
664
|
+
async function tabularClassification(args, options) {
|
|
665
|
+
const res = await request(args, options);
|
|
666
|
+
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
|
|
667
|
+
if (!isValidOutput) {
|
|
668
|
+
throw new InferenceOutputError("Expected number[]");
|
|
669
|
+
}
|
|
670
|
+
return res;
|
|
671
|
+
}
|
|
672
|
+
|
|
666
673
|
// src/HfInference.ts
|
|
667
674
|
var HfInference = class {
|
|
668
675
|
accessToken;
|
|
@@ -724,6 +731,7 @@ var HfInferenceEndpoint = class {
|
|
|
724
731
|
streamingRequest,
|
|
725
732
|
summarization,
|
|
726
733
|
tableQuestionAnswering,
|
|
734
|
+
tabularClassification,
|
|
727
735
|
tabularRegression,
|
|
728
736
|
textClassification,
|
|
729
737
|
textGeneration,
|
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(tasks_exports, {
|
|
|
25
25
|
streamingRequest: () => streamingRequest,
|
|
26
26
|
summarization: () => summarization,
|
|
27
27
|
tableQuestionAnswering: () => tableQuestionAnswering,
|
|
28
|
+
tabularClassification: () => tabularClassification,
|
|
28
29
|
tabularRegression: () => tabularRegression,
|
|
29
30
|
textClassification: () => textClassification,
|
|
30
31
|
textGeneration: () => textGeneration,
|
|
@@ -410,23 +411,18 @@ async function conversational(args, options) {
|
|
|
410
411
|
async function featureExtraction(args, options) {
|
|
411
412
|
const res = await request(args, options);
|
|
412
413
|
let isValidOutput = true;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
} else if (typeof e !== "number") {
|
|
421
|
-
isValidOutput = false;
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
414
|
+
const isNumArrayRec = (arr, maxDepth, curDepth = 0) => {
|
|
415
|
+
if (curDepth > maxDepth)
|
|
416
|
+
return false;
|
|
417
|
+
if (arr.every((x) => Array.isArray(x))) {
|
|
418
|
+
return arr.every((x) => isNumArrayRec(x, maxDepth, curDepth + 1));
|
|
419
|
+
} else {
|
|
420
|
+
return arr.every((x) => typeof x === "number");
|
|
424
421
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
}
|
|
422
|
+
};
|
|
423
|
+
isValidOutput = Array.isArray(res) && isNumArrayRec(res, 2, 0);
|
|
428
424
|
if (!isValidOutput) {
|
|
429
|
-
throw new InferenceOutputError("Expected Array<number[] | number>");
|
|
425
|
+
throw new InferenceOutputError("Expected Array<number[][] | number[] | number>");
|
|
430
426
|
}
|
|
431
427
|
return res;
|
|
432
428
|
}
|
|
@@ -614,6 +610,16 @@ async function tabularRegression(args, options) {
|
|
|
614
610
|
return res;
|
|
615
611
|
}
|
|
616
612
|
|
|
613
|
+
// src/tasks/tabular/tabularClassification.ts
|
|
614
|
+
async function tabularClassification(args, options) {
|
|
615
|
+
const res = await request(args, options);
|
|
616
|
+
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
|
|
617
|
+
if (!isValidOutput) {
|
|
618
|
+
throw new InferenceOutputError("Expected number[]");
|
|
619
|
+
}
|
|
620
|
+
return res;
|
|
621
|
+
}
|
|
622
|
+
|
|
617
623
|
// src/HfInference.ts
|
|
618
624
|
var HfInference = class {
|
|
619
625
|
accessToken;
|
|
@@ -674,6 +680,7 @@ export {
|
|
|
674
680
|
streamingRequest,
|
|
675
681
|
summarization,
|
|
676
682
|
tableQuestionAnswering,
|
|
683
|
+
tabularClassification,
|
|
677
684
|
tabularRegression,
|
|
678
685
|
textClassification,
|
|
679
686
|
textGeneration,
|
package/package.json
CHANGED
package/src/tasks/index.ts
CHANGED
|
@@ -13,9 +13,9 @@ export type FeatureExtractionArgs = BaseArgs & {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Returned values are a list of floats, or a list of list of floats (depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README.
|
|
16
|
+
* Returned values are a list of floats, or a list of list of floats, or a list of list of list of floats (depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README.
|
|
17
17
|
*/
|
|
18
|
-
export type FeatureExtractionOutput = (number | number[])[];
|
|
18
|
+
export type FeatureExtractionOutput = (number | number[] | number[][])[];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
|
|
@@ -26,26 +26,20 @@ export async function featureExtraction(
|
|
|
26
26
|
): Promise<FeatureExtractionOutput> {
|
|
27
27
|
const res = await request<FeatureExtractionOutput>(args, options);
|
|
28
28
|
let isValidOutput = true;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!isValidOutput) {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
} else if (typeof e !== "number") {
|
|
40
|
-
isValidOutput = false;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
29
|
+
|
|
30
|
+
const isNumArrayRec = (arr: unknown[], maxDepth: number, curDepth = 0): boolean => {
|
|
31
|
+
if (curDepth > maxDepth) return false;
|
|
32
|
+
if (arr.every((x) => Array.isArray(x))) {
|
|
33
|
+
return arr.every((x) => isNumArrayRec(x as unknown[], maxDepth, curDepth + 1));
|
|
34
|
+
} else {
|
|
35
|
+
return arr.every((x) => typeof x === "number");
|
|
43
36
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
isValidOutput = Array.isArray(res) && isNumArrayRec(res, 2, 0);
|
|
40
|
+
|
|
47
41
|
if (!isValidOutput) {
|
|
48
|
-
throw new InferenceOutputError("Expected Array<number[] | number>");
|
|
42
|
+
throw new InferenceOutputError("Expected Array<number[][] | number[] | number>");
|
|
49
43
|
}
|
|
50
44
|
return res;
|
|
51
45
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InferenceOutputError } from "../../lib/InferenceOutputError";
|
|
2
|
+
import type { BaseArgs, Options } from "../../types";
|
|
3
|
+
import { request } from "../custom/request";
|
|
4
|
+
|
|
5
|
+
export type TabularClassificationArgs = BaseArgs & {
|
|
6
|
+
inputs: {
|
|
7
|
+
/**
|
|
8
|
+
* A table of data represented as a dict of list where entries are headers and the lists are all the values, all lists must have the same size.
|
|
9
|
+
*/
|
|
10
|
+
data: Record<string, string[]>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A list of predicted labels for each row
|
|
16
|
+
*/
|
|
17
|
+
export type TabularClassificationOutput = number[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Predicts target label for a given set of features in tabular form.
|
|
21
|
+
* Typically, you will want to train a classification model on your training data and use it with your new data of the same format.
|
|
22
|
+
* Example model: vvmnnnkv/wine-quality
|
|
23
|
+
*/
|
|
24
|
+
export async function tabularClassification(
|
|
25
|
+
args: TabularClassificationArgs,
|
|
26
|
+
options?: Options
|
|
27
|
+
): Promise<TabularClassificationOutput> {
|
|
28
|
+
const res = await request<TabularClassificationOutput>(args, options);
|
|
29
|
+
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
|
|
30
|
+
if (!isValidOutput) {
|
|
31
|
+
throw new InferenceOutputError("Expected number[]");
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
}
|