<jupyter_start><jupyter_text>Textblob Demo<jupyter_code>#!pip install textblob
from textblob import TextBlob

testimonial = TextBlob("Textblob is awful. What a disappointment!")
pol, sub = testimonial.sentiment
pol<jupyter_output><empty_output><jupyter_text>Vader Demo<jupyter_code>!pip install vaderSentiment
sentences = ["This book was fantastic.",  
             "This book was good",  # 
             "This book was ok.", # 
             "This book was rather meager.",  # 
             "This book was terrible", # 
             "This book was the worst I ever read", # 
             ]

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyzer = SentimentIntensityAnalyzer()
for sentence in sentences:
    vs = analyzer.polarity_scores(sentence)
    print("{:-<65} {}".format(sentence, str(vs)))


res = []

for currsent in sentences:
   #print(currsent)
   print(TextBlob(currsent).sentiment)
   res.append(TextBlob(currsent).sentiment[0])

res

import tensorflow_datasets as tfds
train_data, validation_data, test_data = tfds.load(
    name="imdb_reviews", 
    split=('train[:60%]', 'train[60%:]', 'test'),
    as_supervised=True)
train_examples_batch, train_labels_batch = next(iter(train_data.batch(10)))
train_examples_batch
a = train_examples_batch[2].numpy()
type(str(a))
print(TextBlob(str(a)).sentiment)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11906501095690285, 'fraction_numerical': 0.007304601899196494, 'mean_word_length': 4.393700787401575, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '319924', 'license': 'MIT', 'n_tokens_mistral': 473, 'n_tokens_neox': 447, 'n_words': 97, 'path': 'chapters/en/slides/Sentiment.ipynb', 'repo_name': 'rschmaelzle/rs103', 'size': '1369'}