Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A Why is spacy word vectors showing unexpected similar words?

Why is spacy word vectors showing unexpected similar words? Here is the code I am using: import spacy import numpy as np nlp=spacy.load('en_core_web_md') with open ('data/us.txt') as f: ...

0 answers  ·  posted 5d ago by Asia‭  ·  edited 4d ago by celtschk‭

#3: Post edited by user avatar celtschk‭ · 2025-01-03T09:42:00Z (4 days ago)
Added the actual question to the post instead of referring to the title. Also, added proper capitalization and punctuation.
  • why is spacy word vectors showing unexpected similar words?
  • Why is spacy word vectors showing unexpected similar words?
  • as the title says. here is the code I am using
  • ```python
  • import spacy
  • import numpy as np
  • nlp=spacy.load('en_core_web_md')
  • with open ('data/us.txt') as f:
  • text=f.read()
  • doc=nlp(text)
  • sentence1=list(doc.sents)[0]
  • # print(sentence1)
  • your_word='country'
  • ms = nlp.vocab.vectors.most_similar(np.asarray([nlp.vocab.vectors[nlp.vocab.strings[your_word]]]), n=10)
  • words = [nlp.vocab.strings[w] for w in ms[0][0]]
  • distances = ms[2]
  • print(words)
  • ```
  • the output I get no matter what word I put in the variable
  • ```python
  • ['anti-poverty', 'SLUMS', 'inner-city', 'Socioeconomic', 'INTERSECT', 'Divides', 'handicaps', 'dropout', 'drop-out', 'Crime-Ridden']
  • ```
  • Why is spacy word vectors showing unexpected similar words?
  • Here is the code I am using:
  • ```python
  • import spacy
  • import numpy as np
  • nlp=spacy.load('en_core_web_md')
  • with open ('data/us.txt') as f:
  • text=f.read()
  • doc=nlp(text)
  • sentence1=list(doc.sents)[0]
  • # print(sentence1)
  • your_word='country'
  • ms = nlp.vocab.vectors.most_similar(np.asarray([nlp.vocab.vectors[nlp.vocab.strings[your_word]]]), n=10)
  • words = [nlp.vocab.strings[w] for w in ms[0][0]]
  • distances = ms[2]
  • print(words)
  • ```
  • The output I get no matter what word I put in the variable:
  • ```python
  • ['anti-poverty', 'SLUMS', 'inner-city', 'Socioeconomic', 'INTERSECT', 'Divides', 'handicaps', 'dropout', 'drop-out', 'Crime-Ridden']
  • ```
#2: Post edited by user avatar Alexei‭ · 2025-01-02T08:13:38Z (5 days ago)
code formatting
  • as the title says. here is the code I am using
  • import spacy
  • import numpy as np
  • nlp=spacy.load('en_core_web_md')
  • with open ('data/us.txt') as f:
  • text=f.read()
  • doc=nlp(text)
  • sentence1=list(doc.sents)[0]
  • # print(sentence1)
  • your_word='country'
  • ms = nlp.vocab.vectors.most_similar(np.asarray([nlp.vocab.vectors[nlp.vocab.strings[your_word]]]), n=10)
  • words = [nlp.vocab.strings[w] for w in ms[0][0]]
  • distances = ms[2]
  • print(words)
  • the output I get no matter what word I put in the variable
  • ['anti-poverty', 'SLUMS', 'inner-city', 'Socioeconomic', 'INTERSECT', 'Divides', 'handicaps', 'dropout', 'drop-out', 'Crime-Ridden']
  • as the title says. here is the code I am using
  • ```python
  • import spacy
  • import numpy as np
  • nlp=spacy.load('en_core_web_md')
  • with open ('data/us.txt') as f:
  • text=f.read()
  • doc=nlp(text)
  • sentence1=list(doc.sents)[0]
  • # print(sentence1)
  • your_word='country'
  • ms = nlp.vocab.vectors.most_similar(np.asarray([nlp.vocab.vectors[nlp.vocab.strings[your_word]]]), n=10)
  • words = [nlp.vocab.strings[w] for w in ms[0][0]]
  • distances = ms[2]
  • print(words)
  • ```
  • the output I get no matter what word I put in the variable
  • ```python
  • ['anti-poverty', 'SLUMS', 'inner-city', 'Socioeconomic', 'INTERSECT', 'Divides', 'handicaps', 'dropout', 'drop-out', 'Crime-Ridden']
  • ```
#1: Initial revision by user avatar Asia‭ · 2025-01-01T19:57:41Z (5 days ago)
why is spacy word vectors showing unexpected similar words?
as the title says. here is the code I am using

import spacy
import numpy as np

nlp=spacy.load('en_core_web_md')

with open ('data/us.txt') as f:
    text=f.read()

doc=nlp(text)
sentence1=list(doc.sents)[0]
# print(sentence1)

your_word='country'
ms = nlp.vocab.vectors.most_similar(np.asarray([nlp.vocab.vectors[nlp.vocab.strings[your_word]]]), n=10)
words = [nlp.vocab.strings[w] for w in ms[0][0]]
distances = ms[2]
print(words)

the output I get no matter what word I put in the variable
['anti-poverty', 'SLUMS', 'inner-city', 'Socioeconomic', 'INTERSECT', 'Divides', 'handicaps', 'dropout', 'drop-out', 'Crime-Ridden']