Skip to content

distilbert-sst-2-int8

Model ID: @cf/huggingface/distilbert-sst-2-int8

Distilled BERT model that was finetuned on SST-2 for sentiment classification

Properties

Task Type: Text Classification

Code Examples

Workers - Typescript

export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const response = await env.AI.run(
"@cf/huggingface/distilbert-sst-2-int8",
{
text: "This pizza is great!",
}
);
return Response.json(response);
},
} satisfies ExportedHandler<Env>;

Python

API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/"
headers = {"Authorization": "Bearer {API_KEY}"}
def run(model, input):
response = requests.post(f"{API_BASE_URL}{model}", headers=headers, json=input)
return response.json()
output = run("@cf/huggingface/distilbert-sst-2-int8", { "text": "This pizza is great!" })
print(output)

curl

Terminal window
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/huggingface/distilbert-sst-2-int8 \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{ "text": "This pizza is great!" }'

Response

{
"items": [
{
"label": "POSITIVE",
"score": 0.9998738765716553
},
{
"label": "NEGATIVE",
"score": 0.00012611268903128803
}
]
}

API Schema

The following schema is based on JSON Schema

Input JSON Schema

{
"type": "object",
"properties": {
"text": {
"type": "string",
"minLength": 1
}
},
"required": [
"text"
]
}

Output JSON Schema

{
"type": "array",
"contentType": "application/json",
"items": {
"type": "object",
"properties": {
"score": {
"type": "number"
},
"label": {
"type": "string"
}
}
}
}