Language Modeling — I
This is Part 1 of the 5 part series on language modeling.
Introduction
As you might have guessed by now, language modeling is a use-case employed by us daily, and still, its a complicated concept to grasp. REALM (Retrieval-Augmented Language Model Pre-Training) is the latest addition to the growing research in this domain. It is a great step ahead and that’s exactly why it makes this a challenging paper to read and review.
This blog assumes that you have a fundamental understanding of deep learning, word vectors, and embeddings space, as these are a prerequisite to master language models.
The principle method of training (deep) computer vision models has gradually reached the doors of natural language processing as well. We are talking about transfer learning.
Once we understand the landscape of model pre-training in NLP, we would be in a comfortable yet confusing spot to grasp what REALM does and how!
To walk us through the field of language modeling and getting a hold over the relevant concepts we will cover the following in this series of blogs:
- Transfer learning and its relevance to model pre-training
- Open Domain Question answering (Open-QA)
- BERT (bidirectional transformers for language understanding)
- Roberta ( robustly optimized BERT pre-training approach)
- Google T5
- REALM: Retrieval-Augmented Language Model Pre-Training
This post will specifically try to explain the following:
- Transfer learning
- Language Model Pre-training
Transfer learning
When we have a huge dataset of images for which we want to solve an image classification and/or localization task, we explicitly utilize the image pixels as the features. Training deep neural networks to solve such tasks requires us to utilize humongous amounts of computing power and data. Usually, big tech companies and research labs working in this domain have already trained many such networks from scratch and released their pre-trained weights online. How can we utilize this?
Let’s consider a simple convolutional neural network (shown above) with 4 convolution layers (conv + relu + max pool) followed by a fully connected (FC) layer which terminates with a loss function like softmax or sigmoid. We are training this model on the ImageNet dataset, which is a collection of over ~1 million images belonging to ~1000 classes.
Get Mandar Deshpande’s stories in your inbox
Join Medium for free to get updates from this writer.
Now the task of deep neural networks is to progressively extract features and combine these features to learn even more complex features. Each of the layers shown in the above figure is doing the following tasks:
- Conv1 — extracts simple edges, curves, and lines
- Conv2 — uses these learned features to extract shapes and geometrical segments in the image
- Conv3 — learns to detect textures like mesh patterns or smooth cloth or roads
- Conv4 — learns even more complex features like eyes, ears, chairs, doors and other fundamental cues which help us understand what the object might be
- FC layer — uses the previously learned features to find out combinations which work out well together to give a coherent picture of the object to be classified
- Loss Function — this combination given out by the FC layer is converted to a score and the high score/probability class is returned as prediction
Now if we observe closely, features learned by the model in the first few layers are quite generic to any image and can be seen as redundant across a range of image classes. The only layer that helps us explicitly differentiate between objects is the fully connected layer with the loss function.
Generally, when we talk about training a deep neural network, we mean we are going to freeze the weights of most of the convolution layers (`marked in pink`) and we just modify the weights of the fully connected layers with the loss function (`marked in the green`). Essentially we can change the entire network after the frozen layers and make it suitable to a similar image-based learning task. Only the part of the weights which are allowed to change is modified through training on new use-case specific data. This update to the weights of a pre-trained model is called fine-tuning.
Eg, we have a pre-trained model for image classification with a particular loss function and we want to solve the task of image segmentation. So we freeze the conv layers and modify the FC layers to optimize the loss function relevant to segmentation, such that our model learns to predict the bounding box (location) along with the object class prediction.
The use of models trained on a particular domain of learning tasks and repurposing the learned weights to solve another similar learning task is called transfer learning.
Since the model trained using transfer learning doesn’t need to learn from scratch, it can easily be trained to a equal or higher performance metric (eg accuracy) without much computational cost and time.
Language Model Pre-Training
When we work with a huge corpus of textual data, it helps to know the probability with which a sequence of words will follow each other and what particular features are needed to understand this dependence.
Language modeling is the task of understanding this probability distribution over a sequence of words. This helps us create features that can distinguish between sentences and phrases, as per the context in which they appear.
Comparison with Word Embeddings
Whenever we want to utilize words or textual data as features in our model, we usually convert them into sparse vectors like one-hot encoding or else dense vectors called embeddings. Though pre-trained embeddings have been widely used in NLP tasks earlier as well, the novelty of language model pre-training is the fact that they are fine-tuned for a particular downstream task and not as widely generalized like embeddings are for texts. Embeddings like word2vec and GloVe are a vector representation of words or sentence which capture the context and semantic features of each word. Pre-trained language models further distill these embeddings to task-specific representation such the specific goal is achieved through training on tasks specific datasets.
In effect, we feed huge corpus (Wikipedia, Quora) of unlabelled/unannotated texts to a language model and expect it to learn the inherent word and sentence level relationships between varying contexts and subjects. Once the model is trained, this essentially means the model has learned the structure of the language i.e. the language has been modeled in some latent vector/embedding space. Once we have a pre-trained language model we can utilize it for any downstream tasks such as text classification, text generation, and sentiment classification.
The use of pre-trained language models has been the most exciting news in natural language processing in a long time and a lot of upcoming research is building upon this concept. This domain can be highlighted by through the following seminal works in pre-trained language models:
- ULMFiT : Universal Language Model Fine-Tuning method
- ELMo: Embeddings from Language Models
- Transformer: Attention is All You Need
- BERT: Bidirectional Encoder Representations from Transformers
We will review a few of these and continue our discussion on language modeling specifically for REALM in the follow-up posts.
Link to Part I: Language Modeling I
Link to Part II: Language Modeling II: ELMo and ULMFiT
Link to Part III : The Transformer: A Quick Run Through
Keep learning and growing till then!
Connect with me on Twitter: https://twitter.com/mandroid_6
All images above have been created by me on my iPad and I have the rights to use them











