saraNour commited on
Commit
bb489f8
Β·
verified Β·
1 Parent(s): 10c654c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +211 -0
README.md ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Phase 3 β€” Product Domain + Taxonomy + Product Grouping
2
+
3
+ ## Compliments Reference DB Pipeline
4
+
5
+ **Version:** 1.0.0
6
+ **Date:** 2026-07-30
7
+ **Status:** PASS
8
+
9
+ ---
10
+
11
+ ## Input
12
+
13
+ | Property | Value |
14
+ |----------|-------|
15
+ | Source | `phase2/outputs/phase2_output.parquet` |
16
+ | HF Repo | `saraNour/compliments-reference-phase2` |
17
+ | Row Count | 4,440 |
18
+ | Column Count | 32 |
19
+
20
+ ---
21
+
22
+ ## What Phase 3 Does
23
+
24
+ ### A. Food / Non-Food Classification
25
+
26
+ Deterministic keyword-based rules. Creates `product_domain` column with values: `food`, `non_food`, `unknown`.
27
+
28
+ - **Food:** Dairy, meat, seafood, bakery, beverages, frozen, produce, pantry, snacks, confectionery
29
+ - **Non-food:** Pet food, medications, personal care, household cleaning, kitchenware, health remedies
30
+ - **Unknown:** Products that don't match any rule
31
+
32
+ ### B. Taxonomy Classification
33
+
34
+ Deterministic keyword-based taxonomy. Classification metadata only β€” NOT used as grouping key.
35
+
36
+ 19 categories: DAIRY, MEAT_SEAFOOD, BEVERAGES, BAKERY, FROZEN, BREAKFAST, PASTA_RICE, CANNED_GOODS, CONDIMENTS_SAUCES, SNACKS, CONFECTIONERY, PRODUCE, PERSONAL_CARE, HOUSEHOLD_CLEANING, HEALTH_REMEDIES, PET_FOOD, HOUSEHOLD_SUPPLIES, BABY_CARE, GENERAL_GROCERY
37
+
38
+ ### C. Product Grouping
39
+
40
+ Identity-based deterministic grouping:
41
+
42
+ ```
43
+ group_key = identity_hash + product_domain + normalized_core_title
44
+ ```
45
+
46
+ - `identity_hash`: 14-field hash from Phase 2 (9 flags + fat + product_line + flavour + formulation)
47
+ - `product_domain`: food/non_food/unknown β€” **structurally prevents food/non-food mixing**
48
+ - `normalized_core_title`: Core title with generic packaging words removed, tokens sorted
49
+
50
+ ### D. Ambiguous Case Detection
51
+
52
+ Groups with >1 product are inspected for:
53
+ - Multiple core_titles
54
+ - Multiple flavours
55
+ - Multiple formulations
56
+ - Multiple fat levels
57
+ - Multiple product lines
58
+
59
+ ### E. Rule-Based Resolution
60
+
61
+ All grouping is deterministic. No LLM was required.
62
+
63
+ ---
64
+
65
+ ## Output Files
66
+
67
+ ### A. reference_product_catalog.csv (Group-Level)
68
+
69
+ | Column | Type | Description |
70
+ |--------|------|-------------|
71
+ | group_id | str | Deterministic UUID |
72
+ | group_name | str | Most frequent core_title |
73
+ | brand | str | Normalized brand |
74
+ | product_domain | str | food/non_food/unknown |
75
+ | taxonomy | str | Taxonomy category |
76
+ | identity_hash | str | 14-field identity hash |
77
+ | product_count | int | Products in group |
78
+ | unique_upcs | int | Unique UPCs in group |
79
+
80
+ ### B. product_group_mapping.csv (Product-Level)
81
+
82
+ | Column | Type | Description |
83
+ |--------|------|-------------|
84
+ | upc | str | Barcode |
85
+ | external_id | str | Voila ID |
86
+ | group_id | str | Group UUID |
87
+ | group_name | str | Core title |
88
+ | core_title | str | Core title |
89
+ | original_title | str | Raw title |
90
+ | brand | str | Normalized brand |
91
+ | size | str | Raw size |
92
+ | variant_attributes | str | Parsed size JSON |
93
+ | identity_hash | str | Identity hash |
94
+ | product_domain | str | Food/non-food |
95
+ | taxonomy | str | Taxonomy |
96
+ | product_line | str | Product line |
97
+ | source | str | Data source |
98
+ | source_url | str | Source URL |
99
+
100
+ ### C. ambiguous_cases.csv
101
+
102
+ Groups with potential ambiguity and the reason.
103
+
104
+ ---
105
+
106
+ ## Deterministic Grouping Rules
107
+
108
+ | # | Rule | Implementation |
109
+ |---|------|----------------|
110
+ | 1 | Identity hash captures 14 fields | `build_identity_hash()` in Phase 2 |
111
+ | 2 | Product domain is part of grouping key | `build_group_key()` in Phase 3 |
112
+ | 3 | Core title normalized (generic words removed, sorted) | `normalize_title_for_grouping()` |
113
+ | 4 | Same normalized title + same identity = same group | Group key construction |
114
+ | 5 | Different identity = different group | Identity hash is first component |
115
+ | 6 | Food vs non_food = always different group | Product domain is second component |
116
+
117
+ ---
118
+
119
+ ## Food/Non-Food Rules
120
+
121
+ 100+ deterministic regex rules based on product title keywords.
122
+
123
+ - Pet food β†’ non_food
124
+ - Medications (ibuprofen, acetaminophen, etc.) β†’ non_food
125
+ - Personal care (tampons, shampoo, etc.) β†’ non_food
126
+ - Household (detergent, garbage bags, etc.) β†’ non_food
127
+ - Kitchenware (light bulbs, pans, etc.) β†’ non_food
128
+ - Everything else matching food keywords β†’ food
129
+ - No match β†’ unknown
130
+
131
+ ---
132
+
133
+ ## Regression Tests β€” ALL PASS
134
+
135
+ | Test | Result |
136
+ |------|--------|
137
+ | PB smooth sizes same group | PASS |
138
+ | PB crunchy sizes same group | PASS |
139
+ | PB organic smooth different | PASS |
140
+ | PB naturally simple different | PASS |
141
+ | PB light different | PASS |
142
+ | PB honey different | PASS |
143
+ | PB cookies different | PASS |
144
+ | PB ice cream different | PASS |
145
+ | PB dog treats different | PASS |
146
+ | CC 1% vs 2% different | PASS |
147
+ | CC 1% vs fat-free different | PASS |
148
+ | Food vs non-food split | PASS |
149
+
150
+ ---
151
+
152
+ ## Validation Results
153
+
154
+ | Check | Result |
155
+ |-------|--------|
156
+ | Row count preserved | PASS |
157
+ | No duplicate mappings | PASS |
158
+ | No food/non-food mixing | PASS |
159
+ | No brand conflicts | PASS |
160
+ | Identity consistent | PASS |
161
+ | Taxonomy populated | PASS |
162
+ | No empty group names | PASS |
163
+ | **Overall** | **PASS** |
164
+
165
+ ---
166
+
167
+ ## Files
168
+
169
+ ```
170
+ phase3/
171
+ README.md
172
+ src/phase3.py
173
+ notebooks/phase3.ipynb
174
+ outputs/
175
+ reference_product_catalog.csv
176
+ product_group_mapping.csv
177
+ ambiguous_cases.csv
178
+ phase3_executed.ipynb
179
+ validation/
180
+ phase3_validation.json
181
+ statistics/
182
+ phase3_statistics.json
183
+ ```
184
+
185
+ ---
186
+
187
+ ## How to Run
188
+
189
+ ```bash
190
+ cd phase3/
191
+ python3 src/phase3.py
192
+ ```
193
+
194
+ ---
195
+
196
+ ## LLM Usage
197
+
198
+ None. All grouping is deterministic.
199
+
200
+ ---
201
+
202
+ ## Handoff
203
+
204
+ Phase 3 outputs are the frozen product-grouping layer.
205
+
206
+ Future phases will add:
207
+ - Phase 4: Variant assignment
208
+ - Phase 5: Nutrition merge
209
+ - Phase 6: Nutrition scoring (NutriScore, NOVA, EcoScore)
210
+ - GPC integration
211
+ - Agribalyse integration