A contextual embedding is a dense numerical vector that represents a token's meaning as a function of its entire linguistic context, rather than assigning a single static representation. Unlike traditional word embeddings like Word2Vec, where the word 'MI' has one fixed vector regardless of usage, a contextual model such as BERT or ClinicalBERT generates a unique embedding for each occurrence. This allows the model to encode the specific semantic properties activated by surrounding words, distinguishing between 'MI' meaning Myocardial Infarction in a cardiology note and 'MI' meaning Mitral Insufficiency in a surgical report.
Glossary
Contextual Embedding

What is Contextual Embedding?
A contextual embedding is a dynamic vector representation of a word that changes based on its surrounding text, enabling models to distinguish between multiple meanings of polysemous terms.
The mechanism relies on a transformer architecture where self-attention layers compute weighted representations of every token relative to every other token in the input sequence. For clinical abbreviation disambiguation, this means the embedding for an ambiguous acronym is directly shaped by diagnostically relevant context words like 'troponin' or 'regurgitation.' The resulting vector positions the token in a high-dimensional semantic space where its proximity to candidate sense embeddings—such as UMLS concept vectors—can be measured via cosine similarity to select the correct expansion from a sense inventory.
Key Characteristics of Contextual Embeddings
Contextual embeddings are the foundational mechanism that allows modern NLP models to resolve linguistic ambiguity by generating word representations that are dynamically shaped by surrounding text, rather than using static, one-size-fits-all vectors.
Dynamic vs. Static Representation
Unlike static embeddings like Word2Vec where the word 'cold' has a single, unchanging vector, a contextual model generates a unique embedding for 'cold' in 'the patient feels cold' versus 'the patient has a cold.' This dynamic generation is the core mechanism enabling disambiguation. The model's internal attention layers weigh the surrounding words to produce a representation that captures the specific activated sense.
Attention-Based Context Weighing
The self-attention mechanism in transformer architectures computes a weighted sum of all other tokens in the input sequence to build the embedding for a target token. For an ambiguous abbreviation like 'MI', the model learns to assign high attention weights to relevant context words:
- Cardiology context: 'chest pain,' 'troponin,' 'EKG' → high attention → 'Myocardial Infarction' sense.
- Cardiology context: 'regurgitation,' 'leaflet,' 'valve' → high attention → 'Mitral Insufficiency' sense. This attention distribution is what makes the embedding contextual.
Bidirectional Context Integration
Contextual models like BERT and ClinicalBERT are bidirectional, meaning the embedding for a word is informed by both the tokens to its left and its right simultaneously. This is critical for clinical text where a defining term may appear after the abbreviation:
- 'The patient's MI was treated with thrombolytics.'
- 'The patient's MI was treated with a mitral clip.' A unidirectional model would fail to disambiguate until after processing the abbreviation, but a bidirectional model builds the correct sense into the embedding from the start.
Cosine Similarity for Sense Mapping
Once a contextual embedding is generated for an ambiguous mention, it must be mapped to a canonical concept. This is typically done by computing the cosine similarity between the mention's embedding and pre-computed embeddings for each candidate sense from a knowledge base like UMLS.
- The mention embedding for 'MI' in a cardiology note will have a high cosine similarity (e.g., 0.95) with the embedding for the UMLS concept C0027051 (Myocardial Infarction).
- The same mention in a dermatology note will score higher against C0025202 (Melanoma In Situ). A cosine similarity threshold is then used to accept or reject the top mapping.
Subword Tokenization for Rare Terms
Contextual models use subword tokenization algorithms like WordPiece or Byte-Pair Encoding (BPE). This allows them to construct embeddings for rare or misspelled clinical abbreviations by composing representations of known subword fragments. For example, an unseen abbreviation like 'TEE' (Transesophageal Echocardiogram) can be tokenized into ['T', '##EE'], and its embedding is built from the context surrounding these fragments. This is essential for handling the long tail of idiosyncratic clinical shorthand.
Layer-Wise Contextualization
Contextual embeddings are not a single output but a hierarchy of representations across the model's layers. Lower layers tend to capture local syntax and morphology, while upper layers capture high-level semantic meaning. For disambiguation, the final hidden layers are typically used as they encode the task-specific sense. Research shows that probing the upper layers of ClinicalBERT reveals distinct vector clusters for different senses of the same abbreviation, confirming that the disambiguation signal is encoded in the embedding geometry.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Explore the mechanics of dynamic vector representations that allow language models to resolve ambiguity in clinical text by understanding surrounding context.
A contextual embedding is a dynamic vector representation of a word whose numerical values change based on the surrounding text, unlike a static embedding which assigns a single, fixed vector regardless of context. Static models like Word2Vec generate one representation for 'MI,' forcing it to conflate the cardiological and dermatological senses. In contrast, a transformer architecture like BERT generates distinct contextual embeddings for 'MI' in 'Patient admitted with acute MI' versus 'MI diagnosed on skin exam,' allowing downstream systems to correctly distinguish between Myocardial Infarction and Malignant Melanoma. This dynamic generation is the foundational mechanism enabling robust Word Sense Disambiguation in clinical NLP.
Related Terms
Master the core mechanisms and complementary techniques that make contextual embedding the backbone of modern clinical NLP disambiguation.
Word Sense Disambiguation (WSD)
The computational task of identifying which meaning of a polysemous or homonymous word is activated by its use in a particular context. Contextual embeddings are the modern solution to this classic NLP problem.
- Core Challenge: Resolving ambiguity for terms like 'cold' (temperature vs. illness) or 'MI' (myocardial infarction vs. mitral insufficiency).
- Pre-Transformer Era: Relied on knowledge-based methods (WordNet) or supervised classifiers with static features.
- Transformer Era: Models like BERT generate dynamic embeddings that inherently capture the correct sense based on surrounding words.
- Clinical Impact: Directly prevents documentation errors by ensuring the correct ICD-10-CM code is assigned to a resolved abbreviation.
Attention-Based Disambiguation
The core mechanism within transformer architectures that enables contextual embeddings to resolve ambiguity. Attention weights quantify how much each surrounding word influences the representation of an ambiguous term.
- Self-Attention: Allows 'MI' to attend to 'troponin' and 'chest pain' (cardiology context) or 'rash' and 'topical' (dermatology context).
- Multi-Head Attention: Different heads can specialize in syntactic dependencies, semantic relatedness, and domain-specific signals simultaneously.
- Visualization: Attention heatmaps provide interpretability, showing clinicians exactly which context words drove the disambiguation decision.
- Clinical BERT: Models like BioBERT and ClinicalBERT have attention heads fine-tuned on MIMIC-III, making them sensitive to clinical co-occurrence patterns.
Candidate Sense Generation
The initial retrieval step in disambiguation that fetches all possible meanings of an abbreviation from a structured sense inventory before contextual scoring.
- UMLS Metathesaurus: The primary source for clinical senses, containing millions of concepts with unique CUIs.
- Inventory Construction: Pre-compiled from resources like SNOMED CT, RxNorm, and LOINC to cover all possible expansions.
- Filtering: Initial pruning using semantic type filtering (e.g., keeping only 'Disease or Syndrome' senses if the section header is 'Diagnoses').
- Embedding Pre-computation: Each candidate sense is encoded into a static embedding using the same model for efficient cosine similarity comparison.
Cosine Similarity Threshold
A mathematical metric measuring the semantic relatedness between the contextualized embedding of an ambiguous abbreviation and the pre-computed embeddings of its candidate senses.
- Calculation: Measures the cosine of the angle between two vectors in high-dimensional space, ranging from -1 (opposite) to 1 (identical).
- Threshold Tuning: A high threshold (e.g., 0.85) ensures high precision but may reject valid matches; a lower threshold increases recall at the cost of potential false positives.
- Clinical Application: When resolving 'CHF', the contextual embedding from 'The patient has CHF' will show high cosine similarity to the 'Congestive Heart Failure' embedding and low similarity to 'Children's Health Fund'.
- Confidence Scoring: The raw similarity score can be surfaced in a human-in-the-loop review interface to prioritize low-confidence predictions for clinical review.
Document-Level Context
The use of information beyond the immediate sentence to resolve abbreviations that remain locally ambiguous. Contextual embeddings can be pooled or aggregated across an entire clinical note.
- Problem List Integration: A patient's coded problem list provides strong prior evidence for disambiguation (e.g., a history of 'I25.10' strongly favors the cardiac sense of 'MI').
- Section Header Awareness: A model can learn that 'MI' in the 'Past Medical History' section is more likely to be a diagnosis than a procedure.
- Long-Range Dependencies: Transformer architectures with sufficient context windows (e.g., 4096 tokens) can attend to relevant information paragraphs away.
- Temporal Reasoning: Combining document-level context with temporal expression normalization ensures that a resolved abbreviation is correctly placed in the patient's clinical timeline.
Negation Scope Detection
The critical task of determining whether a resolved abbreviation falls within the scope of a negation cue, ensuring that 'no MI' is correctly interpreted as the absence of myocardial infarction.
- ConText Algorithm: Extends the classic NegEx algorithm to determine negation, temporality (historical vs. recent), and experiencer (patient vs. family member).
- Scope Boundaries: Defined by syntactic patterns and punctuation; negation typically scopes from the cue ('no', 'denies', 'without') to the next clause boundary.
- Embedding Interaction: The contextual embedding of 'MI' in 'denies any MI' will be influenced by the negation cue, shifting it away from affirmed sense embeddings.
- Downstream Impact: Prevents false-positive extraction that could lead to incorrect quality metrics, billing codes, or clinical decision support triggers.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us