Created
November 27, 2019 07:34
-
-
Save mohdsanadzakirizvi/c2dc2cd03edf6b78135abe11ade70865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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