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();
}
}
Depending on your needs, download one of the pretrained language identification (LID) models provided by Facebook:
For the LID model with 176 languages:
curl --location -o /models/fasttext176.bin https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin
For the LID model with 217 languages:
curl --location -o /models/fasttext217.bin https://huggingface.co/facebook/fasttext-language-identification/resolve/main/model.bin?download=true
Learn more about these models here:
using var fastText = new FastTextDetector();
var modelPath = "/models/fasttext176.bin";
fastText.LoadModel(modelPath);
OR
using var fastText = new FastTextDetector();
var modelPath = "/models/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:
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.