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.

NLP Techniques to Learn for your Next NLP Project

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

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

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.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

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.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

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.

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 Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python