0% found this document useful (0 votes)
2 views3 pages

NLP Lab Programs

The document outlines a series of weekly lessons focused on various natural language processing (NLP) techniques using the NLTK library in Python. Topics include tokenization, stop words removal, stemming, word analysis, word sense disambiguation, part-of-speech tagging, n-grams with Laplace smoothing, and speech recognition with text-to-speech. Each week provides code examples and explanations for implementing these techniques.

Uploaded by

vijayvardhang25
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)
2 views3 pages

NLP Lab Programs

The document outlines a series of weekly lessons focused on various natural language processing (NLP) techniques using the NLTK library in Python. Topics include tokenization, stop words removal, stemming, word analysis, word sense disambiguation, part-of-speech tagging, n-grams with Laplace smoothing, and speech recognition with text-to-speech. Each week provides code examples and explanations for implementing these techniques.

Uploaded by

vijayvardhang25
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

WEEK 1 - Tokenization

import nltk
from [Link] import word_tokenize, sent_tokenize

[Link]('punkt')

text = "hello, how are you? how is life going? i am fine. weather is pleasant today. yes it is"

print(sent_tokenize(text))
print()
print(word_tokenize(text))

WEEK 1 - Stop Words Removal

import nltk
from [Link] import stopwords
from [Link] import word_tokenize

[Link]('stopwords')
[Link]('punkt')

text = "hello, how are you? how is life going?"

words = word_tokenize(text)
stop_words = set([Link]('english'))

not_stopwords = []
for w in words:
if [Link]() not in stop_words:
not_stopwords.append(w)

print(not_stopwords)

WEEK 2 - Porter Stemmer

from [Link] import PorterStemmer

porter_stemmer = PorterStemmer()

words = ["running", "jumps", "happily", "programming"]

stemmed_words = [porter_stemmer.stem(word) for word in words]

print("Original words:", words)


print("Stemmed words:", stemmed_words)

WEEK 3 - Word Analysis

import nltk
from [Link] import word_tokenize
from [Link] import stopwords
from [Link] import FreqDist

[Link]('punkt')
[Link]('stopwords')
[Link]('averaged_perceptron_tagger')

text = "Natural language processing makes computers understand human language"

tokens = word_tokenize(text)
print("Tokens:", tokens)

stop_words = set([Link]('english'))
filtered_words = [word for word in tokens if [Link]() not in stop_words]
print("Filtered words:", filtered_words)

freq_dist = FreqDist(filtered_words)
print("Words Frequency:", freq_dist)

pos_tags = nltk.pos_tag(tokens)
print("POS Tags:", pos_tags)

WEEK 4 - WSD (Lesk Algorithm)

import nltk
from [Link] import lesk
from [Link] import word_tokenize

[Link]('wordnet')
[Link]('punkt')

sentence = "I deposited money in the bank"


tokens = word_tokenize([Link]())

sense = lesk(tokens, 'bank')

print("Sentence:", sentence)
print("Sense:", [Link]())

WEEK 6 - POS Tagging

import nltk
from nltk import pos_tag
from [Link] import word_tokenize

[Link]('punkt')
[Link]('averaged_perceptron_tagger')

sentence = "she runs quickly and is happy"


tokens = word_tokenize(sentence)

pos_tags = pos_tag(tokens)
print("POS Tags:", pos_tags)

WEEK 7 - N-grams with Laplace Smoothing

from [Link] import ngrams


from collections import Counter

text = "natural language processing makes computers understand language"


tokens = [Link]()

bigrams = list(ngrams(tokens, 2))

unigram_counts = Counter(tokens)
bigram_counts = Counter(bigrams)

V = len(set(tokens))

def laplace_probability(w1, w2):


return (bigram_counts[(w1, w2)] + 1) / (unigram_counts[w1] + V)

for w1, w2 in bigrams:


print(f"P({w2}|{w1}) = {laplace_probability(w1, w2):.4f}")

WEEK 8 - Speech Recognition & TTS


import pyttsx3
import speech_recognition as sr

engine = [Link]()

[Link]("NLP is interesting")
[Link]()

You might also like