Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Natural Language Processing using Python/Day 1 Lab .ipynb
3074 views
Kernel: Python 3 (ipykernel)

sample_text = """ Here’s a 5-line sample text containing Data and AI:

"Data is the backbone of modern Artificial Intelligence systems. AI models rely heavily on structured and unstructured data to learn and make predictions. The quality of insights depends on the richness and accuracy of the data. AI advancements are enabling real-time data analysis and decision-making. Together, Data and AI are driving innovation across industries." . """

Ques1

  • Write a Python script to tokenize the following sample text into words.

  • Write a Python script to tokenize the following sample text into sentences.

  • Write a Python script to perform part-of-speech tagging on the following sample text.

  • Write a Python script to perform named entity recognition on the following sample text.

  • Write a Python script to perform stemming on the "Dancing Running and Sleeping".

  • Write a Python script to perform lemmatization on the "Dancing Running and Sleeping".

  • Write a Python script to extract custom named entities

  • Write a Python script to perform dependency parsing on the following sample text.

Ques2

Create chunking, focusing on extracting noun phrases (NP) along with prepositional phrases (PP) from the following sample texts:

  • Ram Loves his Life. He have a cat named RUMMY

  • The quick brown fox jumps over the lazy dog

Ques3 Create a Script which can accept a text. and Ask users of following after word token. 1. Use Stop Words 2. POS tagging 3. generate Antonyms and opposite words.

import nltk from nltk.corpus import stopwords, wordnet from nltk.tokenize import word_tokenize from nltk import pos_tag # Download required resources nltk.download('punkt') nltk.download('stopwords') nltk.download('wordnet') nltk.download('averaged_perceptron_tagger') def remove_stop_words(tokens): stop_words = set(stopwords.words('english')) filtered_tokens = [word for word in tokens if word.lower() not in stop_words] return filtered_tokens def pos_tagging(tokens): return pos_tag(tokens) def generate_antonyms(word): antonyms = set() for syn in wordnet.synsets(word): for lemma in syn.lemmas(): if lemma.antonyms(): antonyms.add(lemma.antonyms()[0].name()) return antonyms if antonyms else "No antonyms found" def main(): text = input("Enter a text: ") tokens = word_tokenize(text) print("\nOptions:") print("1. Remove Stop Words") print("2. Perform POS Tagging") print("3. Generate Antonyms") option = input("\nEnter your choice (1/2/3): ") if option == "1": filtered_tokens = remove_stop_words(tokens) print("\nTokens after removing stop words:") print(filtered_tokens) elif option == "2": pos_tags = pos_tagging(tokens) print("\nPOS tags:") print(pos_tags) elif option == "3": word = input("\nEnter a word to find antonyms: ") antonyms = generate_antonyms(word) print("\nAntonyms:") print(antonyms) else: print("\nInvalid option. Please choose 1, 2, or 3.") if __name__ == "__main__": main()
[nltk_data] Downloading package punkt to [nltk_data] C:\Users\Suyashi144893\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package stopwords to [nltk_data] C:\Users\Suyashi144893\AppData\Roaming\nltk_data... [nltk_data] Package stopwords is already up-to-date! [nltk_data] Downloading package wordnet to [nltk_data] C:\Users\Suyashi144893\AppData\Roaming\nltk_data... [nltk_data] Package wordnet is already up-to-date! [nltk_data] Downloading package averaged_perceptron_tagger to [nltk_data] C:\Users\Suyashi144893\AppData\Roaming\nltk_data... [nltk_data] Package averaged_perceptron_tagger is already up-to- [nltk_data] date!
Enter a text: Great job everyone, thank yoiu for your copo Options: 1. Remove Stop Words 2. Perform POS Tagging 3. Generate Antonyms Enter your choice (1/2/3): 3 Enter a word to find antonyms: Great Antonyms: No antonyms found