Text Generation
Safetensors
English
Khmer
customs
hs-code
classification
cambodia
gemma
unsloth
qlora
conversational
Instructions to use Sothay/gemma4-hscode-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Studio
How to use Sothay/gemma4-hscode-classifier with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Sothay/gemma4-hscode-classifier to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Sothay/gemma4-hscode-classifier to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Sothay/gemma4-hscode-classifier to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="Sothay/gemma4-hscode-classifier", max_seq_length=2048, )
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
---
|
| 3 |
license: gemma
|
| 4 |
pipeline_tag: text-generation
|
|
@@ -47,6 +46,21 @@ This repository contains **only the LoRA adapter**, not the full model.
|
|
| 47 |
Loading it will automatically download the base model (`unsloth/gemma-4-E4B-it`) and apply the adapter in 4-bit.
|
| 48 |
|
| 49 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
from unsloth import FastModel
|
| 51 |
|
| 52 |
model, tokenizer = FastModel.from_pretrained(
|
|
@@ -86,6 +100,52 @@ print(predict_hs_code("Men's cotton knitted T-shirt"))
|
|
| 86 |
|
| 87 |
---
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
## 🧠 Training details
|
| 90 |
|
| 91 |
- **Base model**: `unsloth/gemma-4-E4B-it` (4‑bit QLoRA)
|
|
@@ -154,14 +214,23 @@ Then use with Ollama (see [`Modelfile` example](https://ollama.com) – set temp
|
|
| 154 |
|
| 155 |
| Description | Predicted HS Code | Unit | CD | ST | VAT | ET |
|
| 156 |
|-------------|-------------------|------|----|----|-----|----|
|
| 157 |
-
| Toyota Hilux pickup, diesel 2.8L |
|
| 158 |
-
| iPhone 15 Pro Max 256GB |
|
| 159 |
-
| Heineken beer 330ml can |
|
| 160 |
|
| 161 |
*(Rates from lookup table – not generated by the model.)*
|
| 162 |
|
| 163 |
---
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
## 📝 License
|
| 166 |
|
| 167 |
This model is a derivative of **Gemma‑4‑E4B‑it** and is subject to the [Gemma license](https://ai.google.dev/gemma/terms).
|
|
@@ -176,5 +245,21 @@ The HS‑code dataset and lookup table are the property of their respective owne
|
|
| 176 |
|
| 177 |
---
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
**Author**: [Sothay](https://huggingface.co/Sothay)
|
| 180 |
-
**Model card version**: 1.
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: gemma
|
| 3 |
pipeline_tag: text-generation
|
|
|
|
| 46 |
Loading it will automatically download the base model (`unsloth/gemma-4-E4B-it`) and apply the adapter in 4-bit.
|
| 47 |
|
| 48 |
```python
|
| 49 |
+
|
| 50 |
+
# %% [Install]
|
| 51 |
+
%%capture
|
| 52 |
+
import os, re
|
| 53 |
+
# Install everything needed for the T4 Colab environment
|
| 54 |
+
!pip install sentencepiece protobuf "datasets==4.3.0" "huggingface_hub>=0.34.0" hf_transfer
|
| 55 |
+
!pip install --no-deps unsloth_zoo bitsandbytes accelerate xformers peft trl triton unsloth
|
| 56 |
+
!pip install --no-deps --upgrade "torchao>=0.16.0"
|
| 57 |
+
!pip install --no-deps transformers==5.5.0 "tokenizers>=0.22.0,<=0.23.0"
|
| 58 |
+
!pip install torchcodec
|
| 59 |
+
import torch
|
| 60 |
+
torch._dynamo.config.recompile_limit = 64
|
| 61 |
+
|
| 62 |
+
#------------
|
| 63 |
+
|
| 64 |
from unsloth import FastModel
|
| 65 |
|
| 66 |
model, tokenizer = FastModel.from_pretrained(
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|
| 103 |
+
## 🔍 Raw model output (debugging)
|
| 104 |
+
|
| 105 |
+
If you want to see exactly what the model generated (including the rates it predicted) without the lookup table, use the raw‑output function below.
|
| 106 |
+
**Do not** use these rates in production – they are only for debugging or confidence evaluation.
|
| 107 |
+
|
| 108 |
+
```python
|
| 109 |
+
def predict_hs_code_raw(description: str, max_new_tokens=100) -> dict:
|
| 110 |
+
system_prompt = (
|
| 111 |
+
"You are a customs compliance AI. Classify the product description to its "
|
| 112 |
+
"correct 8-digit HS code and output the corresponding trade rates (Customs Duty, "
|
| 113 |
+
"Special Tax, VAT, Excise Tax) and unit."
|
| 114 |
+
)
|
| 115 |
+
messages = [
|
| 116 |
+
{"role": "system", "content": [{"type": "text", "text": system_prompt}]},
|
| 117 |
+
{"role": "user", "content": [{"type": "text", "text": f"Description: {description}"}]},
|
| 118 |
+
]
|
| 119 |
+
inputs = tokenizer.apply_chat_template(
|
| 120 |
+
messages, add_generation_prompt=True, tokenize=True,
|
| 121 |
+
return_dict=True, return_tensors="pt",
|
| 122 |
+
).to("cuda")
|
| 123 |
+
|
| 124 |
+
out = model.generate(**inputs, max_new_tokens=max_new_tokens, use_cache=True, do_sample=False)
|
| 125 |
+
raw_text = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 126 |
+
|
| 127 |
+
def extract(pattern, text):
|
| 128 |
+
m = re.search(pattern, text)
|
| 129 |
+
return m.group(1).strip() if m else None
|
| 130 |
+
|
| 131 |
+
return {
|
| 132 |
+
"hs_code": extract(r"HS Code:\s*([0-9.]+)", raw_text),
|
| 133 |
+
"unit": extract(r"Unit:\s*(.*)", raw_text),
|
| 134 |
+
"cd_rate": extract(r"Customs Duty:\s*([\d.]+)%?", raw_text),
|
| 135 |
+
"st_rate": extract(r"Special Tax:\s*([\d.]+)%?", raw_text),
|
| 136 |
+
"vat_rate": extract(r"VAT:\s*([\d.]+)%?", raw_text),
|
| 137 |
+
"et_rate": extract(r"Excise Tax:\s*([\d.]+)%?", raw_text),
|
| 138 |
+
"raw_output": raw_text
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
# Example
|
| 142 |
+
raw = predict_hs_code_raw("Men's cotton knitted T-shirt")
|
| 143 |
+
print(raw["raw_output"])
|
| 144 |
+
print(raw["hs_code"]) # model’s guess
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
---
|
| 148 |
+
|
| 149 |
## 🧠 Training details
|
| 150 |
|
| 151 |
- **Base model**: `unsloth/gemma-4-E4B-it` (4‑bit QLoRA)
|
|
|
|
| 214 |
|
| 215 |
| Description | Predicted HS Code | Unit | CD | ST | VAT | ET |
|
| 216 |
|-------------|-------------------|------|----|----|-----|----|
|
| 217 |
+
| Toyota Hilux pickup, diesel 2.8L | 87042110 | UNIT | 35% | 50% | 10% | 0% |
|
| 218 |
+
| iPhone 15 Pro Max 256GB | 85171200 | UNIT | 0% | 0% | 10% | 0% |
|
| 219 |
+
| Heineken beer 330ml can | 22030010 | LTR | 35% | 30% | 10% | 0% |
|
| 220 |
|
| 221 |
*(Rates from lookup table – not generated by the model.)*
|
| 222 |
|
| 223 |
---
|
| 224 |
|
| 225 |
+
## ⚠️ Limitations
|
| 226 |
+
|
| 227 |
+
- The model may output incorrect HS codes for ambiguous, misspelled, or region‑specific descriptions.
|
| 228 |
+
- It was trained on a fixed set of Cambodian HS codes; revisions after the training data cutoff are not covered.
|
| 229 |
+
- Duty rates can become outdated – always cross‑check with the latest official tariff schedule.
|
| 230 |
+
- The model is a classifier, **not** a legal authority. For binding decisions, consult a customs professional.
|
| 231 |
+
|
| 232 |
+
---
|
| 233 |
+
|
| 234 |
## 📝 License
|
| 235 |
|
| 236 |
This model is a derivative of **Gemma‑4‑E4B‑it** and is subject to the [Gemma license](https://ai.google.dev/gemma/terms).
|
|
|
|
| 245 |
|
| 246 |
---
|
| 247 |
|
| 248 |
+
## 📚 Citation
|
| 249 |
+
|
| 250 |
+
If you use this model, please cite:
|
| 251 |
+
|
| 252 |
+
```bibtex
|
| 253 |
+
@misc{gemma4-hscode-classifier,
|
| 254 |
+
author = {Sothay},
|
| 255 |
+
title = {Gemma‑4 HS Code Classifier (Cambodia Customs)},
|
| 256 |
+
year = 2025,
|
| 257 |
+
publisher = {Hugging Face},
|
| 258 |
+
howpublished = {\url{https://huggingface.co/Sothay/gemma4-hscode-classifier}}
|
| 259 |
+
}
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
---
|
| 263 |
+
|
| 264 |
**Author**: [Sothay](https://huggingface.co/Sothay)
|
| 265 |
+
**Model card version**: 1.2
|