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
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: ...
#3: Post edited
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
- 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
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']