File size: 2,620 Bytes
cd899da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9789041
 
29e33ac
 
9789041
 
29e33ac
9789041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd899da
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
pipeline_tag: text-classification
language:
  - de
  - en
tags:
  - food-classification
  - openfoodfacts
  - product-categorization
  - class-mapping
---

# FoodCLS

**FoodCLS** is to map product category tags from [OpenFoodFacts](https://world.openfoodfacts.org/) to a set of predefined, user-friendly food categories.

The model uses the `categories_tags` attribute from the OpenFoodFacts product database to classify products into **12 broader food categories**.

This allows for simplified product categorization, easier data aggregation, and more intuitive overviews of food products.

### Dataset

The model is based on the [OpenFoodFacts Product Database](https://huggingface.co/datasets/openfoodfacts/product-database), using the state from **November 9, 2026**.

## Target Classes

The model predicts one of 12 predefined categories. Each category is assigned a numeric class ID.

| Class ID | German Category | English Equivalent |
|:---:|---|---|
| 0 | Obst & Gemüse | Fruits & Vegetables |
| 1 | Fleisch, Fisch & Alternativen | Meat, Fish & Alternatives |
| 2 | Milchprodukte & Eier | Dairy Products & Eggs |
| 3 | Brot & Backwaren | Bread & Bakery Products |
| 4 | Nudeln, Reis & Getreide | Pasta, Rice & Grains |
| 5 | Fertigprodukte | Ready-Made Meals & Convenience Foods |
| 6 | Backzutaten | Baking Ingredients |
| 7 | Getränke | Beverages |
| 8 | Snacks & Süßigkeiten | Snacks & Sweets |
| 9 | Öle, Gewürze & Saucen | Oils, Spices & Sauces |
| 10 | Brotaufstriche | Spreads |
| 11 | Sonstiges | Other |

## Usage
### 1. Grab files  
First, download the `food_classifier.py` and `requirements.txt`.  
If you want to use only local files (and not rely on internet connection in ordedr to load weights), ensure to download all files and explicitly setting the `local_file_only` parameter when calling the `from_pretrained()`method!
<br>

### 2. Install prerequisites
Next, install the libraries required for running the model:
```
pip install -r requirements.txt
```

### 3. Enjoy usage
For example, like this:  
```python
from food_classifier import FoodClassifier


classifier = FoodClassifier.from_pretrained("emiloetting/FoodCLS")

category = classifier.predict(
  {"categories_tags": ["en:milks", "en:dairies"]},
  string_classes=True)
print(category)
```
When setting `string_classes`, the ouput will not be the integer class encoding but the respective string stored in the model's attribute `self.class_mapping` (a dictionary containing the integer-string mapping)

## About
This model was made for use in a student project, aiming at providing an intuitive overview over food products.