raphael0202 commited on
Commit
dc9ca5b
·
1 Parent(s): db2d64e

Add description

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md CHANGED
@@ -1,3 +1,81 @@
1
  ---
2
  license: cc-by-sa-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-4.0
3
+ language:
4
+ - en
5
+ - fr
6
+ - de
7
+ - it
8
+ - nl
9
+ - ru
10
+ - he
11
+ task_categories:
12
+ - token-classification
13
+ pretty_name: Ingredient List Detection
14
+ size_categories:
15
+ - 1K<n<10K
16
  ---
17
+
18
+ This dataset is used to train a multilingual ingredient list detection model. The goal is to automate the extraction of ingredient lists from food packaging images. See [this issue](https://github.com/openfoodfacts/openfoodfacts-ai/issues/242) for a broader context about ingredient list extraction.
19
+
20
+ ## Dataset generation
21
+
22
+ Raw unannotated texts are OCR results obtained with Google Cloud Vision. It only contains images marked as ingredient image on Open Food Facts.
23
+ The dataset was generated using ChatGPT-3.5: we asked ChatGPT to extract ingredient using the following prompt:
24
+
25
+ Prompt:
26
+ ```
27
+ Extract ingredient lists from the following texts. The ingredient list should start with the first ingredient and end with the last ingredient. It should not include allergy, label or origin information.
28
+ The output format must be a single JSON list containing one element per ingredient list. If there are ingredients in several languages, the output JSON list should contain as many elements as detected languages. Each element should have two fields:
29
+ - a "text" field containing the detected ingredient list. The text should be a substring of the original text, you must not alter the original text.
30
+ - a "lang" field containing the detected language of the ingredient list.
31
+ Don't output anything else than the expected JSON list.
32
+ ```
33
+
34
+ System prompt:
35
+ ```
36
+ You are ChatGPT, a large language model trained by OpenAI. Only generate responses in JSON format. The output JSON must be minified.
37
+ ```
38
+
39
+ A first cleaning step was performed automatically, we removed responses with:
40
+ - invalid JSON
41
+ - JSON with missing fields
42
+ - JSON where the detected ingredient list is not a substring of the original text
43
+
44
+ A first NER model was trained on this dataset. The model prediction errors on this dataset were inspected, which allowed us to spot the different kind of annotation errors made by ChatGPT. Then, using a semi-automatic approach, we manually corrected samples that were likely to have the error spotted during the inspection phase. For example, we noticed that the prefix "Ingredients:" was sometimes included in the ingredient text span. We looked for every sample where "Ingredients" (and translations in other languages) was part of the ingredient text, and corrected these samples manually. This approach allowed us to focus on problematic samples, instead of having to check the full train set.
45
+
46
+ These detection rules were mostly implemented using regex. The cleaning script with all rules [can be found here](https://github.com/openfoodfacts/openfoodfacts-ai/blob/149447bdbcd19cb7c15127405d9112bc9bfe3685/ingredient_extraction/clean_dataset.py#L23).
47
+
48
+ Once the detected errors were fixed using this approach, a new dataset alpha version was released, and we trained the model on this new dataset.
49
+ Dataset was split between train (90%) and test (10%) sets. Train and test splits were kept consistent at each alpha release. Only the test dataset was fully reviewed and corrected manually.
50
+
51
+ We tokenized the text using huggingface pre-tokenizer with the `[WhitespaceSplit(), Punctuation()]` sequence. The dataset generation script [can be found here](https://github.com/openfoodfacts/openfoodfacts-ai/blob/149447bdbcd19cb7c15127405d9112bc9bfe3685/ingredient_extraction/generate_dataset.py).
52
+
53
+ This dataset is exactly the same as `ingredient-detection-alpha-v6` used during model trainings.
54
+
55
+ ## Annotation guidelines
56
+
57
+ Annotations guidelines were updated continuously during dataset refinement and model trainings, but here are the final guidelines:
58
+
59
+ 1. ingredient lists in all languages must be annotated.
60
+ 2. ingredients list should start with the first ingredient, without `ingredient` prefix ("Ingredients:", "Zutaten", "Ingrédients: ") or `language` prefix ("EN:", "FR - ",...)
61
+ 3. ingredient list containing single ingredients without any `ingredient` or `language` prefix should not be annotated. Otherwise, it's very difficult to know whether the mention is the ingredient list or just a random mention of an ingredient on the packaging.
62
+ 4. We have a very restrictive approach on where the ingredient list ends: we don't include any extra information (allergen, origin, trace, organic mentions) at the end of the ingredient list. The only exception is when this information is in bracket after the ingredient. This rule is in place to make it easier for the detector to know what is an ingredient list and what is not. Additional information can be added afterward as a post-processing step.
63
+
64
+ ## Dataset schema
65
+
66
+ The dataset is made of 2 JSONL files:
67
+
68
+ - `ingredient_detection_dataset-v1_train.jsonl.gz`: train split, 5065 samples
69
+ - `ingredient_detection_dataset-v1_test.jsonl.gz`: test split, 556 samples
70
+
71
+ Each sample has the following fields:
72
+
73
+ - `text`: the original text obtained from OCR result
74
+ - `marked_text`: the text with ingredient spans delimited by `<b>` and `</b>`
75
+ - `tokens`: tokens obtained with pre-tokenization
76
+ - `ner_tags`: tag ID associated with each token: 0 for `O`, 1 for `B-ING` and 2 for `I-ING` (BIO schema)
77
+ - `offsets`: a list containing character start and end offsets of ingredients spans
78
+ - `meta`: a dict containing additional meta-data about the sample:
79
+ - `barcode`: the product barcode of the image that was used
80
+ - `image_id`: unique digit identifier of the image for the product
81
+ - `url`: image URL from which the text was extracted