Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to visualize the SpaCy word embedding as scatter plot?

Each word in SpaCy is represented by a vector of length 300. How can I plot these words on a scatter plot to get a visual perspective on how close any 2 words are?

like image 669
zaki41 Avatar asked Oct 20 '25 08:10

zaki41


2 Answers

There's a new package called whatlies that does exactly this: https://rasahq.github.io/whatlies/

See a short spacy example: https://spacy.io/universe/project/whatlies

like image 133
aab Avatar answered Oct 23 '25 08:10

aab


When working with small-to-medium-sized texts, ScatterText is a tool which can be used to discover words that have distinguishing features. It also enables users to create interactive scatter plots that contain non-overlapping term labels.

Intall via -https://pypi.org/project/scattertext/

import spacy
import scattertext as st
nlp = spacy.load('en')
corpus = st.CorpusFromPandas(convention_df,
                         category_col='party',
                         text_col='text',
                         nlp=nlp).build()
like image 38
chamod rathnayake Avatar answered Oct 23 '25 08:10

chamod rathnayake