Esame Semantics 24/25 - Beatrice Scavo, Federico Valentino
HeASe
is a Python library designed to suggest alternative recipes for healthier or more sustainable options. Leveraging machine learning and natural language processing, it compares nutritional profiles and semantic similarities to provide recipe recommendations.
⚠️ Important note: This work is entirely based on the original repository HeASe.
All components of the project remain unchanged, except for the dataset, the quantitative, the qualitative tests, and thesustainameal
package. Regarding the quantitative evaluation, the original files were not uploaded—instead, only the final results are included in the documentation. This choice was made because the goal was not to assess a specific case in detail, but rather to evaluate the general behavior of the system and verify whether it retained the same characteristics as in the previous results. In any case, the same evaluation process as the original was followed, but with different data.
This project was developed and tested in the Kaggle environment.
If you plan to run it elsewhere, please make sure to adjust the dependencies accordingly to match your system.
To perform a quick test of the system’s functionality, you can run the notebook test.ipynb
.
- Upload 'test.ipynb' on kaggle
- Add as input the Embeddings, Recipes Dataset and the Sustainameal Package
- run 'test.ipynb'
Make sure to adapt the package dependencies to your execution environment if not using Kaggle.
- 📦 Download embeddings: Kaggle Dataset
- 📂 Download dataset, documentation and presentation: Google Drive Folder
The library consists of several modules:
- Data Preprocessing: Removes unnecessary recipe data.
- Transformer Embeddings: Generates text embeddings for recipe titles using a transformer model.
- Nutritional Vector Space: Maps recipes into a vector space based on nutritional content.
- Similarity Search: Performs cosine similarity searches to find matching recipes.
- Sort Results: Sorts recipes based on healthiness or sustainability metrics.
sm = SustainaMeal(
recipes_df='your dataset',
load=False,
nutrients=['calories', 'fat', 'protein', ...],
transformer_name='your_transformer_model'
)
Default transformer: davanstrien/autotrain-recipes-2451975973
similar_recipes = sm.find_similar_recipes(
input_text='Creamy Lemon Asparagus Risotto',
k=10,
acceptable_tags=['appetizers', 'main-dish', 'side-dishes', 'fruits', 'desserts',
'breakfast', 'pasta-rice-and-grains', 'beverages', 'drinks'],
match_all_tags=True
)
healthier_recipes = sm.order_recipe_by_healthiness(score="who_score")
order_by_sus_recipes = sm.order_recipe_by_sustainability(score='sustainability_label')
order_by_sus_recipes = sm.order_recipe_by_HeASe()