Skip to content

analyze trump's nonsense, feed in a topic, and generate a new tweet based on a custom corpus.

Notifications You must be signed in to change notification settings

Garrett-Webb/trumptweets

Repository files navigation

trumptweets

Disclaimer

This was made for CruzHacks 2020 by Garrett Webb and Chandni Nagda, please do not steal our work, just ask us. It was posted to Devpost for said hackathon at https://devpost.com/software/what-would-trump-tweet-ds6wxl.

also, due to Donald Trump's twitter ban, this can't be fed any new data, but could be adapted for use on somebody else's twitter page.

Goal

Analyze Trump's nonsense using Microsoft Azure NLP and trigram language model. Generate similar nonsense for a given topic.

Usage

Install what you'll need:

  • go on the internet and get python 3.x.x (latest version)
  • sudo easy_install pip (mac only, or just install pip the way you would)
  • pip install nltk (or pip3)
  • pip install tweepy (or pip3)
  • pip install azure (or pip3)
  • pip install numpy (or pip3)
  • python3 (this will take you to the python interpereter CLI)
  • >> import nltk
  • >> nltk.download('punkt')
  • there may be more but it should tell you.

Simply make your own config.py file with API keys for twitter and Microsoft Azure Text Analytics. Set the following for Microsoft Azure:

  • subscription_key = "whatever"
  • endpoint = "whatever"
  • filename = "whatever"

Set the following for Twitter

  • auth = tweepy.OAuthHandler("whatever")
  • auth.set_access_token("whatever")

Then either run model.py with topic as the command line argument, or run trumptweets.py and let it go (it will continuously tweet at the time interval you set). Here is an example on the command line:

  • python3 model.py <keyword> will output a tweet to the console
  • python3 trumptweets.py will generate and output a tweet to the console as well as post it to twitter on the time interval you specify in the code.

Go to https://twitter.com/R3alFakeDonald (our twitter bot) or your make own twitter developer account and bot to see your madness unfurl.

What Would Trump Tweet?

Summary of work done

Inspiration

Curiosity and President Trump

What it does

Analyzes Donald Trump's tweets, and given a key phrase, constructs a language model for donald trump's tweets on that topic, then uses the model to generate a potential tweet, and tweets it to twitter.

How I built it

First, we cleaned the data of Donald's twitter archive, then used Microsoft Azure Text Analysis API to get key phrases of each tweet. After that, we added functionality to subset the tweets based on appearance of a given word in the set of key phrases of a tweet generated by Azure. With this subset, we then generate and run a language model on the smaller set of more relevant data. This gives a tweet more closely related to the keyword we provide to the system.

Challenges I ran into

the largest challenge by far was finding and incorporating a language model that ran well on a small subset of tweets. we overcame this by using NLTK and a trigram language model. The next challenge was using this to generate a custom corpus based on the data, and not with pre-provided corpuses in the libraries. Yet another challenge was using Microsoft Azure Text Analytics API and thinking about usage limits, with our large amount of tweets that were being analyzed. We overcame this by simply processing them in batches of 1000 tweets every minute to comply by the 1k/60s limit.

Accomplishments that I'm proud of

Improving the standard Neural Net model which gave incomprehensible tweets by using Azure to relate it to a certain topic. This, I believe, was a really good idea for using a small set of data.

What I learned

I learned how to use NLTK, Microsoft Azure Text Analytics API, and Tweepy (twitter API) to make a fully functional twitter bot using Natural Language Processing.

What's next for What Would Trump Tweet

To unleash it on the world, and possibly put it on an AWS or Azure cloud instance to run indefinitely.