Hebrew Grocery Item Classifier v2
Fine-tuned intfloat/multilingual-e5-small
for classifying Hebrew grocery shopping list items into 12 supermarket categories.
finetune code at https://github.com/davidit17/shopping_list_bot
What's new in v2
- Larger dataset โ 1886 total items (1508 train / 378 test), up from ~600 in v1
- 4 training sources โ manual lists, Excel grocery data, Gemini-labelled web data, and a ChatGPT-labelled set
- Synthetic augmentation โ rule-based Hebrew item generator to balance under-represented categories
- Weak-class booster โ extra hand-curated examples for ืืฉืงืืืช, ืงืคืืืื ืืกืืืื, and ืจืืืื ืืืืจืืื
- Per-class F1 tracking โ evaluation now reports per-category F1 to surface weak spots
Categories
ืืืฆืจื ืืื ืืืืฆืื
ืืจืงืืช ืืคืืจืืช
ืืื ืืืคืื ืืืื ืื
ืืืืคืื ืืืชืืงืื
ื ืืงืืื ืืืคืื ืืื ืคืขืื
ืืฉืงืืืช
ืืืฆืจืื ืืืคืืื
ืืฉืจ ืืืืื
ืงืคืืืื ืืกืืืื
ืืืฉืื
ืจืืืื ืืืืจืืื
ืืืจ
Usage
from transformers import pipeline
classifier = pipeline(
"text-classification",
model=f"davidit17/e5-grocery-finetuned-v2",
)
items = ["ืืืื ื ืฆืืืื", "ืขืืื ืืืช ืฉืจื", "ืฉืืคื", "ืงืืงื ืงืืื", "ืืื ืขืืฃ"]
for item in items:
result = classifier(item)[0]
print(item, "โ", result["label"], f"({result['score']:.2f})")
With confidence threshold (recommended)
CONFIDENCE_THRESHOLD = 0.5
def predict(text: str) -> str:
result = classifier(text)[0]
return result["label"] if result["score"] >= CONFIDENCE_THRESHOLD else "ืืืจ"
Training
Data sources
Evaluation
Overall
Per-class F1 (fine-tuned v2)
Limitations
- Primarily covers Israeli supermarket conventions and Hebrew product naming.
- Brand-specific or very niche items may fall back to
ืืืจ.
- Low-confidence predictions (score < 0.5) should be treated as
ืืืจ.
- Synthetic training examples may not fully reflect natural shopping list variation.
- The
ืืืจ category is a catch-all and may have lower precision than domain-specific categories.
๐ ONNX Support
This repository now includes optimized ONNX versions of the model for efficient inference.
๐ CPU Performance Comparison
The repository includes the original PyTorch model as well as optimized ONNX versions for faster CPU inference.
๐ Improvements over the PyTorch model
ONNX (FP32)
- โก 2.02ร lower inference latency (19.83 ms โ 9.80 ms)
- ๐ 2.02ร higher throughput (50.4 โ 102.1 samples/sec)
- โ
No loss in accuracy or F1 score
ONNX (INT8)
- โก 2.96ร lower inference latency (19.83 ms โ 6.70 ms)
- ๐ 2.96ร higher throughput (50.4 โ 149.2 samples/sec)
- ๐ Accuracy: โ4.76 percentage points
- ๐ Weighted F1: โ5.73 percentage points
Recommendation
- PyTorch (
safetensors) โ Best for further fine-tuning and GPU inference.
- ONNX FP32 โ Recommended for CPU deployment when maintaining the original model quality is important.
- ONNX INT8 โ Best for latency-critical CPU applications where a small reduction in predictive performance is acceptable in exchange for nearly 3ร faster inference.
Loading the ONNX model
from optimum.onnxruntime import ORTModelForFeatureExtraction
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"davidit17/e5-grocery-finetuned-v2"
)
model = ORTModelForFeatureExtraction.from_pretrained(
"davidit17/e5-grocery-finetuned-v2",
subfolder="onnx",
)
model = ORTModelForFeatureExtraction.from_pretrained(
"davidit17/e5-grocery-finetuned-v2",
subfolder="onnx-int8",
)