How does contextual biasing teach ASR to recognize rare words?
- Authors
- Name
- Amit Shekhar
- Published on
Contextual biasing is a way to give a speech recognition model a short list of words that are likely to come up, such as contact names or product names, so that it hears those rare words correctly instead of guessing a common word that sounds similar.
In this blog, we will learn about how contextual biasing teaches ASR to recognize rare words. We will also see why ASR struggles with rare words, what a bias list is, how shallow fusion adds a bonus to the words in the list, how a prefix tree takes the bonus back when a match fails, how deep biasing and prompting let the model read the list by itself, and where it works well and where it fails.
We will cover the following:
- What is ASR?
- Why does ASR struggle with rare words?
- What is contextual biasing?
- The bias list
- Approach 1: Fixing the text after recognition
- Approach 2: Shallow fusion
- The prefix tree and taking the bonus back
- Approach 3: Deep biasing
- Prompting as a form of biasing
- Shallow fusion vs Deep biasing
- Where it works well and where it fails
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What is ASR?
ASR stands for Automatic Speech Recognition. It is a model that listens to audio and writes down the words that were spoken.
Most ASR models do not write the whole sentence at once. They write the text one small piece at a time. These pieces are called tokens. A token can be a full word like "call" or a part of a word like "Ama" in "Amaya".
At every step, the model looks at the audio and the text it has written so far, and gives a score to every possible next token. A higher score means the model believes that token is more likely. Then, it picks the token with the best score, or keeps a few of the best options, and moves to the next step.
So, the ASR model picks the next token based on scores. Contextual biasing works by changing these scores, directly or indirectly.
Why does ASR struggle with rare words?
The best way to learn this is by taking an example.
Let's say we have a phone with a voice assistant, and we have a friend named Amaya in our contacts. We say:
"Call Amaya."
The ASR model writes:
"Call Maya."
Why does this happen?
The ASR model learned from thousands of hours of audio along with the correct text. During training, it heard the word "call" a huge number of times. It heard the name "Maya" many times. But it heard the name "Amaya" very few times, or maybe never.
So, when the audio is a little unclear, the model goes with what it has seen most often. Common words win over rare words.
The same problem happens with:
- Names of people: Amaya, Siobhan, Nguyen
- Names of products: a new app name, a new drug name
- Technical terms: medical words, internal project names
- Places: small towns, street names
These are called rare words, or out-of-vocabulary words when the model has never seen them at all.
These rare words are often the most important words in the sentence. If the model writes "Call Maya" instead of "Call Amaya", the assistant calls the wrong person.
Now, the question is: how can we help the model hear these rare words correctly?
One option is to retrain the model with more audio of these words. But every user has different contacts, every company has different product names, and new words appear every day. We cannot retrain the model for every user.
So, here comes contextual biasing to the rescue.
What is contextual biasing?
Contextual biasing is a technique where we give the ASR model a list of words or phrases that are likely to appear in the current situation, and we push the model to prefer these words while it recognizes the speech.
The word contextual means that the list comes from the current situation, which is the context. On a phone, the context can be the contact list. In a food delivery app, the context can be the restaurant names. In a hospital, the context can be the names of medicines.
The model itself is not retrained. We just give it a different list at the time of use. One phone gives its own contacts, another phone gives its own contacts, and the same model works for both.
We have a detailed blog on keyword boosting that explains how a voice agent uses this idea to hear domain words step by step.
The bias list
The list we give to the model is called the bias list (also called the context list, the phrase list, or the hint list).
For example, the bias list for our phone can look like below:
Amaya
Siobhan
Rahul Verma
Nguyen
For a doctor's dictation app, it can be a list of medicine names. It can have a few words, a few hundred, or sometimes a few thousand phrases. It changes from user to user and from situation to situation.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
Now, the next big question is: how does the model actually use the bias list? Let's see different approaches, one by one.
Approach 1: Fixing the text after recognition
The simplest idea is to let the model write the text normally, and then fix it later.
The model writes "Call Maya". Then, we compare the words in the text with the words in our bias list. "Maya" looks and sounds close to "Amaya", so we replace it.
This is called post-processing or spelling correction.
It works for a few simple cases. But the issue with this approach is that the model has already made its decision without knowing about our list. If the model split the name into "Call a maya", or wrote a word that sounds quite different, our fixing step has very less to work with. The information in the audio is already lost. Also, we can replace a word that was actually correct. If the user really meant "Maya", we just broke a correct sentence.
We need the model to know about the list while it is listening, not after. Let's see how the next approach solve this issue.
Approach 2: Shallow fusion
Remember that the ASR model picks the next token based on scores. In shallow fusion, we do not touch the model at all. We just add a bonus to the score of any token that starts or continues a phrase from our bias list.
Let's go step by step for "Call Amaya".
Step 1: The model has written "Call". Now, it gives scores for the next token. For the sake of example, let say the scores are like below:
"Maya" : 6.0
"a" : 5.5
"Ama" : 5.0
Without biasing, the model picks "Maya". This is the mistake.
Step 2: Now, we check our bias list. The token "Ama" is the start of "Amaya", which is in our bias list. So, we add a bonus of 2.0 to it:
"Maya" : 6.0
"a" : 5.5
"Ama" : 5.0 + 2.0 = 7.0
Now, "Ama" has the best score, so the model picks it.
Step 3: The model has written "Call Ama". The next token "ya" completes "Amaya", so it also gets the bonus. The model picks it, and the final text is "Call Amaya".
Here, we can see that the model still listened to the audio. The audio already made "Ama" a strong option with a score of 5.0, and the bonus made it the winner. If the user had said something completely different, like "Call Rahul", the audio score of "Ama" would be very low, and a small bonus would not be enough to win.
This is why it is called shallow fusion. The bias list is joined (fused) with the model only at the surface, at the final scores. The inside of the model does not know anything about the list.
The size of the bonus is very important:
- If the bonus is too small, the rare word still loses.
- If the bonus is too big, the model starts writing words from the list even when the user did not say them. For example, it can write "Amaya" when the user said "a mayor".
Many speech services let us set this value. For example, the speech adaptation feature of Google Cloud Speech-to-Text lets us give a list of phrases with a boost value for each phrase.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
But here, a new question arises. What happens if the model starts a word from the list but does not finish it?
The prefix tree and taking the bonus back
Let's say our bias list has "Amaya", and the user actually said "Amazon".
The model writes "Ama", and it gets the bonus because "Ama" is the start of "Amaya". Now, the next token is "zon", which is not in "Amaya". So, the match has failed. But the model already got a bonus for "Ama", which it did not deserve.
To handle this, the bias list is stored as a prefix tree. A prefix tree is a tree where each path from the top to the bottom spells one phrase from the list, one token at a time. Phrases that start the same way share the same starting path.
For a bias list with "Amaya", "Amani", and "Rahul", the prefix tree looks like below:
(start)
↓ ↓
"Ama" "Ra"
↓ ↓ ↓
"ya" "ni" "hul"
↓ ↓ ↓
Amaya Amani Rahul
Here, "Amaya" and "Amani" share the same starting token "Ama".
While the model writes the text, we keep track of where we are in this tree:
- If the next token follows a path in the tree, we move one step down and give the bonus.
- If we reach the end of a path, a full phrase from the list is complete. We keep the bonus.
- If the next token does not match any path, the match has failed. We go back to the start of the tree, and we take back the bonus that we gave for the partial match.
So, for "Amazon", the model gets the bonus for "Ama", then "zon" fails the match, and the bonus for "Ama" is removed. The final score of "Amazon" is the same as if there was no biasing at all.
This way, only complete phrases from the list keep the bonus, and words that only start the same way are not unfairly pushed. In research papers, this is often built with a structure called a WFST (Weighted Finite State Transducer), where the "take the bonus back" path is called a failure arc.
Shallow fusion is simple and it works with almost any ASR model. But it has one limit: the bonus can only help a token that the model already gave a decent score to. If the model gives "Ama" a very low score because it has never heard anything like it, a bonus cannot save it.
The issue with this approach is that the model itself does not understand the list. Let's see how the next approach solve this issue.
Approach 3: Deep biasing
In deep biasing, the bias list goes inside the model. The model is trained to read the list and decide by itself which phrase, if any, the user is saying.
One of the well-known examples is CLAS (Contextual Listen, Attend and Spell), from Google researchers in 2018. Let's understand how this kind of model works.
Step 1: Each phrase in the bias list is turned into a list of numbers. This list of numbers is called an embedding, and it holds the information about how the phrase is spelled, in a form the model can use. A small part of the model, called the bias encoder, does this job. It is trained together with the rest of the model.
Step 2: At every step of writing the text, the model looks at the audio and also looks at all the phrase embeddings. It uses attention to do this. Attention means the model gives a weight to each phrase, showing how much that phrase matches what it is hearing right now. The weights add up to 1.
Step 3: The model mixes the phrase embeddings based on these weights and uses this mix, along with the audio, to pick the next token.
For example, when the user says "Call Amaya", the attention weights can look like below:
Amaya : 0.85
Amani : 0.05
Rahul Verma : 0.02
no-bias : 0.08
Here, we can notice the entry called no-bias. This is a special option that means "none of the phrases in the list match". When the user says "What is the weather today?", none of the contacts are being spoken, so the model puts most of the weight on no-bias and writes the sentence normally.
So, how does the model learn to do this? During training, for each audio clip, the model is given a random bias list. Sometimes the list contains phrases from the correct text, and sometimes it contains only random phrases that are not in the audio. This way, the model learns two skills: to pick the right phrase when it is there, and to ignore the list when nothing matches.
The best part is that the model is trained only once. After that, we can give it any new list at the time of use, including names it has never seen in training, and it can still use them.
Deep biasing often uses the list better than shallow fusion, because the model learned how to use it. But it has its own costs. It needs a special model trained with this ability. And when the list becomes very long, with thousands of phrases, the attention takes more computing time and gets spread across many phrases. Also, when two phrases sound very similar, like "Joan" and "John", the model can get confused between them.
To get the benefits of both, some systems combine them: deep biasing inside the model and shallow fusion at the scores.
To learn Embeddings, the Attention Mechanism, and how to Design a Real-Time Voice AI Agent in depth, check out our AI and Machine Learning Program at Outcome School.
Prompting as a form of biasing
Some modern ASR models, like Whisper from OpenAI, can take a text prompt along with the audio. The model is trained to treat the prompt as the text that came just before the audio.
Let's say we give a prompt like below:
Meeting notes with Amaya and Siobhan about the Kubernetes migration.
Here, the model is more likely to spell "Amaya", "Siobhan", and "Kubernetes" correctly, because these words have just appeared in the text before.
This is not a separate bias list with bonus scores, but the goal is the same. We give the model context, and the model leans towards the words in that context. The prompt has a length limit. For example, Whisper only looks at the last 224 tokens of the prompt, so we cannot put a very long list of words in it.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
Shallow fusion vs Deep biasing
Let me tabulate the differences between shallow fusion and deep biasing for your better understanding.
| Point | Shallow fusion | Deep biasing |
|---|---|---|
| Where the list is used | Only at the final scores | Inside the model |
| Needs special training | No | Yes |
| Works with any ASR model | Yes | No, only with models trained for it |
| Control over strength | Easy, we set the bonus value | Harder, the model decides |
| Helps a token the model barely considers | Rarely | Often |
| Cost for very long lists | Low | Higher |
Where it works well and where it fails
Contextual biasing works well when:
- The list is short and clearly related to the situation, like the contacts on a phone.
- The rare words are names or terms that the model has not seen enough during training.
- The list changes often and retraining is not possible.
It fails or causes problems when:
- The list is too long. With thousands of phrases, many of them sound like normal words, and the model starts writing list words when they were not spoken.
- The bonus is too strong. Then, the list words win even over clear audio of other words.
- Two phrases in the list sound almost the same, like "John" and "Joan".
So, in practice, we must keep the bias list short and relevant, and we must tune the bonus value by testing with real audio.
Now we must have understood how contextual biasing teaches ASR to recognize rare words, how shallow fusion and deep biasing use the bias list, and where it works well and where it fails.
Frequently Asked Questions
Do we need to retrain the ASR model to use contextual biasing?
No. With contextual biasing, the model is not retrained for each user. We just give it a different bias list at the time of use. One phone gives its own contacts, another phone gives its own contacts, and the same model works for both. Deep biasing needs a model trained once with this ability, and after that it accepts any new list.
Can contextual biasing help with names the model never heard in training?
Yes, but it depends on the approach. Shallow fusion can only help a token that the model already gave a decent score to, so a bonus cannot save a word the model scores very low. Deep biasing can use names it has never seen in training, because the model learned how to read the bias list.
Can shallow fusion and deep biasing be used together?
Yes. Some systems combine them to get the benefits of both. Deep biasing works inside the model, where the model reads the bias list and decides which phrase the user is saying. Shallow fusion then adds a bonus at the final scores to the tokens that match a phrase from the list.
How long should a bias list be?
The bias list should be short and relevant to the current situation, like the contacts on a phone. With thousands of phrases, many of them sound like normal words, and the model starts writing list words when they were not spoken. In deep biasing, a very long list also takes more computing time and spreads the attention across many phrases.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
