Query2Diagram: Answering Developer Queries with UML Diagrams Submitted to the Journal of Mathematical Sciences .
Oleg Baryshnikov, Anton M. Alekseev, Sergey I. Nikolenko · 2026
Read Query2Diagram: Answering Developer Queries with UML Diagrams Submitted to the Journal of Mathematical Sciences . by Oleg Baryshnikov, Anton M. Alekseev, Sergey I. Nikolenko (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2604-23816.txt.
Introduction
Baryshnikov, Alekseev, and Nikolenko present query-driven UML diagram making. Language models draw diagrams that answer coders' questions about code. Unlike tools that dump too much detail, their method shows only key parts with context notes. Fine-tuning a code model on modest fixed data lifts shape scores. It also cuts defect rates below leading models.
Catalog record
| CREATOR | Oleg Baryshnikov, Anton M. Alekseev, Sergey I. Nikolenko |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 38722 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2604.23816
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Query2Diagram: Answering Developer Queries with UML Diagrams Submitted to the Journal of Mathematical Sciences . Oleg Baryshnikov, Anton M. Alekseev, Sergey I. Nikolenko Abstract Software documentation frequently becomes outdated or fails to exist entirely, yet developers need focused views of their codebase to understand complex systems. While automated reverse engineering tools can generate UML diagrams from code, they produce overwhelming detail without considering developer intent. We introduce query-driven UML diagram generation , where LLMs create diagrams that directly answer natural language questions about code. Unlike existing methods, our approach produces semantically focused diagrams containing only relevant elements with contextual descriptions. We fine-tune Qwen2.5-Coder-14B on a curated dataset of code files, developer queries, and corresponding diagram representations in a structured JSON format, evaluating with both automatic detection of structural defects and human assessment of semantic relevance. Results demonstrate that fine-tuning on a modest amount of manually corrected data yields dramatic improvements: our best model achieves the highest F1 scores while reducing defect rates below state-of-the-art LLMs, generating diagrams that are both structurally sound and semantically faithful to developer queries. Thus, we establish the feasibility of using LLMs for scalable contextual, on-demand documentation generation. We make our code and dataset publicly available at https://github.com/i-need-a-pencil/query2diagram . Keywords: Large Language Models ⋅ \cdot Code QA ⋅ \cdot UML ⋅ \cdot Documentation Maintenance. 1 Introduction Software documentation, particularly UML diagrams, plays a crucial role in system comprehension and maintenance. Studies confirm that UML usage improves code quality and modularity, reduces defects, and increases developer productivity [ 3 , 30 , 31 , 29 ] . However, manually creating and, crucially, maintaining up-to-date diagrams requires significant effort, leading to a common problem: documentation that either does not exist or diverges from the actual implementation [ 20 ] . In the absence of up-to-date UML documentation, diagrams can be generated with automated reverse-engineering (RE) tools. However, the resulting UML diagrams often contain overwhelming detail that hinders comprehension; studies and developer surveys show that these diagrams have to be severely simplified for clarity [ 33 , 32 ] . Some approaches propose interactive filtering mechanisms [ 12 ] , but typically ignore semantic context and user intent. This creates a gap: developers need focused, contextual views of their codebase, not exhaustive structural dumps. Figure 1: A sample response to the user query ‘‘Map out the event listeners set up in the CRServiceWorker constructor and their corresponding actions’’ based on the TypeScript file microsoft/playwright/… /crServiceWorker.ts . Recent advances in NLP, specifically large language models (LLMs), offer a promising solution. LLMs excel at understanding both code and natural language, making them uniquely suited to bridge the gap between developer queries and visual representations. Although LLM applications in software engineering are expanding rapidly [ 46 , 28 ] , including tools such as GitHub Copilot [ 41 ] and Cursor [ 42 ] , their potential for query-driven diagram generation remains unexplored. Motivated by this gap, we present a novel approach: using LLMs to generate RE-UML diagrams that directly answer developer queries about code. Unlike traditional RE tools or recent LLM-based approaches that generate complete diagrams, our method produces query-focused diagrams that include only relevant elements with contextual descriptions. Fig. 1 illustrates this: given a query about event listeners in a TypeScript file, the system generates a targeted diagram showing only the relevant components and their relationships. Our approach offers several key advantages: it (1) eliminates the need for pre-existing diagrams, (2) provides direct answers to developer questions through visual representation, (3) includes explanatory descriptions for all elements, and (4) supports multiple programming languages through a single model. We address two research questions: RQ1 Can LLMs generate relevant, comprehensible graph-like structures (UML diagrams) when provided with code files and high-level queries about design patterns, component interactions, or architectural concerns? RQ2 Can training on synthetic and curated data effectively control the quality properties of LLM-generated diagrams? In this work, we fine-tune Qwen2.5-Coder-14B on a carefully curated dataset of code-query-diagram triples, introducing a JSON-based intermediate representation that reduces syntax errors while enabling structured generation. Our dual evaluation strategy combines automatic defect analysis with human relevance assessment. Results demonstrate that fine-tuning on manually corrected data yields diagrams that are both structurally sound and semantically relevant, achieving the best F1 scores while dramatically reducing defect rates. Our contributions include: (1) a new task formulation for query-driven UML generation from code, (2) a practical method using fine-tuned LLMs with structured output generation, (3) a comprehensive evaluation framework combining structural and semantic metrics, and (4) empirical evidence that even small amounts of high-quality training data can significantly improve diagram quality. We release our code and dataset at https://github.com/i-need-a-pencil/query2diagram . In the following, Section 2 reviews related work on diagram generation, Section 3 provides a description of our approach, Section 5 presents evaluation results and discussions, and Section 6 concludes the article. 2 Related Work Recent studies document both the demand for and the friction in keeping diagrams useful in practice: informal diagrams dominate real projects yet are rarely updated [ 24 ] ; API–scale structure benefits from interactive, automatically generated visualizations [ 39 ] ; and large ecosystems require continuously refreshed, machine-generated views to track versions, dependencies, and CVEs [ 25 ] . Reverse-engineered models also drive downstream tasks beyond comprehension, such as early defect prediction from UML metrics [ 5 ] and guided system migration [ 26 ] . These findings jointly motivate focused , on-demand diagramming from code, rather than one-shot, complete diagrams that quickly drift from developers’ information needs. Traditional UML Generation. Classical reverse engineering (RE) approaches for UML generation fall into three categories. Static analysis tools [ 43 , 40 ] extract structural relationships without code execution; they effectively detect inheritance but struggle with runtime behaviors. Dynamic analysis tools such as Caffeine [ 17 ] capture runtime behavior and can discover specific object relationships, but require executable code and sufficient coverage. Hybrid approaches like Ptidej [ 18 ] , which enhances a static model with dynamic traces, combine both but demand complex heuristics and manual configuration. Beyond comprehension, traditional RE feeds downstream uses (e.g., migration [ 26 ] or defect prediction from UML metrics [ 5 ] ), yet the shared limitation remains: they generate complete structural views without considering user intent or information needs. LLM-Based UML Generation. Recent research explores large language models (LLMs) for UML generation from both source code and natural language artifacts. [ 35 ] used GPT-4 [ 1 ] to generate class diagrams directly from codebases, reporting frequent syntax errors and missing elements. [ 38 ] embedded an LLM into a model-driven reverse-engineering (MDRE) pipeline to extract class diagrams from Java programs, while [ 36 ] fine-tuned Mistral-7B on AgileUML-derived Java/Python \leftrightarrow UML/OCL pairs, achieving high precision and recall; [ 37 ] targeted explicit OCL generation from code, substantially outperforming rule-based baselines; and [ 7 ] combined LLMs with MDRE, introducing diagram-granularity levels (CLASS, COARSE, FINE) to control abstraction. [ 2 ] evaluated GPT-4o, Gemini 1.5 Pro, Claude 3.5 Sonnet, and Mistral Large on architecture recovery, showing that self-reflection prompts reduce hallucinations and omissions. Beyond code, several studies use LLMs to translate textual specifications into UML: [ 8 , 9 , 14 , 23 ] focus on requirements-to-model