Browse Source

Embeddings example: improve documentation and styling

pull/525/head
Scott W Harden 2 years ago
parent
commit
fa85962ba2
1 changed files with 17 additions and 1 deletions
  1. +17
    -1
      LLama.Examples/Examples/GetEmbeddings.cs

+ 17
- 1
LLama.Examples/Examples/GetEmbeddings.cs View File

@@ -9,18 +9,34 @@ namespace LLama.Examples.Examples
Console.Write("Please input your model path: ");
var modelPath = Console.ReadLine();

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(
"""
This example displays embeddings from a text prompt.
Embeddings are numerical codes that represent information like words, images, or concepts.
These codes capture important relationships between those objects,
like how similar words are in meaning or how close images are visually.
This allows machine learning models to efficiently understand and process complex data.
Embeddings of a text in LLM is sometimes useful, for example, to train other MLP models.
"""); // NOTE: this description was AI generated

var @params = new ModelParams(modelPath) { EmbeddingMode = true };

using var weights = LLamaWeights.LoadFromFile(@params);
var embedder = new LLamaEmbedder(weights, @params);

while (true)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please input your text: ");
Console.ForegroundColor = ConsoleColor.Green;
var text = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;

Console.WriteLine(string.Join(", ", embedder.GetEmbeddings(text)));
float[] embeddings = embedder.GetEmbeddings(text).Result;
Console.WriteLine($"Embeddings contain {embeddings.Length:N0} floating point values:");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(string.Join(", ", embeddings.Take(20)) + ", ...");
Console.WriteLine();
}
}


Loading…
Cancel
Save