Generate Emoji Reactions for Tweets using MindsDB

Generate Emoji Reactions for Tweets using MindsDB

How I solved the problem of Generating Emoji Reactions for tweets using MindsDB

ยท

3 min read

Introduction

Generate Emoji Reactions for Tweets using MindsDB is an exciting project that explores the use of natural language processing and machine learning to predict and generate emoji reactions for tweets. The MindsDB - Hugging face model powers this project.

The article provides an overall guide to building a machine-learning model that can predict emoji reactions for tweets based on their content and deploying the same in the production environment

Problem Statement

Generate Emotions for text is sometimes challenging for the humans themselves. We have huge volumes of data generated by Twitter every day, and understanding the emotions of each particular tweet is daunting.

Solution Proposed

Therefore the proposed solution is to automate the extraction of tweets of the particular user and run the MindsDB machine learning model on top of it.

Design & Implementation

This Project uses the Tweepy library for extracting tweets from the given user, and it extracts the latest 10 tweets. Once added the logic for extracting the tweets of the given user using the below snippet

 tweets = api.user_timeline(screen_name=username, count=10, tweet_mode='extended')
 df = pd.DataFrame({
                'tweet_id': [tweet.id for tweet in tweets],
                'created_at': [tweet.created_at for tweet in tweets],
                'text': [tweet.full_text for tweet in tweets],
                'retweet_count': [tweet.retweet_count for tweet in tweets],
                'favorite_count': [tweet.favorite_count for tweet in tweets],
                'lang': [tweet.lang for tweet in tweets],
                'source': [tweet.source for tweet in tweets]
            })

And the next step is to create the below ML model in MindsDB.

CREATE MODEL mindsdb.hf_emotions_6
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'j-hartmann/emotion-english-distilroberta-base',
input_column = 'text';

Once the model is created, you can query the status of the model using the below command.

SELECT *
FROM mindsdb.models 
WHERE name = 'hf_emotions_6';

Now use the below Python function to pass your data & query the predictions

def predict_from_mindsdb(df: pd.DataFrame):
    server=mdb.connect(login=MDB_EMAIL,password=MDB_PWD)
    model=server.get_project('mindsdb').get_model(MODEL_NAME)
    pred_df = pd.DataFrame(columns=['text'])
    pred_df['text'] = df['text']
    try: 
        ret_df = model.predict(pred_df)
    except Exception as e:
        print('Not able to generate predictions at the moment')
    return ret_df

The entire code is listed in this repository here, and the project is live here

Working Screenshots

The project is live and hosted in the following link: https://bala-ceg-tweets-emotion-classifer-mindsdb.streamlit.app/

Conclusion

In conclusion, the use of MindsDB to generate emoji reactions for tweets provides an innovative and efficient way to analyze social media sentiment. By leveraging the power of machine learning, this approach allows for more accurate and comprehensive sentiment analysis, which can be useful for various applications such as brand monitoring, customer service, and market research. With the ease of use and accessibility of MindsDB, anyone can leverage the power of machine learning to gain insights from social media data.

If you want to contribute to this project, you are most welcome! And finally, a big thank you for taking the time to read my article. Please support me by liking the article and sharing the article if you like it, and follow me for more related articles.

#mindsdb @mindsdb @hashnode #machinelearning #AI #datascience #mindsdbhackathon

Did you find this article valuable?

Support Balaji Seetharaman by becoming a sponsor. Any amount is appreciated!

ย