Skip to content

Commit b863909

Browse files
authored
Fix zero-shot tasks specs (#1037)
Related to [slack thread](https://huggingface.slack.com/archives/C069KSP486B/p1731923978189269) (private). This PR fixes the specs for `zero-shot-classification`, `zero-shot-image-classification` and `zero-shot-object-detection`. The candidate labels must be sent as parameters, not in `inputs`. The Inference API itself **did not change**, it's just the specs that were not aligned with the existing API.
1 parent f1685ed commit b863909

File tree

7 files changed

+65
-108
lines changed

7 files changed

+65
-108
lines changed

packages/tasks/src/tasks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export type * from "./zero-shot-image-classification/inference.js";
102102
export type {
103103
BoundingBox,
104104
ZeroShotObjectDetectionInput,
105-
ZeroShotObjectDetectionInputData,
106105
ZeroShotObjectDetectionOutput,
107106
ZeroShotObjectDetectionOutputElement,
108107
} from "./zero-shot-object-detection/inference.js";

packages/tasks/src/tasks/zero-shot-classification/inference.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,13 @@
88
*/
99
export interface ZeroShotClassificationInput {
1010
/**
11-
* The input text data, with candidate labels
11+
* The text to classify
1212
*/
13-
inputs: ZeroShotClassificationInputData;
13+
inputs: string;
1414
/**
1515
* Additional inference parameters
1616
*/
17-
parameters?: ZeroShotClassificationParameters;
18-
[property: string]: unknown;
19-
}
20-
/**
21-
* The input text data, with candidate labels
22-
*/
23-
export interface ZeroShotClassificationInputData {
24-
/**
25-
* The set of possible class labels to classify the text into.
26-
*/
27-
candidateLabels: string[];
28-
/**
29-
* The text to classify
30-
*/
31-
text: string;
17+
parameters: ZeroShotClassificationParameters;
3218
[property: string]: unknown;
3319
}
3420
/**
@@ -38,8 +24,12 @@ export interface ZeroShotClassificationInputData {
3824
*/
3925
export interface ZeroShotClassificationParameters {
4026
/**
41-
* The sentence used in conjunction with candidateLabels to attempt the text classification
42-
* by replacing the placeholder with the candidate labels.
27+
* The set of possible class labels to classify the text into.
28+
*/
29+
candidate_labels: string[];
30+
/**
31+
* The sentence used in conjunction with `candidate_labels` to attempt the text
32+
* classification by replacing the placeholder with the candidate labels.
4333
*/
4434
hypothesis_template?: string;
4535
/**

packages/tasks/src/tasks/zero-shot-classification/spec/input.json

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@
66
"type": "object",
77
"properties": {
88
"inputs": {
9-
"description": "The input text data, with candidate labels",
10-
"type": "object",
11-
"title": "ZeroShotClassificationInputData",
12-
"properties": {
13-
"text": {
14-
"type": "string",
15-
"description": "The text to classify"
16-
},
17-
"candidateLabels": {
18-
"type": "array",
19-
"description": "The set of possible class labels to classify the text into.",
20-
"items": {
21-
"type": "string"
22-
}
23-
}
24-
},
25-
"required": ["text", "candidateLabels"]
9+
"description": "The text to classify",
10+
"type": "string"
2611
},
2712
"parameters": {
2813
"description": "Additional inference parameters",
@@ -35,16 +20,24 @@
3520
"description": "Additional inference parameters for Zero Shot Classification",
3621
"type": "object",
3722
"properties": {
23+
"candidate_labels": {
24+
"type": "array",
25+
"description": "The set of possible class labels to classify the text into.",
26+
"items": {
27+
"type": "string"
28+
}
29+
},
3830
"hypothesis_template": {
3931
"type": "string",
40-
"description": "The sentence used in conjunction with candidateLabels to attempt the text classification by replacing the placeholder with the candidate labels."
32+
"description": "The sentence used in conjunction with `candidate_labels` to attempt the text classification by replacing the placeholder with the candidate labels."
4133
},
4234
"multi_label": {
4335
"type": "boolean",
4436
"description": "Whether multiple candidate labels can be true. If false, the scores are normalized such that the sum of the label likelihoods for each sequence is 1. If true, the labels are considered independent and probabilities are normalized for each candidate."
4537
}
46-
}
38+
},
39+
"required": ["candidate_labels"]
4740
}
4841
},
49-
"required": ["inputs"]
42+
"required": ["inputs", "parameters"]
5043
}

packages/tasks/src/tasks/zero-shot-image-classification/inference.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,13 @@
88
*/
99
export interface ZeroShotImageClassificationInput {
1010
/**
11-
* The input image data, with candidate labels
11+
* The input image data to classify as a base64-encoded string.
1212
*/
13-
inputs: ZeroShotImageClassificationInputData;
13+
inputs: string;
1414
/**
1515
* Additional inference parameters
1616
*/
17-
parameters?: ZeroShotImageClassificationParameters;
18-
[property: string]: unknown;
19-
}
20-
/**
21-
* The input image data, with candidate labels
22-
*/
23-
export interface ZeroShotImageClassificationInputData {
24-
/**
25-
* The candidate labels for this image
26-
*/
27-
candidateLabels: string[];
28-
/**
29-
* The image data to classify
30-
*/
31-
image: unknown;
17+
parameters: ZeroShotImageClassificationParameters;
3218
[property: string]: unknown;
3319
}
3420
/**
@@ -38,8 +24,12 @@ export interface ZeroShotImageClassificationInputData {
3824
*/
3925
export interface ZeroShotImageClassificationParameters {
4026
/**
41-
* The sentence used in conjunction with candidateLabels to attempt the text classification
42-
* by replacing the placeholder with the candidate labels.
27+
* The candidate labels for this image
28+
*/
29+
candidate_labels: string[];
30+
/**
31+
* The sentence used in conjunction with `candidate_labels` to attempt the image
32+
* classification by replacing the placeholder with the candidate labels.
4333
*/
4434
hypothesis_template?: string;
4535
[property: string]: unknown;

packages/tasks/src/tasks/zero-shot-image-classification/spec/input.json

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,8 @@
66
"type": "object",
77
"properties": {
88
"inputs": {
9-
"description": "The input image data, with candidate labels",
10-
"type": "object",
11-
"title": "ZeroShotImageClassificationInputData",
12-
"properties": {
13-
"image": {
14-
"description": "The image data to classify"
15-
},
16-
"candidateLabels": {
17-
"description": "The candidate labels for this image",
18-
"type": "array",
19-
"items": {
20-
"type": "string"
21-
}
22-
}
23-
},
24-
"required": ["image", "candidateLabels"]
9+
"type": "string",
10+
"description": "The input image data to classify as a base64-encoded string."
2511
},
2612
"parameters": {
2713
"description": "Additional inference parameters",
@@ -34,12 +20,20 @@
3420
"description": "Additional inference parameters for Zero Shot Image Classification",
3521
"type": "object",
3622
"properties": {
23+
"candidate_labels": {
24+
"description": "The candidate labels for this image",
25+
"type": "array",
26+
"items": {
27+
"type": "string"
28+
}
29+
},
3730
"hypothesis_template": {
3831
"type": "string",
39-
"description": "The sentence used in conjunction with candidateLabels to attempt the text classification by replacing the placeholder with the candidate labels."
32+
"description": "The sentence used in conjunction with `candidate_labels` to attempt the image classification by replacing the placeholder with the candidate labels."
4033
}
41-
}
34+
},
35+
"required": ["candidate_labels"]
4236
}
4337
},
44-
"required": ["inputs"]
38+
"required": ["inputs", "parameters"]
4539
}

packages/tasks/src/tasks/zero-shot-object-detection/inference.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,25 @@
88
*/
99
export interface ZeroShotObjectDetectionInput {
1010
/**
11-
* The input image data, with candidate labels
11+
* The input image data as a base64-encoded string.
1212
*/
13-
inputs: ZeroShotObjectDetectionInputData;
13+
inputs: string;
1414
/**
1515
* Additional inference parameters
1616
*/
17-
parameters?: {
18-
[key: string]: unknown;
19-
};
17+
parameters: ZeroShotObjectDetectionParameters;
2018
[property: string]: unknown;
2119
}
2220
/**
23-
* The input image data, with candidate labels
21+
* Additional inference parameters
22+
*
23+
* Additional inference parameters for Zero Shot Object Detection
2424
*/
25-
export interface ZeroShotObjectDetectionInputData {
25+
export interface ZeroShotObjectDetectionParameters {
2626
/**
2727
* The candidate labels for this image
2828
*/
29-
candidateLabels: string[];
30-
/**
31-
* The image data to generate bounding boxes from
32-
*/
33-
image: unknown;
29+
candidate_labels: string[];
3430
[property: string]: unknown;
3531
}
3632
/**

packages/tasks/src/tasks/zero-shot-object-detection/spec/input.json

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,8 @@
66
"type": "object",
77
"properties": {
88
"inputs": {
9-
"description": "The input image data, with candidate labels",
10-
"type": "object",
11-
"title": "ZeroShotObjectDetectionInputData",
12-
"properties": {
13-
"image": {
14-
"description": "The image data to generate bounding boxes from"
15-
},
16-
"candidateLabels": {
17-
"description": "The candidate labels for this image",
18-
"type": "array",
19-
"items": {
20-
"type": "string"
21-
}
22-
}
23-
},
24-
"required": ["image", "candidateLabels"]
9+
"description": "The input image data as a base64-encoded string.",
10+
"type": "string"
2511
},
2612
"parameters": {
2713
"description": "Additional inference parameters",
@@ -33,8 +19,17 @@
3319
"title": "ZeroShotObjectDetectionParameters",
3420
"description": "Additional inference parameters for Zero Shot Object Detection",
3521
"type": "object",
36-
"properties": {}
22+
"properties": {
23+
"candidate_labels": {
24+
"description": "The candidate labels for this image",
25+
"type": "array",
26+
"items": {
27+
"type": "string"
28+
}
29+
}
30+
},
31+
"required": ["candidate_labels"]
3732
}
3833
},
39-
"required": ["inputs"]
34+
"required": ["inputs", "parameters"]
4035
}

0 commit comments

Comments
 (0)