Page 387 - AI_Ver_3.0_class_11
P. 387

#Experiential Learning
                             Video Session

                       Check out https://sites.research.google/versebyverse/
                       This is an experimental AI-powered muse that helps you write poetry inspired by
                       classic American poets.
                       Create your own poem on "Roses" or "A clear blue sky"










                        For Advanced Learners


                  Program 1: Create a simple Python code to display the POS (Parts of Speech) tags

                 # First, make sure to install nltk by executing following steps"
                 # open cmd prompt and type

                 # py -m pip install nltk
                 import nltk
                 from nltk.tokenize import word_tokenize
                 from nltk import pos_tag

                 # Download necessary NLTK data files
                 nltk.download('punkt')
                 nltk.download('averaged_perceptron_tagger')
                 # Sample sentence
                 sentence = "The elephant is a majestic animal"

                 # Tokenize the sentence into words
                 words = word_tokenize(sentence)
                 # Perform part-of-speech tagging
                 pos_tags = pos_tag(words)

                 # Print the tokens with their respective parts of speech
                 for word, pos in pos_tags:
                     print(f"Word: {word}, POS: {pos}")
                 Output:
                   Word: The, POS: DT

                 Word: elephant, POS: NN
                 Word: is, POS: VBZ
                 Word: a, POS: DT
                 Word: majestic, POS: JJ

                 Word: animal, POS: NN

                                                                   Leveraging Linguistics and Computer Science  385
   382   383   384   385   386   387   388   389   390   391   392