Metric learning trains models to output a semantically meaningful distance between data points rather than a class label. The objective is to learn an embedding space where a simple distance function—such as Euclidean distance or cosine similarity—directly reflects semantic similarity. This is achieved through loss functions like triplet loss or contrastive loss, which explicitly pull anchor-positive pairs together while pushing anchor-negative pairs apart during training.
Glossary
Metric Learning

What is Metric Learning?
Metric learning is a branch of machine learning that learns a distance function to map similar samples close together and dissimilar samples far apart in an embedding space.
In few-shot modulation recognition, metric learning enables classifiers to compare a query signal against a small support set of labeled examples without retraining. Architectures like prototypical networks and relation networks rely on this principle to compute distances to class prototypes or learned relation scores. The approach is foundational for open set recognition and zero-shot classification, where the learned distance thresholds can reject unknown modulation schemes that fall beyond a calibrated margin.
Key Characteristics of Metric Learning
Metric learning fundamentally redefines how models perceive similarity by learning a task-specific distance function, rather than relying on generic, pre-defined metrics.
Learned Distance Functions
Unlike standard classification that learns decision boundaries, metric learning learns a distance function directly from data. This function maps inputs to an embedding space where Euclidean or cosine distance reflects semantic similarity. The objective is to minimize intra-class distance while maximizing inter-class distance, creating tightly clustered, well-separated manifolds.
Contrastive and Triplet Losses
Training relies on structured loss functions that operate on pairs or triplets of samples:
- Contrastive Loss: Penalizes similar pairs that are far apart and dissimilar pairs that are too close.
- Triplet Loss: Uses an anchor, a positive sample (same class), and a negative sample (different class) to enforce a margin of separation. These losses directly shape the geometry of the embedding space.
Non-Linear Similarity via Deep Networks
Deep metric learning uses neural networks as non-linear embedding functions. A convolutional or transformer backbone extracts hierarchical features, transforming raw inputs (like IQ samples) into a compact vector where complex, non-linear relationships are flattened into a simple distance metric. This allows the model to learn invariances to nuisance factors like noise or channel impairments.
Generalization to Novel Classes
A defining characteristic is the ability to generalize to classes never seen during training. Because the model learns a universal similarity function rather than class-specific boundaries, it can compare a new, unlabeled query sample against a small support set of novel classes. Classification is performed by a nearest-neighbor lookup in the learned embedding space, making it foundational for few-shot learning.
Proxy-Based and Proxy-Anchor Losses
To overcome the computational burden of sampling tuples from large datasets, modern approaches use proxies. A proxy is a learnable vector representing a class prototype. Losses like Proxy-NCA or Proxy-Anchor pull samples toward their class proxy and push them away from others. This reduces training complexity from O(N²) or O(N³) to O(N) while maintaining high retrieval performance.
Angular Margin Penalties
Advanced metric learning objectives, such as ArcFace or CosFace, introduce an additive angular margin penalty in the softmax loss. By normalizing weights and features and adding a margin to the target logit, these methods enforce a stricter geodesic distance constraint on a hypersphere. This significantly enhances intra-class compactness and inter-class discrepancy, producing highly discriminative embeddings.
Frequently Asked Questions
Direct answers to the most common questions about learning distance functions for few-shot modulation recognition and embedding space design.
Metric learning is a branch of machine learning that learns a distance function to map input data into an embedding space where semantically similar samples cluster together and dissimilar samples are pushed apart. Unlike traditional classification that learns decision boundaries, metric learning explicitly optimizes for relative distances between data points. The core mechanism involves a Siamese or triplet network architecture that processes pairs or triplets of examples through shared-weight neural networks. A loss function—such as contrastive loss, triplet loss, or N-pair loss—then penalizes the model when similar items are far apart or dissimilar items are close together. For modulation recognition, this means learning an embedding where QPSK signals from different transmitters map to nearby vectors, while QAM64 signals map to a distant region, enabling classification via simple nearest-neighbor lookup even with very few labeled examples.
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.
Metric Learning vs. Standard Classification
Fundamental architectural and behavioral differences between metric-based embedding approaches and traditional softmax classifiers for signal recognition tasks.
| Feature | Metric Learning | Standard Classification |
|---|---|---|
Core Objective | Learn a distance function that maps similar samples close and dissimilar samples far apart in embedding space | Learn a direct mapping from input features to fixed class labels via decision boundaries |
Output Layer | Embedding vector (e.g., 64-256 dimensions); no fixed class head | Softmax layer with N neurons, one per known class |
Supports Novel Classes at Inference | ||
Requires Retraining for New Classes | ||
Training Loss Function | Triplet loss, contrastive loss, N-pair loss, or proxy-based losses | Cross-entropy loss with one-hot encoded labels |
Generalization Mechanism | Episodic training on N-way K-shot tasks; learns to compare rather than memorize | Memorizes class-specific decision boundaries; struggles with unseen classes |
Few-Shot Learning Capability | Native support via support set comparison | Requires transfer learning or fine-tuning with additional data |
Open Set Recognition | Natural fit via distance thresholding on embedding space | Requires additional out-of-distribution detection modules |
Related Terms
Metric learning provides the mathematical foundation for comparing signals in a learned space. These core concepts define how distance, similarity, and representation interact to enable few-shot modulation recognition.
Embedding Space
A learned, lower-dimensional vector representation where semantically similar inputs are mapped to nearby points. In modulation recognition, raw IQ samples are transformed into compact embeddings where signals of the same modulation scheme cluster together.
- Dimensionality Reduction: Compresses high-dimensional signal data into dense feature vectors
- Semantic Structure: Euclidean distance in this space corresponds to modulation similarity
- Visualization: t-SNE or UMAP projections reveal class separation quality
A well-trained embedding space is the prerequisite for any metric-based few-shot classifier.
Cosine Similarity
A measure of similarity between two non-zero vectors computed as the cosine of the angle between them, ranging from -1 to 1. Unlike Euclidean distance, cosine similarity is magnitude-invariant, making it robust to variations in signal power.
- Formula: cos(θ) = (A·B) / (||A|| ||B||)
- Use Case: Default similarity metric in prototypical networks for comparing query embeddings to class prototypes
- Advantage: Normalizes out amplitude differences that are irrelevant to modulation identity
Often preferred over Euclidean distance when signal gain varies across captures.
Prototypical Networks
A metric-based meta-learning algorithm that classifies query samples by computing their distance to a prototype representation—the mean vector of embedded support samples—for each class. The class with the nearest prototype wins.
- Prototype Calculation: c_k = (1/|S_k|) Σ f_φ(x_i) for all x_i in class k
- Distance Metric: Typically squared Euclidean distance or cosine similarity
- Training Objective: Minimize negative log-probability of correct class via softmax over distances
Simple yet highly effective for few-shot modulation recognition when combined with a strong embedding function.
N-way K-shot
The standard episodic training paradigm for few-shot learning where a model must discriminate between N novel classes given only K labeled examples per class in the support set. This explicitly simulates deployment conditions.
- 5-way 1-shot: Classify among 5 modulation types with only 1 example each
- 5-way 5-shot: Same 5 classes but with 5 labeled samples per class
- Episodic Structure: Each episode draws random classes and samples to prevent overfitting
Higher K generally improves accuracy, but metric learning aims to maximize performance even at K=1.
Contrastive Loss
A loss function that trains embedding networks by pulling positive pairs (same class) together and pushing negative pairs (different classes) apart in the embedding space. This directly optimizes for the clustering behavior metric classifiers rely on.
- Siamese Networks: Twin networks process pairs with shared weights
- Triplet Loss: Uses anchor-positive-negative triplets with a margin constraint
- Supervised Contrastive Loss: Leverages full class labels for richer negative sampling
Contrastive objectives produce embeddings where simple nearest-neighbor rules achieve high accuracy.
Relation Networks
A metric-based architecture that learns a deep nonlinear distance metric via a relation module—a small neural network—rather than using a fixed similarity function like cosine or Euclidean distance. The relation module takes a concatenated query-support pair and outputs a relation score.
- Learnable Metric: The relation module discovers complex similarity patterns
- Flexibility: Can capture non-linear relationships that fixed metrics miss
- End-to-End: Both the embedding function and the relation module are trained jointly
Particularly useful when modulation classes have subtle, non-linear distinguishing features in the embedding space.

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