REALM: Integrating Retrieval into Language Representation Models
REALM (Retrieval-Augmented Language Model) is a breakthrough in Natural Language Processing (NLP), designed to combine knowledge retrieval with pre-trained language models.
Unlike traditional models (e.g., BERT, RoBERTa) that memorize world knowledge, REALM retrieves relevant information from external text corpora/Knowledge bases, like Wikipedia, to improve predictions. ๐
๐ก Why Itโs Needed:
- Traditional models store knowledge in their parameters, limiting scalability and interpretability.
- REALM enables models to explicitly reference knowledge, making them efficient and more accurate.

๐ How Does REALM Work?
Masked Language Modeling (MLM):
The model fills in the blanks in a sentence (e.g., "Einstein was a __-born scientist."). REALM retrieves supporting knowledge from external sources to help fill these gaps.
Retrieval System:
Finds helpful passages from a document collection (e.g., Wikipedia). Passes retrieved content along with the input to the language model for better predictions.
Reward Mechanism:
Retrievals that improve predictions are rewarded. Irrelevant retrievals are discouraged to ensure efficiency.

๐ How REALM Finds the Right Information Quickly ๐
REALM (Retrieval-Augmented Language Model) is designed to retrieve the most useful information from millions of documents to answer questions or fill in missing details. But how does it find the right document so quickly? Letโs break it down! ๐ง
๐งฉ How Does REALM Work?
- Imagine every document and every query are placed into a shared virtual space (like a 3D globe but with more dimensions).
- Each document and query is turned into a vector (a point in this space).
- REALM uses MIPS (Maximum Inner Product Search) to find the document that is closest to the query in this space.
Pre-Computation:
All documents are pre-analyzed and stored as vectors before the search begins. This saves time when a query comes in.
Efficient Searching:
REALM uses a tool called ScaNN to quickly compare the query vector to millions of document vectors and find the best match.