Logo for AiToolGo

How Ultimate Built the Most Accurate Language Detection Model for Chatbots

In-depth discussion
Technical
 0
 0
 1
Ultimate, a multilingual AI customer support provider, describes building its own in-house Language Detection model because existing tools fail on short, noisy chat messages. The article explains the challenges (short texts, domain mismatch, English bias, poor calibration), reviews existing tools, and details design choices: fastText with BPE subword tokenization and n-grams, a 145M-sample dataset combining OpenSubtitles with customer-service data, noise removal and token dropout, a greeting dictionary, and overconfidence mitigation. Benchmarks show it outperforms alternatives on accuracy and is fast in production.
  • main points
  • unique insights
  • practical applications
  • key topics
  • key insights
  • learning outcomes
  • • main points

    • 1
      Clearly articulates the specific difficulties of language detection in chat contexts (short messages, greetings, noise, domain mismatch, bias, calibration)
    • 2
      Provides a comparative review of multiple tools with accuracy, speed, and hosting criteria
    • 3
      Benchmarks on both an in-house chat dataset and a generic test set with transparent speed comparisons
  • • unique insights

    • 1
      Using BPE subword tokenization with fastText to handle morphologically rich languages and out-of-vocabulary words without relying on lemmatizers
    • 2
      Applying token dropout to generate noise-robust training samples and to reduce overconfidence, bringing calibration error to around 1%
  • • practical applications

    • Gives engineers building NLP pipelines for conversational or social-media text concrete, reusable techniques (dataset balancing, dropout-based augmentation, greeting dictionaries, calibration checks) for improving short-text classification and deployment speed.
  • • key topics

    • 1
      Language detection for short and noisy chat text
    • 2
      Subword (BPE) tokenization and n-gram features with fastText
    • 3
      Domain adaptation, bias reduction, and model calibration
  • • key insights

    • 1
      Practical end-to-end account of building a production language detector for chat, from problem definition to benchmarking
    • 2
      Combines dataset design, noise-injection via tokenization dropout, and greeting dictionaries in a single pragmatic pipeline
    • 3
      Transparent benchmark tables comparing accuracy and throughput across many open-source and commercial tools
  • • learning outcomes

    • 1
      Understand why language detection fails on short, noisy chat messages and how to diagnose domain mismatch and English bias
    • 2
      Learn how BPE subword tokenization and n-gram features improve fastText-based classifiers for morphologically rich and out-of-vocabulary text
    • 3
      Apply dataset balancing, token-level dropout, and calibration checks to build more accurate and trustworthy classifiers
examples
tutorials
code samples
visuals
fundamentals
advanced content
practical tips
best practices

“ Introduction: Why Language Detection Matters for Multilingual Chatbots

Over the past five years, Ultimate has grown from a monolingual Finnish customer-support solution into a multilingual AI provider. Its language-agnostic model can predict intent in more than 100 languages, regardless of the language of the training data. Yet understanding a language is only half the job: a chatbot must also respond in the visitor's chosen language. This requirement made accurate language detection essential, and because existing market tools did not fit the chat domain, Ultimate set out to build its own Language Detection Model that could become one of the most accurate in the field.

“ What Is Language Detection and Why Chat Makes It Hard

Language detection is the automatic identification of the language present in a document based on its content. It is typically treated as a special case of text categorization and solved with statistical methods. For well-written, long texts, detection is correct over 99% of the time, so it is not among the hardest NLP tasks. Chat is different. Conversational bots mostly handle short interactions, often just a word or a few words. Users also mix languages within a single message, and closely related pairs such as Spanish and Catalan or Serbian and Croatian are difficult to separate. Good performance on short text is therefore the decisive factor.

“ Requirements for a Chat-Ready Language Detection Model

Four requirements guided the selection and design. First, the model had to cover all 109 languages the product supports. Second, it had to be highly accurate even when a message contained only one or two words. Third, it had to be small, keeping costs low. Fourth, it had to run in real time so that language detection would never become a bottleneck in the chat flow.

“ Reviewing Existing Language Detection Tools

Most research on language detection was conducted on long, clean sentences and paragraphs, where results look impressive. The explosion of text messages and social media has changed the picture: slang, misspellings, and acronyms degrade performance sharply. Ultimate reviewed a range of tools, including Lingua, NLLB (a fastText model), Franc, the Google API, Langdetect, Langid, pycld2, gcld3, and fastText's lid.176 variants, comparing cost, hosting, language coverage, general and short-text accuracy, and speed. None could handle short texts quickly, accurately, and across many languages at once, so the team concluded that a ready-to-use solution did not exist and decided to build one in-house.

“ Key Challenges: Short Text, Domain Mismatch, Noise, Bias, and Calibration

