|
|
--- |
|
|
license: apache-2.0 |
|
|
base_model: unsloth/mistral-7b-v0.3-bnb-4bit |
|
|
tags: |
|
|
- unsloth |
|
|
- mistral |
|
|
- recipe-generation |
|
|
- fine-tuning |
|
|
- qlora |
|
|
- nlp |
|
|
--- |
|
|
|
|
|
# π¨βπ³ Chef-Mistral-7B: Constraint-Aware Recipe Generator |
|
|
|
|
|
**Chef-Mistral-7B** is a fine-tuned language model designed to generate cooking recipes based on strict user constraints. Unlike general-purpose LLMs, this model is optimized to minimize "hallucinations" (inventing ingredients the user doesn't have) and strictly adhere to dietary restrictions (Keto, Vegan, Gluten-Free). |
|
|
|
|
|
It was trained using **QLoRA** (Quantized Low-Rank Adaptation) on a consumer GPU (RTX 4070 Super) using the `unsloth` library for 2x faster training. |
|
|
|
|
|
## π Capabilities |
|
|
|
|
|
* **Pantry-Based Cooking:** Generates recipes using *only* the ingredients provided by the user. |
|
|
* **Dietary Adherence:** Respects hard constraints like "No Dairy," "Keto," or "Gluten-Free." |
|
|
* **Context Awareness:** Can distinguish between breakfast, dinner, and dessert contexts based on ingredients. |
|
|
|
|
|
## ποΈ Agent Architecture Recommendation |
|
|
|
|
|
This model was specifically trained to serve as the **reasoning engine (Brain)** in a modular agentic system. For optimal performance, we recommend the following architecture: |
|
|
|
|
|
* **Front-End Router ("The Waiter"):** Use a lightweight model (e.g., Phi-3, Qwen-1.5B) to handle user chit-chat and extract structured constraints (ingredients, diet) into JSON. |
|
|
* **The Brain (Chef-Mistral):** Use this model *only* to generate the final recipe based on the structured input. It performs best when stripped of conversational filler. |
|
|
* **RAG Layer:** Augment the prompt with retrieved safety facts (e.g., cooking temps, allergen data) to minimize hallucinations before generation. |
|
|
|
|
|
## π» How to Use |
|
|
|
|
|
You can load this model directly in Python using the `unsloth` or `peft` library. |
|
|
|
|
|
### Installation |
|
|
```bash |
|
|
pip install unsloth torch transformers |
|
|
|
|
|
from unsloth import FastLanguageModel |
|
|
|
|
|
# 1. Load the Model |
|
|
model, tokenizer = FastLanguageModel.from_pretrained( |
|
|
model_name = "YourUsername/Chef-Mistral-7B", # REPLACEME WITH YOUR USERNAME |
|
|
max_seq_length = 2048, |
|
|
dtype = None, |
|
|
load_in_4bit = True, |
|
|
) |
|
|
FastLanguageModel.for_inference(model) |
|
|
|
|
|
# 2. Define the Prompt Template |
|
|
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. |
|
|
|
|
|
### Instruction: |
|
|
{} |
|
|
|
|
|
### Input: |
|
|
{} |
|
|
|
|
|
### Response: |
|
|
""" |
|
|
|
|
|
# 3. Run Inference |
|
|
inputs = tokenizer( |
|
|
[ |
|
|
alpaca_prompt.format( |
|
|
"I have chicken breast, spinach, and heavy cream. I want a keto-friendly dinner.", # Instruction |
|
|
"", # Input |
|
|
"", # Output - leave blank for generation |
|
|
) |
|
|
], return_tensors = "pt").to("cuda") |
|
|
|
|
|
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True) |
|
|
print(tokenizer.batch_decode(outputs)[0]) |
|
|
``` |
|
|
|
|
|
## π Training Details |
|
|
|
|
|
* **Base Model:** Mistral-7B-v0.3 (4-bit quantization) |
|
|
* **Method:** QLoRA (LoRA Rank = 16, Alpha = 32) |
|
|
* **Dataset Size:** ~25,000 instruction-response pairs (Recipe/Culinary dataset). |
|
|
* **Hardware:** Trained on a single NVIDIA RTX 4070 Super (12GB VRAM). |
|
|
* **Training Time:** ~3.5 hours (1545 Steps). |
|
|
* **Final Loss:** ~0.65-0.7 |
|
|
|
|
|
## β οΈ Limitations & Bias |
|
|
|
|
|
* **Hallucination:** While significantly reduced, the model may occasionally hallucinate common pantry staples (e.g., assuming you have salt, pepper, or oil even if not listed). |
|
|
* **Adversarial Prompts:** The model generally refuses illogical requests (e.g., "Chicken Dessert") but may exhibit repetition loops if forced into contradictory constraints. |
|
|
* **Medical Advice:** This model is for culinary inspiration only. Do not rely on it for severe medical allergies. |
|
|
|
|
|
## π¨βπ» Author |
|
|
Developed by **[Hazar Utku Sozer]** as part of the Deep Learning Engineering curriculum. |