# Few-shot text classifier

Classify text from labeled examples. Choose TF-IDF, nearest-neighbor or centroid scoring, then get predictions, confidence and explanations.

## Run it

- **CLI:** `gizza tool few-shot-text-classifier "billing,invoice charge refund
billing,subscription payment failed
support,password reset login issue
support,account locked cannot sign in" 'text=I cannot sign in after resetting my password.'`
- **Web:** https://gizza.ai/tools/few-shot-text-classifier/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/few-shot-text-classifier/tool.json

## Inputs

- `examples` — Labeled examples _(field)_
- `text` — Text to classify _(field)_
- `separator` — Example separator _(field)_
- `input_mode` — Classify text as _(field)_
- `method` — Decision method _(field)_
- `k` — Nearest examples (k) _(field)_
- `similarity` — Similarity metric _(field)_
- `weighting` — Feature weighting _(field)_
- `analyzer` — Feature analyzer _(field)_
- `ngram_max` — Maximum n-gram length _(field)_
- `lowercase` — Lowercase before tokenizing _(field)_
- `strip_accents` — Strip accented Latin letters _(field)_
- `remove_stopwords` — Remove English stop words _(field)_
- `sublinear_tf` — Use sublinear term frequency _(field)_
- `min_df` — Minimum example frequency _(field)_
- `min_confidence` — Minimum confidence _(field)_
- `top_k` — Labels to show _(field)_
- `explain` — Show explanation terms _(field)_
- `output` — Output format _(field)_

## Output

- Classification result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `examples` — Labeled examples
- `text` — Text to classify
- `separator` — Example separator
- `input_mode` — Classify text as
- `method` — Decision method
- `k` — Nearest examples (k)
- `similarity` — Similarity metric
- `weighting` — Feature weighting
- `analyzer` — Feature analyzer
- `ngram_max` — Maximum n-gram length
- `lowercase` — Lowercase before tokenizing
- `strip_accents` — Strip accented Latin letters
- `remove_stopwords` — Remove English stop words
- `sublinear_tf` — Use sublinear term frequency
- `min_df` — Minimum example frequency
- `min_confidence` — Minimum confidence
- `top_k` — Labels to show
- `explain` — Show explanation terms
- `output` — Output format

Example: `https://gizza.ai/tools/few-shot-text-classifier/?examples=billing%2Cinvoice%20charge%20refund%0Abilling%2Csubscription%20payment%20failed%0Asupport%2Cpassword%20reset%20login%20issue%0Asupport%2Caccount%20locked%20cannot%20sign%20in&text=I%20cannot%20sign%20in%20after%20resetting%20my%20password.&separator=auto&input_mode=single&method=centroid&k=3&similarity=cosine&weighting=tfidf&analyzer=word&ngram_max=1&lowercase=true&strip_accents=true&remove_stopwords=true&sublinear_tf=true&min_df=1&min_confidence=0.0&top_k=3&explain=true&output=report`

---

## About this tool

`few-shot-text-classifier` labels text from a small set of examples that you provide at run time. Paste one labeled example per line, such as `billing,invoice charge refund`, then paste the document or list of lines you want classified. The tool builds a deterministic local similarity model from that support set and returns the predicted label, confidence, per-label scores, shared terms, and nearest example.

This is useful for quick triage and lightweight labeling: support tickets, feedback themes, short content moderation queues, routing emails into buckets, or testing whether a proposed label taxonomy is separable before you train a larger model. It does not call an API, download embeddings, or learn a persistent model. Every run uses only the examples in the **Labeled examples** box.

### Worked example

With these examples:

```text
billing,invoice charge refund
billing,subscription payment failed
support,password reset login issue
support,account locked cannot sign in
sales,pricing quote enterprise plan
sales,demo request for buying team
```

and this text:

```text
I cannot sign in after resetting my password.
```

the default centroid + cosine + TF-IDF settings predict `support`, show the support score above the other labels, and list terms such as `password` and `sign` as the explanation. Switch **Classify text as** to **One document per non-blank line** to batch-label a list and choose **CSV** when you want one result row per input line.

### Options and limits

