Skip to content

distilbert-sst-2-int8

Text ClassificationHuggingFace
@cf/huggingface/distilbert-sst-2-int8

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

    Usage

    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!" }'

    Parameters

    Input

    • text string min 1

      The text that you want to classify

    Output

    • items object

      • score number

        Confidence score indicating the likelihood that the text belongs to the specified label

      • label string

        The classification label assigned to the text (e.g., 'POSITIVE' or 'NEGATIVE')

    API Schemas

    The following schemas are based on JSON Schema

    {
    "type": "object",
    "properties": {
    "text": {
    "type": "string",
    "minLength": 1,
    "description": "The text that you want to classify"
    }
    },
    "required": [
    "text"
    ]
    }