NLP: How to use spaCy, python ver. 2

Last Updated on January 5, 2022 by shibatau

The last link is added.

I. What do you learn?

Let’s learn how to do the Natural Language Processing tasks, tokenization, stemming and lemmatization using the spaCy library.

Learning from the articles:

Python for NLP: Tokenization, Stemming, and Lemmatization with SpaCy Library

spaCy Cheat Sheet: Advanced NLP in Python

II. Install spaCy on Google Colaboratory

Install spaCy 2.3.5 and you will get the same results as in the explanation here.

!pip install spacy==2.3.5 

You can see all the scripts here:

https://colab.research.google.com/drive/1znH2Pp5MecYEnxto14fHgepEvq4LriHi?usp=sharing

III. Sample strings

Sentences

  1. ‘Manchester United is looking to sign a forward for $90 million’
  2. “Manchester United isn’t looking to sign any forward.”
  3. ‘”They\’re leaving U.K. for U.S.A.”‘
  4. “Hello, I am non-vegetarian, email me the menu at abc-xyz@gmai.com”
  5. ‘Manchester United is looking to sign Harry Kane for $90 million’
  6. ‘compute computer computed computing’
  7. ‘A letter has been written, asking him to be released’

Document

‘Hello from Stackabuse. The site with the best Python Tutorials. What are you looking for?’

Creating Doc objects:

IV. Tokenize a document

You can tokenize a document and access the token attributes.

Show the part of speech and dependencies

You can also visualize the dependencies. You can learn more in my post.

You can visualize dependencies of words online here:

https://explosion.ai/demos/displacy

To be continued.

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.