Inspiration

With the rapid progress in Machine Learning (ML) and Natural Language Processing (NLP), new algorithms are able to generate texts that seem more and more human-produced. One such algorithm, GPT2, has been used in many open-source applications. I have recently been inspired to delve into AI driven text generation and I decided to utilize GPT2 to make a machine learning story generator. I decided to create an app that would help students' mental health. The best way to do this was to make my software that would help people laugh and enjoy themselves. In keeping with the theme of entertainment and fun, I have used transcripts from the first 3 seasons of Rick and Morty as my training dataset for the stories that are generated.

What it does

MortyAI takes a pre-trained GPT2 model on Rick and Morty transcripts and uses Hugging Face’s Transformers library to generate text that resembles the structure of the show's writing.

How I built it

First, the dataset used to fine-tune GPT2 consisted of the first 3 seasons of Rick and Morty transcripts. The data was downloaded and stored in a raw text format. Each line represents a speaker and their utterance or an action/scene description. The dataset was split into training and test data, which contain 6905 and 1454 lines, respectively.

Next, utilizing Hugging Face’s Transformers library, the GPT2 model trained the data on Google Notebooks. GPT2 works by using transformers, which eliminates the need for a convolutional neural network. Instead it works on an encoder-decoder configuration, or in this case, sequence-to-sequence learning. In short the encoder takes the input sequence and maps it into a higher dimensional space. That abstract vector is fed into the decoder which turns it into an output sequence. The output sequence can be symbols, a language translation, or in this case, a transcript similar to the input in the same language. After the model was finished training, the trained model output folder containing all relevant model files was downloaded.

Moving onto the app, I utilized the stream lit API to develop the frontend UI (also note that I manually took lines from a couple of episodes to be starting prompts when generating a story). Finally, to improve the quality of the output I adjusted the parameters for the decoding method, and applied Google API's bad-word filter to keep the content of the stories censored, considering the vulgar content that is in Rick and Morty.

Challenges I ran into

I was pressed for time at this hackathon, and the output still is not incredibly cohesive. Stories make somewhat sense, but the pacing and events can get confusing and random.

Accomplishments that I'm proud of

Creating this model in the short time frame of the hackathon

What I learned

How to utilize GPT2 and use streamlit's API for python UI development.

What's next for MortyAI

Hopefully a more proper model and a robust UI.

Built With

  • gpt2
  • neural-network
  • python
  • transformer
Share this project:

Updates