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.
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.
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
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
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