<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NaturalLanguage",
  "identifier" : "/documentation/NaturalLanguage/NLContextualEmbeddingResult/enumerateTokenVectors(in:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Natural Language",
      "NaturalLanguage"
    ],
    "preciseIdentifier" : "s:So27NLContextualEmbeddingResultC15NaturalLanguageE21enumerateTokenVectors2in5usingySnySS5IndexVG_SbSaySdG_AItXEtF"
  },
  "title" : "enumerateTokenVectors(in:using:)"
}
-->

# enumerateTokenVectors(in:using:)

Iterates over the embedding vectors corresponding to the subword tokens within the specified range of the input string.

```
@nonobjc func enumerateTokenVectors(in range: Range<String.Index>, using block: ([Double], Range<String.Index>) -> Bool)
```

## Parameters

`range`

The range in the string to enumerate.

`block`

A block that contains each token’s embedding vector and its corresponding character range in the string.

## Discussion

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)