1.
Write a python program to perform tokenization by word and sentence using NLTK
# Install NLTK (Run this only once in Google Colab)
!pip install nltk
# Import NLTK
import nltk
# Download required tokenizer
[Link]('punkt')
[Link]('punkt_tab') # Required for newer NLTK versions
# Import tokenizers
from [Link] import word_tokenize, sent_tokenize
# Input text
text = """
Natural Language Processing (NLP) is a branch of Artificial Intelligence.
It helps computers understand human language.
Python provides the NLTK library for NLP tasks.
Tokenization is the first step in text preprocessing.
"""
# -------------------------------
# Sentence Tokenization
# -------------------------------
sentences = sent_tokenize(text)
print("Sentence Tokenization:")
for i, sentence in enumerate(sentences, start=1):
print(f"{i}. {sentence}")
# -------------------------------
# Word Tokenization
# -------------------------------
words = word_tokenize(text)
print("\nWord Tokenization:")
print(words)