Every year at getaround, we (The engineering team) take part in what we call a “Hack Day”.We can work on a subject of our choice for a day, in a team of developers.
We can work on pretty much anything we want as long as it is remotely related to Getaround. It could be exciting beta features, or tooling to make our lives better. It does not necessarily needs to be shippable.
This time, I wanted to work on something both fun and challenging. I always wanted to look into machine learning but never got the chance, so it didn’t took me long to find a fun topic to work on.
As a slack emoji reactions power user, I thought building a bot that could react on slack messages with a relevant emoji would be very useful funny.
Disclaimer: This approach is most likely far from good, this is the result of 3 full-stack engineers working for 8 hours on a topic they didn’t know anything about beforehand.
The following video helped us a lot to grasp the concepts of neural networks :
What I retained of this video, which may not be 100% correct but was enough to build this project, is as follows :
A neural network makes use of a graph data structure to predict a different set of outputs, given a different set of inputs.You have to choose the number of inputs (only rational numbers) and outputs (between 0 and 1).Those are the input layer and output layer, there are also one or more hidden layers in the middle, where the “magic happens”.
My rough understanding is that when you train a neural network, you basically try to find mathematical correlations between the input and the output, you kind of bruteforce coefficients which will transform your inputs into your outputs. There is also things such as the activation function that are taken into account.
Choosing the good number of inputs and outputs is primmordial, as well as number of hidden layers, and depends a lot on the shape of your data and what you expect to get from it.
For our project, as inputs we have a list of words, and as output we want one emoji.
Since the number of inputs and outputs has to be fixed, here is what we decided to do :
First step is to get enough data to work with, we used the slack-ruby-client
gem to fetch messages on a selected list of channels, we only kept the messages with emoji reactions.
We stored the message content and the emoji reactions in a JSON file.
The interesting code is available here.
One important thing to do when working with machine learning is to control how well your model is doing. An usual approach is to keep a certain amount of your data for testing purposes. That’s what we do in train.rake
. We keep 10% of the data apart in another file, and we don’t use this data for training. Later on, we can try to apply our model on this data and see if the results make sense.
To be quite honest, we didn’t obtain a very good result statistically speaking. However, the emoji predictions were quite hilarious, so we decided to stick with it.
Then it’s just a matter of plumbing, we created a slack app and made use of message shortcuts.
Each slack message now has a link in the contextual menu. When clicking on this link, a request is sent to our app from slack, with a payload containing informations about the clicked message. Then, we clean the message with the same process we used for training, and we run it throught the machine learning model.
Finally, we add a reaction to the message, from our bot API key.
Writing this bot was very fun and informative, and made us realize that machine learning concepts, although obscure from the uninformed eye, can be grasped pretty quickly.
If you know about machine learning, I’d love to know what would be the best way to have done that, feel free to leave a comment in the gist I shared.