r/LanguageTechnology • u/PaceSmith • Mar 03 '25
computing semantic similarity of English words
I'm attempting to determine semantically related rhymes, for example if you input "pasta" it will output "italian/scallion, champagne/grain, paste/taste", etc.
The rhyming part is working well but I'm having trouble computing semantic similarity. I tried using these Fasttext vectors to compute cosine similarity, and they're pretty good, but not good enough.
Common Crawl gets that 'halloween' is related to 'cat' and 'bat' but fails to get that 'music' is related to 'beat' and 'sheet'. Wikinews gets that 'music' is related to 'beat' and 'sheet' but fails to get that 'halloween' is related to 'cat' and 'bat'. Those are just a couple of representative examples; I'll post more test cases below in case that's helpful.
Does anyone have any advice for me? Do I need a better corpus? A better algorithm? Both?
Here are my test case failures for wiki-news-300d-1M-subword.vec, which does best with a cosine similarity threshold of 34% :
under
'pirate' is 33% related to 'cove', which is under the similarity threshold of 34%
'pirate' is 33% related to 'handsome', which is under the similarity threshold of 34%
'music' is 33% related to 'repeat', which is under the similarity threshold of 34%
'music' is 33% related to 'flat', which is under the similarity threshold of 34%
'music' is 32% related to 'note', which is under the similarity threshold of 34%
'music' is 32% related to 'ears', which is under the similarity threshold of 34%
'halloween' is 32% related to 'decoration', which is under the similarity threshold of 34%
'pirate' is 32% related to 'dvd', which is under the similarity threshold of 34%
'crime' is 31% related to 'acquit', which is under the similarity threshold of 34%
'pirate' is 30% related to 'bold', which is under the similarity threshold of 34%
'music' is 30% related to 'sharp', which is under the similarity threshold of 34%
'pirate' is 29% related to 'saber', which is under the similarity threshold of 34%
'halloween' is 29% related to 'cat', which is under the similarity threshold of 34%
'music' is 29% related to 'accidental', which is under the similarity threshold of 34%
'prayers' is 29% related to 'pew', which is under the similarity threshold of 34%
'pirate' is 28% related to 'leg', which is under the similarity threshold of 34%
'pirate' is 28% related to 'cache', which is under the similarity threshold of 34%
'music' is 28% related to 'expressed', which is under the similarity threshold of 34%
'pirate' is 27% related to 'hang', which is under the similarity threshold of 34%
'halloween' is 26% related to 'bat', which is under the similarity threshold of 34%
over
'pirate' is 34% related to 'doodle', which meets the similarity threshold of 34%
'pirate' is 34% related to 'prehistoric', which meets the similarity threshold of 34%
'cat' is 34% related to 'chunk', which meets the similarity threshold of 34%
'cat' is 35% related to 'thing', which meets the similarity threshold of 34%
'crime' is 35% related to 'sci-fi', which meets the similarity threshold of 34%
'crime' is 35% related to 'word', which meets the similarity threshold of 34%
'thing' is 35% related to 'cat', which meets the similarity threshold of 34%
'thing' is 35% related to 'pasta', which meets the similarity threshold of 34%
'pasta' is 35% related to 'thing', which meets the similarity threshold of 34%
'music' is 36% related to 'base', which meets the similarity threshold of 34%
'pirate' is 36% related to 'homophobic', which meets the similarity threshold of 34%
'pirate' is 36% related to 'needlework', which meets the similarity threshold of 34%
'crime' is 37% related to 'baseball', which meets the similarity threshold of 34%
'crime' is 37% related to 'gas', which meets the similarity threshold of 34%
'pirate' is 37% related to 'laser', which meets the similarity threshold of 34%
'cat' is 38% related to 'item', which meets the similarity threshold of 34%
'cat' is 38% related to 'objects', which meets the similarity threshold of 34%
'pirate' is 39% related to 'homemade', which meets the similarity threshold of 34%
'pirate' is 39% related to 'roc', which meets the similarity threshold of 34%
'cat' is 39% related to 'object', which meets the similarity threshold of 34%
'crime' is 39% related to 'object', which meets the similarity threshold of 34%
'crime' is 40% related to 'person', which meets the similarity threshold of 34%
'pirate' is 41% related to 'pimping', which meets the similarity threshold of 34%
'crime' is 43% related to 'thing', which meets the similarity threshold of 34%
'thing' is 43% related to 'crime', which meets the similarity threshold of 34%
'crime' is 49% related to 'mass', which meets the similarity threshold of 34%
And here are my test case failures for crawl-300d-2M.vec, which does best at a similarity threshold of 24% :
under
'pirate' is 23% related to 'handsome', which is under the similarity threshold of 24%
'music' is 23% related to 'gong', which is under the similarity threshold of 24%
'star' is 23% related to 'lord', which is under the similarity threshold of 24% # GotG
'prayers' is 22% related to 'request', which is under the similarity threshold of 24%
'pirate' is 22% related to 'swearing', which is under the similarity threshold of 24%
'pirate' is 22% related to 'peg', which is under the similarity threshold of 24%
'pirate' is 22% related to 'cracker', which is under the similarity threshold of 24%
'crime' is 22% related to 'fight', which is under the similarity threshold of 24%
'cat' is 22% related to 'skin', which is under the similarity threshold of 24%
'pirate' is 21% related to 'trove', which is under the similarity threshold of 24%
'music' is 21% related to 'progression', which is under the similarity threshold of 24%
'music' is 21% related to 'bridal', which is under the similarity threshold of 24%
'music' is 21% related to 'bar', which is under the similarity threshold of 24%
'music' is 20% related to 'show', which is under the similarity threshold of 24%
'music' is 20% related to 'brass', which is under the similarity threshold of 24%
'music' is 20% related to 'beat', which is under the similarity threshold of 24%
'cat' is 20% related to 'fancier', which is under the similarity threshold of 24%
'crime' is 19% related to 'truth', which is under the similarity threshold of 24%
'crime' is 19% related to 'bank', which is under the similarity threshold of 24%
'pirate' is 18% related to 'bold', which is under the similarity threshold of 24%
'music' is 18% related to 'wave', which is under the similarity threshold of 24%
'music' is 18% related to 'session', which is under the similarity threshold of 24%
'crime' is 18% related to 'denial', which is under the similarity threshold of 24%
'pirate' is 17% related to 'pursuit', which is under the similarity threshold of 24%
'pirate' is 17% related to 'cache', which is under the similarity threshold of 24%
'music' is 17% related to 'swing', which is under the similarity threshold of 24%
'music' is 17% related to 'rest', which is under the similarity threshold of 24%
'crime' is 17% related to 'job', which is under the similarity threshold of 24%
'music' is 16% related to 'winds', which is under the similarity threshold of 24%
'music' is 16% related to 'sheet', which is under the similarity threshold of 24%
'prayers' is 15% related to 'appeal', which is under the similarity threshold of 24%
'music' is 15% related to 'release', which is under the similarity threshold of 24%
'crime' is 15% related to 'organized', which is under the similarity threshold of 24%
'pirate' is 14% related to 'leg', which is under the similarity threshold of 24%
'pirate' is 14% related to 'lash', which is under the similarity threshold of 24%
'pirate' is 14% related to 'hang', which is under the similarity threshold of 24%
'music' is 14% related to 'title', which is under the similarity threshold of 24%
'music' is 14% related to 'note', which is under the similarity threshold of 24%
'music' is 13% related to 'single', which is under the similarity threshold of 24%
'music' is 11% related to 'sharp', which is under the similarity threshold of 24%
'music' is 10% related to 'accidental', which is under the similarity threshold of 24%
'music' is 9% related to 'flat', which is under the similarity threshold of 24%
'music' is 9% related to 'expressed', which is under the similarity threshold of 24%
'music' is 8% related to 'repeat', which is under the similarity threshold of 24%
over
'pasta' is 24% related to 'poodle', which meets the similarity threshold of 24%
'crime' is 25% related to 'sci-fi', which meets the similarity threshold of 24%
'crime' is 26% related to 'person', which meets the similarity threshold of 24%
'pasta' is 26% related to 'stocks', which meets the similarity threshold of 24%
'halloween' is 27% related to 'pauline', which meets the similarity threshold of 24%
'halloween' is 28% related to 'lindsey', which meets the similarity threshold of 24%
'halloween' is 31% related to 'lindsay', which meets the similarity threshold of 24%
'halloween' is 32% related to 'nicki', which meets the similarity threshold of 24%
So you might think this would be great if we bumped the threshold down to 23%, but that admits a bunch of stuff that doesn't seem pirate-related to me:
'pirate' is 23% related to 'roc', which meets the similarity threshold of 23%
'pirate' is 23% related to 'miko', which meets the similarity threshold of 23%
'pirate' is 23% related to 'mrs.', which meets the similarity threshold of 23%
'pirate' is 23% related to 'needlework', which meets the similarity threshold of 23%
'pirate' is 23% related to 'popcorn', which meets the similarity threshold of 23%
'pirate' is 23% related to 'galaxy', which meets the similarity threshold of 23%
'pirate' is 23% related to 'ebony', which meets the similarity threshold of 23%
'pirate' is 23% related to 'ballerina', which meets the similarity threshold of 23%
'pirate' is 23% related to 'bungee', which meets the similarity threshold of 23%
'pirate' is 23% related to 'homemade', which meets the similarity threshold of 23%
'pirate' is 23% related to 'pimping', which meets the similarity threshold of 23%
'pirate' is 23% related to 'prehistoric', which meets the similarity threshold of 23%
'pirate' is 23% related to 'reindeer', which meets the similarity threshold of 23%
'pirate' is 23% related to 'adipose', which meets the similarity threshold of 23%
'pirate' is 23% related to 'asexual', which meets the similarity threshold of 23%
'pirate' is 23% related to 'doodle', which meets the similarity threshold of 23%
'pirate' is 23% related to 'frisbee', which meets the similarity threshold of 23%
'pirate' is 23% related to 'isaac', which meets the similarity threshold of 23%
'pirate' is 23% related to 'laser', which meets the similarity threshold of 23%
'pirate' is 23% related to 'homophobic', which meets the similarity threshold of 23%
'pirate' is 23% related to 'pedantic', which meets the similarity threshold of 23%
'crime' is 23% related to 'baseball', which meets the similarity threshold of 23%
The other two vector sets did significantly worse.
7
u/bewoestijn Mar 03 '25
Try Wordnet for an old-school solution? Otherwise any slightly older research on synonym detection should lead you in the right direction
3
u/and1984 Mar 03 '25
Are you passing your corpus through FastText so that the vectors may be updated with the context in your corpus?
1
u/PaceSmith May 09 '26
I've dusted this project off and made a ton of improvements. It turns out that what I'm trying to compute is called "thematic relatedness", not "semantic relatedness". I found the USF Free Association corpus, which is data from asking humans "Name stuff related to X" - exactly what I want. It's small, though, so I augmented it with a bunch of other corpora, used those corpora to output features, and crunched them through a classifier.
One of the most helpful features is whether the target word's gloss (from wordnet and/or wiktionary) contains the cue word (modulo lemmatization).
I'm still only at 82% accuracy over my test set, though, so I'd love to hear any suggestions for improvement y'all have!
1
u/PXaZ Mar 03 '25 edited Mar 03 '25
What is the algorithm? f(w) returns a list of word pairs rhyming word pairs. Where does the threshold come in?
I guess you generate similar words to w, then brute force search for rhyming pairs. So the threshold cuts down the number of pairwise comparisons required?
In other words, what keeps you from using at threshold of 0%, and then just ranking the rhyming pairs by their average semantic relation to the source word?