Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Created November 27, 2019 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohdsanadzakirizvi/c2dc2cd03edf6b78135abe11ade70865 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/c2dc2cd03edf6b78135abe11ade70865 to your computer and use it in GitHub Desktop.
// 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