---
title: NLContextualEmbedding
framework: Natural Language
role: symbol
role_heading: Class
platforms: [iOS 17.0+, iPadOS 17.0+, Mac Catalyst 17.0+, macOS 14.0+, tvOS 17.0+, visionOS 1.0+, watchOS 10.0+]
path: naturallanguage/nlcontextualembedding
---

# NLContextualEmbedding

A model that computes sequences of embedding vectors for natural language utterances.

## Declaration

```swift
class NLContextualEmbedding
```

## Overview

Overview NLContextualEmbedding provides a dense vector representation of natural language utterances using models trained with contextualized language understanding. Unlike static word embeddings provided by NLEmbedding, contextual embeddings dynamically adjust based on surrounding words, enabling deeper language comprehension. If you are building text classification or word tagging models, you can use NLContextualEmbedding with Create ML by selecting MLTextClassifier.FeatureExtractorType.bertEmbedding as the feature extraction component in your model. For more information on how to create your own text classification model refer to Creating a text classifier model. note: For semantic similarity tasks, consider using NLEmbedding. To learn more on how to implement semantic similarity, refer to Finding similarities between pieces of text. Before configuring your contextual embedding: Select a model that’s appropriate for your target language when initializing the embedding. Call requestAssets(completionHandler:) before computing the embedding to confirm assets are available. Some models support multiple languages; for example, you can use the same object to compute embeddings for both English and Spanish. However, this isn’t always the case — languages like English and Chinese may require separate models. For more information about supported languages, refer to languages.

## Topics

### Creating a contextual embedding

- [init(modelIdentifier:)](naturallanguage/nlcontextualembedding/init(modelidentifier:).md)
- [init(language:)](naturallanguage/nlcontextualembedding/init(language:).md)
- [init(script:)](naturallanguage/nlcontextualembedding/init(script:).md)

### Discovering available contextual embeddings

- [contextualEmbeddings(forValues:)](naturallanguage/nlcontextualembedding/contextualembeddings(forvalues:).md)

### Inspecting the contextual embedding

- [dimension](naturallanguage/nlcontextualembedding/dimension.md)
- [hasAvailableAssets](naturallanguage/nlcontextualembedding/hasavailableassets.md)
- [languages](naturallanguage/nlcontextualembedding/languages.md)
- [maximumSequenceLength](naturallanguage/nlcontextualembedding/maximumsequencelength.md)
- [modelIdentifier](naturallanguage/nlcontextualembedding/modelidentifier.md)
- [revision](naturallanguage/nlcontextualembedding/revision.md)
- [scripts](naturallanguage/nlcontextualembedding/scripts.md)

### Requesting assets

- [requestAssets(completionHandler:)](naturallanguage/nlcontextualembedding/requestassets(completionhandler:).md)
- [NLContextualEmbedding.AssetsResult](naturallanguage/nlcontextualembedding/assetsresult.md)

### Loading and unloading assets

- [load()](naturallanguage/nlcontextualembedding/load().md)
- [unload()](naturallanguage/nlcontextualembedding/unload().md)

### Applying an embedding

- [embeddingResult(for:language:)](naturallanguage/nlcontextualembedding/embeddingresult(for:language:).md)
- [NLContextualEmbeddingResult](naturallanguage/nlcontextualembeddingresult.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Contextual embedding

- [NLContextualEmbeddingKey](naturallanguage/nlcontextualembeddingkey.md)
- [NLScript](naturallanguage/nlscript.md)
