Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to do word stemming using nltk library in NLP

Description

To understand how to do word stemming in natural language processing using nltk library.

Input

Sample text

Output

Prefix or suffix removed words.

Process

  Import necessary libraries.

  Took sample text.

  Build portstemmer constructor.

  Fit the text data into the constructor.

  Stem the words.

  Print the results.

Sample Code

from nltk.stem import PorterStemmer

#sample words
example_words=[“studies”,”leaves”,”pythoning”,”pythoned”,”pythonly”,”having”]

print(“Sample words”)
print(example_words)
print(“\n”)

#stemmer constructor
ps = PorterStemmer()

re = []
for i in example_words:
re.append(ps.stem(i))
print(“After stemming”)
print(re)

Screenshots
word stemming using nltk library in NLP