- **Labeled examples** must contain at least two distinct labels. Each non-empty line is split into `label` and `text` using tab, comma, pipe, or colon; **Auto** chooses the separator that appears on the most lines. Lines beginning with `#` are ignored. The examples input is capped at 1 MiB, 5,000 examples, and 200 labels.
- **Decision method** controls how label scores are built. **Label centroids** averages each label's examples and is the steadier default. **k nearest examples** lets the closest `k` examples vote by similarity. **Best single example** lets one very close example win for its label.
- **Similarity metric** can be cosine, dot product, inverted Euclidean distance, or Jaccard term overlap. Cosine is usually best for text of uneven length. Jaccard compares term sets only, so it ignores the weighting option.
- **Feature weighting** can be TF-IDF, raw term frequency, or binary presence. TF-IDF downweights words that appear across many examples; binary helps when every input is very short.
- **Feature analyzer** can use word n-grams or character n-grams. Character n-grams with length 3-5 are handy for typos, short names, and languages that do not use spaces between words.
- **Lowercase**, **Strip accents**, **Remove English stop words**, **Sublinear term frequency**, and **Minimum example frequency** tune how the vocabulary is prepared before scoring.
- **Minimum confidence** reports `uncertain` instead of the top label when the winner's vote share is below the threshold. Confidence is a relative vote share across labels, not a calibrated probability.
- **Labels to show** controls the score table; `0` lists every label. **Show explanation terms** adds the strongest shared terms and nearest example.
- **Text to classify** is capped at 256 KiB. Batch mode classifies up to 1,000 non-blank lines.
- This is a lexical similarity classifier, not a semantic embedding model. It will not infer that `refund` and `reimbursement` match unless similar words appear in your examples. Add representative examples, use character n-grams for typo tolerance, or lower the confidence threshold when labels are intentionally broad.

## FAQ

<details>
<summary>How many examples do I need per label?</summary>

Two examples per label is the practical minimum; three to eight per label is a better starting point. Include the words and phrases you expect to see at classification time. If a label covers several different topics, use **k nearest examples** or add examples for each subtopic so one centroid is not trying to average unrelated language.

</details>

<details>
<summary>Is this the same as an embedding or LLM classifier?</summary>

No. It uses local lexical features — word or character n-grams with TF-IDF, term frequency, or binary weights — and similarity scoring. That makes it fast, deterministic, private, and transparent, but it does not understand synonyms or paraphrases unless your examples contain overlapping features. For semantic generalisation, use a real embedding or model workflow outside this pure local tool.

</details>

<details>
<summary>Why did it return `uncertain`?</summary>

`uncertain` means the best label did not clear the **Minimum confidence** threshold, or the input shared no vocabulary with the support set. Lower the threshold to always return the top label, add examples that contain the input vocabulary, or inspect the label score table to see which labels were close. Confidence is the label's share of the vote weight for this support set, not a probability calibrated on held-out data.

</details>

<details>
<summary>Can I paste CSV examples?</summary>

Yes for simple two-column data. Choose **Comma** as the separator, or leave **Auto** if comma is the dominant separator. The first separator on each line divides the label from the text, so the text may contain more separators after that point. One layer of surrounding double quotes is stripped and doubled quotes are unescaped, which covers common spreadsheet pastes, but this is not a full RFC 4180 CSV importer with multi-line quoted cells.

</details>

<details>
<summary>Does any text leave my machine?</summary>

No. The classifier core is compiled to WebAssembly for this page and runs in the browser, and the same Rust code is used by the local CLI. There is no network request, model download, remote training job, or saved model. Refreshing the page forgets the support set.

</details>

## Related tools

- [Train a local Naive Bayes text classifier](https://gizza.ai/tools/naive-bayes-text-classifier/): Train a naive Bayes classifier from labeled examples, then classify text with multinomial, Bernoulli, or complement scoring and token explanations.
- [RAKE Keyword Extractor](https://gizza.ai/tools/rake-keywords/): Extract the top keywords and keyphrases from any document using the RAKE algorithm — ranked by relevance, right in your browser. Nothing is uploaded.
- [Decision tree classifier](https://gizza.ai/tools/decision-tree-classifier/): Train a CART, ID3, or C4.5-style decision tree from a pasted CSV table and read the if/then rules, feature importance, accuracy, and predictions.
- [Topic Modeler](https://gizza.ai/tools/topic-modeler/): Discover latent topics across pasted documents with deterministic browser-local LDA, including topic word lists, document mixtures, JSON, and CSV output.
- [ARFF Converter](https://gizza.ai/tools/arff-converter/): Convert Weka ARFF datasets to CSV and CSV tables back to ARFF locally — nominal attributes, numeric types, dates, sparse rows, missing values, and type rows.
