FastText<T>

Models & Types · AiDotNet.NeuralNetworks

FastText neural network implementation, an extension of Word2Vec that considers subword information.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → TextEmbeddingModelLayoutBase<T> → FastText<T>

Implements: IEmbeddingModel<T>

For Beginners

Most models see words like “playing” and “played” as completely different things. FastText is smarter: it breaks words into pieces (like “play”, “ing”, and “ed”). Because it knows what “play” means, it can guess the meaning of a new word like “player” even if it has never seen it before. It’s like a person who can understand a complex new word by looking at its root and its suffix.

How It Works

FastText is a library for learning of word representations and sentence classification. It improves upon the original Word2Vec by representing each word as a bag of character n-grams. This approach allows the model to compute word representations for words that did not appear in the training data (out-of-vocabulary words).

Example

var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var input = Tensor<float>.CreateRandom(new[] { 1, 50 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new FastText<float>(architecture))
    .Build(trainX, trainY);
var embedding = result.Predict(input);

Constructors

Constructor Summary
FastText() Initializes a new instance with default architecture settings.
FastText(NeuralNetworkArchitecture<T> architecture, FastTextOptions options, ITokenizer tokenizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the FastText model.

Properties

Property Summary
int EmbeddingDimension { get; }
int MaxTokens { get; }

Methods

Method Summary
Matrix<T> EmbedBatch(IEnumerable<string> texts) Encodes a batch of texts for high-throughput processing.
ModelMetadata<T> GetModelMetadata() Retrieves detailed metadata about the FastText model configuration.
Task<Matrix<T>> EmbedBatchAsync(IEnumerable<string> texts)
Task<Vector<T>> EmbedAsync(string text)
Tensor<T> Forward(Tensor<T> input) Performs a forward pass to retrieve representations.
Vector<T> Embed(string text) Turns text into a robust embedding vector using both word and subword information.