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,5 +1,6 @@
|
|
| 1 |
---
|
| 2 |
license: gemma
|
|
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
- km
|
|
@@ -12,8 +13,7 @@ tags:
|
|
| 12 |
- unsloth
|
| 13 |
- qlora
|
| 14 |
base_model:
|
| 15 |
-
-
|
| 16 |
-
pipeline_tag: text-classification
|
| 17 |
---
|
| 18 |
|
| 19 |
# Gemma‑4 HS Code Classifier (Cambodia Customs)
|
|
@@ -29,7 +29,7 @@ Built with **[Unsloth](https://github.com/unslothai/unsloth)** for fast, memory
|
|
| 29 |
Given a plain‑English product description, the model generates:
|
| 30 |
|
| 31 |
```text
|
| 32 |
-
HS Code:
|
| 33 |
Unit: PIECE
|
| 34 |
Customs Duty: 25%
|
| 35 |
Special Tax: 0%
|
|
@@ -44,12 +44,16 @@ For production, always use the included **lookup table** (`hs_code_lookup.json`)
|
|
| 44 |
|
| 45 |
## 🚀 Quick start (in Colab or locally)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
```python
|
| 48 |
from unsloth import FastModel
|
| 49 |
|
| 50 |
model, tokenizer = FastModel.from_pretrained(
|
| 51 |
-
"Sothay/gemma4-hscode-classifier",
|
| 52 |
-
load_in_4bit=True,
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
# ---------- Inference with the authoritative lookup table (recommended) ----------
|
|
@@ -59,8 +63,13 @@ with open("hs_code_lookup.json") as f:
|
|
| 59 |
rate_lookup = json.load(f)
|
| 60 |
|
| 61 |
def predict_hs_code(description: str) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
messages = [
|
| 63 |
-
{"role": "system", "content": [{"type": "text", "text":
|
| 64 |
{"role": "user", "content": [{"type": "text", "text": f"Description: {description}"}]},
|
| 65 |
]
|
| 66 |
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
|
@@ -86,7 +95,7 @@ print(predict_hs_code("Men's cotton knitted T-shirt"))
|
|
| 86 |
- **Dataset**: Custom Cambodian HS‑code dataset (`hs_code.csv`) with descriptions, codes, and official rates
|
| 87 |
- Cleaned, deduplicated, split into 90/10 train/validation
|
| 88 |
- Chat roles fixed to system/user/assistant (Gemma‑4 standard)
|
| 89 |
-
- **Training config**:
|
| 90 |
- **Hardware**: Google Colab T4 (16 GB) – peak memory ~10 GB thanks to QLoRA
|
| 91 |
- **Accuracy**: Evaluated on held‑out examples (exact HS‑code match) – see model card for current numbers
|
| 92 |
|
|
@@ -117,10 +126,12 @@ hf_hub_download("Sothay/gemma4-hscode-classifier", "hs_code_lookup.json")
|
|
| 117 |
| File | Description |
|
| 118 |
|------|-------------|
|
| 119 |
| `adapter_model.safetensors` | LoRA adapter weights (few MB) |
|
|
|
|
| 120 |
| `tokenizer.json`, `tokenizer_config.json` | Tokenizer files |
|
| 121 |
| `hs_code_lookup.json` | Authoritative rate table for production inference |
|
| 122 |
| `README.md` | This file |
|
| 123 |
|
|
|
|
| 124 |
> If you need a **merged, full‑precision model** (for vLLM, TGI, etc.), generate it locally with Unsloth:
|
| 125 |
> ```python
|
| 126 |
> model.save_pretrained_merged("merged_fp16", tokenizer, save_method="merged_16bit")
|
|
@@ -130,7 +141,7 @@ hf_hub_download("Sothay/gemma4-hscode-classifier", "hs_code_lookup.json")
|
|
| 130 |
|
| 131 |
## 🦙 Ollama / llama.cpp (GGUF)
|
| 132 |
|
| 133 |
-
Export a quantized GGUF directly from the
|
| 134 |
|
| 135 |
```python
|
| 136 |
model.save_pretrained_gguf("gguf_model", tokenizer, quantization_method="q4_k_m")
|
|
@@ -167,4 +178,4 @@ The HS‑code dataset and lookup table are the property of their respective owne
|
|
| 167 |
---
|
| 168 |
|
| 169 |
**Author**: [Sothay](https://huggingface.co/Sothay)
|
| 170 |
-
**Model card version**: 1.
|
|
|
|
| 1 |
---
|
| 2 |
license: gemma
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
language:
|
| 5 |
- en
|
| 6 |
- km
|
|
|
|
| 13 |
- unsloth
|
| 14 |
- qlora
|
| 15 |
base_model:
|
| 16 |
+
- unsloth/gemma-4-E4B-it
|
|
|
|
| 17 |
---
|
| 18 |
|
| 19 |
# Gemma‑4 HS Code Classifier (Cambodia Customs)
|
|
|
|
| 29 |
Given a plain‑English product description, the model generates:
|
| 30 |
|
| 31 |
```text
|
| 32 |
+
HS Code: 61091000
|
| 33 |
Unit: PIECE
|
| 34 |
Customs Duty: 25%
|
| 35 |
Special Tax: 0%
|
|
|
|
| 44 |
|
| 45 |
## 🚀 Quick start (in Colab or locally)
|
| 46 |
|
| 47 |
+
This repository contains **only the LoRA adapter**, not the full model.
|
| 48 |
+
Loading it will automatically download the base model (`unsloth/gemma-4-E4B-it`) and apply the adapter in 4-bit.
|
| 49 |
+
|
| 50 |
```python
|
| 51 |
from unsloth import FastModel
|
| 52 |
|
| 53 |
model, tokenizer = FastModel.from_pretrained(
|
| 54 |
+
"Sothay/gemma4-hscode-classifier", # LoRA adapter on Hugging Face
|
| 55 |
+
load_in_4bit = True, # required – the adapter was trained in 4-bit
|
| 56 |
+
max_seq_length = 1024,
|
| 57 |
)
|
| 58 |
|
| 59 |
# ---------- Inference with the authoritative lookup table (recommended) ----------
|
|
|
|
| 63 |
rate_lookup = json.load(f)
|
| 64 |
|
| 65 |
def predict_hs_code(description: str) -> dict:
|
| 66 |
+
system_prompt = (
|
| 67 |
+
"You are a customs compliance AI. Classify the product description to its "
|
| 68 |
+
"correct 8-digit HS code and output the corresponding trade rates (Customs Duty, "
|
| 69 |
+
"Special Tax, VAT, Excise Tax) and unit."
|
| 70 |
+
)
|
| 71 |
messages = [
|
| 72 |
+
{"role": "system", "content": [{"type": "text", "text": system_prompt}]},
|
| 73 |
{"role": "user", "content": [{"type": "text", "text": f"Description: {description}"}]},
|
| 74 |
]
|
| 75 |
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
|
|
|
| 95 |
- **Dataset**: Custom Cambodian HS‑code dataset (`hs_code.csv`) with descriptions, codes, and official rates
|
| 96 |
- Cleaned, deduplicated, split into 90/10 train/validation
|
| 97 |
- Chat roles fixed to system/user/assistant (Gemma‑4 standard)
|
| 98 |
+
- **Training config**: 3 epochs, effective batch size 8, learning rate 2e‑4, linear schedule, eval & save every epoch, best model loaded
|
| 99 |
- **Hardware**: Google Colab T4 (16 GB) – peak memory ~10 GB thanks to QLoRA
|
| 100 |
- **Accuracy**: Evaluated on held‑out examples (exact HS‑code match) – see model card for current numbers
|
| 101 |
|
|
|
|
| 126 |
| File | Description |
|
| 127 |
|------|-------------|
|
| 128 |
| `adapter_model.safetensors` | LoRA adapter weights (few MB) |
|
| 129 |
+
| `adapter_config.json` | Adapter configuration (references base model) |
|
| 130 |
| `tokenizer.json`, `tokenizer_config.json` | Tokenizer files |
|
| 131 |
| `hs_code_lookup.json` | Authoritative rate table for production inference |
|
| 132 |
| `README.md` | This file |
|
| 133 |
|
| 134 |
+
> **Note**: Only the adapter is stored here – the full Gemma‑4 base model is automatically fetched from Unsloth when you call `FastModel.from_pretrained`.
|
| 135 |
> If you need a **merged, full‑precision model** (for vLLM, TGI, etc.), generate it locally with Unsloth:
|
| 136 |
> ```python
|
| 137 |
> model.save_pretrained_merged("merged_fp16", tokenizer, save_method="merged_16bit")
|
|
|
|
| 141 |
|
| 142 |
## 🦙 Ollama / llama.cpp (GGUF)
|
| 143 |
|
| 144 |
+
Export a quantized GGUF directly from the loaded adapter:
|
| 145 |
|
| 146 |
```python
|
| 147 |
model.save_pretrained_gguf("gguf_model", tokenizer, quantization_method="q4_k_m")
|
|
|
|
| 178 |
---
|
| 179 |
|
| 180 |
**Author**: [Sothay](https://huggingface.co/Sothay)
|
| 181 |
+
**Model card version**: 1.1
|