This is a .NET wrapper for the FastText library by Facebook AI Research (FAIR). This package facilitates the integration of language identification capabilities into .NET applications, leveraging the powerful and efficient FastText library to recognize and classify texts in multiple languages. Ideal for applications that require fast and accurate language detection.
$ dotnet add package Panlingo.LanguageIdentification.FastTextWelcome to Panlingo.LanguageIdentification.FastText, a .NET wrapper for the FastText library by Facebook AI Research (FAIR). This package seamlessly integrates language identification capabilities into .NET applications, leveraging the powerful and efficient FastText library to recognize and classify texts in multiple languages. Ideal for applications that require fast and accurate language detection.
To integrate the FastText functionality, follow these steps:
Install the NuGet package:
dotnet add package Panlingo.LanguageIdentification.FastText
Integrating the FastText library into your .NET application is straightforward. Here’s a quick guide to get you started:
Panlingo.LanguageIdentification.FastText package to your project using the provided installation command.using Panlingo.LanguageIdentification.FastText;
class Program
{
static void Main()
{
using var fastText = new FastTextDetector();
fastText.LoadDefaultModel();
var predictions = fastText.Predict(
text: "Привіт, як справи?",
count: 10
);
foreach (var prediction in predictions)
{
Console.WriteLine($"{prediction.Label}: {prediction.Probability}");
}
var dimensions = fastText.GetModelDimensions();
var labels = fastText.GetLabels();
}
}
The default model for this package is quantized lid.176.ftz (see below).
You can use the default model by calling the LoadDefaultModel() method.
We recommend using the following models, but you can use any model depending on your needs. It could even be a model for another text classinfiction tasks, e.g: supervised models
| Model | Vendor | Languages | Label format | Learn more | Download |
|---|---|---|---|---|---|
| lid.176 | Meta Platforms, Inc. | 176 | __label__en __label__uk __label__hi | fasttext.cc | lid.176.bin |
| lid218e | Meta Platforms, Inc. | 217 | __label__eng_Latn __label__ukr_Cyrl __label__hin_Deva | @facebook/fasttext-language-identification | model.bin |
| GlotLID | CIS, LMU Munich | 2155(?) | __label__eng_Latn __label__ukr_Cyrl __label__hin_Deva | @cis-lmu/glotlid | model_v3.bin |
You can use the model included in this NuGet package:
using var fastText = new FastTextDetector();
fastText.LoadDefaultModel();
You can specify the path to the model file:
using var fastText = new FastTextDetector();
var modelPath = "/path/to/model/fasttext176.bin";
fastText.LoadModel(modelPath);
Also you can also load the model as a memory stream:
using var fastText = new FastTextDetector();
var modelPath = "/path/to/model/fasttext176.bin";
using var stream = File.Open(modelPath, FileMode.Open);
fastText.LoadModel(stream);
If you are exploring other options, here are some alternatives to consider:
This project is licensed under the MIT License © 2024–2025 Alexander Gluschenko.
Includes software from the following project(s):
See the LICENSE file for full details.
We value your feedback. Feel free to open issues or contribute to the repository. Let’s make language detection in .NET even more powerful and versatile! 🌍📝
Happy coding! 👩💻👨💻
Stay updated by following our repository. For any inquiries or support, reach out through the issues page.