Estimating Nutrient Composition of Packaged Foods Using Natural Language Processing and Optimization Modeling Authors: Mélina Côté, Wiam Hamadi, Catherine Laramée, Sonia Pomerleau, Véronique Provencher, Christian Gagné, Benoît Lamarche Published: 2026 ABSTRACT BackgroundFood composition databases are fundamental for rigorous dietary assessment, yet they often include information only for generic foods.ObjectivesThis study aimed to estimate the full nutrient composition of packaged foods using natural language processing (NLP) and optimization modeling.MethodsNutrition Facts tables (NFTs) and ingredient lists for 5371 packaged foods collected by the food quality observatory across 17 food categories available in Québec, Canada, were used. First, an NLP algorithm matched individual ingredients from packaged foods to the closest equivalents in the Canadian Nutrient File 2015, which contains full nutrient profiles for over 5690 ingredients and foods in Canada. Match quality was assessed using cosine similarity scores. Second, an optimization model estimated the proportion of all ingredients (grams per 100 g) from the packaged foods, enabling the reverse-engineering of nutrient composition data found on the NFT. Model performance was assessed using relative errors comparing estimated with known nutrient values reported on NFTs.ResultsOver 55% of ingredients were matched to the Canadian Nutrient File with cosine similarity scores ≥0.9, indicating high-quality matches. Across all food categories combined, the median relative error for the estimates of energy and the 10 nutrients reported on NFTs was <|20%|, consistent with Health Canada’s accepted variance for NFT declarations, suggesting reliable estimations. Six food categories showed strong results, with all nutrient estimates having median relative errors <|20%|. Eight food categories obtained moderate results, with all nutrient estimates having median relative errors <|20%|, but with a broader range of error values. Three food categories obtained poor results, with several nutrient estimates having relative errors beyond the |20%| threshold.ConclusionsA method based on NLP and optimization modeling can reliably estimate ingredient proportions of a wide variety of packaged foods, allowing for the generation of complete nutrient profiles. Introduction Accurately collecting dietary intake data is a persistent challenge in nutrition research. For instance, most self-reported dietary assessment tools are prone to both random and systematic errors, which can introduce bias into dietary intake estimates [1]. Beyond this, a major source of error stems from food composition databases that are used to calculate nutrient intakes from dietary assessment tools. Indeed, several studies have raised concerns regarding such databases, citing the presence of errors, as well as missing and outdated information [[2], [3], [4], [5]]. In addition, food composition databases often only comprise generic foods because of the frequent changes in nutrient composition of packaged foods and rapid shifts in the commercial food supply [4]. This is particularly problematic considering that packaged and ultra-processed foods may account for nearly half of the average caloric intake in many countries, including Canada [6], and that there is important variability in terms of nutrient composition between different products for a given category of packaged foods [7,8]. Given that food composition databases are a cornerstone of rigorous dietary assessment in nutrition and health research, completeness, accuracy, precision, and being up-to-date are key elements to address [2,4]. Yet, this is challenging because of the complexity involved and the burden on resources. Automating the updating process could substantially improve the quality, reliability, and frequency of upgrades of food composition databases and hence of dietary assessment. To address this gap, several studies have explored the use of machine learning, deep learning, and natural language processing (NLP) to generate accessible information on packaged foods, such as food quality scores or nutrient composition. For instance, various algorithms, including gradient-boosted trees, k-nearest neighbors (KNN), support vector machines, and neural networks, have been trained to estimate the specific nutrient content of packaged foods such as lactose [9], fiber [10], added sugars [11], as well as carbohydrates, protein, and sodium [12]. More recently, Razavi et al. [13] trained 9 different machine learning algorithms to predict multiple micronutrients not listed on the Nutrition Facts table (NFT) of packaged foods. Their results revealed considerable prediction variability across both algorithms and nutrients, suggesting that while promising, there is significant room for improvement in this area of research. Finally, existing food composition databases in Canada typically include full nutrient information on several ingredients and foods, but are limited to generic foods, whereas NFTs on commercially available packaged foods provide nutrient information for only energy and 12 nutrients. Nutrition science studies often require information on a much broader range of nutrients. Therefore, estimating the full nutrient composition of commercially available packaged foods would be highly valuable. This study aimed to estimate the full nutrient composition of commercially available packaged foods in Québec, Canada, using NLP and optimization modeling. Briefly, NLP was first used to automatically match ingredients of packaged foods to corresponding entries in the Canadian Nutrient File (CNF) 2015. Packaged foods do not disclose the quantity of each ingredient in Canada. Optimization modeling was used to estimate ingredient proportions by weight by minimizing the error between estimated and actual (known) nutrient values reported on the NFT. Methods Figure 1 presents a general overview of the methodology employed in the present study. Phase 1 refers to the matching of calorie-containing ingredients on the ingredient lists of packaged foods to corresponding entries in the CNF 2015 using NLP. The output from this phase is a list of candidate matches from the CNF 2015 for each ingredient in a given packaged food. Phase 2 refers to the optimization modeling, which A) iteratively tests the different candidate matches identified in phase 1, and B) estimates the proportion of each ingredient in a packaged food by minimizing the sum of relative errors between estimated nutrient values and actual (known) nutrient values reported on the NFT. The output from phase 2 is the identification of best CNF 2015 matches for each ingredient for a given packaged food, an estimation of ingredient proportions by weight for each packaged food, and the relative error assessment between estimated and known nutrient values reported on the NFT. The final output is the estimation of the complete nutrient composition of packaged foods.FIGURE 1Overview of methodology. Phase 1: Matching ingredients with NLP, Phase 2: Optimization modeling. BERT, Bidirectional Encoder Representations from Transformers; NFT, Nutrition Facts table; NLP, natural language processing. Overview of methodology. Phase 1: Matching ingredients with NLP, Phase 2: Optimization modeling. BERT, Bidirectional Encoder Representations from Transformers; NFT, Nutrition Facts table; NLP, natural language processing. Databases Two nutrition databases were used for the analyses. The first was the CNF 2015, a comprehensive database maintained by Health Canada containing nutrient profiles for over 5690 ingredients and foods commonly consumed in Canada [14]. It provides nutrient values for ≤152 nutrients, derived from laboratory analyses, industry sources, or adaptations of the data from the USDA to reflect Canadian contexts. The 2015 version of the CNF is the latest version made available by Health Canada. Missing data for the 10 nutrients of interest (see below) in the present study were limited, with no missing values for carbohydrates, protein and fats, <5% missing values for calcium, cholesterol, dietary fibers, iron, sodium and saturated fats, and 18% missing values for sugars. Missing values were not imputed to avoid introducing potential bias in the nutrient profiles. The second set of data used were those from the food quality observatory (FQO) [15], which includes the NFTs and ingredient lists of 5371 packaged foods [7,8]. Briefly, the FQO aims to objectively collect data on commercially available packaged foods in Québec supermarkets to measure quality and accessibility of the food supply over time. Starting in 2016, data were collected on packaged foods, including NFTs, ingredient lists, percent daily values, serving size and cost, among others. Further information on data collection has been previously detailed [7]. For the present analyses, NFTs and ingredient lists were available for 17 categories of packaged foods (no missing values): processed cheeses (n = 118), cookies (n = 728), salty snacks (n = 437), breakfast cereals (n = 392), crackers (n = 434), salad dressings (n = 64), granola bars (n = 358), pasta sauces (n = 342), meat spreads (n = 60), frozen dishes (n = 335), ready-to-serve soups (n = 204), luncheon meats (n = 506), yogurts and dairy-based desserts (n = 372, henceforth referred to as “yogurts”), dairy-based and plant-based beverages (n = 198, henceforth referred to as “dairy-based beverages”), sliced breads (n = 304), pizzas (n = 203) and sausages (n = 316). The packaged foods were collected in supermarkets, grocery stores and specialty grocery stores from the Greater Québec City area and the Greater Montreal area between 2016 and 2022. One category (pizzas) included packaged foods from across Canada. The extent to which this FQO database reflected all packaged food availability across Québec or Canada remains uncertain. However, evidence from a separate study using this database showed that 3941 of the 5371 products were successfully matched with sales data, representing an average market coverage of 79% [8]. These findings suggest that the FQO database likely captured a substantial proportion of the packaged food market in Québec or Canada. In 2017, Health Canada revised its regulations on mandatory nutrient labeling by removing vitamins A and C and including potassium [16]. However, since the food industry had until December 2021 to fully implement these changes, potassium was excluded from the present analyses due to limited availability across food products. Trans fats were also excluded from the analyses because artificial trans fats have been completely banned from Canadian food products since 2018 and because of their frequent absence in the CNF 2015. Therefore, energy and 10 nutrients (fats, saturated fats, carbohydrates, dietary fibers, sugars, protein, cholesterol, sodium, calcium, and iron) were included in the analyses. Data preparation and NLP algorithm (phase 1) Ingredient lists from packaged foods in the FQO database were linked to corresponding ingredients in the CNF 2015 using an NLP algorithm (see below). NLP is a subfield of artificial intelligence regrouping algorithms that interpret and analyze human language, making it possible to identify, classify, and extract relevant information from text data [17]. NLP algorithms represent words as embeddings (vectors in a multi-dimensional space) that capture semantic meaning and contextual relationships. The relative distance and direction between vectors indicate word similarity, with closer vectors reflecting similar meanings. To generate optimal word embeddings, both the CNF 2015 and FQO databases were pre-processed. For the CNF 2015 database, recipes and mixed dishes were excluded to retain only individual food and ingredient items likely to appear on the ingredient lists of packaged foods (n = 4338). Each CNF 2015 entry is described by a sequence of character strings. For example, “black beans” appears as “beans, black, mature seeds, raw.” To streamline the data, only the first 2 strings of characters in the sequence were retained (e.g., “beans” and “black”), as they typically capture the essential identity of the food item. Including additional strings increased computational time, without providing meaningful gains in information. Specifically, third strings were mostly descriptive adjectives (e.g., related to processing, preparation, or flavor), which tended to have embeddings that were semantically more distant from those of the underlying food ingredients. This introduced noise into the similarity calculations and ultimately reduced matching accuracy. For the FQO database, food additives, listed as permitted food additives in Canada by Health Canada [18], were excluded first because most food additives have no nutritional value and second because the CNF 2015 does not provide nutrient profiles for additives. Ingredients used for the purpose of food fortification, such as vitamins, minerals, or amino acids, were not specifically excluded in the matching phase. However, these micronutrients per se are not found as individual ingredients in the CNF 2015. As a result, data on fortification micronutrients could not be included in the optimization modeling phase. Sub-ingredients (i.e., detailed composition of a given ingredient appearing between parentheses or square brackets) were removed to simplify the creation of word embeddings and because the ingredient that precedes a string of ingredients in parentheses can generally be found in the CNF 2015 [e.g., in “shortening (vegetable oil, modified palm oil),” only “shortening” was kept]. In cases where ingredients were presented as an “and/or” string, only the first item was retained. Additionally, adjectives describing ingredients were removed, as they often hindered algorithm performance without altering the core identity of the food item. For example, removing “organic” in “organic oats” does not alter the food item or its general composition. Distinction between cooked and raw/dry forms was not taken into account, since NFTs do not provide information on specific preparation or processing of ingredients. All text data underwent stemming and lemmatization, which is the process of transforming words into their base or dictionary forms (e.g., removing conjugation, pluralization, adverbial form, and suffixes). This was performed using the spaCy library, a widely used NLP tool, and custom Python pre-processing and rule-based functions to account for the specific structure of ingredient lists. These steps enhance the consistency and performance of NLP algorithms. The Bidirectional Encoder Representations from Transformers (BERT) is a widely adopted pre-trained transformer-based NLP model that provides contextual understanding of text [19]. BERT is pre-trained on large text corpora, including BooksCorpus (800 million words) and English Wikipedia (2.5 billion words), allowing it to effectively capture semantic meaning and achieve state-of-the-art performance across various NLP tasks. For the present analyses, a variant of BERT, FoodBERT, was employed [20]. FoodBERT is an NLP algorithm trained on Recipe1M+, which includes over 1 million recipes [21]. This pre-training enables FoodBERT to accurately interpret culinary language and ingredient contexts relevant to nutrition research. In the context of this study, the FoodBERT model was not further fine-tuned, as it already recognized most ingredients from the CNF 2015. For ingredients not originally present in the model’s vocabulary, vector representations for these words were generated using embedding aggregation, i.e., the model made an educated guess about a new word by combining known words. For example, if “cornstarch” is unknown in the FoodBERT models’ vocabulary, it could aggregate vectors “corn” and “starch.” FoodBERT was employed using the transformers library (BERTModel). The FoodBERT model was used to generate word embeddings for all ingredients in the cleaned FQO and CNF 2015 databases (English versions). This subsequently allowed matching ingredients in packaged foods from the FQO database to the corresponding food or ingredient in the CNF 2015 database. Cosine similarity, a standard metric in NLP, was used to quantify the similarity between word embeddings [22]. The cosine similarity metric measures the angle between 2 vectors in a multi-dimensional space, with smaller angles indicating greater similarity. For a given ingredient in a packaged food, there are potentially many matches in the CNF 2015 database with a cosine similarity value of 1, which is considered a perfect match. All matches with a cosine similarity of 1 were retained for each ingredient. For matches with cosine similarity scores below 1, the 40 candidates with the highest cosine similarity values were retained. The “milk ingredient,” frequently listed as the first component in cheese products and dairy-based or plant-based beverages, lacks a clear definition and is not present in the CNF 2015. Milk ingredients plausibly represent a range of dairy components such as milk, cream, butter, or protein concentrates. For that reason, the “milk ingredient” was manually matched with 1 of 4 ingredients in the CNF 2015: skim milk (code 115), 15% cream (code 151), butter (code 92), and whey protein isolate (code 7229). Optimization modeling (phase 2) Optimization modeling is a mathematical approach used to find the best possible solution to a problem by minimizing or maximizing an objective function, given a set of constraints. Here, the objective function minimized the sum of relative errors between estimated and known nutrient values of energy and 10 nutrients reported on the NFT of each packaged food. Relative error was defined as the absolute difference between estimated and known nutrient values reported on the NFT, divided by the known value. The objective function was defined as follows:minα∑j=1M(ϵj)2where M denotes the number of nutrients, and ϵj denotes the relative error for the j-th nutrient, defined as follows:(1)ϵj=∑i=1Nωi,jαi−νjνj,j=1,…,Mωi=[ωi,1,ωi,2,…,ωi,M]⊺α=[α1,α2,…,αN]⊺where N is the number of ingredients in the food, ωi,j,denotes the quantity of the j-th nutrient in grams for the i-th ingredient, αi represents the proportion of the i-th ingredient for 100 g of the product and νj represents the total amount (in grams) of the j-th nutrient for 100 g of the food product. Note that M (total number of nutrients), N (total number of ingredients), and νj (total amount in grams of each nutrient) are known values found on the NFTs. Equation 1 was formulated to minimize relative error rather than absolute error because nutrient values vary in terms of scale. Although fats, carbohydrates, and protein are reported on NFTs in terms of grams, iron, sodium, and cholesterol are reported in milligrams. This approach ensured that errors were evaluated proportionally to each nutrient’s true value and gave equal importance to nutrients of different magnitudes (e.g., fat with a value of 20 and iron with a value of 0.0002). However, minimizing relative error in the optimization modeling equation posed challenges for nutrients with values equal to “0” on the NFT, as division by 0 is not possible. Thus, for each food product, only nutrient values not equal to “0” were included in the optimization modeling. Meaning M in Equation 1 varies according to the number of nutrients equal to “0” for a given product. For example, if all nutrients for a given product are not equal to “0,” then M = 11, whereas if fats were equal to “0”, M = 10. The optimization model was subjected to the following constraints:αi≥0.0000001,i=1,…,Nαi−αi+1≥0,i=1,…,N−1∑i=1Nαi=1 These constraints ensured 1) that each ingredient on the ingredient list of a food was present in a non-zero amount, 2) that the amounts of each ingredient were in decreasing order as per the regulated format of the ingredient list [16], and 3) that the sum of the proportions of gram amounts of ingredients was equal to 1. From this modeling, a constrained optimization solver was applied over the optimization objective given as Equation 1, respecting the constraints stated above, to find, in phase 2A (see below), values of ωi,j, (quantity of each nutrient for 1 ingredient in a food) by finding the best match among candidate CNF 2015 matches previously identified in phase 1 (NLP algorithm), and in phase 2B (see below), values of αi (proportion by weight of each ingredient in a food). Phases 2A and 2B occurred simultaneously and were interdependent. Specifically, estimating the quantity of each nutrient for a given ingredient depended on the proportion by weight of that ingredient in the food, whereas these proportions were, in turn, informed by the estimated nutrient quantities. For clarity, however, the 2 phases are described separately below. The optimization model was implemented using the Pyomo optimization library using a concrete model with the Interior Point OPTimizer (IPOPT) solver for nonlinear programming with continuous variables. Phase 2A (estimating ωi,j,) As a first part of the optimization modeling, all candidate ingredient matches from phase 1 were iteratively tested to find the best ingredient CNF 2015 matches that minimized the sum of relative errors (ϵj) between estimated and known values of energy and 10 nutrients reported on the NFT of that food. This approach proceeded ingredient by ingredient. Specifically, the first ingredient of a packaged food was optimized by iteratively testing all CNF 2015 matches, fixing all other ingredients to their first candidate match. Once the optimal match for the first ingredient was determined, the process was repeated for the next ingredients. Phase 2A allowed estimating ωi,j, in the optimization modeling Equation 1. The identification of the best ingredient match was dependent on phase 2B, as the estimated ingredient proportions were used to evaluate which candidate match most accurately reproduced the NFT of a food. Missing nutrient values for CNF ingredient matches were excluded from the optimization modeling, consistent with the treatment of nutrients equal to “0.” Phase 2B (estimating αi) With the nutrient composition of each ingredient being known (phase 2A), phase 2B consisted of estimating αi (proportion by weight of each ingredient in a food) in the optimization modeling Equation 1 for each ingredient in the 5371 packaged foods from the FQO database by minimizing the sum of relative errors (ϵj) between the estimated nutrient values and known nutrient values of energy and 10 nutrients reported on the NFT. The final output of the modeling is the complete nutrient composition of each individual packaged food. Statistical analyses All analyses were conducted in Python 3.11.13. Cosine similarity scores of the best matches between ingredients from packaged foods and the CNF 2015 were reported. To evaluate the performance of the optimization model, relative errors expressed in percentage (%) were reported for energy and the 10 nutrients listed on the NFT (fats, saturated fats, carbohydrates, dietary fibers, sugars, protein, cholesterol, sodium, calcium, and iron). Because relative errors cannot be calculated with a value of 0 as the denominator, only nutrients with non-zero values were used in the optimization modeling. For example, optimization modeling of a packaged food with 5 nutrients having values of 0 on the NFT was performed using the other 5 nutrients with non-zero values. Descriptive statistics, including the median, IQR, 2.5th and 97.5th percentiles, were used to summarize relative errors of nutrient estimations across all foods and by food category. To assess overall nutrient estimation precision within each category, a summary metric denoted as “All” was calculated as the relative error for all nutrients combined per food item. The percentage of packaged foods with a relative error of <|5%|, <|10%| and <|20%| are reported for each nutrient and food category. A threshold of <|20%| aligns with the acceptable tolerance for nutrient declarations on NFTs in Canada. Indeed, Health Canada allows ≤20% deviation in declared nutrient values to account for variability in food composition [23]. To assess the performance of the model for nutrient values equal to “0” on the NFT, small threshold values were used as “true” estimates, using the Canadian Food Inspection Agency rounding rules, which determine if a value can be rounded to “0” [24]. These values were 0.5 g for fats, carbohydrates, dietary fibers and sugars, 0.2 g for saturated fats, 0.002 g for cholesterol, 0.005 g for sodium and calcium, and 0.00005 g for iron. No value was available for protein; therefore, 0.5 g was used because of its similar scale to fats. Results Table 1 presents the number of unique foods, unique ingredients, and the mean number of ingredients per food item for each of the 17 food categories, along with cosine similarity scores, which reflect the precision of ingredient matches between the FQO and CNF 2015 databases. Across all 17 food categories, over 55% of ingredients had cosine similarity scores above 0.9. The highest proportion of exact ingredient matches (cosine similarity = 1.0) was observed for crackers (49.0%), meat spreads (47.5%), and sliced breads (47.2%) (not shown). In contrast, salad dressings (45.1%), pizzas (43.2%), and frozen dishes (41.2%) had the greatest share of ingredients with similarity scores below 0.9, indicating possibly less precise matches in these categories.TABLE 1Food categories, ingredients, and cosine similarity scores per categoryTABLE 1CategoryNumber of uniquefoodsNumber of unique ingredientsMean number of ingredients per foodCosine similarity score1 ≥0.9 (%)Breakfast cereals3923488.674.1Processed cheeses118885.059.1Cookies7283817.866.7Crackers4343127.469.6Dairy-based beverages1981094.361.5Frozen dishes33556613.958.8Granola bars35829610.160.1Meat spreads60809.066.3Pasta sauces34224410.359.8Pizzas20325713.356.8Luncheon meats5061647.061.0Ready-to-serve soups20428012.761.4Sausages3162478.760.7Sliced breads3042869.574.5Salty snacks4372385.268.1Salad dressings641029.154.9Yogurts3721526.359.9Abbreviations: CNF, Canadian Nutrient File; FQO, Food Quality Observatory.1The cosine similarity score reflects the precision of ingredient matches between the FQO and CNF 2015 databases. TABLE 1Food categories, ingredients, and cosine similarity scores per categoryTABLE 1CategoryNumber of uniquefoodsNumber of unique ingredientsMean number of ingredients per foodCosine similarity score1 ≥0.9 (%)Breakfast cereals3923488.674.1Processed cheeses118885.059.1Cookies7283817.866.7Crackers4343127.469.6Dairy-based beverages1981094.361.5Frozen dishes33556613.958.8Granola bars35829610.160.1Meat spreads60809.066.3Pasta sauces34224410.359.8Pizzas20325713.356.8Luncheon meats5061647.061.0Ready-to-serve soups20428012.761.4Sausages3162478.760.7Sliced breads3042869.574.5Salty snacks4372385.268.1Salad dressings641029.154.9Yogurts3721526.359.9Abbreviations: CNF, Canadian Nutrient File; FQO, Food Quality Observatory.1The cosine similarity score reflects the precision of ingredient matches between the FQO and CNF 2015 databases. Food categories, ingredients, and cosine similarity scores per category Abbreviations: CNF, Canadian Nutrient File; FQO, Food Quality Observatory. The cosine similarity score reflects the precision of ingredient matches between the FQO and CNF 2015 databases. The next series of results presents the data for all food categories combined and for each individual food category. Figure 2 summarizes the precision of the optimization model to estimate energy content and 10 nutrients reported on the NFTs across all food categories combined. As indicated above, the error tolerance regulated by Health Canada for the nutrient composition of foods on NFTs is <|20%|. The optimization model estimated the nutrient content with relative errors <|20%| in >75% of packaged foods. For energy, fats, saturated fats, sugars, and sodium, the optimization model estimated nutrient values with relative errors <|10%| in 2/3 of all packaged foods. The right panel of Figure 2 shows that there was no systematic shift in overestimating or underestimating the value of each nutrient, with both the median relative errors and IQRs falling well within the |20%| error threshold across all nutrients. However, the relatively wide distribution of relative errors at the extremes (2.5th–97.5th percentiles) indicates that certain nutrients in some foods were poorly estimated by the optimization model, with errors >|20%|.FIGURE 2Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for all food categories combined. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for all food categories combined. Red dotted lines represent a <|20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. NFT, Nutrition Facts table. Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for all food categories combined. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for all food categories combined. Red dotted lines represent a <|20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. NFT, Nutrition Facts table. Figures 3‒5 present heatmaps and box plots of relative errors in nutrient estimates for each food category separately. Figure 3 shows results for the food categories for which the optimization model achieved the best results, namely ready-to-serve soups, frozen dishes, pasta sauces, pizzas, sliced breads, and crackers. In these categories, the model estimated nutrient content with relative errors <|20%| for 65% or more of packaged foods. The optimization model performed particularly well for ready-to-serve soups, with ∼2/3 of products having relative errors <|5%| across all nutrients. Moreover, for nutrients of concern such as fats, saturated fats, sugars, and sodium, estimates were <|10%| from actual values for 2/3 of these foods. Median relative errors and IQRs were consistently <|20%| across all nutrients with no evidence of systematic over- or underestimation, suggesting an overall strong performance of the optimization model to estimate nutrient content for these foods.FIGURE 3Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with the strongest results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a <|20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. (A) Ready-to-serve soups, (B) frozen dishes, (C) pasta sauces, (D) pizzas, (E) sliced breads, (F) crackers. NFT, Nutrition Facts table. Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with the strongest results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a <|20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. (A) Ready-to-serve soups, (B) frozen dishes, (C) pasta sauces, (D) pizzas, (E) sliced breads, (F) crackers. NFT, Nutrition Facts table. Figure 4 shows results for sausages, cookies, breakfast cereals, luncheon meats, granola bars, salad dressings, yogurts, and meat spreads, for which the nutrient values were estimated with less precision. For these categories, nutrient content was estimated with relative errors <|20%| in >50% of packaged foods, except for cholesterol in the salad dressing food category, where only 32% of foods met this threshold. For nutrients of concern, the optimization model estimated nutrient values with errors <|10%| for >40% of products. One to 3 nutrients per food category exhibited IQRs exceeding the |20%| threshold, most often being iron, dietary fiber, and cholesterol. However, there was no evidence of systematic over- or underestimation of known nutrient values. Figure 5 presents optimization modeling data for processed cheeses, salty snacks, and dairy-based beverages, the food groups for which known nutrient values were estimated with the lowest precision, indicating suboptimal performance. Multiple nutrients per food category exhibited IQRs exceeding the |20%| mark. Best results for these food categories were for fats, saturated fats, sodium, and iron, with >55% of food products having estimates for these nutrients with errors <|20%|.FIGURE 4Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with average results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a |20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. (A) Sausages, (B) cookies, (C) breakfast cereals, (D) luncheon meats, (E) granola bars, (F) salad dressings, (G) yogurts, (H) meat spreads. NFT, Nutrition Facts table.FIGURE 5Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with poor results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a |20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. Dairy-based beverages had 97.5th percentiles of relative errors above 100% (all, 307.9%; energy, 217.5%; saturated fats, 245.2%; carbohydrates, 1222.0%; dietary fibers, 150.9%; sugars, 263.1%; protein, 181.3%; sodium, 152.2%; iron, 643.8%). (A) Processed cheeses, (B) salty snacks, (C) dairy-based beverages. NFT, Nutrition Facts table. Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with average results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a |20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. (A) Sausages, (B) cookies, (C) breakfast cereals, (D) luncheon meats, (E) granola bars, (F) salad dressings, (G) yogurts, (H) meat spreads. NFT, Nutrition Facts table. Heatmap of the relative error (left panel) and distribution of relative errors (right panel) in estimates of nutrient content based on optimization modeling for food categories with poor results. The heatmap represents the percentage of packaged foods for which nutrients are estimated with relative errors <|5%|, |10%|, and |20%|, respectively. The numbers within each square of the heatmap and the corresponding colors correspond to the percentage of packaged foods for which the known nutrient value was estimated with a relative error that is less than the corresponding error margin. The box plot on the right presents median (central line), 25th and 75th percentiles (ends of box), and 2.5th and 97.5th percentiles (ends of whiskers) of the relative errors in nutrient estimates for each food category. Red dotted lines represent a |20%| relative error, which is the error tolerance regulated by Health Canada when reporting nutrient values on NFTs. Dairy-based beverages had 97.5th percentiles of relative errors above 100% (all, 307.9%; energy, 217.5%; saturated fats, 245.2%; carbohydrates, 1222.0%; dietary fibers, 150.9%; sugars, 263.1%; protein, 181.3%; sodium, 152.2%; iron, 643.8%). (A) Processed cheeses, (B) salty snacks, (C) dairy-based beverages. NFT, Nutrition Facts table. As indicated above, nutrients with values of “0” on the NFT could not be used in the optimization models. However, examining the extent to which the models can estimate a value of “0” for such nutrients is relevant. Table 2 compares estimated with “0” values for such nutrients among all foods combined. As indicated in the Statistical analyses, a nutrient-specific threshold value slightly above “0” was used to obtain relative errors and hence document deviations from the known values. The optimization model yielded estimates of “0” for very few nutrients. However, estimates of dietary fibers (54.6%) and of cholesterol (62.2%) were below the nutrient-specific threshold to round a value to “0” on the NFT, indicating relatively good performance. Estimates were below thresholds in 25.5% of foods for saturated fats and 39.4% for sugars. For the remaining nutrients, estimating values equal to “0” with accuracy proved to be challenging. Nonetheless, relative to the average daily nutrient intakes in Canada [25], median estimates for nutrients with values of “0” on the NFT remained low for total fats, saturated fats, carbohydrates, dietary fibers, sugars, protein, and cholesterol. For example, the median estimate for carbohydrate values equal to “0” on the NFT was 5.4 g, which represents 2% of an average daily intake of approximately 265 g in Canada [25]. In contrast, median estimates for iron, sodium, and calcium diverged more from actual “0” values.TABLE 2Accuracy of the model predicting nutrients with values equal to “0” on the Nutrition Facts table, all food categories combinedTABLE 2NutrientValues equal to “0” on the NFT (n)Estimates equal to “0” (% of n)Median (Q1-Q3) estimates(g/ 100 g)A priori defined threshold1 (g/ 100 g)Foods with values below threshold1 (%)Fats14401.3 (0.8, 2.1)0.518.1Saturated fats38400.5 (0.2, 0.9)0.225.5Carbohydrates2773.25.4 (1.9, 55.5)0.59.7Dietary fibers17507.00.4 (0.1, 1.1)0.554.6Sugars9984.70.7 (0.2, 1.5)0.539.4Protein3101.2 (0.6, 3.2)0.519.3Cholesterol292532.60.001 (0.0, 0.005)0.00262.2Sodium14300.2 (0.03, 0.7)0.0054.9Iron211800.002 (0.001, 0.003)0.000050.8Calcium224000.05 (0.03, 0.1)0.0050.8Abbreviation: NFT, Nutrition Facts table.1Threshold to round a nutrient value to “0” on the NFT in Canada as defined by the Canadian Food Inspection Agency (see Methods section Statistical analyses). Q1 and Q3 are the 25th and 75th percentiles. TABLE 2Accuracy of the model predicting nutrients with values equal to “0” on the Nutrition Facts table, all food categories combinedTABLE 2NutrientValues equal to “0” on the NFT (n)Estimates equal to “0” (% of n)Median (Q1-Q3) estimates(g/ 100 g)A priori defined threshold1 (g/ 100 g)Foods with values below threshold1 (%)Fats14401.3 (0.8, 2.1)0.518.1Saturated fats38400.5 (0.2, 0.9)0.225.5Carbohydrates2773.25.4 (1.9, 55.5)0.59.7Dietary fibers17507.00.4 (0.1, 1.1)0.554.6Sugars9984.70.7 (0.2, 1.5)0.539.4Protein3101.2 (0.6, 3.2)0.519.3Cholesterol292532.60.001 (0.0, 0.005)0.00262.2Sodium14300.2 (0.03, 0.7)0.0054.9Iron211800.002 (0.001, 0.003)0.000050.8Calcium224000.05 (0.03, 0.1)0.0050.8Abbreviation: NFT, Nutrition Facts table.1Threshold to round a nutrient value to “0” on the NFT in Canada as defined by the Canadian Food Inspection Agency (see Methods section Statistical analyses). Q1 and Q3 are the 25th and 75th percentiles. Accuracy of the model predicting nutrients with values equal to “0” on the Nutrition Facts table, all food categories combined Abbreviation: NFT, Nutrition Facts table. Threshold to round a nutrient value to “0” on the NFT in Canada as defined by the Canadian Food Inspection Agency (see Methods section Statistical analyses). Q1 and Q3 are the 25th and 75th percentiles. Discussion Food composition databases are fundamental to dietary assessment and nutrition research, yet they are infrequently updated and often contain only generic foods. Leveraging new technologies to automate their generation and updating could markedly improve their completeness, accuracy, and reliability, contributing to more rigorous dietary assessment. This study aimed to estimate nutrient composition of packaged foods using NLP and optimization modeling. First, an NLP algorithm linked ingredient lists of packaged foods to corresponding entries in the CNF 2015, which provides comprehensive nutrient data for individual ingredients. Second, an optimization model minimizing the errors between estimated and known nutrient values from the NFT of packaged foods was used to estimate amounts of each of the best-matched CNF 2015 ingredients. When accurate and precise, this approach enables the estimation of the full nutrient composition of each individual packaged food. Results suggest that the NLP model generally performed well in identifying appropriate matches for each ingredient when considering all food categories together. Most ingredients had cosine similarity scores above 0.9, indicating a high degree of similarity between the known packaged food ingredients and their CNF 2015 counterparts. Between 25% and 45% of ingredient matches had cosine similarity scores below 0.9, depending on the food category. This could reflect either possible important textual divergences between names of ingredients from each database or incorrect ingredient matches, requiring further improvements. Among potential improvements, extending certain embeddings to capture greater detail could enhance accuracy but would also require substantially more computational resources. Moreover, due to these computational constraints, CNF 2015-to-ingredient matching was optimized sequentially, i.e., 1 ingredient at a time, rather than by evaluating all possible combinations simultaneously, which should be experimented with in subsequent studies. A potential mitigation strategy for high computational costs would be to precompute embeddings for static content, for example, the CNF 2015 database, and store them in an indexed database, avoiding repeated Graphic Processing Unit (GPU) processing during retrieval. Regarding the estimation of ingredient proportions in grams and subsequent nutrient estimation, the NLP and optimization modeling pipeline yielded promising results. When aggregating the data across all 17 categories of packaged foods, there was no evidence of a systematic shift in the median relative errors when estimating the known values of nutrients on the NFT, and IQRs remained well within |20%|, which is the accepted error tolerance for nutrient declarations on NFTs in Canada. Achieving relative errors <|20%| indicates that the estimates are sufficiently accurate to meet Health Canada’s standards for consumer information. Estimating nutrient values of “0” on the NFT with precision proved to be more challenging. Given that the CNF 2015 contains detailed nutrient data for relatively few packaged foods and has not been updated in the past decade, this approach offers a relevant and practical solution for estimating nutrient composition with reliability. Whether an updated CNF yields better precision will need to be tested. When examining results by food category, notable differences in performance were observed. The model performed particularly well for 6 categories of packaged foods, namely ready-to-serve soups, frozen dishes, pasta sauces, pizzas, sliced breads, and crackers, with no major shift in median relative errors of estimates for all nutrients and with IQRs of relative errors <|20%|. For food categories with moderate performance (sausages, cookies, breakfast cereals, luncheon meats, granola bars, salad dressings, yogurts, and meat spreads), most nutrient estimates also fell within the acceptable |20%| range, though greater deviances were observed for iron, cholesterol, and dietary fibers. Nutrients present in small quantities are typically reported in milligrams. In such cases, even small absolute deviations between estimated and known nutrient values from the NFT can result in disproportionately large relative errors. Although results overall are promising, the model’s performance was suboptimal for categories such as processed cheeses, salty snacks, and dairy-based beverages, with systematic shifts in median relative errors for some nutrients and a large distribution of relative errors for others. This indicates that the method does not perform equally well across all food products, suggesting a need for further refinement of the model for specific food categories. One of the main distinctions between food categories with low and high precision in nutrient estimation was the average number of ingredients included in the optimization modeling. Specifically, processed cheeses, salty snacks, and dairy-based beverages had an average of 4.3, 5.0, and 5.2 ingredients per product, respectively, compared to 12.7, 13.9, and 13.3 for ready-to-serve soups, frozen dishes, and pizzas (excluding additives, see Methods). This suggests that the optimization model performs better when more ingredients are available, possibly because the model has more flexibility to adjust ingredient proportions and to better estimate nutrient values on the NFT. Furthermore, with more ingredients, the estimation error is distributed across more nutrients, helping to reduce relative errors in each nutrient estimate. Additionally, 40.9% (processed cheeses), 38.5% (dairy-based beverages), and 31.9% (salty snacks) of ingredients being matched to the corresponding CNF 2015 list had cosine similarity scores below 0.9, and nutrients equal to “0” on the NFT were not included in the optimization modeling. These 2 factors contributed to reducing the quantity of information available with which ingredient proportions were estimated and may have exacerbated the suboptimal performance for these food categories. Furthermore, in the processed cheeses category, the “milk ingredient” is among the most commonly listed ingredients. However, this designation refers to a range of ingredients, including milk, cream, milk fat, buttermilk, and related derivatives. Due to current labeling regulations in Canada, which do not require further specification, it is not possible to precisely identify this ingredient, thereby affecting performance. Future changes to labeling requirements could improve the accuracy of ingredient matching for such packaged products. Further developments in the ingredient matching step of this approach should be explored in future studies. Several studies have explored the use of artificial intelligence-based approaches to estimate the nutrient composition of foods, typically employing machine learning algorithms and focusing on a limited number of nutrients. For instance, Davies et al. [10] trained a KNN algorithm to predict fiber content of packaged foods using a dataset of 11 441 foods with known fiber content. The algorithm predicted fiber content based on 6 nutrients and achieved an R2 of 0.84 and a mean absolute error of 1.52 g/100 g. In a subsequent study, the same research group trained and tested a KNN algorithm to predict added sugars using 70 522 products with known added sugar content for training and a synthetic database of 500 packaged foods for testing [11]. The algorithm predicted added sugars based on 6 nutrients and obtained an R2 of 0.96 and a mean absolute error of 1.68 g/100 g. Razavi et al. [13] trained multiple machine learning algorithms to estimate the composition of multiple vitamins and minerals not declared on food labels, using 14 nutrients available on an NFT from a dataset of 5624 foods. Their models reached R2 values ranging from 0.22 to 0.75 for vitamins and 0.16 to 0.82 for minerals. Similarly, Ma et al. [12] tested 5 machine learning algorithms to predict sodium, protein, and carbohydrate content based solely on ingredient lists of food products. A neural network outperformed other models, with R2 values of 0.90 for carbohydrates, 0.80 for protein, and 0.70 for sodium. Although these approaches yielded promising results, they relied on access to large, annotated datasets for effective model training. Machine learning algorithms may also be sensitive to data sources and may require extensive validation to ensure generalizability. Despite differences in evaluation metrics, the findings from these studies align with ours in demonstrating a generally strong model performance, but with varying results across nutrients and food products. Our approach differed fundamentally from previous studies in not having relied on the pre-training of a model, but instead applying optimization on a per-product basis. This makes it more flexible and broadly applicable across food categories and databases. Similar to our approach, studies have attempted to incorporate NLP to estimate nutrient composition based on information available on packaged foods. Ma et al. [26] compiled nutrition data, including ingredients and nutrient values, for 133,925 packaged foods. Their neural network model, which integrated NLP to process text-based ingredient lists, achieved an R2 of 0.98 for calcium and 0.93‒0.97 for energy and other nutrients such as protein, total carbohydrates, fats, and sodium. Although results from this study suggest that the neural network is a promising approach for nutrient estimation, it relied heavily on extensive pre-processing to ensure learning efficiency, and the model did not yield ingredient proportions. In another study, Chin et al. [9] explored 2 methods for predicting lactose content in foods. The first approach manually compiled lactose content for 378 foods for training and 189 for testing across 9 machine learning algorithms. The best model, an eXtreme Gradient Boosting (XGB)-regressor, achieved an R2 of 0.33 and a mean absolute error of 1.18 g/100 g. The second approach used an automated NLP-based database-matching algorithm to pair foods to foods with nutrient information, resulting in improved performance with an R2 of 0.76 and a reduced mean absolute error of 0.54 g/100 g when evaluated on the full dataset. Consistent with our findings, these results suggest that NLP can enhance nutrient estimation by leveraging ingredient-level information. However, a key distinction in our approach lies in the matching of databases. Rather than linking entire foods to a food and nutrient database, an approach limited by the presence or absence of a matching food, we linked individual ingredients in packaged foods to corresponding ingredient entries in a food and ingredient database, namely the CNF 2015. This method allows for automatic matching even when new products are introduced, reducing the need for manual updates and improving scalability and flexibility over time. Our combined NLP and optimization modeling approach suggests promising results both to facilitate matching of packaged food products to their corresponding nutrient information and to estimate nutrient composition. Limitations need to be addressed. First, we simplified the CNF 2015 embeddings by retaining only the first 2 character strings, which can obscure important distinctions in food items, such as seed oils (e.g., all oils collapse to “vegetable oil”), potentially biasing nutrient estimates. Extending embeddings for some ingredients to capture more detail would likely improve accuracy but would also demand greater computational resources and, in some instances, arbitrary choices. Second, due to computational constraints, CNF 2015-to-ingredient matching was optimized 1 ingredient at a time rather than evaluating all possible combinations simultaneously. Although the approach used in this study can be universally reproduced using different databases, the full nutrient content of foods used in our study cannot be generalized to other food supplies because our dataset mainly represents packaged foods sold in Québec. Also, the ingredient nomenclature in the CNF 2015 and the FQO databases is not standardized, which could have influenced the accuracy of ingredient matching. The relative time mismatch between foods and ingredients in the CNF database (2015) and the FQO database (2016 onward) is unlikely to have affected the results because the nutrient content of foods and ingredients in the CNF is unlikely to have changed substantially over time. In addition, vitamins, minerals, and amino acids added through food fortification are not found in the CNF 2015 and therefore could not be matched and included in the optimization modeling. Whether the proposed approach can precisely and accurately estimate the nutrient composition of nutrients not provided on the NFT, for example, magnesium and vitamin D, remains to be assessed. Addressing this is largely conditional on the capacity to collect dietary intake data in a product-specific way, and on relying on up-to-date nutrient composition databases and dietary intake data collection methods, which are major challenges in nutrition. The study also has several notable strengths. We used a sizable dataset of 5371 packaged foods spanning multiple categories of foods available in the Province of Québec, enabling a robust evaluation of our combined NLP and optimization modeling approach. Automating ingredient matching from the FQO database to the CNF 2015 database via NLP dramatically reduces the time and resources required compared to manual lookup. Moreover, by matching ingredients rather than whole foods, our method can be readily applied to new products, enhancing both flexibility and scalability. Similarly, the optimization modeling does not rely on a training phase, which makes it easier to apply even on a per-product basis. Also, unlike earlier NLP algorithms such as Word2Vec [27], which process text in a single direction, BERT captures context from both the left and right texts of each word, resulting in more accurate word representations. Finally, an important distinction from other studies is that our approach enables the estimation of ingredient proportions, which in turn allows for the generation of complete nutrient profiles of packaged foods, covering ≤152 nutrients. In conclusion, this study presents a promising method for generating a comprehensive nutrient composition profile of packaged foods, addressing a significant gap in maintaining food databases. Although overall results indicate that the approach yields reliable estimates for nutrients listed on the NFT of most packaged foods, several avenues for improvement remain. Enhancing the accuracy of the reference CNF 2015 matches, refining the handling of "0" values, and increasing computational power to enable more robust optimization could further improve performance. Additionally, certain foods with notably high nutrient estimate errors, particularly those with a small number of ingredients, warrant closer examination, as they may disproportionately affect overall results. Despite these challenges, the method stands out for being relatively simple to implement, for not relying on extensive model training, and for being easily applicable to new foods. Most importantly, it enables the estimation of ingredient proportions, something that is not available in the United States and Canada, allowing for the generation of complete nutrient profiles in the absence of existing automated tools. Author contributions The authors’ responsibilities were as follows– BL, CG, VP: designed the study; CL, SP, MC, WH: conducted the research; WH, MC: analyzed data and performed statistical analyses; MC: drafted the manuscript; BL: had primary responsibility for the final content; and all authors: read and approved the final manuscript. Data availability Data described in the manuscript, code book, and analytic code will be made available upon request pending application and approval. Declaration of generative AI and AI-assisted technologies in the writing process The author(s) declare that no generative AI or AI-assisted technologies were used in the writing of this manuscript. Funding The Food Quality Observatory received financial support from the ministère de l’Agriculture, des Pêcheries et de l’Alimentation du Québec (MAPAQ), the ministère de l’Économie et de l’Innovation and the Institut sur la nutrition et les aliments fonctionnels at Université Laval. They had no role in the design, analysis or writing of this manuscript. Conflict of interest The authors report no conflicts of interest.