Library / SDK
pemistahl/lingua-rs avatar
pemistahl/lingua-rs

Four version numbers, one repository, and no neural network

The most accurate natural language detection library for Rust, suitable for short text and mixed-language text

1,154 stars65 forksRustApache-2.0

At a glance

What is it?
Lingua is a Rust library for detecting which language a piece of text is written in, and its selling point is accuracy on short strings rather than scale. The evidence behind that claim is a specific benchmark design, the method is deliberately old-fashioned, and the repository ships four different version numbers for the same code.
Who is it for?
Judgment: Lingua is the right kind of library for a preprocessing step, because it is small, offline, and honest about the two things that usually make language detection libraries annoying, short text and a long language list.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • pemistahl/lingua-rs1,154 ★ · +17
Star history
Repository2026-09-182026-11-23
pemistahl/lingua-rs1.1k1.2k

17 Stars in the last 66 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Four version numbers describe the same codebase

The repository builds a Rust crate and a Python package from one source tree, and each carries its own version. The Cargo manifest declares the crate as `lingua` at version 1.9.0, with edition 2024. The same manifest also carries a workspace package block, and there the version reads 1.3.0, with a workspace whose members are a glob over the language model directories. The Python manifest declares `lingua-language-detector` at 2.3.0, requiring Python 3.12 or newer. And the newest published release is 1.8.0, from March 2026, so the crate version is ahead of any tag. Nothing in the documentation explains the split, and for a user the practical rule is to install by tag and check which artefact you ended up with. The build dependencies are pinned exactly rather than ranged, with maturin at 1.15.0 and pytest at 9.1.1 in the requirements file, which suggests the author treats the Python build path as reproducible.

A cdylib is how a Rust library becomes a Python package

The manifest declares the library with two crate types, a cdylib and an rlib, and that pair is the whole explanation of the Python packaging. The rlib is the normal Rust artefact that other Rust crates link against. The cdylib is a C-compatible dynamic library, which is what a native extension module for CPython has to be, and maturin is the tool that builds and packages it. The repository supports that split with a type stub for the extension, a separate README for the PyPI listing, and its own Python manifest, all in the same tree as the Rust sources. So a Python user installs a wheel containing compiled code and gets its interface described by a stub file rather than by Python source. It is the standard arrangement for a scientific or systems library that wants both audiences, and it does mean the Python install carries a compiler-built artefact with the platform and Python version constraints that implies.

Quality over quantity, and two Norwegian variants

The stated policy is quality over quantity: getting detection right for a small set of languages before adding more. The current count is 75. What is in the list is more informative than the number. Both written Norwegian forms are treated separately, Bokmal and Nynorsk, which doubles the cost of the two for a linguistic distinction most tools collapse. A handful of constructed and historical languages are present: Esperanto and Latin. And a large group of African languages appears, Ganda, Shona, Sotho, Tsonga, Tswana, Xhosa, Yoruba, Zulu and Swahili, which is a much wider net than the usual set of European languages plus Chinese, Japanese and Korean. That distribution is a direct consequence of the method: because the library combines rules with statistical models and uses no dictionary of words, adding a language is a modelling problem rather than a vocabulary problem.

Rule-based plus Naive Bayes, deliberately no neural network

The method is stated as two parts. Lingua draws on rule-based methods and on statistical Naive Bayes methods, and it explicitly does not use neural networks, nor any dictionary of words. It also needs no connection to an external API or service, so once the crate is downloaded it runs completely offline. Configuration is described as close to unnecessary: the library nearly needs none to work. Those four constraints together are what make short text tractable. A neural classifier trained on sentences learns a distribution over word shapes that a five-character word barely samples, whereas Naive Bayes over character or script features and a set of orthographic rules can produce a decision from very little evidence. The no-dictionary constraint is the interesting one for a language with a large vocabulary and unusual orthography, since it removes the failure mode where a word simply is not in the list.

The complaints about rival libraries are specific

Three other Rust libraries are named as comprehensive alternatives: CLD2, Whatlang and Whichlang. Two drawbacks are attributed to them, and both are concrete rather than matters of taste. The first is that detection only works with quite lengthy text fragments, so for very short snippets such as social media messages they do not give adequate results. The second is that the more languages take part in the decision process, the less accurate the results become. Both are real properties of the approach rather than bugs in a particular implementation, and Lingua's answer is to constrain the language set and work on short strings. One detail about the README's voice is worth noting if you read it closely: the library is repeatedly referred to in the feminine, with sentences about what she does and what she needs, which is a stylistic choice that runs through the whole document.

The accuracy comparison is restricted to sixteen languages to stay fair

