Case Study: How to code your ex?
“How did you handle your breakup? I need some tips; my friend is down since weeks!” she said,
“Tell her, not to be stupid enough and delete any of their pics/chatlogs/audio messages” I Added,
“Are you mad? why would anyone do that?”
Why shouldn’t you flush out your ex’s logs?
“Breakups are tough, part of life, people change, objectives change, shit happens” and tonnes of other quotes thrown at people who are going through a break-up, It’s natural for them to try to make you feel better in the best way they can. — At the risk of sounding absurd, I’d say “people who are suffering from breakup need a little more than these quotes”, perhaps an emotional support from the person they’ve been in a relationship with, share laugh, smiles, they shared once. Relationship — is a personal affair, and it can’t happen with “just another person.”
Coming through, to the sad part, people change. In most of the break-ups stories, their partner are the one’s who are trying to make them uncomfortable,(#BreakUpSwagYo! :P). How to tackle this situation? You can’t be with the person, and even if you are, chances are that person is not the same with whom you want to be with. That persons behaviour may have changed towards you.
How to get similar responses that were shared? *
*(excluding post breakup ego offcourse)
Answer: ChatBots
yes, chatbots! Here’s a small little definition of chatbots:
Short for chat robot, a computer program that simulates human conversation, or chat, through artificial intelligence. Typically, a chat bot will communicate with a real person. (source)
Question Two: How to ‘humanize’ the bot?
*(this is where I shall put up my bot’s introduction)*
so let’s assume I had a relationship which ended up being messy, and let’s call her Priye(प्रिये)(Means “Beloved” in Hindi), Priye is (a beautiful 18 YO, Free-soul, Proud Tamilian, happy go lucky, caring, pampered, posessive) girl.(again, ASSUME!)
How to ‘humanize the bot’?
Neural Networks
Artificial Neural Networks or ANN’s are the build up of nodes, which imitate biological neurones of the human brain. The model creates a series of filtration methods, (which act’s like middle layer, between input and output) parameter received as input is transferred to these middle layer node’s which filter’s out possible results in a node value (or Activision) which is then transferred to another node for better filtration.
Machine Learning:
1. Supervised* (need of the moment)
2. Unsupervised
3. Forced
Since we have inputs and outputs via chatlog, this sounds like a perfect case for building supervised learning machine model.
There are three important steps to implement an NN, a) Building Model b) Training the data set, and c)Test it.
I tried different things, scraping via emails, scraping via msn chat’s, it took lot of work to find the context of the answers (remember, we’re building a personality service backed by Neutral Networks via service API’s) did get pretty close to train the Machine Learning Model, however the best part was to get Facebook’s messages, following is a small tutorial on how to get your partner’s chat log’s
open Index.html, from the archive, open ‘messages.html’, click on your partner’s link, and run a quick jquery for loop to fetch, input and output. (your chat log’s as input, partner’s response as output)
PS: (the context here needs to get it done manually :( )
So now we have our DataSet to work with, which contain’s chatlogs (A, B)
how to get the context?
Introducing WIT.AI
WIT.AI is a Facebook backed API service that turns natural language speech into Intent based reply resulting into actionable data. Get started with wit.ai here
So we have Data+Context+Natural language process taken care of, how else we can humanize this bot?
Again! Let’s ASSUME, priye used to call me up early morning, can this bot call me up as well?
HELL YEAH!!
here’s a call snippet from Twillo that’s helping this bot make calls.
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);
client.calls.create({
url: "http://demo.twilio.com/docs/voice.xml",
to: "+14155551212",
from: "+15017250604"
}, function(err, call) {
process.stdout.write(call.sid);
});
Scheduling calls & Messages
usually this can be done via inbuilt cron jobs, however i used this npm module to invoke this script,
var cron = require('node-cron');cron.schedule('* * * Jan,Sep Sun', function(){console.log('running on Sundays of January and September'); GetACall() //invokes twillo API's to get a call. });
Randomization:
Randomization is the key here, (let’s ASSUME, Priye is full of mood swings) add up a function with randomised value to invoke the GetACall function.
Similar things can be done, for good morning/good night messages, or random surprises :)
Authorization
Adding up “approval to chat” becomes more of necessity rather than a feature, you don’t want other’s to know how your conversations looked like with your “bae”, do you? :)
Responding with your day — to — day events
let’s thank google to put up a proper calender API, the bot would be able to respond to your events and send surprised messages “best of luck messages” depending upon the context ! ;) #SoMuchSwagRight?
(following is the quick snippet to read an event one in Python)
event = service.events().get(calendarId='primary', eventId='eventId').execute()
print event['summary']
Check the google document’s on calender here
What’s next?
I will be open sourcing few snippet that was used to build up Priye; perhaps it could help the poor broken soul as well! :) Feel free to ping me on facebook or tweet me — if you have any questions/query or you would like to team up with something awesome. :)
Extended Note: I’ve been following this medium post and other reddit threads, regarding a similar concepts, where comments like “it’s sad to see people trying fall in love with bots rather than real people” are common, this chatbot was meant to be a fun project, and it’s working out really well for me.
comments? feel free to get in touch here ❤ :)