Platforms to show: All Mac Windows Linux Cross-Platform

Back to NLContextualEmbeddingResultMBS class.

NLContextualEmbeddingResultMBS.averageToken as NLContextualEmbeddingResultVectorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Natural Language MBS MacFrameworks Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Calculates an average over the vectors in the result.
Example
const lang = "en"
Var n As NLContextualEmbeddingMBS = NLContextualEmbeddingMBS.contextualEmbeddingWithLanguage(lang)

var e as NSErrorMBS
var r1 as NLContextualEmbeddingResultMBS = n.embeddingResultForString("Hello World", lang, e)
Var r2 As NLContextualEmbeddingResultMBS = n.embeddingResultForString("Hallo World", lang, e)

Var average1 As NLContextualEmbeddingResultVectorMBS = r1.averageToken
Var average2 As NLContextualEmbeddingResultVectorMBS = r2.averageToken

Var compare As Double = average1.cosineSimilarity(average2)

MessageBox compare.ToString // 0.93

The "Hello World" has six tokens. We sum them up and later divide by count to get the average.

NLContextualEmbeddingResultMBS.Constructor   Private

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Natural Language MBS MacFrameworks Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
The private constructor.

NLContextualEmbeddingResultMBS.tokenVectorAtIndex(characterIndex as Integer) as NLContextualEmbeddingResultVectorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Natural Language MBS MacFrameworks Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a token vector at the specified character index.

characterIndex: The index to get the token vector at.

NLContextualEmbeddingResultMBS.tokenVectors as NLContextualEmbeddingResultVectorMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Natural Language MBS MacFrameworks Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Provides the embedding vectors corresponding to the result.
Example
const lang = "en"
Var n As NLContextualEmbeddingMBS = NLContextualEmbeddingMBS.contextualEmbeddingWithLanguage(lang)

var e as NSErrorMBS
var r as NLContextualEmbeddingResultMBS = n.embeddingResultForString("Hello World", lang, e)

Var tokenVectors() As NLContextualEmbeddingResultVectorMBS = r.tokenVectors
Break // inspect array in debugger

Use this method to access the individual (subword) token embeddings. You can apply pooling or combination techniques to aggregate these subword vectors into a single representation for a word, phrase, or entire input.

Common pooling techniques include

  • Mean pooling to take the average of subword vectors.
  • Max pooling for finding the element-wise maximum across tokens.
  • Use the embeddings of the first or last subword tokens to represent the entire input.

The items on this page are in the following plugins: MBS MacFrameworks Plugin.


The biggest plugin in space...