The benchmark section is the most careful part of the documentation. The test data for each language is split three ways: single words with a minimum length of five characters, word pairs with a minimum length of ten characters, and complete grammatical sentences of various lengths. The models and the test data were built from separate documents of the Wortschatz corpora offered by Leipzig University. Training used data crawled from news websites, one million sentences per corpus; testing used corpora from arbitrarily chosen websites, ten thousand sentences each, from which a random unsorted subset of a thousand items per category was drawn. The comparison runs Lingua against the three rivals over its own 75 languages, ignoring languages a rival does not support. The fairness correction is the part to note: the first box plots cover all languages, which makes Whichlang look best, but Whichlang supports only 16 languages, so the last two plots in every section restrict both Whatlang and Lingua to that same set of 16.

Single-word accuracy is measured on words of five characters or more

The minimum lengths in the test design are easy to skim past and they bound what the headline numbers mean. Single-word detection is evaluated on words of at least five characters, and word-pair detection on pairs of at least ten. There is no bucket for a two-letter token, no bucket for a single character, and no mixed-language bucket even though mixed-language text is named in the package description as a target use case. So the accuracy figures describe behaviour on words with enough surface to classify, which is the case that matters for routing and preprocessing and is not the case that matters for a chat message of three words. The presentation itself also defers the evidence: each section's plots sit inside collapsed detail elements, so the numbers behind the most-accurate-in-this-comparison conclusion are not visible without expanding them.

One workspace member per language model, and a gated report binary

The repository layout explains a lot about the build. The Cargo workspace takes its members from a glob over the language models directory, so each language's model is compiled as its own crate rather than being a data file loaded at runtime, which is what lets the whole thing work with no configuration and no external files to ship alongside. Alongside it sit an accuracy reports directory, a tables directory, an images directory, a benchmarks directory and a tests directory. There is also a binary named for the accuracy reports, and it is gated behind a required feature, so it does not build unless you ask for it. The development profile is compiled at optimisation level one rather than zero, a small choice that reflects how much time is spent in test and report code. Release notes are kept in their own file at the root, and the licence is Apache 2.0.

Editorial conclusion

Judgment: Lingua is the right kind of library for a preprocessing step, because it is small, offline, and honest about the two things that usually make language detection libraries annoying, short text and a long language list. The comparison against CLD2, Whatlang and Whichlang is worth reading for its structure rather than its conclusion, since the author restricts the final plots to the sixteen languages all four tools support precisely so the comparison is fair, which is rarer than it should be. Two things to check before you adopt it. The single-word accuracy numbers are measured on words of at least five characters, so a two-letter token is outside the evidence. And the version numbers are a mess: the Rust crate, the newest tag, the workspace package and the Python package all carry different numbers, so pin by tag and read which artefact you actually installed. For Python users, remember it is a compiled extension, not a pure-Python package.

Frequently asked questions

What does lingua-rs do?

It tells you which language a piece of text is written in, which makes it useful as a preprocessing step for text classification, spell checking, or routing mail to a customer service department in the sender's language. It also handles short text and mixed-language text.

How does Lingua detect languages without a neural network?

It combines rule-based methods with statistical Naive Bayes methods, and explicitly uses no neural networks and no dictionaries of words. It needs no external API or service, so it runs entirely offline once downloaded, and requires almost no configuration.

Which languages does Lingua support?

Seventy-five, chosen on a quality over quantity policy. The list separates Bokmal and Nynorsk Norwegian, includes Esperanto and Latin, and covers a wide set of African languages including Ganda, Shona, Sotho, Tsonga, Tswana, Xhosa, Yoruba, Zulu and Swahili.

How is Lingua's accuracy measured?

Per language, on bundled test data split into single words of at least five characters, word pairs of at least ten characters, and complete sentences. Models and test data come from separate Wortschatz corpora, with training on news-site corpora of a million sentences and testing on ten thousand sentence corpora. Comparisons with CLD2, Whatlang and Whichlang are restricted to the sixteen languages all four support.

Can I use Lingua from Python?

Yes, as the lingua-language-detector package on PyPI, requiring Python 3.12 or newer. It is a compiled extension rather than pure Python, built from the same source as the Rust crate with maturin, and the repository ships a separate README for the PyPI listing.

Official sources

  1. Issues
  2. License: Apache-2.0
  3. pemistahl/lingua-rs on GitHub
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/pemistahl-lingua-rs.svg)](https://hysenlabs.com/projects/pemistahl-lingua-rs)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/pemistahl-lingua-rs.svg)](https://hysenlabs.com/projects/pemistahl-lingua-rs)

Was this useful?