KGEmbeddingBase<T>
Base Classes · AiDotNet.RetrievalAugmentedGeneration.Graph.Embeddings
Abstract base class for knowledge graph embedding models providing shared training infrastructure.
Implements: IKnowledgeGraphEmbedding<T>
Known derived types: ComplExEmbedding<T>, DistMultEmbedding<T>, RotatEEmbedding<T>, TemporalTransEEmbedding<T>, TransEEmbedding<T>
For Beginners
This class handles the “plumbing” of training:
- Builds entity/relation vocabularies from the graph
- Initializes random embedding vectors
- For each epoch, shuffles triples into mini-batches
- For each positive triple, generates corrupted (negative) triples
- Computes loss and gradients, then updates embeddings via SGD
- Subclasses define how to score triples and compute gradients
How It Works
This base class implements the common training loop with mini-batch SGD and negative sampling. Subclasses only need to implement scoring, gradient computation, and post-epoch normalization.
Properties
| Property | Summary |
|---|---|
bool IsDistanceBased { get; } |
|
bool IsTrained { get; set; } |
|
int EmbeddingDimension { get; } |
Methods
| Method | Summary |
|---|---|
KGEmbeddingTrainingResult Train(KnowledgeGraph<T> graph, KGEmbeddingOptions options) |
|
T ScoreTriple(string headId, string relationType, string tailId) |
|
T[] GetEntityEmbedding(string entityId) |
|
T[] GetRelationEmbedding(string relationType) |