---
title: NLEmbedding
framework: naturallanguage
role: symbol
role_heading: Class
path: naturallanguage/nlembedding
---

# NLEmbedding

A map of strings to vectors, which locates neighboring, similar strings.

## Declaration

```swift
class NLEmbedding
```

## Mentioned in

Finding similarities between pieces of text

## Overview

Overview Use an NLEmbedding to find similar strings based on the proximity of their vectors. The vocabulary is the entire set of strings in an embedding. Each string in the vocabulary has a vector, which is an array of doubles, and each double corresponds to a dimension in the embedding. An NLEmbedding uses these vectors to determine the distance between two strings, or to find the nearest neighbors of a string in the vocabulary. The higher the similarity of any two strings, the smaller the distance is between them. Natural Language provides built-in word embeddings that you can retrieve by using the wordEmbedding(for:) method. You can also compile your own custom embedding into an efficient, searchable, on-disk representation. Typically, you compile an embedding by using Create ML’s MLWordEmbedding and save it as a file for your Xcode project at development time. Alternatively, you can compile an embedding at runtime by using Natural Language’s writeEmbeddingForDictionary:language:revision:toURL:error: method. Your custom embedding can use any kind of string that’s useful to your app, such as phrases, brand names, serial numbers, and so on. For example, you could make an embedding of movie titles. Each movie title could have a vector that places similar movies close together in the embedding.

## Topics

### Creating a word embedding

- [wordEmbedding(for:)](naturallanguage/nlembedding/wordembedding(for:).md)
- [wordEmbedding(for:revision:)](naturallanguage/nlembedding/wordembedding(for:revision:).md)
- [init(contentsOf:)](naturallanguage/nlembedding/init(contentsof:).md)

### Creating a sentence embedding

- [sentenceEmbedding(for:)](naturallanguage/nlembedding/sentenceembedding(for:).md)
- [sentenceEmbedding(for:revision:)](naturallanguage/nlembedding/sentenceembedding(for:revision:).md)

### Finding strings and their distances in an embedding

- [neighbors(for:maximumCount:distanceType:)](naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8f1jc.md)
- [neighbors(for:maximumCount:distanceType:)](naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8lp4z.md)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-72jda.md)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-6dy4x.md)
- [distance(between:and:distanceType:)](naturallanguage/nlembedding/distance(between:and:distancetype:).md)
- [NLDistance](naturallanguage/nldistance.md)

### Inspecting the vocabulary of an embedding

- [dimension](naturallanguage/nlembedding/dimension.md)
- [vocabularySize](naturallanguage/nlembedding/vocabularysize.md)
- [language](naturallanguage/nlembedding/language.md)
- [contains(_:)](naturallanguage/nlembedding/contains(_:).md)
- [vector(for:)](naturallanguage/nlembedding/vector(for:).md)
- [revision](naturallanguage/nlembedding/revision.md)

### Saving an embedding

- [write(_:language:revision:to:)](naturallanguage/nlembedding/write(_:language:revision:to:).md)

### Checking for Natural Language support

- [currentRevision(for:)](naturallanguage/nlembedding/currentrevision(for:).md)
- [supportedRevisions(for:)](naturallanguage/nlembedding/supportedrevisions(for:).md)
- [currentSentenceEmbeddingRevision(for:)](naturallanguage/nlembedding/currentsentenceembeddingrevision(for:).md)
- [supportedSentenceEmbeddingRevisions(for:)](naturallanguage/nlembedding/supportedsentenceembeddingrevisions(for:).md)

### Initializers

- [init(contentsOfURL:)](naturallanguage/nlembedding/init(contentsofurl:).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

### Text embedding

- [Finding similarities between pieces of text](naturallanguage/finding-similarities-between-pieces-of-text.md)
