What is padding in NLP?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

What is padding in NLP?

What is padding in NLP?

This recipe explains what is padding in NLP

0

Recipe Objective

What is padding in NLP?

Padding As we know all the neural networks needs to have the inputs that should be in similar shape and size. When we pre-process the texts and use the texts as an inputs for our Model. Note that not all the sequences have the same length, as we can say naturally some of the sequences are long in lengths and some are short. Where we know that we need to have the inputs with the same size, now here padding comes into picture. The inputs should be in same size at that time padding is necessary.

Step 1 - Take Sample text

Detail1 = ['Jon', '26', 'Canada'] Detail2 = ['Heena', '24', 'India'] Detail3 = ['Shawn', '27', 'California']

Here we are taking the sample text as "name", "age" and "address" of different person.

Step 2 - Apply left padding

for Details in [Detail1,Detail2,Detail3]: for entry in Details: print(entry.ljust(25), end='') print()
Jon                      26                       Canada                   
Heena                    24                       India                    
Shawn                    27                       California               

In the above we applying left padding to text by using .ljust

Step 3 - Center Padding

Sample_text = ["Jon playes cricket", "His favourite player is MS Dhoni","Sometimes he loves to play football"] for text in Sample_text: print(text.center(50, ' '))
                Jon playes cricket                
         His favourite player is MS Dhoni         
       Sometimes he loves to play football        

Step 4 - Right Padding

for ele in [Detail1, Detail2, Detail3]: for entry in ele: print(entry.rjust(30), end='') print()
                           Jon                            26                        Canada
                         Heena                            24                         India
                         Shawn                            27                    California

Relevant Projects

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.