Introduction
Legal documents—judgments, court orders, and contracts—are notoriously difficult for non-experts to parse. They rely on "legal syllogisms" and implicit rules that require years of training to interpret. While Natural Language Processing (NLP) has made strides in legal named entity recognition (NER) and summarization, there is a significant gap in legal visualization.
LegalViz is a new multilingual dataset and framework designed to help non-experts navigate complex legal documents by automatically generating structured, easy-to-understand diagrams. By fine-tuning Large Language Models (LLMs) to produce Graphviz (DOT) code, the researchers demonstrate that specialized, smaller models can outperform even general-purpose giants like GPT-4 in accurately visualizing legal entities, transactions, and judicial logic.
Methodology: Text-to-Code Generation
The authors treat legal visualization as a text-to-code generation task. Instead of asking a model to draw an image directly, they train it to generate code in the DOT graph description language (used by Graphviz).
Structural Mapping and Fine-tuning
The team defined specific visual "formalisms" for legal concepts: legal entities are represented as double octagons, legal sources (laws/statutes) as trapeziums, and factual statements as squares. They performed supervised fine-tuning (SFT) on several open-source model families, including Llama 3.1/3.2 and Gemma 2, comparing them against few-shot performance from closed models like GPT-4.
Novel Evaluation Metrics
To move beyond simple string matching, three hierarchical metrics were introduced:
- Graph: Measures the F1 score of matched edges (pure structure).
- Graph&Node: Structure plus the semantic similarity of node text (using BERTScore).
- Graph&Node&Edge: The most stringent metric, accounting for structure, node text, and edge labels.
The LegalViz Dataset
The core contribution is the LegalViz dataset, which consists of 7,010 cases sourced from EUR-LEX, covering judgments and orders from EU countries. The dataset is inherently multilingual, spanning 23 languages. This ensures the model can handle diverse linguistic structures while maintaining consistent legal logic. Each case was manually annotated by experts to identify entities, relationships, and the legal basis for decisions, then converted into DOT code.
Results and Discussion
One of the most striking findings is that fine-tuning trumps scale. A fine-tuned Gemma 2 9B model consistently outperformed GPT-4 in few-shot mode. For highly structured, domain-specific tasks like graph generation, specialized training data is more valuable than raw parameter count.
Quantitative and Qualitative Superiority
In the "Graph" metric (structural accuracy), the fine-tuned Gemma 2 9B scored 43.38, significantly higher than GPT-4’s 33.46. Qualitatively, fine-tuned models were much better at distinguishing between a "request" (a square node) and a "legal entity" (an octagon), whereas few-shot models often misclassified node shapes or struggled to produce syntactically valid DOT code.
While models performed best in high-resource languages like English and French, the fine-tuning process provided a massive boost to lower-resource languages (like Maltese or Latvian) where few-shot models often failed completely.
Limitations and Future Outlook
Despite its success, LegalViz faces challenges with languages from the Uralic group (Finnish, Hungarian) and other low-resource languages. Furthermore, "Statement" nodes require complex summarization; if the model fails to capture the core legal point, the resulting graph—while syntactically correct—may be misleading. The authors emphasize that these visualizations are meant to support understanding, not replace professional legal advice. Future work may involve "expert-in-the-loop" systems where legal professionals can refine the generated graphs.
Summary updated