🦄 How to build a State-of-the-Art Conversational AI with Transfer Learning

Thomas Wolf
May 9, 2019 · 12 min read
Image for post
Image for post
Online demo of the pretrained model we’ll build in this tutorial at convai.huggingface.co. The “suggestions” (bottom) are also powered by the model putting itself in the shoes of the user.
Image for post
Image for post

An AI with a personality 🤠

Image for post
Image for post

What would be a good pretrained model for our purpose?

🦄 OpenAI GPT and GPT-2 models

Image for post
Image for post
A decoder/causal Transformer attends to the left context to generate next words

👻 Adapting a language model to a dialog task

Image for post
Image for post
Input sequence: a concatenation of persona (blue), history (pink) and reply (green) with delimiters (light pink). Here we generate the word “you” to complete the reply.
Image for post
Image for post
Summing three types of inputs embeddings indicating words (grey), position (gradient) and segments (blue/pink/green)

👑 Multi-tasks losses

We will use a multi-task loss combining language modeling with a next-sentence prediction objective.

Image for post
Image for post
Multi-task training objective — the model is provided with two heads for language modeling prediction (orange) and next-sentence classification (blue)

🦊 Training on a dialog dataset

Image for post
Image for post
Image for post
Image for post
Organization of the JSON version of PERSONA-CHAT

👻 Talking with the Model — the Decoder

Image for post
Image for post
Generating a sentence word by word (source)
Image for post
Image for post
Left: Probability assigned to tokens generated by humans and beam search using GPT-2 (Note the strong variance in human text not reproduced by beam-search). Right: N-gram distributions in human and machine-generated texts (Note the complete separation between greedy/beam-search and sampling decoding methods).

Image for post
Image for post
Example using the interactive scripts with default settings — Bot personality: I read twenty books a year. I’m a stunt double as my second job. I only eat kosher. I was raised in a single parent household.

👻 Conclusion


References:

HuggingFace

Stories @ Hugging Face

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store