Recipe/Tool

From Open Food Facts wiki
Revision as of 16:51, 9 February 2025 by Johngom (talk | contribs) (Adding some observations)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The recipe-estimator tool uses optimisation techniques to estimate the proportion of ingredients based on a product's nutritional composition.

Some key areas where the tool has recently been changed include:

  • Using min and max values from Ciqual
  • Adjusting the variance "penalty" to take the above into account (values within the min-max range have a lower relative penalty than those outside the range).
  • Unknown ingredients (with no Ciqual code or proxy) are giving a min-max range of 0 - 100g per 100g with a nominal value of 0g
  • The Ciqual code is always looked up from the ingredients taxonomy so that this can be changed easily without having to refresh all products
  • Carbohydrates are ignored in the analysis because of the lack of clarity on whether these are net or gross (excluding or including fibre)

The recipe-estimator-metrics tool is then used to compare results with other algorithms (such as the existing Product Opener algorithm). The metrics tool hides any existing known percentages from the model and then compares these knwon percentages against those estimated by the model.

At the moment, however, the receipe-estimator still give worse average differences than the existing approach where the estimate is basically by taking a mid point of the minimum and maximum values that could occur given an ingredient's order in the ingredient list.

The following notes look at specific examples to try and determine why this is happening:

Notes on Ad-hoc Product Review

The receipe-estimator-metrics tools has been run on the fr-1000-some-specified-popular test set and the product_stats.csv table used to compare the results for different models by product.

A first pass is to review products that have a greater variance where the number of ingredients with no Ciqual code is zero

Nut & fruit mix classic (20005726)

This has a much higher estimate for the first ingredient (the raisins) because they are mapped to Ciqual code 13112 (Grape, raw). There is no Ciqual code for raisins.

Mixed nuts (20047238)

Very difficult as all nuts have similar composition. Also en:walnut is currently mapped to 15023 (Walnut, fresh) where it should be 15005 (Walnut, dried, husked)

Röstzwiebeln (20173074)

The issue here is that the oils "huiles végétales (palme, tournesol)" are being parsed as the second and third ingredient, rather than one "second" ingredient with two sub-ingredients. So, the flour, which should be limited to be no more than the combination of both oils, is now being limited to no more than the second (sunflower) oil. There was a recent PR #11251 that addressed something similar, but I think this is a different issue.

Sardinillas en aceite de oliva (20703622)

In this case the recipe estimator comes up with a much lower estimate for the oil. The Ciqual sardine (26065) chosen seems to have a higher fat content than the one used in the product, which means that once the protein nutrient target is reached (which only comes from the sardines) the fat target has also almost been reached so only a small amount of oil is needed to match the nutrients.

It may be that calculating a min and max for each ingredient could mitigate this, but the "best estimate" would still remain the same.

Nuts Royal (20816445)

This also has the issue with en:walnut being mapped to a fresh, rather than dried, walnut. Once this is corrected the estimate for Almonds (last ingredient) improves from 0 to 9%, but the overall nutrient difference is slightly worse. This is potentially because each ingredient has a relatively similar nutrient profile, so minor differences in the quality of nut used could significantly affect the results.

Filets de maquereaux Vin blanc et aromates (3019081241216)

This currently over-estimates the Mackerel and underestimates the vegetables. This may be because carbohydrates are currently being ignored (due to differences in reporting net and gross) and because fibre is not quoted, sugars are the only other carbohydrate involved, but they have relatively low quantities so don't influence the results significantly. Also including carbohydrates in the analysis, or increasing the weight of that sugar has on the variance, gives some improvement in the estimate.

Rillettes du Mans - La véritable (3024720022422)

In this case the estimator assumes a higher level of pork fat (second ingredient) is needed to meet the nutrient targets. It would appear that the default Ciqual pork used (28205) has a lower fat content than the pork used by the producer. A similar recipe is estimated if "Pork, jowl, rindless, raw" (28471) is used. This shows the variability of some ingredients.

A side-effect of this is that we could potentially help identify the variant / quality of an ingredient based on the stated percentage.

Note that for this estimate the last ingredient (pepper) is higher than the previous one (salt) and the optimiser reports "Inequality constraints incompatible" which requires further investigation. Switching from LinearConstraint to a function based constraint seems to resolve this although the optimisation takes about 3 times longer (from 0.1s to 0.27s)

Excellence 99% Cacao Noir Absolu (3046920028721)

In this case the ingredients parser is incorrectly creating a cocoa solids ingredient with a 99% estimate because of the "Cocoa solids: 99% min" claim, whereas this total actually applies to the all of the ingredients, apart from the sugar.

Ratatouille cuisinée à la provençale (3083680901024)

This contains a lot of vegetables, which will have similar nutrient profiles, so there is the potential for a wide variance. Including carbohydrates in the analysis gives some improvement.