In this talk we’ll go over the process of making a twitter bot: user interaction, scheduling bot actions (tweeting, replying etc) and deployment. I’ll do a mini showcase of bots people have made. The focus will be on the creative and generative possibilities of twitter bots rather than simulating human conversation or automating tasks.
9. I hope people like this talk I am giving. Otherwise it will be very
very awkward. Well at least there are waffles, sorry donuts.
"I ho" -> "hope" -> "ope " -> "pe p" -> "epeo" -> " peop" -> "eopl"
-> "ople" -> "ple " -> "le l" -> "e li" -> "like" -> "ike " -> "ke t" -> "e
th " -> "this" - > ...
10. I am not a number! I am a person! I am a person I tell you! I mean it, I am tired
actually. I am very tired.
Key Value Probability
I am a (⅖)
I am not (⅕)
I am tired (⅕)
I am very (⅕)
And I’m going to be talking to you about twitter bots!
So what is a twitter bot? Well a bot is software designed to perform a certain task.
For twitter bots, those tasks would the things you and I do on twitter.
So, things like looking to see who is following us, tweeting, retweeting, liking, SUBTWEETING And a twitter bots would be able to do all or some of that but without a human involved in every stage of the process.
There are different kinds of bots that you can find out in the wild on twitter, I’m going to go through some of them.
There are bots that are just kind of random. This bot OminousZoom just tweets images and zooms in on them.
There are Markov chain bots: You feed text through a Markov chain algorithm and then it mixes it up to produce something like this. The source text can be in a Google Sheet or collected from a twitter source, or any kind of data really. For this the input text was a database of Star Trek scripts.
This markov chain bot was trained on the King James Bible & crypto whitepapers.
And if you’re wondering what the hell a markov chains are, they are mathematical systems that hop from one state to another.
For example, if you made a Markov chain model of a baby's behavior, you might include "playing," "eating", "sleeping," and "crying" as states and all those states would form a a state space which is a list of all the states.
In addition to the state space, the markov chain tells you you the probability of going from one state to another. For example, the probability that a baby currently playing will fall asleep next.
And how this works for text generation is every couple of letters would be a state and the Markov process transitions from state to state as the text is read.
The text on the screen is using a Markov model of order 4, so each sequence of 4 letters is a state and you can see the transitions from one state to another.
And then the second part is the probability of transitioning. So for example in english, the letter q is often followed by the letter u, so there would be a high probability that when the current state is q the next state would be u.
Same goes when the markov chain is fed a lot of text. It’ll count the number of times a word follows a state.
So if we are starting our text generation with the current state being “I am,” the next word will be chosen at random with probability based on what words historically have followed the current word.
http://www.stat.purdue.edu/~mdw/CSOI/MarkovLab.html
https://blog.codinghorror.com/markov-and-you/
But you don’t actually need to know all of that, you can just use one of these libraries if you want to create a markov chain bot.
Ok back to bots! There are bots that just pull from data sources. Sometimes they manipulate the data.
censusAmericans tweets biographies of Americans based on data they provided to the U.S. Census Bureau. It gets numbers and info from the data and reconstructs that as a mini narrative.
Deleted Wiki Titles just tweets article titles that have been removed from Wikipedia.
There are bots that generate sentences that follow a certain structure. So for this, it’s the same sentence with a few changes each time. what’s being replaced in each permutation is the people performing the action and what is being replaced. This is corpus generated.
Which means it gets data from a corpus which is a static collection of organized data.
The creator of that bot we just saw, created a repo which contains a static collection of corpora. So for his project he uses the list of venues and new technologies
And you can get stuff like a list of adverbs, adjectives also.
This corpus generated bot is what we’re going to be making today!
So a little background information on what we’re making: it’s a bot that generates awards to any and everyone because I’m not a big fan of the forbes 30 under 30.
We’re going to be using:
Twit: Twitter API Client for node (REST & Streaming API)
Glitch: Friendly community for building apps, we’re going to host our code there
Tracery: A tool for generating text
Corpora: to get data
So the first step to making a twitter bot is signing up for an account. You’ll need a phone number for that.
Then you can create your application.
That process looks like that. For website you can typically put in any URL but the URL we have there is where our bot is being hosted on glitch.
And then you can also change your permissions depending on what you want you app to do.
After you created your app, you should have access to your key and access tokens which will be in that tab.
What we’ll need for our app and what twitter will give you after you create an application are the consumer key, consumer secret, access token and access token secret. After setting up twit with that information, we’re ready to start tweeting.
But before we start tweeting we have to figure out what we’re going to tweet.
So remember when you were in school, to learn the basics of grammar you would do mad-libs where you would have to fill out the blanks in a story?
Well that’s what we’re going to do with this twitter bot.
We’re going to be replacing the nouns, adjectives and prepositions so it becomes something like
THIS. And we do that using Tracery which is a tool for generating text.
So brightspiral is a way of playing with tracery without any code.
how Tracery works is that you provide it with replacement grammar.
A replacement grammar takes a starting symbol, and replaces it with one of several rules.
Replacement grammar -> origin
Starting symbols (in hashes): name and occupation
Rules for occupation: baker, wizard, soldier
In this case the replacement grammar is origin. So here the starting symbols are ‘name’ and ‘occupation.’ The rules is the list you see after the symbol so for name the rules are Bertram....
And on the right you see the starting symbols have been replaced with one of their rules.
How this would work in code would be that the replacement grammar would be in JSON format.
At the top is the structure we’re trying to get. We’re generating from the verb onwards.
flatten is a tracey method that actually generates the text.
So if we generate the numbers randomly and concatenate everything we end with something like this:
Some of my favs are "10 under 89 working unbearably until Food & Beverages" and "3 under 55 working happily minus Military."
And then back to the tweeting, this is how you post a tweet using twit. This is the easy part, methods for tweeting, replying, liking are all available in the twit documentation and you can just copy and paste which is what I did.
Now all that’s left is to schedule tweeting. We can use a free service called CronJob to do that. There are also others available like uptimerobot.
And that’s it! Our bot is tweeting!
And as a bonus, since svg is just structured text, you can also use tracery to create generative image bots. This one creates tiny spires.
And this one auto generates fictional tropical paradises
And both of those use cheapbotsdonequick.com which is something you can use to create bots without any programming!
And if you do want to write code, there are a bunch of starter templates for making bots on glitch!