Hands-On Machine Learning with scikit-learn and Scientific Python Toolkits by Tarek Amr
Author:Tarek Amr [Tarek Amr]
Language: eng
Format: epub
Tags: COM037000 - COMPUTERS / Machine Theory, COM051360 - COMPUTERS / Programming Languages / Python, COM062000 - COMPUTERS / Data Modeling and Design
Publisher: Packt Publishing
Published: 2020-07-24T04:35:40+00:00
pip install spacy
python -m spacy download en_core_web_lg
Then, we can assign the downloaded vectors to our five words as follows:
import spacy
nlp = spacy.load('en_core_web_lg')
terms = ['I', 'like', 'apples', 'oranges', 'pears']
vectors = [
nlp(term).vector.tolist() for term in terms
]
Here is the representation for apples:
# pd.Series(vectors[terms.index('apples')]).rename('apples')
0 -0.633400 1 0.189810 2 -0.535440 3 -0.526580 ... 296 -0.238810 297 -1.178400 298 0.255040 299 0.611710 Name: apples, Length: 300, dtype: float64
I promised you that the representations for apples, oranges, and pears would not be orthogonal as in the case with CountVectorizer. However, with 300 dimensions, it is hard for me to visually prove that. Luckily, we have already learned how to calculate the cosine of the angle between two vectors. Orthogonal vectors should have 90o angles between them, whose cosines are equal to 0. The cosine for the zero angle between two vectors going in the exact same direction is 1.
Here, we calculate the cosine between all the five vectors we got from spaCy. I used some pandas and seaborn styling to make the numbers clearer:
import seaborn as sns
from sklearn.metrics.pairwise import cosine_similarity
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Computer Vision & Pattern Recognition | Expert Systems |
Intelligence & Semantics | Machine Theory |
Natural Language Processing | Neural Networks |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7852)
Hadoop in Practice by Alex Holmes(5660)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5514)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(4508)
Functional Programming in JavaScript by Mantyla Dan(3723)
The Age of Surveillance Capitalism by Shoshana Zuboff(3423)
Big Data Analysis with Python by Ivan Marin(3012)
Blockchain Basics by Daniel Drescher(2891)
The Rosie Effect by Graeme Simsion(2708)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2602)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2519)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2479)
Dawn of the New Everything by Jaron Lanier(2438)
Test-Driven Development with Java by Alan Mellor(2385)
The Art Of Deception by Kevin Mitnick(2298)
Data Augmentation with Python by Duc Haba(2230)
Rapid Viz: A New Method for the Rapid Visualization of Ideas by Kurt Hanks & Larry Belliston(2195)
The Infinite Retina by Robert Scoble Irena Cronin(2179)
Human Dynamics Research in Smart and Connected Communities by Shih-Lung Shaw & Daniel Sui(2178)