<jupyter_start><jupyter_text>Core Module> API details.<jupyter_code>#hide
from nbdev.showdoc import *
#hide
#!pip install flair
#export
from flair.models import TextClassifier
from flair.data import Sentence

def get_sentiment(message):
    classifier = TextClassifier.load('en-sentiment') # rely on sentiment-en-mix-distillbert.pt
    sentence = Sentence(message)
    classifier.predict(sentence)
    #print('Sentence sentiment: ', sentence.labels)
    label = sentence.labels[0]
    return {'result': label.value, 'polarity':label.score}
res = get_sentiment("I hate you !")
print(res)
assert res['result'] == 'NEGATIVE'
res = get_sentiment("I love you !")
print(res)
assert res['result'] == 'POSITIVE'
res = get_sentiment("Trump is the President of the USA.")
print(res)
assert res['result'] == 'POSITIVE'
res = get_sentiment("Biden is the President of the USA.")
print(res)
assert res['result'] == 'POSITIVE'
#hide
from nbdev.export import notebook2script
notebook2script()<jupyter_output>Converted 00_core.ipynb.
Converted index.ipynb.
{'fraction_non_alphanumeric': 0.12993262752646775, 'fraction_numerical': 0.004812319538017324, 'mean_word_length': 5.887417218543046, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '40128', 'license': 'Apache-2.0', 'n_tokens_mistral': 355, 'n_tokens_neox': 346, 'n_words': 88, 'path': '00_core.ipynb', 'repo_name': 'trancept/nbdev_flask-api_docker_demo', 'size': '1039'}