<jupyter_start><jupyter_text><jupyter_code>def gender_features(word):
  return {'last_letter':word[-1]}
gender_features('Obama')
import nltk
nltk.download('all')
from nltk.corpus import names
names.words()
len(names.words())
labeled_names = ([(name,'male') for name in names.words('male.txt')] + [(name, 'female')  for name in names.words('female.txt')])
labeled_names
import random
random.shuffle(labeled_names)
labeled_names
featuresets = [(gender_features(n),gender) for (n,gender) in labeled_names]
train_set,test_set = featuresets[5000:],featuresets[:2000]
classifier = nltk.NaiveBayesClassifier.train(train_set)
classifier.classify(gender_features('David'))
classifier.classify(gender_features('Rocky'))
classifier.classify(gender_features('Michael'))
nltk.classify.accuracy(classifier,test_set)
from sklearn.feature_extraction.text import CountVectorizer
vect=CountVectorizer(binary=True)
corpus = ["Tessaract is good optical character recognition engine  ", "optical character recognition is significant "]
vect.fit(corpus)
vocab=vect.vocabulary_
vocab
for key in sorted(vocab.keys()):
    print("{}:{}".format(key, vocab[key]))
print(vect.transform(["This is a good optical illusion"]).toarray())
from sklearn.metrics.pairwise import cosine_similarity
similarity = cosine_similarity(vect.transform(["Google Cloud Vision is a character recognition engine"]).toarray(), vect.transform(["OCR is an optical character recognition engine"]).toarray())
print(similarity)<jupyter_output>[[0.89442719]]
{'fraction_non_alphanumeric': 0.13715046604527298, 'fraction_numerical': 0.011984021304926764, 'mean_word_length': 9.155405405405405, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '652296', 'license': 'MIT', 'n_tokens_mistral': 512, 'n_tokens_neox': 482, 'n_words': 99, 'path': 'NLP_week4.ipynb', 'repo_name': 'holps-7/NLP-weekly', 'size': '1502'}