Docsity

Artificial Intelligence lecture notes, Lecture notes of Artificial Intelligence

Partial preview of the text

Download Artificial Intelligence lecture notes and more Lecture notes Artificial Intelligence in PDF only on Docsity!

Python with NLP

Introduction

  • (^) The process of converting data to something a computer can understand is referred to as pre-processing. One of the major forms of pre-processing is to filter out useless data. In natural language processing, useless words (data), are referred to as stop words.

Introduction

  • (^) We would not want these words to take up space in our database, or taking up valuable processing time. For this, we can remove them easily, by storing a list of words that you consider to stop words.
  • (^) NLTK(Natural Language Toolkit) in python has a list of stopwords stored in 16 different languages.

Program

  • (^) To check the list of stopwords you can type the following commands in the python shell.
  • (^) import nltk
  • (^) from nltk.corpus import stopwords print(stopwords.words('english'))

Program

  • (^) Removing stop words with NLTK
  • (^) The following program removes stop words from a piece of text:
  • (^) Import nltk
  • (^) from nltk.corpus import stopwords
  • (^) from nltk.tokenize import word_tokenize
  • (^) example_sent = """This is a sample sentence,
  • (^) showing off the stop words filtration."""
  • (^) stop_words = set(stopwords.words('english'))