I'm currently learning spaCy, and I have an exercise on word and sentence embeddings. Sentences are stored in a pandas DataFrame columns, and, we're requested to train a classifier based on the vector of these sentences.
I have a dataframe that looks like this:
+---+---------------------------------------------------+
| | sentence |
+---+---------------------------------------------------+
| 0 | "Whitey on the Moon" is a 1970 spoken word poe... |
+---+---------------------------------------------------+
| 1 | St Anselm's Church is a Roman Catholic church ... |
+---+---------------------------------------------------+
| 2 | Nymphargus grandisonae (common name: giant gla... |
+---+---------------------------------------------------+
Next, I apply an NLP function to these sentences:
import en_core_web_md
nlp = en_core_web_md.load()
df['tokenized'] = df['sentence'].apply(nlp)
Now, if I understand correctly, each item in df['tokenized'] has an attribute that returns the vector of the sentence in a 2D array.
print(type(df['tokenized'][0].vector))
print(df['tokenized'][0].vector.shape)
yields
<class 'numpy.ndarray'>
(300,)
How do I add the content of this array (300 rows) as columns to the df dataframe for the corresponding sentence, ignoring stop words?
Thanks!