VisML Lab: Visualization for NLP

DS-GA 3001 - Fall 2026 - Visualization for NLP

Bhavya Matam

NYU Center for Data Science

2026-11-03

Lab Overview

  • Today: look inside language models with three hands-on tools
  • Work in pairs. For every experiment: predict first, then run, then explain any surprise
  • Embeddings, then attention, then a perturbation-based explanation (LIME)
  • Last week: dimensionality reduction. Next week: topological data analysis

Plan for tonight (50 minutes)

Minutes
Set-up and framing 3
Part 1: word embeddings in the Embedding Projector 14
Part 2: attention in Transformer Explainer 15
Part 3: LIME on a text classifier (Colab) 13
Debrief and proposal feedback 5
  • Experiments marked optional are the first to cut
  • Chart QA and chart-to-text are a backup block at the end: skip them tonight

Three Ways to Look at an NLP Model

Representations

What does the model think is similar?

Embedding Projector

Project word vectors, read neighbors

Internals

Where does the model look?

Transformer Explainer

Read attention maps head by head

Behavior

Which words changed the answer?

LIME

Perturb the input, watch the output

Each view answers a different question. None of them is the full story.

Part 1: Word Embeddings

Tool: Embedding Projector (browser)  ·  Time: about 14 minutes

What does the model think is similar?

Embedding Projector: Set-up

Open https://projector.tensorflow.org/

  • In the dataset menu (top left), choose Word2Vec 10K: 10,000 words, each a 200-dimensional vector
  • The bottom-left tabs choose the projection: UMAP, T-SNE, PCA, Custom
  • Type a word in the Search box (right panel) and click a result: its nearest neighbors are listed, with distances
  • Drag to rotate the 3-D view. Click a point to select it. Isolate keeps only the selected points

Find: the same word in PCA and in t-SNE. Does it land in the same neighborhood?

Experiment 1: Who Are the Neighbors?

Predict: what are the nearest neighbors of bank? Of apple? Of python?

  1. Search each word and read the nearest-neighbor list in the right panel
  2. For each: does the list reflect one meaning of the word, or all of them?
  3. Try three words of your own. Find one whose neighbors surprise you

Connect to lecture: a static embedding assigns one vector per word type, so a word with several senses gets one blended position.

Experiment 2: Same Vectors, Three Pictures

Predict: pick a word and note its 10 nearest neighbors. Will the same neighbors be close together in PCA? In t-SNE? In UMAP?

  1. Select the word. Note which neighbors from the list you can see near it in each tab
  2. Click Isolate 101 points (the word and its neighbors), then run t-SNE again. Change the perplexity (5, then 50)
  3. Which projection keeps the most neighbors nearby? Which one shows the largest gaps between clusters, and can you trust those gaps?

Connect to last week: crowding, perplexity, and what each method preserves.

Experiment 3 (optional): A Custom Axis

Predict: if you define an axis from he to she, where do doctor, nurse, engineer and teacher fall?

  1. Open the Custom tab. Set Left to a search pattern such as he and Right to she (try man and woman too)
  2. Read where occupations and other words land between the two ends
  3. Try another axis of your own (for example rich to poor, or good to bad)

Discuss: what is the embedding learning from the data? Is that what you want from a tool you deploy?

Part 2: Attention

Tool: Transformer Explainer (browser)  ·  Time: about 15 minutes

Where does the model look?

Transformer Explainer: Set-up

Open https://poloclub.github.io/transformer-explainer/

  • A small GPT-2 model runs live in your browser
  • Type your own text, or pick an example, then press Generate
  • The diagram flows left to right: embedding → transformer block (attention, MLP) → next-token probabilities
  • Click the attention block to expand it. Temperature (and top-k / top-p) control the sampling

Find: where do the token embeddings go, and where do the attention heads sit?

Experiment 4: Next-Token Probabilities

Predict: type Data visualization helps people and look at the output distribution. What happens to it when you set the temperature to 0.2? To 2.0?

  1. Generate with the default temperature. Which words get the most probability?
  2. Lower the temperature, generate again. Then raise it
  3. Which setting gives the same answer every time? Which gives surprising ones?

Connect to lecture: the model is a function from a token sequence to a probability distribution. Everything we visualize is a window onto how it computes that distribution.

Experiment 5: Read an Attention Map

Predict: attention maps are tokens × tokens. Which half of the matrix will be empty for this model?

  1. Type a sentence of 8-10 tokens, for example: The animal didn't cross the street because it was too tired
  2. Expand the attention block and look at one head
  3. Hover over a token. Where does its attention go?

Connect to lecture: the lower-triangular shape is the mask in scaled dot-product attention. A token may only look at earlier tokens.

Experiment 6 (optional): Heads Are Not Interchangeable

Predict: do all heads in a layer look alike?

  1. Step through several heads in the same layer. Sketch what each one attends to
  2. Find a head that mostly looks at the previous token, and one that spreads attention widely
  3. Change one word in the sentence (tired → wide). Which heads change, and which do not?

Discuss: with layers × heads maps per sentence, how would you decide which ones to look at? (SANVis aggregated, Dodrio ranked, AttentionViz projected.)

Does Attention Explain the Prediction?

Attention is not explanation. Attention weights often do not agree with other importance measures, and very different weights can give the same prediction.

Attention is not not explanation. It depends on what you mean by “explanation”. Under some definitions and tests, attention is informative.

A highlighted token tells you where the model looked, not whether the answer would change without it.

Next: a test that changes the input and watches the output.

Part 3: LIME on a Text Classifier

Tool: Google Colab notebook  ·  Time: about 13 minutes

Which words changed the answer?

LIME: Perturb, Query, Fit

  1. Perturb: remove random words from the text
  2. Query: ask the model for its prediction on each variant
  3. Fit: a small linear model on the variants. Its weights are the explanation

Treats the model as a black box. Explains one prediction at a time.

Set-up: Open the Notebook

Open the Colab notebook:

https://colab.research.google.com/github/ctsilva/ctsilva.github.io/blob/main/2026-VisML-CDS/labs/nlp-vis/lime_text.ipynb

  • File → Save a copy in Drive, then run the cells from the top (first cell installs lime)
  • The model is a TF-IDF + logistic regression classifier for two newsgroups: alt.atheism vs soc.religion.christian
  • The model gets about 90 percent test accuracy. LIME will tell us why

Predict: is a 90 percent accurate model for the right reasons?

Exercise 1: Right Answer, Wrong Reason

  1. Run section 2 on the default post. Read the highlighted words
  2. Run the loop that prints the top words for five posts
  3. Find a post where the model is correct but a top word has nothing to do with religion. Record the post number, the word, and its weight

Discuss with your partner: if you only had accuracy, would you have found this?

Exercise 2: Take the Shortcut Away

Predict: reload the data with headers, footers and quotes removed. Will test accuracy go up, down, or stay the same?

  1. Run section 4 and compare the accuracy with section 1
  2. Explain the same post again with the cleaned model. How do the highlighted words change?
  3. Which model would you rather deploy? Which one looks better on a leaderboard?

Connect to lecture: the explanation exposed a shortcut that a single accuracy number hid.

Exercise 3 (optional): Probe It Yourself

  1. Write your own short text and run section 5. Try one that mixes both topics, and one that mentions neither
  2. Read the prediction and the highlighted words. Does the model say something confident about a text with no signal?
  3. Run section 6 to compare LIME’s local weights with the model’s global top words

Discuss: how would you show these explanations to a non-technical user? What would you change in the visualization?

Debrief

  • Which prediction did you get wrong? What did the visualization show that you did not expect?
  • Part 1 showed representations, Part 2 internals, Part 3 behavior. Which one would you trust to decide whether a model is safe to deploy? Why?
  • What can each tool not show? (A projection distorts distances; attention may not explain; LIME is local and can vary from run to run.)
  • Which of these would help your project?

Project Proposal Feedback

  • For the remainder of the lab, please look over the feedback on your project proposals with your group members
    • Any questions? Concerns? Any progress you want feedback on? Feel free to ask now

Further Exploration

Backup: NLP + Vis Applications

Chart question answering, chart-to-text, and open challenges. Not needed tonight.

NLP + Vis Applications

  • These slides are adapted from a half-day tutorial at the 2023 EMNLP Conference by Shafiq Joty (Salesforce AI Research and Nanyang Technological University), Enamul Hoque (York University), and Jesse Vig (Salesforce AI Research)
  • You can find their full tutorial slides here

What Can NLP + Vis Be Used For?

  • Visual text analytics
  • Natural language interfaces for visualizations
  • Text generations for visualizations
  • Automatic visual story generation
  • Visualization retrieval and recommendation
  • Etc.

What Can NLP + Vis Be Used For?

  • We will first divide these applications into two categories:
    • Natural language as input
    • Natural language as output

NL as Input: ChartQA

ChartQA Dataset

9.6K human-written and 23.1K machine-generated questions over real-world charts.

ChartQA Approach

ChartQA Evaluation

VisionTaPas is the strongest model, but accuracy drops on the human-written questions.

OpenAI’s Study of GPT-4 on ChartQA Benchmark

NL as Input: Multimodal Inputs for Visualizations

  • Ambiguity widgets: Eviza (Setlur et al., 2016)
  • Allows users to rectify queries

NL as Input: Multimodal Inputs for Visualizations

Query completion through text and interactive vis: Sneak Pique (Setlur et al., 2020).

NL as Output: Chart-to-Text

NL as Output: Chart-to-Text

Chart-to-Text Example Models

Fine-tune BART or T5 on the authors’ datasets, with two different input setups.

Chart-to-Text Sample Output

VisText

12.4K charts with generated and crowd-sourced captions, plus a scene graph for each chart.

VisText Sample Output

The model identifies the upward trend, but repeats the claim twice.

NL as Output: Open-Ended Question Answering with Charts

Combining Language and Visualizations as Output

  • Roles of natural language
    • Generating an explanatory answer
    • Explaining the answer

Combining Language and Visualizations as Output

An example of combining text and vis as a multimodal output.

Combining Language and Visualizations as Output

DataShot (Yun et al., 2019): automatic generation of fact sheets from tables.

Conversational QA With Visualization

Evizeon (Hoque et al., TVCG 2017): follow-up questions that keep context.

Open Challenges: Natural Language Interfaces

  • Design of natural language interfaces
    • Must consider richness and ambiguities of natural language
    • Complex reasoning required to predict the answer
    • Computer vision challenges for automatic understanding of image charts
    • Inherently interdisciplinary (HCI, ML, NLP, InfoVis, Computer Vision)

Open Challenges: Datasets

  • Dataset creation
    • Need for large-scale, real-world benchmark datasets
    • Most existing datasets lack realism
    • For many problem setups, there is no benchmark

Open Challenges: Language Generation

  • Challenges with natural language generation
    • Hallucinations
    • Factual errors
    • Perceptual and reasoning aspects
    • Computer Vision Challenges

Open Challenges: A Factual Error

  • The model attaches the top value to the wrong entity
  • It describes a “Brazilian singer” that does not appear in the chart

Open Challenges: A Fluent but Unreliable Summary

A confident paragraph with many specific numbers. Check a few against the chart.

Open Challenges: Visual and Logical Reasoning

Questions that need arithmetic or a reference to color.

Open Challenges: Chart Data Extraction

Boxes mark the chart elements a detector found. Some labels were missed.

Open Challenges: Data Stories

How can we effectively combine text and visualization in data stories?

Open Challenges: Accessibility

  • NLP for visualization accessibility
  • A voice interface answers questions about a chart, and follow-ups

Open Challenges: Accessibility

A chart with a generated description, a length slider, and narration.

References

Alam, Md Zubair Ibne, Shehnaz Islam, and Enamul Hoque. 2023. SeeChart: Enabling Accessible Visualizations Through Interactive Natural Language Interface for People with Visual Impairments. IUI ’23. Association for Computing Machinery. https://doi.org/10.1145/3581641.3584099.
Kantharaj, Shankar, Xuan Long Do, Rixie Tiffany Leong, Jia Qing Tan, Enamul Hoque, and Shafiq Joty. 2022. “OpenCQA: Open-Ended Question Answering with Charts.” In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, edited by Yoav Goldberg, Zornitsa Kozareva, and Yue Zhang. Association for Computational Linguistics. https://doi.org/10.18653/v1/2022.emnlp-main.811.
Kantharaj, Shankar, Rixie Tiffany Leong, Xiang Lin, et al. 2022. “Chart-to-Text: A Large-Scale Benchmark for Chart Summarization.” In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), edited by Smaranda Muresan, Preslav Nakov, and Aline Villavicencio. Association for Computational Linguistics. https://doi.org/10.18653/v1/2022.acl-long.277.
Masry, Ahmed, Xuan Long Do, Jia Qing Tan, Shafiq Joty, and Enamul Hoque. 2022. “ChartQA: A Benchmark for Question Answering about Charts with Visual and Logical Reasoning.” In Findings of the Association for Computational Linguistics: ACL 2022, edited by Smaranda Muresan, Preslav Nakov, and Aline Villavicencio. Association for Computational Linguistics. https://doi.org/10.18653/v1/2022.findings-acl.177.
Setlur, Vidya, Enamul Hoque, Dae Hyun Kim, and Angel X. Chang. 2020. “Sneak Pique: Exploring Autocompletion as a Data Discovery Scaffold for Supporting Visual Analysis.” Proceedings of the 33rd Annual ACM Symposium on User Interface Software and Technology (New York, NY, USA), UIST ’20, 966–78. https://doi.org/10.1145/3379337.3415813.
Sharif, Ather, Olivia H. Wang, Alida T. Muongchan, Katharina Reinecke, and Jacob O. Wobbrock. 2022. “VoxLens: Making Online Data Visualizations Accessible with an Interactive JavaScript Plug-in.” Proceedings of the 2022 CHI Conference on Human Factors in Computing Systems (New York, NY, USA), CHI ’22. https://doi.org/10.1145/3491102.3517431.
Shi, Danqing, Xinyue Xu, Fuling Sun, Yang Shi, and Nan Cao. 2020. “Calliope: Automatic Visual Data Story Generation from a Spreadsheet.” CoRR abs/2010.09975. https://arxiv.org/abs/2010.09975.
Tang, Benny, Angie Boggust, and Arvind Satyanarayan. 2023. “VisText: A Benchmark for Semantically Rich Chart Captioning.” In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), edited by Anna Rogers, Jordan Boyd-Graber, and Naoaki Okazaki. Association for Computational Linguistics. https://doi.org/10.18653/v1/2023.acl-long.401.
Wang, Yun, Zhida Sun, Haidong Zhang, et al. 2020. “DataShot: Automatic Generation of Fact Sheets from Tabular Data.” IEEE Transactions on Visualization and Computer Graphics 26: 895–905. https://api.semanticscholar.org/CorpusID:201093978.