0% found this document useful (0 votes)
3 views1 page

Vatsav Assign 2

The document presents a Python program designed to remove stop words from a given sentence. It defines a function that filters out specified common words and demonstrates its use with an example input about machine learning. The output shows the modified sentence after stop words have been removed.

Uploaded by

17godblessyou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Vatsav Assign 2

The document presents a Python program designed to remove stop words from a given sentence. It defines a function that filters out specified common words and demonstrates its use with an example input about machine learning. The output shows the modified sentence after stop words have been removed.

Uploaded by

17godblessyou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

NATURAL LANGUAGE PROCESSING-Assignment

1. Python Program to implement stop words removal.

Code
import re
def filter_stopwords_A6603(sentence_A6603):
stop_words_A6603 = {"a", "are", "how", "an", "the", "on", "in", "up", "i", "am",
"he", "she", "they", "and", "or", "is", "you"}
sentence_A6603 = sentence_A6603.lower()
for word_A6603 in stop_words_A6603:
sentence_A6603 = re.sub(r'\b' + word_A6603 + r'\b', '', sentence_A6603)

return " ".join(sentence_A6603.split())

input_text_A6603 = "Machine learning improves with data. Supervised learning uses


labels, while unsupervised finds patterns. It is useful in healthcare and finance."
print("Given:", input_text_A6603)
print("Modified :", filter_stopwords_A6603(input_text_A6603))

Input
Machine learning improves with data. Supervised learning uses labels, while
unsupervised finds patterns. It is useful in healthcare and finance.
Output
Given: Machine learning improves with data. Supervised learning uses labels, while
unsupervised finds patterns. It is useful in healthcare and finance.
Modified : machine learning improves with data. supervised learning uses labels,
while unsupervised finds patterns. it useful healthcare finance.

B. Sri
SriVatsav
Vathsav
22011A6603

You might also like