An intelligent nutrition coaching system that combines CatBoost machine learning models with Microsoft's Phi-3 fine-tuned language model to provide personalized meal planning and nutritional guidance.
- Personalized Nutritional Target Prediction: Uses CatBoost regression models to predict optimal daily calories, protein, carbs, and fats based on user profile
- AI-Powered Meal Planning: Fine-tuned Phi-3 model generates contextual nutrition advice and meal recommendations
- 7-Day Meal Schedule Generation: Automatically creates balanced weekly meal plans aligned with user goals
- Multi-Goal Support: Tailored plans for fat burn, muscle gain, and maintenance goals
- Recipe Database Integration: Smart meal selection from a comprehensive recipe dataset
โโโโโโโโโโโโโโโโโโโ
โ User Profile โ
โ (Age, Weight, โ
โ Goal, etc.) โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ CatBoost Models โ
โ (Predict Targets) โ
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โโโบ Calories Target
โโโบ Protein Target
โโโบ Carbs Target
โโโบ Fats Target
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Phi-3 Fine-tuned โ
โ (Generate Advice) โ
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Meal Planner โ
โ (Recipe Selection) โ
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ 7-Day Meal Plan โ
โโโโโโโโโโโโโโโโโโโโโโโ
- Python 3.8 or higher
- CUDA-capable GPU (recommended for model inference)
- At least 8GB RAM (16GB recommended)
- ~10GB disk space for models and datasets
git clone https://github.com/yourusername/phi3-nutrition-ai.git
cd phi3-nutrition-aipip install -r requirements.txtThe project uses:
- Microsoft Phi-3-mini-4k-instruct (downloaded automatically)
- Fine-tuned checkpoint (place in
phi3_finetuned/folder) - CatBoost models (place in
user model/folder)
Ensure you have the following CSV files in the dataset/ folder:
recipes.csv- Recipe database with nutritional informationGYM.csv- User fitness and health data for training
phi3-nutrition-ai/
โโโ README.md
โโโ requirements.txt
โโโ .gitignore
โโโ Nutrition_phi3 model.ipynb # Main training notebook
โโโ meal_generate.ipynb # Meal generation script
โโโ dataset/
โ โโโ recipes.csv
โ โโโ GYM.csv
โโโ user model/
โ โโโ catboost_reco_calories.cbm
โ โโโ catboost_reco_protein.cbm
โ โโโ catboost_reco_carbs.cbm
โ โโโ catboost_reco_fats.cbm
โ โโโ preprocess.py
โ โโโ schema.json
โโโ phi3_finetuned/ # Fine-tuned adapter checkpoint
โโโ phi3_merged_standard/ # Merged model (auto-generated)
โโโ evaluation/
โโโ phi3_confusion_matrix.png
โโโ phi3_text_evaluation.png
โโโ meal_plan_evaluation.png
โโโ rouge_bert_evaluation.png
jupyter notebook meal_generate.ipynbfrom meal_generate import NutritionAI
# Initialize the system
app = NutritionAI()
# Define user profile
user_profile = {
"Gender": "Female",
"Age": 30,
"Weight_kg": 65,
"Height_cm": 165,
"Goal": "muscle_gain", # Options: fat_burn, muscle_gain, maintenance
"Activity_Level": "Moderate",
"BMI": 23.9,
"Blood_Pressure_Systolic": 120,
"Blood_Pressure_Diastolic": 80,
"Cholesterol_Level": 180,
"Blood_Sugar_Level": 90,
"Daily_Steps": 6000,
"Sleep_Hours": 7,
"Chronic_Disease": "None",
"Allergies": "None",
"Dietary_Habits": "Non-Vegetarian",
"Exercise_Frequency": "3-4 times a week"
}
# Generate personalized meal plan
targets, ai_guidance, weekly_plan = app.generate_7_day_plan(user_profile)
print(f"Daily Targets: {targets}")
print(f"AI Guidance: {ai_guidance}")
print(f"Weekly Plan: {weekly_plan}")Four separate CatBoost regression models predict optimal daily intake:
- Calories: Total daily energy needs
- Protein: Muscle maintenance/growth requirements
- Carbohydrates: Energy and performance needs
- Fats: Hormonal balance and satiety
Input features include:
- Demographics (age, gender, height, weight)
- Health metrics (BMI, blood pressure, cholesterol, blood sugar)
- Lifestyle factors (activity level, sleep, steps)
- Goals (fat burn, muscle gain, maintenance)
The fine-tuned Phi-3 model generates:
- Personalized nutrition advice
- Meal timing recommendations
- Hydration and supplement guidance
- Exercise integration tips
The model is optimized with:
- 4-bit quantization for faster inference
- LoRA adapters for efficient fine-tuning
- Goal-specific prompting for relevant advice
The system:
- Filters recipes based on user goals and targets
- Balances macros across breakfast, lunch, dinner, and snacks
- Ensures variety throughout the 7-day plan
- Provides per-meal and daily nutritional summaries
The system includes comprehensive evaluation metrics:
- Text Generation Quality: ROUGE and BERT scores
- Meal Plan Accuracy: Nutritional target alignment
- Classification Performance: Confusion matrices for goal prediction
See evaluation visualizations in the evaluation/ folder.
- Prepare your training dataset with nutrition Q&A pairs
- Open
Nutrition_phi3 model.ipynb - Follow the step-by-step training process
- The notebook includes:
- Data preprocessing
- LoRA configuration
- Training with gradient accumulation
- Evaluation and metric visualization
CatBoost models can be retrained with new user data:
- Update
dataset/GYM.csvwith additional user profiles - Run the CatBoost training cells in the notebook
- Models are automatically saved to
user model/folder
You can expose this system as a REST API using FastAPI:
from fastapi import FastAPI
from meal_generate import NutritionAI
app = FastAPI()
nutrition_ai = NutritionAI()
@app.post("/generate-plan")
async def generate_plan(user_profile: dict):
targets, guidance, plan = nutrition_ai.generate_7_day_plan(user_profile)
return {
"targets": targets,
"guidance": guidance,
"weekly_plan": plan
}Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Microsoft for the Phi-3 model
- Hugging Face for the Transformers library
- CatBoost team for the gradient boosting framework
- Recipe dataset contributors
For questions or feedback, please open an issue on GitHub.
- Add support for dietary restrictions (vegan, keto, paleo)
- Implement real-time nutritional tracking
- Mobile app integration
- Multi-language support
- Community recipe sharing
- Integration with fitness trackers
- Meal prep optimization
Note: This is an AI-powered nutrition system for informational purposes. Always consult with healthcare professionals for medical advice.