Skip to content

Fix zero-shot tasks specs #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/tasks/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export type * from "./zero-shot-image-classification/inference.js";
export type {
BoundingBox,
ZeroShotObjectDetectionInput,
ZeroShotObjectDetectionInputData,
ZeroShotObjectDetectionOutput,
ZeroShotObjectDetectionOutputElement,
} from "./zero-shot-object-detection/inference.js";
Expand Down
28 changes: 9 additions & 19 deletions packages/tasks/src/tasks/zero-shot-classification/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@
*/
export interface ZeroShotClassificationInput {
/**
* The input text data, with candidate labels
* The text to classify
*/
inputs: ZeroShotClassificationInputData;
inputs: string;
/**
* Additional inference parameters
*/
parameters?: ZeroShotClassificationParameters;
[property: string]: unknown;
}
/**
* The input text data, with candidate labels
*/
export interface ZeroShotClassificationInputData {
/**
* The set of possible class labels to classify the text into.
*/
candidateLabels: string[];
/**
* The text to classify
*/
text: string;
parameters: ZeroShotClassificationParameters;
[property: string]: unknown;
}
/**
Expand All @@ -38,8 +24,12 @@ export interface ZeroShotClassificationInputData {
*/
export interface ZeroShotClassificationParameters {
/**
* The sentence used in conjunction with candidateLabels to attempt the text classification
* by replacing the placeholder with the candidate labels.
* The set of possible class labels to classify the text into.
*/
candidate_labels: string[];
/**
* The sentence used in conjunction with `candidate_labels` to attempt the text
* classification by replacing the placeholder with the candidate labels.
*/
hypothesis_template?: string;
/**
Expand Down
33 changes: 13 additions & 20 deletions packages/tasks/src/tasks/zero-shot-classification/spec/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,8 @@
"type": "object",
"properties": {
"inputs": {
"description": "The input text data, with candidate labels",
"type": "object",
"title": "ZeroShotClassificationInputData",
"properties": {
"text": {
"type": "string",
"description": "The text to classify"
},
"candidateLabels": {
"type": "array",
"description": "The set of possible class labels to classify the text into.",
"items": {
"type": "string"
}
}
},
"required": ["text", "candidateLabels"]
"description": "The text to classify",
"type": "string"
},
"parameters": {
"description": "Additional inference parameters",
Expand All @@ -35,16 +20,24 @@
"description": "Additional inference parameters for Zero Shot Classification",
"type": "object",
"properties": {
"candidate_labels": {
"type": "array",
"description": "The set of possible class labels to classify the text into.",
"items": {
"type": "string"
}
},
"hypothesis_template": {
"type": "string",
"description": "The sentence used in conjunction with candidateLabels to attempt the text classification by replacing the placeholder with the candidate labels."
"description": "The sentence used in conjunction with `candidate_labels` to attempt the text classification by replacing the placeholder with the candidate labels."
},
"multi_label": {
"type": "boolean",
"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."
}
}
},
"required": ["candidate_labels"]
}
},
"required": ["inputs"]
"required": ["inputs", "parameters"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@
*/
export interface ZeroShotImageClassificationInput {
/**
* The input image data, with candidate labels
* The input image data to classify as a base64-encoded string.
*/
inputs: ZeroShotImageClassificationInputData;
inputs: string;
/**
* Additional inference parameters
*/
parameters?: ZeroShotImageClassificationParameters;
[property: string]: unknown;
}
/**
* The input image data, with candidate labels
*/
export interface ZeroShotImageClassificationInputData {
/**
* The candidate labels for this image
*/
candidateLabels: string[];
/**
* The image data to classify
*/
image: unknown;
parameters: ZeroShotImageClassificationParameters;
[property: string]: unknown;
}
/**
Expand All @@ -38,8 +24,12 @@ export interface ZeroShotImageClassificationInputData {
*/
export interface ZeroShotImageClassificationParameters {
/**
* The sentence used in conjunction with candidateLabels to attempt the text classification
* by replacing the placeholder with the candidate labels.
* The candidate labels for this image
*/
candidate_labels: string[];
/**
* The sentence used in conjunction with `candidate_labels` to attempt the image
* classification by replacing the placeholder with the candidate labels.
*/
hypothesis_template?: string;
[property: string]: unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,8 @@
"type": "object",
"properties": {
"inputs": {
"description": "The input image data, with candidate labels",
"type": "object",
"title": "ZeroShotImageClassificationInputData",
"properties": {
"image": {
"description": "The image data to classify"
},
"candidateLabels": {
"description": "The candidate labels for this image",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["image", "candidateLabels"]
"type": "string",
"description": "The input image data to classify as a base64-encoded string."
},
"parameters": {
"description": "Additional inference parameters",
Expand All @@ -34,12 +20,20 @@
"description": "Additional inference parameters for Zero Shot Image Classification",
"type": "object",
"properties": {
"candidate_labels": {
"description": "The candidate labels for this image",
"type": "array",
"items": {
"type": "string"
}
},
"hypothesis_template": {
"type": "string",
"description": "The sentence used in conjunction with candidateLabels to attempt the text classification by replacing the placeholder with the candidate labels."
"description": "The sentence used in conjunction with `candidate_labels` to attempt the image classification by replacing the placeholder with the candidate labels."
}
}
},
"required": ["candidate_labels"]
}
},
"required": ["inputs"]
"required": ["inputs", "parameters"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@
*/
export interface ZeroShotObjectDetectionInput {
/**
* The input image data, with candidate labels
* The input image data as a base64-encoded string.
*/
inputs: ZeroShotObjectDetectionInputData;
inputs: string;
/**
* Additional inference parameters
*/
parameters?: {
[key: string]: unknown;
};
parameters: ZeroShotObjectDetectionParameters;
[property: string]: unknown;
}
/**
* The input image data, with candidate labels
* Additional inference parameters
*
* Additional inference parameters for Zero Shot Object Detection
*/
export interface ZeroShotObjectDetectionInputData {
export interface ZeroShotObjectDetectionParameters {
/**
* The candidate labels for this image
*/
candidateLabels: string[];
/**
* The image data to generate bounding boxes from
*/
image: unknown;
candidate_labels: string[];
[property: string]: unknown;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,8 @@
"type": "object",
"properties": {
"inputs": {
"description": "The input image data, with candidate labels",
"type": "object",
"title": "ZeroShotObjectDetectionInputData",
"properties": {
"image": {
"description": "The image data to generate bounding boxes from"
},
"candidateLabels": {
"description": "The candidate labels for this image",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["image", "candidateLabels"]
"description": "The input image data as a base64-encoded string.",
"type": "string"
},
"parameters": {
"description": "Additional inference parameters",
Expand All @@ -33,8 +19,17 @@
"title": "ZeroShotObjectDetectionParameters",
"description": "Additional inference parameters for Zero Shot Object Detection",
"type": "object",
"properties": {}
"properties": {
"candidate_labels": {
"description": "The candidate labels for this image",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["candidate_labels"]
}
},
"required": ["inputs"]
"required": ["inputs", "parameters"]
}
Loading