Views
No views yet
bert-base-uncased engineered specifically for fine-grained binary classification of food ingredients, composition text, and menu item descriptions into Halal (Class 0) or Haram (Class 1) categories.pork, gelatin, lard, bacon, alcohol, wine, shortening, cochineal) were isolated and dynamically injected with contextual negation prefixes including non-X, X free, zero X, no X, and without X—synthesizing 206,500 unique, hard-negative Halal references.query and value attention projection modules. By tuning a rank matrix of $r=8$ and a scaling factor of $\alpha=16$, the total active footprint was restricted to just 296,450 parameters (0.27% of the total network) while freezing the underlying 110M parameter foundational architecture.| Epoch | Training Loss | Validation Loss | Accuracy | F1 Macro | Precision Macro | Recall Macro |
|---|---|---|---|---|---|---|
| 1 | 0.1635 | 0.1421 | 0.9391 | 0.9235 | 0.9040 | 0.9509 |
| 2 | 0.1079 | 0.0941 | 0.9507 | 0.9378 | 0.9184 | 0.9644 |
| 3 | 0.0926 | 0.0887 | 0.9543 | 0.9421 | 0.9237 | 0.9666 |
| 4 | 0.0830 | 0.0848 | 0.9562 | 0.9442 | 0.9268 | 0.9669 |
| 5 | 0.0782 | 0.0820 | 0.9584 | 0.9468 | 0.9308 | 0.9670 |
| METRIC TYPE | BASE UN-TUNED BERT BASELINE | FINE-TUNED LORA ADAPTER |
|---|---|---|
| Test Accuracy | 0.2496 | 0.9581 |
| Test F1-Macro | 0.1998 | 0.9464 |
| Test Precision-Macro | 0.1248 | 0.9302 |
| Test Recall-Macro | 0.5000 | 0.9670 |
1 precision recall f1-score support
2Halal (Class 0) 0.00 0.00 0.00 3821
3Haram (Class 1) 0.24 1.00 0.38 11791 precision recall f1-score support
2Halal (Class 0) 0.99 0.95 0.97 3821
3Haram (Class 1) 0.85 0.98 0.91 1179white wine as Haram while tracking white wine vinegar accurately as Halal).1import torch
2from transformers import BertTokenizer, BertForSequenceClassification
3from peft import PeftModel
4
5base_model_name = 'bert-base-uncased'
6peft_model_id = 'Umair1710/Bert-Lora-Finedtuned-Hala_Haram_Detection'
7
8tokenizer = BertTokenizer.from_pretrained(base_model_name)
9base_model = BertForSequenceClassification.from_pretrained(base_model_name, num_labels=2)
10model = PeftModel.from_pretrained(base_model, peft_model_id)
11
12inputs = tokenizer('gourmet sauce with white wine vinegar', return_tensors='pt')
13with torch.no_grad():
14 logits = model(**inputs).logits
15 pred_class = torch.argmax(logits, dim=-1).item()
16print('Prediction:', 'HALAL' if pred_class == 0 else 'HARAM')1@misc{umair2026berthelalharam,
2 author = {Umair},
3 title = {BERT-LoRA Fine-Tuned Halal/Haram Detection System},
4 year = {2026},
5 publisher = {Hugging Face},
6 howpublished = {\url{[https://huggingface.co/Umair1710/Bert-Lora-Finedtuned-Hala_Haram_Detection](https://huggingface.co/Umair1710/Bert-Lora-Finedtuned-Hala_Haram_Detection)}},
7 note = {Final Year Project (FYP) Core Implementation Engine}
8}