Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Find similar words based on embedding
func embedCheck(word: String){
// Extract the language type
let lang = NLLanguageRecognizer.dominantLanguage(for: word)
// Get the OS embeddings for the given language
let embedding = NLEmbedding.wordEmbedding(for: lang!)
// Find the 5 words that are nearest to the input word based on the embedding
let res = embedding?.neighbors(for: word, maximumCount: 5)
// Print the words
print(res ?? [])
// Find words similar to cheese
embedCheck(word: "cheese")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment