Large Language Models (LLMs) are surprisingly good at In-Context Learning (ICL)—the ability to learn a new task just by seeing a few examples in a prompt. But while we know they can do it, we don't quite understand the "shape" of the logic they use to get there.
In their NeurIPS 2024 paper, researchers from UCLA propose a classic machine learning approach to peek under the hood: visualizing decision boundaries. By treating LLMs as simple classifiers, they reveal that the internal logic of ICL is far messier than we previously thought.
TL;DR
Visualizing how LLMs classify data reveals that their in-context decision boundaries are often fragmented and "jagged," even for simple linear tasks where classical models excel. However, these boundaries can be smoothed and made more robust through targeted fine-tuning on synthetic tasks or uncertainty-aware active prompting.
What Problem Does This Paper Address?
Most research on ICL focuses on accuracy—did the model get the answer right? But accuracy is a coarse metric. A model can have high accuracy on a specific test set while possessing a highly brittle internal logic that fails if an input is shifted slightly.
Classical machine learning uses decision boundaries to visualize how a model partitions feature space. A "smooth" boundary usually indicates good generalization, while a "jagged" or fragmented one suggests overfitting or poor inductive bias. This paper applies this lens to LLMs to understand why ICL is often sensitive to prompt order, label names, and small perturbations.
Methods
The authors developed a framework to probe LLMs by:
- Visualization: They prompted models (ranging from Llama-2-7B to GPT-4o) with 2D coordinate pairs and labels. By querying the model across a dense grid of points, they mapped out the decision regions.
- CustomLLM Architecture: They experimented with freezing the transformer backbone and adding fresh, task-specific MLP heads to handle numerical data directly, bypassing the standard text-based output.
- Synthetic Supervised Fine-Tuning (SFT): They trained models on thousands of synthetic classification tasks (lines, circles, moons) to see if "learning to learn" on simple shapes improves ICL on complex ones.
- Active Prompting: Instead of providing random examples, they used an uncertainty-aware strategy, selecting points where the model’s prediction entropy was highest to include in the prompt.
Datasets
- Synthetic Tasks: Generated via
scikit-learn, including linearly separable clusters, concentric circles, and interleaving "moons." - NLP Benchmarks: To test real-world text classification, they used datasets like SST-2 (sentiment), AG_NEWS (topic), and RTE (entailment), projecting high-dimensional text embeddings into 2D space using t-SNE for visualization.
Key Insights and Ideas
-
The Fragmentation Paradox: Even state-of-the-art models like GPT-4o produce "Swiss cheese" decision boundaries on simple linear tasks. While a Support Vector Machine (SVM) draws a clean line, LLMs create islands of conflicting predictions.
Figure 1: Decision boundaries of LLMs and traditional machine learning models on a linearly separable binary classification task. The background colors represent the model’s predictions, while the points represent the in-context or training examples. LLMs exhibit non-smooth decision boundaries compared to the classical models. See Appendix E for model hyperparameters. -
Accuracy is Deceptive: As you add more in-context examples, test accuracy goes up, but the decision boundary often remains fragmented. This suggests that "more data" doesn't automatically fix the underlying lack of robustness in ICL.
- Semantic Priors vs. Data: LLMs are heavily biased by label names. Using "Foo/Bar" as labels results in different boundaries than "Yes/No," proving that the model's pre-trained knowledge of words often fights against the patterns provided in the prompt.
-
Order Matters (Visually): The paper visualizes how shuffling the order of examples drastically reshapes the decision boundary, providing a geometric explanation for the known sensitivity of LLMs to prompt ordering.
Figure 5: The sensitivity of the Llama3-8b model’s decision boundary to the order of in-context examples. Each subplot (Order 0 to Order 4) shows the model’s decision boundary with the same 32 examples shuffled differently.
Key Results
- Synthetic SFT is a "Smoothie": Fine-tuning Llama-3-8B on simple binary linear tasks allowed it to generalize to 4-class non-linear tasks with remarkably smooth boundaries. This suggests that exposure to simple geometric tasks can regularize the model's ICL behavior.
- Active Learning Efficiency: Using uncertainty-aware sampling to pick prompt examples significantly smoothed boundaries and improved accuracy more quickly than random sampling. For instance, active sampling reached 0.96 accuracy with 256 examples, compared to just 0.88 for random sampling.
- Quantization Effects: Moving from 8-bit to 4-bit quantization primarily affects the "fuzzy" regions near the decision boundary, flipping predictions in areas where the model is already uncertain.
Limitations and Future Work
- Dimensionality: Most visualizations are in 2D. While t-SNE was used for text, the behavior of these boundaries in high-dimensional space remains an open question.
- Numerical Bias: LLMs are trained on text, not raw coordinates. The "jaggedness" might partially stem from the model's struggle to interpret numerical strings as continuous spatial features.
- Future Directions: The authors suggest exploring whether these irregular boundaries are linked to adversarial vulnerabilities—if a boundary is fragmented, it's much easier to find a "nearby" point that tricks the model.
By moving beyond simple accuracy scores and looking at the "geometry" of ICL, this work provides a new roadmap for making LLMs more reliable and predictable in few-shot settings.
Summary updated