license: mit base_model: - mistralai/Mistral-7B-Instruct-v0.3
🌱 Lyra – Mistral 7B Agronomy (QLoRA)
Diagnostic azoté de la tomate • DO → SPAD • Stress non-azoté • Chlorose ferrique
Ce modèle est une version fine-tunée de Mistral-7B-Instruct-v0.3, spécialisée pour produire un diagnostic agronomique complet à partir de :
- NO₃ du sol (mg/kg)
- pH eau
- DO verte (densité optique foliaire) mesurée par scanner
Le modèle fournit :
- un diagnostic azote nuancé
- une estimation SPAD équivalente (corrélée au taux de chlorophylle)
- une explication agronomique
- la détection optionnelle de :
- stress non-azoté (hydrique / maladies / parasitisme)
- chlorose ferrique (pH > 7.8 + DO basse + NO₃ élevé)
- recommandations en lutte intégrée lorsque DO est élevée
🔧 Modèle — Méthodologie
- Base :
mistralai/Mistral-7B-Instruct-v0.3 - Méthode : QLoRA, rank 64
- Précision : fp16
- Dataset : 1000 exemples agronomiques synthétiques (format chat Mistral)
- Entraînement : 3 epochs, LR = 2e-4
- Accuracy token : ~0.945
- Entropie : 0.22 (sorties stables, non-hallucinées)
Ce fine-tuning encode réellement la relation physiologique DO → SPAD, ce qu’un simple fine-tuning serveur ne permettait pas.
📘 Données utilisées
Chaque exemple combine :
- NO₃ (0 → 200 mg/kg)
- pH (6.0 → 8.2)
- DO verte (250 → 550)
- diagnostic azote
- estimation SPAD via :
SPAD = 0.178 × DO − 36.454
Cas particuliers incorporés :
- 100 cas de chlorose ferrique
- 100 cas de stress non-azoté
- 0 % de doublons (stricts ou sémantiques)
📈 Relation DO → SPAD : stabilité numérique
Le modèle a appris la relation DO → SPAD dans ses couches profondes :
| DO | SPAD théorique | SPAD modèle |
|---|---|---|
| 354 | 26.6 | 27 |
| 275 | 12.5 | 13 |
| 510 | 54.3 | 55 |
| 268 | 11.3 | 11 |
| 271 | 11.8 | 12 |
➡️ Erreur < ±1 SPAD → parfaite assimilation de la fonction.
🧪 Exemple d’utilisation
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_id = "jeromex1/lyra_DO_vert_mistral7B_qLoRA"
base_model = "mistralai/Mistral-7B-Instruct-v0.3"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype="auto", device_map="auto")
model.load_adapter(model_id)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
prompt = """Culture : tomate
Stade : végétatif
NO3- (sol) : 48.2 mg/kg
pH (eau) : 6.8
DO verte (scanner) : 354
Merci de me donner un diagnostic détaillé."""
print(pipe(prompt)[0]["generated_text"])
📊 Statistiques du dataset Distribution des diagnostics azote
(si disponibles dans le dépôt) graphs_statistics/statistic_dataset_nitrogen.png
Distribution de la DO verte
graphs_statistics/statistic_DO_vert_barchart.png
✔️ Usages adaptés
Diagnostic rapide (serre / parcelle)
Projets IoT à faible coût (scanner DO)
Recherche agronomique / phénomènes azotés
Projets open-science
❌ Non recommandé pour
Décisions engageant un rendement élevé
Cultures autres que la tomate
Sols extrêmes (> pH 8.5)
Pathologies avancées hors du domaine d’entraînement
🔗 Liens utiles
🔬 Modèle SPAD ↔ DO (projet d’origine) https://github.com/Jerome-openclassroom/Lyra_DO_Green_Mesurim
🧪 Code complet du pipeline QLoRA https://github.com/Jerome-openclassroom/Lyra_Mistral7B_agronomy
📄 Licence
MIT
🇬🇧 Lyra – Mistral 7B Agronomy (QLoRA)
Tomato nitrogen diagnosis • DO → SPAD estimation • Non-nitrogen stress • Ferric chlorosis
This model is a fine-tuned version of Mistral-7B-Instruct-v0.3, specialized for agronomic diagnosis using three simple input variables:
- Soil nitrate (NO₃, mg/kg)
- Soil pH (water method)
- Green optical density (DO) measured from leaf scans
The model produces:
- a nuanced nitrogen diagnosis
- an estimated SPAD-equivalent (chlorophyll indicator)
- a structured agronomic explanation
- optional detection of:
- non-nitrogen stress (water deficit, pathogens, parasitism)
- ferric chlorosis (pH > 7.8 + low DO + high NO₃)
- IPM recommendations when DO is high
🔧 Model — Methodology
- Base model:
mistralai/Mistral-7B-Instruct-v0.3 - Training method: QLoRA (rank 64)
- Precision: fp16
- Dataset: 1000 synthetic agronomic examples (Mistral chat format)
- Training: 3 epochs, LR = 2e-4
- Token accuracy: ~0.945
- Low entropy: 0.22 → stable, non-hallucinatory outputs
This QLoRA training encodes the actual physiological relationship DO → SPAD, which the server-side 8B fine-tune failed to learn.
📘 Dataset Summary
Each training row includes:
- NO₃ (0 → 200 mg/kg)
- pH (6.0 → 8.2)
- DO Green (250 → 550)
- nitrogen diagnosis
- SPAD estimation using: SPAD = 0.178 × DO − 36.454
Special cases included:
- 100 ferric chlorosis cases
- 100 non-nitrogen stress cases
- 0% duplicates (strict + semantic)
📈 DO → SPAD Numerical Consistency
The model learned the DO → SPAD mapping with high precision:
| DO | Theoretical SPAD | Predicted SPAD |
|---|---|---|
| 354 | 26.6 | 27 |
| 275 | 12.5 | 13 |
| 510 | 54.3 | 55 |
| 268 | 11.3 | 11 |
| 271 | 11.8 | 12 |
➡️ Error < ±1 SPAD (simple rounding)
➡️ The function is genuinely encoded inside the model layers.
🧪 Inference Example
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_id = "jeromex1/lyra_DO_vert_mistral7B_qLoRA"
base_model = "mistralai/Mistral-7B-Instruct-v0.3"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype="auto", device_map="auto")
model.load_adapter(model_id)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
prompt = """Crop: tomato
Stage: vegetative
NO3- (soil): 48.2 mg/kg
pH (water): 6.8
Green optical density (scanner): 354
Please provide a detailed diagnosis."""
print(pipe(prompt)[0]["generated_text"])
📊 Dataset Graphs Nitrogen diagnosis distribution
graphs_statistics/statistic_dataset_nitrogen.png
DO Green distribution
graphs_statistics/statistic_DO_vert_barchart.png
✔️ Intended Uses
Rapid nitrogen diagnosis (greenhouse or field)
Low-cost DO-based sensing workflows
Agronomic research projects
Open-science crop modelling
❌ Not Intended For
High-stakes fertilization decisions
Crops other than tomato
Extreme soil conditions (pH > 8.5)
Severe diseases outside the training domain
🔗 Useful Links
🔬 SPAD ↔ DO correlation project https://github.com/Jerome-openclassroom/Lyra_DO_Green_Mesurim
🧪 Complete QLoRA training pipeline https://github.com/Jerome-openclassroom/Lyra_Mistral7B_agronomy
📄 License
MIT