AI Text Classifier
Run sentiment analysis on text right in your browser. Get positive/negative classification and confidence scores with a local DistilBERT model.
This AI text classifier runs a machine learning model directly in your browser to determine whether text expresses positive or negative sentiment. It uses DistilBERT fine-tuned on the Stanford Sentiment Treebank (SST-2), loaded via Transformers.js with WebAssembly inference. No server calls, no API keys, and no data leaves your device. Paste any English text and get a confidence score within seconds.
About AI Text Classifier
How Does Browser-Based Sentiment Analysis Work?
Traditional sentiment analysis requires sending text to a cloud API, which raises privacy concerns and costs money per request. This tool takes a different approach by running the entire model locally. On first use, the browser downloads approximately 67 MB of model weights from a CDN and caches them. Every analysis after that runs entirely on your CPU through WebAssembly, with no network requests.
| Step | What Happens |
|---|---|
| 1. Model loading | On first use, ~67 MB of DistilBERT weights download and cache in your browser via ONNX Runtime |
| 2. Tokenization | Your text is split into subword tokens using the BERT WordPiece tokenizer (vocabulary of 30,522 tokens) |
| 3. Encoding | Tokens are converted to numerical IDs with positional embeddings added |
| 4. Inference | The model processes the token sequence through 6 transformer encoder layers via WebAssembly |
| 5. Classification | A linear classification head maps the [CLS] token output to two logits (positive and negative) |
| 6. Softmax | Logits are converted to probabilities that sum to 100% |
| 7. Results | The label with the higher probability is shown alongside confidence bars |
The inference engine is ONNX Runtime compiled to WebAssembly, which runs at near-native speed in modern browsers. Transformers.js v3 added WebGPU support as well, though this tool uses the WASM backend for maximum browser compatibility. A single sentence typically classifies in under 200 milliseconds once the model is loaded.
What Is DistilBERT?
DistilBERT was introduced in 2019 by Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf at Hugging Face. The paper, presented at the EMC2 workshop at NeurIPS 2019, demonstrated that knowledge distillation could compress BERT into a model with 40% fewer parameters while retaining 97% of its language understanding ability. The distilled model runs 60% faster than BERT-base on comparable hardware.
Knowledge distillation works by training a smaller "student" model to mimic the outputs of a larger "teacher" model. The DistilBERT authors used a triple loss function combining language modelling loss, distillation loss (soft target probabilities from the teacher), and a cosine distance loss between hidden state representations. This approach preserved far more of BERT's capability than simply training a smaller model from scratch.
| Property | DistilBERT | BERT-base |
|---|---|---|
| Parameters | 66 million | 110 million |
| Transformer layers | 6 | 12 |
| Hidden size | 768 | 768 |
| SST-2 accuracy | 91.3% | 92.7% |
| Inference speed | ~60% faster | Baseline |
| Model file size | ~67 MB (ONNX) | ~440 MB |
The version used here was fine-tuned on SST-2, a widely used English sentiment benchmark. SST-2 is a binary classification subset of the Stanford Sentiment Treebank, originally published by Socher et al. in 2013. The dataset contains 67,349 phrases extracted from 11,855 movie review sentences sourced from Rotten Tomatoes, each labelled as positive or negative by human annotators.
Understanding Confidence Scores
The model outputs a probability distribution across two classes. A result of "92% positive" means the model assigns a 0.92 probability to the positive class and 0.08 to negative. These probabilities always sum to 1.0 (100%). Higher confidence generally means the text contains clearer sentiment signals.
| Confidence Range | What It Means | Example Text |
|---|---|---|
| 95-100% | Strong, unambiguous sentiment - the model is very certain | "This product is absolutely amazing, best purchase I've ever made" |
| 80-95% | Clear sentiment with minor ambiguity | "Really good experience overall, would recommend" |
| 65-80% | Moderate confidence - text may contain mixed signals | "It was okay, nothing special but not bad either" |
| 50-65% | Low confidence - the model is nearly guessing. Treat results with caution | "Great food but awful service and a long wait" |
Scores below 65% often indicate genuinely mixed sentiment rather than a model failure. A review that praises a restaurant's food but criticises the service contains real contradictory signals. For these cases, the raw confidence percentages are more informative than the positive/negative label alone.
Batch Analysis Mode
For analysing multiple texts at once, put each text on a separate line. The tool runs inference on each line individually and displays all results together with colour-coded labels. This is practical for scanning a list of product reviews, survey responses, or social media comments without copying them one at a time.
| Batch Size | Typical Processing Time | Best For |
|---|---|---|
| 1-10 texts | 1-3 seconds | Quick spot checks on a handful of reviews or comments |
| 10-50 texts | 3-15 seconds | Scanning a page of survey responses or support tickets |
| 50-100 texts | 15-45 seconds | Bulk analysis of an export from a review platform |
Processing time depends on text length and your device's CPU speed. Shorter sentences classify faster because the tokenizer produces fewer tokens for the model to process. The 512-token input limit is a BERT architecture constraint - texts longer than roughly 400 words get truncated before classification.
Practical Use Cases
The global sentiment analytics market was valued at roughly $5.7 billion in 2025, according to Precedence Research, reflecting how central opinion mining has become across industries. While enterprise teams typically use API-based services, this browser tool provides a quick, private way to run the same underlying NLP technique on smaller datasets.
| Use Case | How It Helps |
|---|---|
| Customer review analysis | Sort reviews by sentiment before reading them - spot negative outliers in a batch of mostly positive feedback |
| Social media monitoring | Paste mentions or comments about a brand and check the overall tone without a paid tool |
| Support ticket triage | Identify angry or frustrated messages that need priority response |
| Survey response screening | Flag negative free-text responses for follow-up before reading every answer |
| Content tone checking | Verify that marketing copy, emails, or announcements read as positive rather than inadvertently negative |
| NLP education | See a real transformer model classify text without writing code or setting up a Python environment |
For understanding how tokenizers break text into subwords before classification, the AI token counter shows exact token counts and boundaries. To estimate API costs if you need sentiment analysis at scale, the AI pricing calculator compares per-token pricing across providers. And for checking overall text quality alongside sentiment, the readability score tool measures reading level and complexity.
Known Limitations
No model is perfect, and DistilBERT has well-documented blind spots. Understanding these helps interpret results more accurately.
| Limitation | Details |
|---|---|
| English only | Trained exclusively on English text. Other languages produce unreliable results. A multilingual model like XLM-RoBERTa would be needed for non-English text. |
| Binary classification | Only positive vs negative. There is no neutral class, no emotion detection (anger, joy, sadness), and no intensity scale beyond the confidence percentage. |
| Short text bias | SST-2 training data consists of single movie review sentences. Very long texts (paragraphs or full articles) get truncated at 512 tokens, so only the opening portion influences the result. |
| Sarcasm and irony | Sarcastic statements like "Oh great, another meeting" tend to be classified as positive because the surface-level words are positive. Detecting sarcasm requires pragmatic reasoning that this model architecture does not support. |
| Domain-specific language | Medical, legal, or highly technical text uses vocabulary that may not appear in the model's training data. Clinical terms, legal jargon, or code-related text may produce low-confidence or incorrect results. |
| Negation handling | Complex negation chains ("I wouldn't say it wasn't good") can sometimes confuse the model. Simple negations ("not good") are generally handled correctly. |
Tips for Better Results
The model was trained on single sentences from movie reviews, so input that resembles short opinion statements tends to classify most accurately. A few practical tips can improve the quality of results.
Keep inputs to one idea per line. A sentence like "The camera is excellent but the battery life is terrible" contains both positive and negative signals, and the model has to pick one label for the whole input. Splitting it into two lines ("The camera is excellent" and "The battery life is terrible") produces more accurate per-topic results.
Remove boilerplate and greetings. Text like "Hi team, hope you're well" at the start of an email adds neutral noise that dilutes the sentiment signal from the actual message content. Trim down to the opinion-bearing sentences before analysing.
Watch for domain mismatch. The model was trained on movie reviews, which use colloquial English. Formal business language, medical terminology, or legal text may produce low-confidence scores not because the sentiment is ambiguous, but because the vocabulary is unfamiliar to the model. Scores below 65% on professional text should be treated as "uncertain" rather than taken at face value.
Use batch mode for comparison. When analysing a set of customer reviews, the relative ranking of confidence scores is often more useful than the absolute values. A review scored at 88% positive is probably more positive than one scored at 62% positive, even if both carry the same "POSITIVE" label.
How Does This Compare to API-Based Sentiment Analysis?
Cloud APIs from providers like Google Cloud Natural Language, AWS Comprehend, and Azure Text Analytics offer more advanced features - multi-language support, entity-level sentiment, and fine-grained emotion categories. They also charge per request, which adds up when processing thousands of texts. This browser tool trades those advanced features for complete privacy and zero cost. No API key is needed, no text leaves the browser, and there are no usage limits.
| Feature | This Tool (Browser) | Cloud APIs |
|---|---|---|
| Privacy | Text never leaves your device | Text sent to provider servers |
| Cost | Free, unlimited | $1-3 per 1,000 requests typical |
| Setup | None - works instantly | API key, SDK, billing account |
| Languages | English only | 20-100+ languages |
| Classification | Binary (positive/negative) | Multi-class, entity-level, aspect-based |
| Throughput | Limited by CPU speed | Thousands of requests per second |
| Offline use | Works after first model download | Requires internet connection |
For quick checks on English text where privacy matters, the browser approach is ideal. For production-scale multilingual analysis, a cloud API or self-hosted model is the better choice.
Sources
- Sanh et al. - DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter (2019)
- Hugging Face - distilbert-base-uncased-finetuned-sst-2-english model card
- Hugging Face - Transformers.js documentation
- Stanford NLP - SST-2 dataset
- Precedence Research - Sentiment Analytics Market Size (2025)
Frequently Asked Questions
Does this tool send my text to a server?
No. The entire AI model runs in your browser. Your text never leaves your device. The model file is downloaded once from a CDN and cached locally for future visits.
Why does the first analysis take so long?
On first use, the tool downloads a ~67 MB machine learning model. This only happens once. Your browser caches the model, so subsequent visits load it from the cache almost instantly.
What model does this tool use?
It uses DistilBERT fine-tuned on the SST-2 dataset, a well-known English sentiment benchmark. The model was converted to run in browsers via Transformers.js by Xenova.
Can I analyze text in languages other than English?
The model was trained on English text, so it works best with English input. Results for other languages may be unreliable. For non-English sentiment analysis, a multilingual model would be needed.
How does batch mode work?
Put each text on a separate line in the input box and click Analyze. The tool runs sentiment analysis on each line individually and shows all results at once.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/ai-text-classifier/" title="AI Text Classifier - Free Online Tool">Try AI Text Classifier on ToolboxKit.io</a>