#language #nlp

bin+lib whichlang

A blazingly fast and lightweight language detection library for Rust

1 unstable release

0.1.0 May 10, 2023

#196 in Internationalization (i18n)

Download history 617/week @ 2024-07-27 662/week @ 2024-08-03 567/week @ 2024-08-10 551/week @ 2024-08-17 589/week @ 2024-08-24 643/week @ 2024-08-31 507/week @ 2024-09-07 465/week @ 2024-09-14 604/week @ 2024-09-21 622/week @ 2024-09-28 607/week @ 2024-10-05 638/week @ 2024-10-12 786/week @ 2024-10-19 818/week @ 2024-10-26 759/week @ 2024-11-02 818/week @ 2024-11-09

3,349 downloads per month
Used in 3 crates

MIT license

745KB
4.5K SLoC

Whichlang

This is a language detection library, aiming for both precision and performance.

Features

  • No dependency
  • Throughput above 100 MB/s for short and long strings.
  • Good accuracy (99.5% on my validation dataset, but it really depends on the size of your input.)

How does it work?

It uses a multiclass logistic regression model over:

  • 2, 3, 4-grams of letters on ASCII
  • codepoint / 128
  • a slightly smarter projection of codepoints over a given class.

We use the hashing trick and project these features over a space of size 4_096.

The logistic regression is trained in the python notebook attached, and used to generate weight.rs.

No runtime deps