demo · v130

Batch Classifier

Process a list of product reviews, social-media posts, or any text snippets through the LanguageDetector in one go. The API is created once and reused — each item is detected sequentially, showing results as they arrive.

requires Built-in AI / Language Detection Enable chrome://flags/#language-detection-api in Chrome 130+, or join the Built-in AI origin trial. Falls back to a character-script heuristic so the demo always runs.

items to classify

the code

// One detector, many texts — amortise initialisation cost
const detector = await LanguageDetector.create();

async function classifyBatch(texts) {
  const results = [];
  for (const text of texts) {
    const [top] = await detector.detect(text);
    results.push({ text, lang: top.detectedLanguage, confidence: top.confidence });
  }
  return results;
}

// Or in parallel for maximum throughput:
const results = await Promise.all(
  texts.map(async (t) => {
    const [top] = await detector.detect(t);
    return { text: t, lang: top.detectedLanguage, confidence: top.confidence };
  })
);

see also