How to use Spacy lemmatizer?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to use Spacy lemmatizer?

How to use Spacy lemmatizer?

This recipe helps you use Spacy lemmatizer

Recipe Objective

How to use Spacy lemmatizer, As we have discussed earlier only what is Spacy and what is lemmatizer. Spacy Lemmatization which gives the lemma of the word, lemma is nothing the but base word which has been converted through the process of lemmatization for e.g 'hostorical', 'history' will become 'history' so the lemma is 'history' here.

Step 1 - Import Spacy

import spacy

Step 2 - Initialize the Spacy en model.

load_model = spacy.load('en', disable = ['parser','ner'])

In the above code we have initialized the Spacy model and kept only the things which is required for lemmatization which is nothing but the tagger and disabled the parser and ner which are not required for now.

Step 3 - Take a simple text for sample

My_text = "This is just a sample text for the purpose of testing"

Step 4 - Parse the text

doc = load_model(My_text)

here in the above we have parsed the text that we have taken for sample by using the model that we have initialized i.e load_model.

Step 5 - Extract the lemma for each token

" ".join([token.lemma_ for token in doc])

So from the above we can see that there is slight change in the sentence which is, original - 'this is' and extracted - 'this be'.

Step 6 - Lets try with another example

text2 = "I am hanging out in a garden" doc2 = load_model(text2) " ".join([token.lemma_ for token in doc2])

So we can see whenever Spacy detects a pronoun it adds a -PRON- in the text.

Relevant Projects

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Machine learning for Retail Price Recommendation with Python
Use the Mercari Dataset with dynamic pricing to build a price recommendation algorithm using machine learning in Python to automatically suggest the right product prices.

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Build a Music Recommendation Algorithm using KKBox's Dataset
Music Recommendation Project using Machine Learning - Use the KKBox dataset to predict the chances of a user listening to a song again after their very first noticeable listening event.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Ola Bike Rides Request Demand Forecast
Given big data at taxi service (ride-hailing) i.e. OLA, you will learn multi-step time series forecasting and clustering with Mini-Batch K-means Algorithm on geospatial data to predict future ride requests for a particular region at a given time.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Time Series Python Project using Greykite and Neural Prophet
In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.