- A. About the App
- B. Samples: AI-Generated Advice
- C. How Models were Trained
- D. Deployment and Serving the App
- E. Web App Design
- F. Language Model (GPT-2) - How it Works
- G. Mastermind Principle Explained
🧠 Mastermind is a GPT-2 (OpenAI) powered web app that generates short, life advice in the style of world-class experts.
There is a separate language model (117M = small GPT-2) per expert and each was fine-tuned using the language model script from the amazing folks at Hugging Face 🤗.
Retired Navy SEAL and current record holder for the most pull-ups in 24-hours (4,030), David Goggins will teach you the definition of toughness #stayhard 🦾.
Meet your empathy coach, Brene Brown. Goggins may not care about hurting your "feelings," but Brene will teach you to lean into them and be brave ❤️.
Seneca, the "Sentient" Stoic, is a seeker of wisdom and helps guide you to a life of happiness, peace, and prosperity 📜🖋️
Each language model was fine-tuned with the Hugging Face script and 3-4 training epochs were used for each model with the default script settings (took around 5-10 minutes on NVIDIA's Tesla P100 GPU, 16GB on GCP).
A single .txt training file (.csv also works) was prepared and cleaned for each mentor using various sources of text from books/articles they've written and speeches/interview on YouTube if "captions" with punctuation were available (you can use YouTube filter criteria to search for videos with "captions").
The amount of data used for each is incredibly small, yet the language generation model still does a remarkably good job of picking up the speaker's style in word choice/patterns.
- Tony Robbins (2 MB, 465K)
- Paul Graham (1.1 MB, 240K)
- David Goggins (616 KB, 156K)
- Brene Brown (899 KB, 219K)
- Seneca (1.3 MB, 334K)
Hosting: The app was deployed using a docker image on a stand-alone VM from Digital Ocean (2GB RAM, $10/month) and the domain (.fyi) was purchased from namecheap.com. Each model is 550MB and hosted on Dropbox. During the Docker build, the models (separate zipped folders) get downloaded (see 'server.py' script) and unzipped. The .yaml file is not used with Digital Ocean, but works if you deploy the app with Google's App Engine.
GPT-2 Generation Length: By default, the advice generation length is set to a max of 50 tokens in the "server.py" script and the generated text gets truncated down to end (typically) with the last punctuation (., ?, !) found before it reaches 50 tokens. If the generated text does not contain ending punctuation, it automatically gets truncated to 100 characters (user-defined parameter in server.py script).
Scale-ability: Only 1 concurrent request can be ran at a time. Subsequently, 2 users cannot use the app at the same time (creates a "traffic queue") and this decision was made to control costs. Google App Engine offers greater flexibility and load balancing, but comes at a higher cost. Google Cloud Run is Google's stateless option that is cheaper; however, I experienced long delays (30-45 seconds minimum) to start/serve the site ("cold start problem") because of the size of the Docker image (about 1GB).
How App is Ran: The app is built using the Starlette app framework (lightweight, similar to Flask). After clicking the "Generate Advice" button, the app loads the selected mentor's language model and for the chosen question, the language model uses 1 of 3 short "prompts/seeds" (selected at random) to generate the advice.
Helpful Deployment Resources:
- GPT-2: Google Cloud Run Example from Max Woolf and Tutorial
- GPT-2: Basic Web App #1 and Tutorial
- GPT-2: Basic Web App #2
Inspiring Language Generation Demos:
- Hugging Face Web Apps
- Writeup.ai and Tutorial/Lessons Learned
- "News You CAN'T use" from Adam Geitgey and Tutorial
- Max Woolf's Interactive GPT-2 apps
- Allen NLP GPT-2 app
- GPT-2 Poetry & Insights from Gwern
The front-end website was designed using the Blocs app for the majority of the http/css and served with the Starlette app.
To optimize the css/javascript for faster web page loading, I used some insights from Google's "PageSpeed Insights" and leveraged PurifyCSS to remove unused css. In Google Chrome, I also used DevTools to run the audit pages to find recommendations to improve user experience.
Here are some incredible tutorials on language models 👏 👏 👏
Unlock your potential with the world class experts across disciplines!
The "mastermind principle" comes from Napoleon Hill (author of "Think and Grow Rich") and consists of an alliance of two or more minds working in perfect harmony for the attainment of a common definite objective. Success does not come without the cooperation of others.