OpenMRS NLP-to-SQL Stage 2 is a specialized language model fine-tuned for converting natural language queries into accurate MySQL queries for the OpenMRS electronic medical records system. This model is specifically trained on the OpenMRS 3.4.0 data model, covering all 188 core database tables.
Key Features
🏥 Healthcare-Specialized: Fine-tuned exclusively on OpenMRS clinical database schema
🎯 Production-Ready: Trained with exact SQL matching for high precision
📊 Comprehensive Coverage: Supports queries across all 188 OpenMRS tables
⚡ Efficient: LoRA-based fine-tuning for optimal inference performance
🔒 Privacy-Focused: Trained on synthetic data, no patient information used
📊 Performance Metrics
Metric
Score
Exact Match
2.0%
Structural Similarity (BLEU)
76.9%
Clinical Domain Coverage
188/188 tables
Training Examples
15,000+ SQL pairs
Note: Stage 2 focused on exact SQL syntax matching. Stage 3 (in development) implements semantic evaluation with execution accuracy metrics for more realistic performance assessment.
🎯 Use Cases
Primary Use Cases
Clinical Query Automation: Convert clinician natural language questions to SQL
EHR Data Analysis: Enable non-technical staff to query patient data
Research Data Extraction: Facilitate clinical research data queries
Healthcare Analytics: Support business intelligence tools with SQL generation
Training & Education: Teach SQL through natural language examples
Example Queries
python
1# Example 1: Patient Demographics2Input:"How many patients are male and aged over 50?"3Output: SELECT COUNT(*) FROM patient p
4 INNER JOIN person pe ON p.patient_id = pe.person_id
5 WHERE pe.gender ='M' AND TIMESTAMPDIFF(YEAR, pe.birthdate, NOW())>5067# Example 2: Encounter History8Input:"List all encounters for patient ID 12345 in 2024"9Output: SELECT * FROM encounter WHERE patient_id =1234510 AND YEAR(encounter_datetime)=20241112# Example 3: Medication Orders13Input:"Show active drug orders with Aspirin"14Output: SELECT o.*, d.name FROM orders o
15 INNER JOIN drug d ON o.concept_id = d.concept_id
16 WHERE d.name LIKE '%Aspirin%' AND o.voided =0
Checkpointing: Best model selection based on validation loss
Early Stopping: Patience of 5 evaluation steps
Evaluation Methodology
Test Data
Size: 3,000 held-out question-SQL pairs
Distribution: Stratified by query complexity and table coverage
Schema Coverage: Representative sample across all 188 tables
Metrics
Exact Match (EM): Exact string match between predicted and gold SQL
Structural Similarity: Token-level overlap and SQL AST comparison
Execution Accuracy: (Stage 3) Query result equivalence on sample database
Results
Metric
Stage 2
Target (Stage 3)
Exact Match
2.0%
15-20%
BLEU Score
76.9%
90%
Execution Accuracy
TBD
60-70%
Analysis
The 2% exact match rate indicates the model successfully learns SQL structure and OpenMRS schema relationships, but struggles with exact syntax matching due to:
Multiple valid SQL formulations for the same query
Variation in whitespace, aliasing, and formatting
Different join orders producing equivalent results
Stage 3 focuses on semantic evaluation (execution accuracy) rather than exact syntax matching.
This model is released under the Apache License 2.0.
Copyright 2025 thegeeksinfo Community
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Base Model License
The base model (NumbersStation NSQL-350M) is subject to its own licensing terms. Please review the NSQL license before use.
Built with ❤️ by independent contributor to OpenMRS AI Community