Cloudflare Docs
Workers AI
Edit this page on GitHub
Set theme to dark (⇧+D)

distilbert-sst-2-int8

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

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

More Information  

​​ Properties

Task Type: Text Classification

​​ Code Examples

Worker - TypeScript
export interface Env {
AI: Ai;
}
export default {
async fetch(request: Request, env: Env) {
const response = await env.AI.run(
"@cf/huggingface/distilbert-sst-2-int8",
{
text: "This pizza is great!",
}
);
return Response.json(response);
},
};
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
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"
}
},
"required": [
"text"
]
}
Output JSON Schema
{
"type": "array",
"contentType": "application/json",
"items": {
"type": "object",
"properties": {
"score": {
"type": "number"
},
"label": {
"type": "string"
}
}
}
}