GloVe<T>

Models & Types · AiDotNet.NeuralNetworks

GloVe (Global Vectors for Word Representation) neural network implementation.

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

Implements: IEmbeddingModel<T>

For Beginners

If Word2Vec is like a student learning from reading newspapers one page at a time, GloVe is like a researcher who looks at the entire library all at once. It builds a giant table showing how often every word in the dictionary appears near every other word. It then uses clever math to find the best “address” for each word so that the distance between addresses matches those counts perfectly.

How It Works

GloVe is an unsupervised learning algorithm for obtaining vector representations for words. Training is performed on aggregated global word-word co-occurrence statistics from a corpus, and the resulting representations showcase interesting linear substructures of the word vector space.

The GloVe model is famous for its ability to solve word analogies, like: “King - Man + Woman = Queen.”

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 GloVe<float>(architecture))
    .Build(trainX, trainY);
var embedding = result.Predict(input);

Constructors

Constructor Summary
GloVe() Initializes a new instance of the GloVe embedding model.
GloVe(NeuralNetworkArchitecture<T> architecture, GloVeOptions options, ITokenizer tokenizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the GloVe model.

Properties

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

Methods

Method Summary
GloVe<T> CreateBertCompatible() Creates a GloVe instance with the legacy 768-dim default that this project’s parameterless constructor used before the paper-faithful d = 100 switch.
Matrix<T> EmbedBatch(IEnumerable<string> texts) Encodes a whole batch of sentences at once for speed.
ModelMetadata<T> GetModelMetadata() Returns technical details and configuration info about the GloVe model.
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 embeddings for given token IDs.
Tensor<T> ForwardForTraining(Tensor<T> input)
Vector<T> Embed(string text) Turns a sentence into a single, summary coordinate (embedding).