Before designing the model, the team identified why general tools fail on chat messages. The first problem is length: short strings often belong to several languages. The word 'api' is Indonesian for 'fire' and an English abbreviation for 'application programming interface.' Chat users also write queries such as 'Login issue' instead of full sentences, and many messages are greetings like 'Hi,' 'Ciao,' or 'Hola,' which appear across languages and can mislead a detector. The second problem is domain mismatch. Most tools were trained on Wikipedia, which features complete sentences and general vocabulary, while customer-support chat uses specialized terms such as 'reset password' or 'delivery issues.' The third problem is noise: typos, abbreviations, missing punctuation, and filler words such as 'um' and 'uh' confuse models, as in 'cn i get ma ordr statos.' The fourth problem is bias. Off-the-shelf models, including the pretrained fastText model, favor English and other European languages because they are overrepresented in training data; fastText, for instance, labels '9999999' as English with 0.357 confidence. The fifth problem is calibration. A well-calibrated model's confidence should match its accuracy, so that predictions made with 0.8 confidence are correct about 80% of the time. Many models are overconfident and wrong with high certainty, which makes them untrustworthy.

“ Designing the Model: Classifier and Tokenization Choices

The team chose fastText as the classifier: it is open source, fast to train and run, simple in architecture, and has already performed well in language identification benchmarks. The harder question was how to feed text into the model. Splitting text into words creates an unmanageably large vocabulary across dozens of languages and fails on inflection-heavy languages such as Finnish and Hungarian, where a single noun can take many forms, and on compound words, abbreviations, and scripts without spaces such as Chinese, Japanese, and Korean. Splitting into characters avoids unknown words but produces many more tokens and makes closely related languages with similar character sets hard to tell apart. The solution was a subword-level approach using Byte-Pair Encoding (BPE). BPE starts from individual characters and repeatedly merges the most frequent adjacent pairs, learning units without any language-specific knowledge. It handles out-of-vocabulary words by breaking them into known subwords, produces shorter sequences than character tokenization, and avoids 'UNK' tokens. Because a standard fastText model treats tokens as an unordered bag and ignores word order, the team also added n-gram representations of the tokens. Since the number of unique n-grams is huge, they applied hashing into a fixed number of buckets (around two million), bounding memory requirements.

“ Solving Domain Mismatch and Bias Through Dataset Design

The most effective remedy for domain mismatch is a training dataset that closely fits the target domain, though in-domain data is often scarce. Ultimate combined two sources. The primary source was OpenSubtitles, a corpus of movie and TV subtitles in many languages, whose natural conversation and short sentences and greetings made it a strong starting point. To close the gap with customer-service language, the team added customer-support data. The final dataset contained around 145 million samples with balanced languages. This careful design improved overall performance, especially on short messages; reduced the domain mismatch with chat; removed languages irrelevant to the business, such as Latin and Esperanto; and eliminated the heavy English bias of the off-the-shelf model.

“ Handling Noise and Greetings

Noise is the easiest problem to attack. The team handled it in two steps. First, text cleaning removed line breaks, tabs, URLs, digits, punctuation, and emojis. Second, to make the model resilient to misspellings, they applied dropout during tokenization: each training sample was tokenized twice with different random subword splits, so that 'this is a sentence' might appear both as one segmentation and as another that splits 'sentence' differently. Greetings required a dedicated solution despite these measures. Ultimate built a greeting dictionary covering 3,500 greetings across all required languages. Each key is a greeting and each value is the list of possible languages ordered by probability, so that 'ciao' maps to Italian, German, and others in ranked order.

“ Building Trust: Model Calibration

A language model must be trustworthy in production, which requires good calibration. The team measured that the fastText model was typically overconfident, meaning it predicted wrong labels with high confidence because it had overfit the data. Two ideas addressed this. The first applied dropout to highly frequent tokens during training to combat overfitting. The second was the tokenization dropout described above. Together these methods made the model far more reliable, bringing its calibration error to roughly 1%.

“ Benchmark Results: Accuracy and Speed

The model was benchmarked against Langdetect, pycld2, gcld3, fastText (large and small), Franc, NLLB, and Lingua. Two datasets were used. The first was an in-house chat dataset of 2,800 samples in English, Spanish, French, Finnish, and German, mostly single words, word pairs, and very short sentences. The second was the Lingua test set, a standardized generic-domain benchmark covering 75 languages with one-word, two-word, and short sentences. Lingua was run in its LowAccuracyMode for speed, and accuracies for 45 languages were taken from its reports for a fair comparison. On the in-house chat dataset, Ultimate's model achieved the best performance, meeting its goal of high accuracy in its own domain. On the Lingua test set, it was also the most accurate, showing that its strength extends to generic text. Speed was measured alongside accuracy because production systems cannot tolerate bottlenecks. The model predicts about 28,359 samples per second, behind only pycld2 (about 418,809), fastText base models (about 92,532 and 165,477), and ahead of Franc, gcld3, and NLLB. Langdetect and Lingua were the slowest.

“ Conclusion and Lessons Learned

Ultimate's journey shows that an older model such as fastText can achieve excellent results when paired with careful training data design, thoughtful text processing, and targeted techniques. The in-house model is the most accurate language detector in both the chat-specific and generic domains, and it is very fast, making language detection nearly solved for long messages and state-of-the-art for short ones. No model is perfect, and there will always be uncertain cases. In those situations, Ultimate's chat platform guides the user toward the best way to connect with the chatbot, preserving the continuity of the conversation.

 Original link: https://rnd.ultimate.ai/blog/language-detection-tips-tricks

Comment(0)

user's avatar

      Related Tools