A map of strings to a vector space that enable your app to find similar strings by looking at a string’s neighbors.
- macOS 10.15+
- Xcode 11.0+
- Create ML
MLWord 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.
Once you’ve configured an
MLWord, save it to an
.mlmodel file to include in your app.
A word embedding file can efficiently store many strings and their vectors.