React
Classification
Hooks for text classification, zero-shot classification, and NER.
Classification Hooks
See it in action
Try Sentiment Analyzer and Email Classifier for working demos of these hooks.
useClassify
Classify text into predefined categories.
import { useClassify } from '@localmode/react';
import { transformers } from '@localmode/transformers';
const model = transformers.classifier('Xenova/distilbert-base-uncased-finetuned-sst-2-english');
function Demo() {
const { data, isLoading, execute } = useClassify({ model });
return (
<div>
<button onClick={() => execute('I love this!')}>Classify</button>
{data && <p>{data.label}: {(data.score * 100).toFixed(1)}%</p>}
</div>
);
}useClassifyZeroShot
Classify text with custom labels — no model fine-tuning required.
import { useClassifyZeroShot } from '@localmode/react';
const { data, execute } = useClassifyZeroShot({ model });
await execute({ text: 'The server is down', candidateLabels: ['bug', 'feature', 'question'] });
// data.labels = [{ label: 'bug', score: 0.89 }, ...]useExtractEntities
Extract named entities (NER) from text.
import { useExtractEntities } from '@localmode/react';
const { data, execute } = useExtractEntities({ model });
await execute('John works at Google in Seattle');
// data.entities = [{ entity: 'PER', word: 'John' }, { entity: 'ORG', word: 'Google' }, ...]For full API reference, see the Core Classification guide.