Visualization
LangExtract provides powerful visualization tools to help you understand, explore, and debug extraction results. Visualize source grounding, explore extracted data structures, and share results with stakeholders.
Overview
LangExtract's visualization features help you:
- See source grounding: Visual highlights showing where each extracted value came from
- Explore structures: Interactive views of nested extracted data
- Debug extractions: Identify issues and understand model behavior
- Share results: Export visualizations for documentation and presentations
Span Highlighting
One of the most powerful visualization features is span highlighting, which shows exactly where in the source text each extracted value originated:
- Color-coded highlights: Different colors for different field types
- Hover interactions: Hover over highlights to see field names and values
- Multiple spans: Handle cases where a field spans multiple locations
- Overlapping spans: Visual distinction for overlapping extractions
This makes it immediately clear where information came from and helps verify extraction accuracy.
Structured Data View
LangExtract provides formatted views of extracted data structures:
- Formatted JSON: Pretty-printed structured data
- Tree view: Hierarchical display of nested structures
- Field details: Expandable views showing field metadata
- Source links: Click through to source locations
Interactive Exploration
Visualization tools support interactive exploration:
- Click to navigate: Click on extracted values to jump to source locations
- Filter views: Filter by field type, confidence, or other attributes
- Search: Search through extracted values and source text
- Compare: Side-by-side comparison of multiple extractions
Using Visualization in Code
LangExtract provides programmatic access to visualization features:
import langextract as lx
result = lx.extract(
text_or_documents=text,
prompt_description="Extract information",
examples=[...]
)
# Generate visualization
visualization = lx.visualize(result, source_text=text)
# Display in Jupyter notebook
visualization.show()
# Export to HTML
visualization.export_html("extraction.html")
# Export to image
visualization.export_image("extraction.png")
Jupyter Notebook Integration
LangExtract works seamlessly in Jupyter notebooks:
- Inline display: Visualizations render directly in notebook cells
- Interactive widgets: Use interactive controls to explore extractions
- Export options: Save visualizations as part of notebook outputs
This makes LangExtract ideal for exploratory data analysis and documentation.
Web-Based Visualization
For production deployments, LangExtract can generate web-based visualizations:
- HTML export: Standalone HTML files with interactive visualizations
- Embeddable widgets: Embed visualizations in web applications
- API endpoints: Serve visualizations via REST APIs
See the RadExtract demo for a live example of web-based visualization.
Best Practices
- Use for debugging: Visualize extractions to understand model behavior
- Verify accuracy: Check source highlights to verify extraction quality
- Share results: Export visualizations to share with stakeholders
- Document workflows: Include visualizations in documentation and reports