Skip to main content


I am playing with the NaturalLanguage framework in #Swift and I am having some interesting results. Here are the most similar words to the word „Dictatorship”. The left column are the words, the right is the distance. The more distant, the less similar the word is.

dictator 0.7791867852210999
autocracy 0.7871801853179932
dictatorial 0.7904724478721619
regime 0.7980139851570129
democracy 0.8397299647331238
totalitarian 0.845069408416748
repressive 0.8523193001747131
oligarchy 0.8619794845581055
despotism 0.8681145310401917
despot 0.8691430687904358
Here is the code I used.
import NaturalLanguage
guard let embedding = NLEmbedding.wordEmbedding(for: .english) else {
print("Nic z tego nie będzie.")
fatalError()
}
let words = embedding.neighbors(for: "dictatorship", maximumCount: 10)
for word in words {
print("\(word.0)\t\(word.1)")
}
#apple #swift #programming #CodingFun #iOS #macOS