NLP with Tensorflow — Padding sentences

DataOil St.
Analytics Vidhya
Published in
1 min readJun 13, 2020

Alright in the previous post we have learned to tokenize and sequence the tokens from a sentence. We can observe that the length of tokens differ.

We need to make sure that inputs are of the same length. Padding saves us from this problem!

Padding sequences

‘pad_sequences’ padded the sequences into the same length. You can observe that 0’s are padded in the beginning of a list which is smaller in size.

‘pad_sequence’ can be used to pad a sentence in the end or in the beginning, or padding a sentence to a desired length by truncating the sequence…

Okay, that’s enough! In the next post we will handle a real dataset by applying the techniques we have learned!

--

--

Analytics Vidhya
Analytics Vidhya

Published in Analytics Vidhya

Analytics Vidhya is a community of Generative AI and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

DataOil St.
DataOil St.

Written by DataOil St.

Talks about implementing AI for real-world use cases