<jupyter_start><jupyter_text>Classifier<jupyter_code>from nltk.corpus import names
names.words()
def gender_features(word):
    return {'last_letter':word[-1]}

gender_features("Obama")
gender_features("Purushottam")
print(len(names.words()))
labeled_names = ([(name,'male') for name in names.words('male.txt')] + [(name,'female') for name in names.words('female.txt')])
import random
random.shuffle(labeled_names)
featuresets = [(gender_features(n),gender) for(n,gender) in labeled_names]
train_set , test_set = featuresets[5000:],featuresets[:2000]
import nltk
classifier = nltk.NaiveBayesClassifier.train(train_set)
classifier.show_most_informative_features()
classifier.classify(gender_features("David"))
print(nltk.classify.accuracy(classifier,test_set))
classifier.classify(gender_features("Purushottam"))
classifier.classify(gender_features("Shweta"))
classifier.classify(gender_features("Surya"))<jupyter_output><empty_output><jupyter_text>POS Tagger<jupyter_code>import nltk 
from nltk.corpus import stopwords 
from nltk.tokenize import word_tokenize, sent_tokenize 
stop_words = set(stopwords.words('english')) 
  

txt = ("Sukanya, Rajib and Naba are my good friends. " 
    "Sukanya is getting married next year. " 
    "Marriage is a big step in one’s life."  
    "It is both exciting and frightening. "  
    "But friendship is a sacred bond between people." 
    "It is a special kind of love between us. " 
    "Many of you must have tried searching for a friend " 
    "but never found the right one.")
  
# sent_tokenize is one of instances of  
# PunktSentenceTokenizer from the nltk.tokenize.punkt module 
  
tokenized = sent_tokenize(txt) 
for i in tokenized: 
      
    # Word tokenizers is used to find the words  
    # and punctuation in a string 
    wordsList = nltk.word_tokenize(i) 
  
    # removing stop words from wordList 
    wordsList = [w for w in wordsList if not w in stop_words]  
  
    #  Using a Tagger. Which is part-of-speech  
    # tagger or POS-tagger.  
    tagged = nltk.pos_tag(wordsList) 
  
    print(tagged)<jupyter_output>[('Sukanya', 'NNP'), (',', ','), ('Rajib', 'NNP'), ('Naba', 'NNP'), ('good', 'JJ'), ('friends', 'NNS'), ('.', '.')]
[('Sukanya', 'NNP'), ('getting', 'VBG'), ('married', 'VBN'), ('next', 'JJ'), ('year', 'NN'), ('.', '.')]
[('Marriage', 'NN'), ('big', 'JJ'), ('step', 'NN'), ('one', 'CD'), ('’', 'NN'), ('life.It', 'NN'), ('exciting', 'VBG'), ('frightening', 'NN'), ('.', '.')]
[('But', 'CC'), ('friendship', 'NN'), ('sacred', 'VBD'), ('bond', 'NN'), ('people.It', 'NN'), ('special', 'JJ'), ('kind', 'NN'), ('love', 'VB'), ('us', 'PRP'), ('.', '.')]
[('Many', 'JJ'), ('must', 'MD'), ('tried', 'VB'), ('searching', 'VBG'), ('friend', 'NN'), ('never', 'RB'), ('found', 'VBD'), ('right', 'JJ'), ('one', 'CD'), ('.', '.')]
StarcoderdataJupyterStructuredCleanDedup