<jupyter_start><jupyter_text>Using ML model for Emotion AnalysisSimilar to the notebook for lexicon-based model, this is just a quick walkthrough to understand how to load and use the ML model pre-built in the `limbic` package.First, you need to understand the constraints and limitations of the model:- It was built only for a very narrow set of emotions (called Affection Emotions in `limbic`), which are "joy", "sadness", "anger", and "fear".- It was built with a synthetic dataset created using the lexicon-based model from a very particular dataset (top ~90 books from different websites). This means that any biases that could come from this setup will be included in the trained model.- Emotions were not computed using any context disambiguation for the books used, as shown in the Game of Thrones example, it's important that you setup some context when computing emotions (words could mean totally different things depending on the context), so any unfortunate relationship associated by the lexicon-based model could be included in the ML model.- Parameters for the ML model were not tweaked with the full extend of hyper-parameter search parameters (given that I fit the models in my current laptop), which means that it might not be the best version of itself. Same goes for the benchmark experiments with other models (FastText and Scikilearn-based models).<jupyter_code>from limbic.emotion.models.tf_limbic_model import TfLimbicModel

tf_model = TfLimbicModel()  
tf_model.predict('I have a lot of joy and sadness')
tf_model.get_sentence_emotions('I have a lot of joy and sadness.')<jupyter_output><empty_output><jupyter_text>Note that this works within the boundaries for a full sentence. If the sentence is larger than 150 words, then it will be clipped to the first 150 words, and it doesn't consider special relationship for the context of the sentence. Another special difference between this model and the lexicon-based, is that in this case the negation has not been properly learned. This is for sure one of the main areas of improvement for this model (e.g. "I'm not happy" will be classified with a high likelihood of "joy")<jupyter_code>tf_model.get_sentence_emotions('i am not happy')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.04863900044622936, 'fraction_numerical': 0.0035698348951361, 'mean_word_length': 5.2105263157894735, 'pattern_counts': {'":': 0, '<': 9, '<?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': '29664', 'license': 'MIT', 'n_tokens_mistral': 578, 'n_tokens_neox': 544, 'n_words': 327, 'path': 'scripts/ML-model-example.ipynb', 'repo_name': 'glhuilli/srt-analysis', 'size': '2241'}