CoolFace
Modelpublic

DataScienceWFSR/modernbert-food-product-sr

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes7downloads
Model Card

ModernBERT Food Product Classification Model - Synonym Replacement Augmentation

Model Details

Model Description

This model is finetuned on multi-class food product text classification using synonym replacement augmentation and ModernBERT.

Model Sources

How to Get Started With the Model

Use the code below to get started with the model in PyTorch.

python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from huggingface_hub import hf_hub_download
import pandas as pd

model, category, augmentation = 'modernbert', 'product', 'sr'

repo_id = f"DataScienceWFSR/{model}-food-{category}-{augmentation}"
lb_path = hf_hub_download(repo_id=repo_id, filename=f"labelencoder_{category}.pkl")
lb =  pd.read_pickle(lb_path)
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
model.eval()

sample = ('Case Number: 039-94 Date Opened: 10/20/1994 Date Closed: 03/06/1995 Recall Class: 1'
        ' Press Release (Y/N): N Domestic Est. Number: 07188 M Name: PREPARED FOODS Imported '
        'Product (Y/N): N Foreign Estab. Number: N/A City: SANTA TERESA State: NM Country: USA'
        ' Product: HAM, SLICED Problem: BACTERIA Description: LISTERIA '
        'Total Pounds Recalled: 3,920 Pounds Recovered: 3,920')

inputs = tokenizer(sample, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)
predictions = outputs.logits.argmax(dim=-1)
predicted_label = lb.inverse_transform(predictions.numpy())[0]
print(f"The predicted label is: {predicted_label}")

Training Details

Training Data

Training and Validation data provided by SemEval-2025 Task 9 organizers : Food Recall Incidents dataset (only English) link

Training Procedure

Training Hyperparameters
  • batch_size: 8
  • epochs: 5
  • lr_scheduler: cosine with Restarts

Evaluation

<!-- This section describes the evaluation protocols and provides the results. -->

Testing Data & Metrics

Testing Data

Test data: 997 samples (link)

Metrics

F<sub>1</sub>-macro

Results

F<sub>1</sub>-macro scores for each model in the official test set utilizing the text field per category and subtasks scores (ST1 and ST2) rounded to 3 decimals. With bold, we indicated the model's specific results.

Modelhazard-categoryproduct-categoryhazardproductST1ST2
BERT<sub>base</sub>0.7470.7570.5810.1700.7530.382
BERT<sub>CW</sub>0.7600.7610.6710.2800.7620.491
BERT<sub>SR</sub>0.7700.7540.6660.2750.7640.478
BERT<sub>RW</sub>0.7520.7570.6510.2750.7560.467
DistilBERT<sub>base</sub>0.7610.7570.5930.1540.7600.378
DistilBERT<sub>CW</sub>0.7660.7530.6350.2460.7630.449
DistilBERT<sub>SR</sub>0.7560.7590.6440.2400.7630.448
DistilBERT<sub>RW</sub>0.7490.7470.6470.2610.7530.462
RoBERTa<sub>base</sub>0.7600.7530.5790.1230.7550.356
RoBERTa<sub>CW</sub>0.7730.7390.6300.0000.7600.315
RoBERTa<sub>SR</sub>0.7770.7550.6370.0000.7670.319
RoBERTa<sub>RW</sub>0.7570.6110.6150.0000.6860.308
ModernBERT<sub>base</sub>0.7810.7450.6670.2750.7690.485
ModernBERT<sub>CW</sub>0.7610.7120.6090.2520.7410.441
ModernBERT<sub>SR</sub>0.7900.7280.5910.2530.7610.434
ModernBERT<sub>RW</sub>0.7610.7510.6290.2370.7590.440

Technical Specifications

Compute Infrastructure

Hardware

NVIDIA A100 80GB and NVIDIA GeForce RTX 3070 Ti

Software
LibraryVersionURL
Transformers4.49.0https://huggingface.co/docs/transformers/index
PyTorch2.6.0https://pytorch.org/
SpaCy3.8.4https://spacy.io/
Scikit-learn1.6.0https://scikit-learn.org/stable/
Pandas2.2.3https://pandas.pydata.org/
Optuna4.2.1https://optuna.org/
NumPy2.0.2https://numpy.org/
NLP AUG1.1.11https://nlpaug.readthedocs.io/en/latest/index.html
BeautifulSoup44.12.3https://www.crummy.com/software/BeautifulSoup/bs4/doc/#

Citation

BibTeX:

For the original paper:

@inproceedings{brightcookies-semeval2025-task9, 
    title="BrightCookies at {S}em{E}val-2025 Task 9: Exploring Data Augmentation for Food Hazard Classification}, 
    author="Papadopoulou, Foteini and Mutlu, Osman  and Özen, Neris and van der Velden, Bas H. M. and Hendrickx, Iris  and Hürriyetoğlu, Ali",
    booktitle = "Proceedings of the 19th International Workshop on Semantic Evaluation (SemEval-2025)",
    month = jul, 
    year = "2025", 
    address = "Vienna, Austria", 
    publisher = "Association for Computational Linguistics", 
} 

For the SemEval2025 Task9:

@inproceedings{semeval2025-task9, 
    title = "{S}em{E}val-2025 Task 9: The Food Hazard Detection Challenge", 
    author = "Randl, Korbinian and Pavlopoulos, John and Henriksson, Aron and Lindgren, Tony and Bakagianni, Juli", 
    booktitle = "Proceedings of the 19th International Workshop on Semantic Evaluation (SemEval-2025)",
    month = jul, 
    year = "2025", 
    address = "Vienna, Austria", 
    publisher = "Association for Computational Linguistics", 
} 

Model Card Authors and Contact

Authors: Foteini Papadopoulou, Osman Mutlu, Neris Özen, Bas H.M. van der Velden, Iris Hendrickx, Ali Hürriyetoğlu

Contact: ali.hurriyetoglu@wur.nl