# imessage-chatbot **Repository Path**: yohannlee/imessage-chatbot ## Basic Information - **Project Name**: imessage-chatbot - **Description**: Recurrent neural network -- generates messages in your style of speech! Trained on imessage data. Sqlite3, TensorFlow, Flask, Twilio SMS, AWS. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-26 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # imessage-rnn In-progress project: Building a neural network to learn an individual's style of speaking, and respond in their manner. **Current State:** Trained on my iMessages from the past year (many of which are with my mom). ~**60%** accuracy in letter-by-letter message generation. Disclaimer: I am not responsible for what the neural network generates! [Live Chat](http://chat.anastassia.io/). ### Technologies * Training messages obtained with **SQL** * Recurrent Neural Network (RNN) built with **TensorFlow** * **Flask** app responds with generated messages to a **Twilio SMS** webhook * **AWS EC2**: Trained RNN on p2.xlarge instance, message generator deployed through t2.micro instance ### Implementation #### 1. Extract Data Data was extracted from the iMessage sqlite3 database, located in `/Library/Messages/chat.db`. Getting all messages from yourself: ```sql SELECT text FROM message WHERE is_from_me = 1; ``` Getting all messages from another person: ```sql -- get their handle_id SELECT * FROM handle WHERE id="(their_phone_number)"; -- use it to extract their messages SELECT text FROM message WHERE handle_id = "(handle_id)" AND is_from_me = 0; ``` Save the ascii messages to a .txt file and format it (ie; deal with emojis). #### 2. Process Data With `dataset.py`, process the text data with parameters from `config.py` into _batches_. The input shape for the recurrent neural network is: (None, 32, 62, 256). #### 3. Train the Recurrent Neural Network model Now draw the rest of the owl #### 4. Use the model to generate text When a text is sent to our Twilio webhook, it hits out app, which generates a message and responds.
Chatbot available through both SMS and online chat.
Our app is very basic. It has two backend routes, one to respond to texts via Twilio and one that responds to messages on the [online app version](http://chat.anastassia.io/). ```python @app.route("/sms", methods=['GET', 'POST']) def sms_reply(): resp = MessagingResponse() rnn_message = generate_message(459) resp.message(rnn_message) return str(resp) @app.route("/message", methods=['GET']) def message_reply(): return str(generate_message(459)) ``` The current step is to generate responses of varying natural lengths 🤔. ### Next Steps - [x] Add a second layer to the model - [x] Improve RNN performance with LSTM cells - [x] In progress: Build web app version with **React** - [x] In progress: Generate responses of varying lengths - [ ] Look into Natural Language Processing (NLP) - [ ] Increase training data