---
title: MLWordEmbedding
framework: createml
role: symbol
role_heading: Structure
path: createml/mlwordembedding
---

# MLWordEmbedding

A map of strings in a vector space that enable your app to find similar strings by looking at a string’s neighbors.

## Declaration

```swift
struct MLWordEmbedding
```

## Overview

Overview Use an MLWordEmbedding to configure and save a word embedding to a file, which you then add to your project in Xcode. Your project uses that word embedding file at runtime to create an NLEmbedding instance, which finds similar strings based on the proximity of their vectors. You configure a word embedding with a dictionary, keyed by strings which make up the vocabulary of the word embedding. The value for each string is an array of doubles, which represents a vector. The length of the arrays is arbitrary but all arrays in a word embedding must be the same length. The length of the arrays determine the number of dimensions in the vector space. For example, the following listing creates a word embedding with four dimensions and a vocabulary of two strings. let wordEmbedding = try! MLWordEmbedding(dictionary: [     "Hello"   : [0.0, 1.2, 5.0, 0.0],     "Goodbye" : [0.0, 1.3, -6.2, 0.1] ]) Once you’ve configured an MLWordEmbedding, save it to an .mlmodel file to include in your app. try wordEmbedding.write(toFile: "~/Desktop/WordEmbedding.mlmodel") A word embedding file can efficiently store many strings and their vectors.

## Topics

### Creating a word embedding

- [init(dictionary:parameters:)](createml/mlwordembedding/init(dictionary:parameters:).md)
- [MLWordEmbedding.ModelParameters](createml/mlwordembedding/modelparameters-swift.struct.md)
- [modelParameters](createml/mlwordembedding/modelparameters-swift.property.md)

### Testing a word embedding

- [prediction(from:maxCount:maxDistance:distanceType:)](createml/mlwordembedding/prediction(from:maxcount:maxdistance:distancetype:).md)
- [distance(between:and:distanceType:)](createml/mlwordembedding/distance(between:and:distancetype:).md)
- [NLDistanceType](naturallanguage/nldistancetype.md)
- [contains(_:)](createml/mlwordembedding/contains(_:).md)
- [vector(for:)](createml/mlwordembedding/vector(for:).md)

### Saving a word embedding

- [write(to:metadata:)](createml/mlwordembedding/write(to:metadata:).md)
- [write(toFile:metadata:)](createml/mlwordembedding/write(tofile:metadata:).md)

### Describing a word embedding

- [dimension](createml/mlwordembedding/dimension.md)
- [vocabularySize](createml/mlwordembedding/vocabularysize.md)
- [model](createml/mlwordembedding/model.md)
- [description](createml/mlwordembedding/description.md)
- [debugDescription](createml/mlwordembedding/debugdescription.md)
- [playgroundDescription](createml/mlwordembedding/playgrounddescription.md)

### Default Implementations

- [CustomDebugStringConvertible Implementations](createml/mlwordembedding/customdebugstringconvertible-implementations.md)
- [CustomPlaygroundDisplayConvertible Implementations](createml/mlwordembedding/customplaygrounddisplayconvertible-implementations.md)
- [CustomStringConvertible Implementations](createml/mlwordembedding/customstringconvertible-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomPlaygroundDisplayConvertible](swift/customplaygrounddisplayconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)

## See Also

### Text models

- [Creating a text classifier model](createml/creating-a-text-classifier-model.md)
- [Creating a word tagger model](createml/creating-a-word-tagger-model.md)
- [MLTextClassifier](createml/mltextclassifier.md)
- [MLWordTagger](createml/mlwordtagger.md)
- [MLGazetteer](createml/mlgazetteer.md)
