SPARQL Wikidata Explorer
An intuitive interface that leverages small, offline LLMs to transform natural language into SPARQL queries, making Wikidata's knowledge graph accessible without specialized expertise.
Personal Motivation & Background
Why I Built This Tool
This project was an exploration of possibilities - I wanted to see if I could create a simple UI that could effectively query Wikidata using locally hosted LLM models running on less than 8GB of RAM. The goal was to democratize access to knowledge graph exploration without requiring specialized SPARQL expertise and see if genAI like this could be used locally for offline applications on laptops or phones.
As someone with a background in data science and knowledge graphs, I was curious to test the boundaries of what lightweight LLMs could achieve in interpreting natural language and generating complex SPARQL queries, making semantic web technologies more accessible to everyone. I've explained more about the project and linked the code repo below!

A example of a query asking the population of London - click to enlarge
Project Overview
SPARQL's complexity limits accessibility for non-experts.
Most people can't search knowledge bases easily using spoken language.
SPARQL has a steep learning curve that excludes non-technical users.
The semantic web's power remains inaccessible to many potential users.
A dual-LLM approach for accessibility:
- Small, coding-focused LLM (Qwen2.5) to translate natural language to SPARQL
- General-purpose LLM (Qwen3) to interpret results in natural language
- Transparent reasoning by showing all possible results with explanations
- Fully local operation for privacy and offline use
- Explores the application of offline AI in mobile phone apps
Get Started
Explore the code and documentation on GitHub to learn more about the SPARQL Wikidata Explorer.
Tech Stack
Simple and lightweight for local deployment:
Frontend
Dash, dash-bootstrap-components
Backend
Flask (via Dash)
Data Access
SPARQL, SPARQLWrapper
Query Generation
Qwen2.5 Coder LLM
Result Processing
Qwen3 LLM
Model Hosting
Ollama, Custom Modelfiles
Deployment
Docker, Docker Compose
HTTP Client
Requests
LLM Query Workflow
Leveraging lightweight LLMs to translate natural language into SPARQL and interpret complex results
SPARQL Wikidata Explorer processes natural language using lightweight LLMs: Qwen2.5 Coder generates SPARQL queries, while Qwen3 intelligently interprets and reasons about query results
Qwen2.5 Coder LLM
Parses natural language to identify entities and relationships
Transforms user intent into proper SPARQL syntax
Optimizes queries for performance and accuracy
Qwen3 LLM
Processes raw Wikidata result sets into natural language
When multiple results exist, employs reasoning to select most relevant answer
Provides explanations of why certain results were selected over others
Skills Gained
Technical Skills
- Docker containerization and Docker Compose orchestration
- Dash/Flask web application development
- Ollama model configuration and custom Modelfile creation
- Multi-model LLM system integration and orchestration
Domain Knowledge
- SPARQL query language and Wikidata structure
- Prompt engineering for specialized tasks like query generation
- Natural language to formal query translation techniques
- Lightweight LLM deployment for resource-constrained environments
Lessons Learned
Current Limitations: The SPARQL Wikidata Explorer is best suited for straightforward, fact-based questions like "What is the population of London?" or "Who is the president of France?". The model has difficulty with more complex or novel SPARQL queries, even when provided with additional guidance.
Interestingly, even when more complex queries like "How many writers were born in 19th-century Germany?" are included in the model file, the small LLM struggles to understand the underlying pattern for creating similar queries. This reveals a fundamental limitation in the model's ability to generalize from examples rather than simply memorizing specific cases.
For best results, simple questions about facts related to people, places, or organizations work best. For anything outside these simple patterns, the tool may return unpredictable results or no results at all.
Future Enhancements
Wikidata Schema Integration
Dynamically obtain and cache the complete Wikidata schema to enable comprehensive graph traversal and handle arbitrary queries across the entire knowledge base.
Conversational Chatbot Interface
Implement a more natural, conversational experience that maintains context across multiple queries and helps users refine their questions through dialogue.
Advanced Visualization Options
Add interactive graph visualization with zoom, filter, and exploration capabilities to make the knowledge graph structure more intuitive and discoverable.
Multi-Knowledge Base Support
Extend beyond Wikidata to support other knowledge bases and SPARQL endpoints, creating a unified interface for semantic web exploration.
LoRA Fine-Tuning for Improved Generalization
To help the model handle a broader range of question types and more complex SPARQL queries, a promising next step would be to fine-tune it using the LoRA (Low-Rank Adaptation) method. LoRA enables efficient adaptation of large language models to new tasks with limited data and compute resources. By training on a wider variety of SPARQL question/answer pairs, this approach could help the model learn more generalizable patterns and improve its flexibility for real-world use.