What is padding in NLP?

What is padding in NLP?

What is padding in NLP?

This recipe explains what is padding in NLP


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

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

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

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

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

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.