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 Desktop
Update README.md
Browse files123456 unmodified lines12131415161718199 unmodified lines293031323334358 unmodified lines4445464748495051525354553 unmodified lines596061626364656619 unmodified lines8687888990919224 unmodified lines1171181191201211221231241251263 unmodified lines13013113213313413513630 unmodified lines167168169170---license: gemmalanguage:- en- km6 unmodified lines- unsloth- qlorabase_model:- google/gemma-4-12B-itpipeline_tag: text-classification---# Gemma‑4 HS Code Classifier (Cambodia Customs)9 unmodified linesGiven a plain‑English product description, the model generates:```textHS Code: 6105.10.00Unit: PIECECustoms Duty: 25%Special Tax: 0%8 unmodified lines## 🚀 Quick start (in Colab or locally)```pythonfrom unsloth import FastModelmodel, tokenizer = FastModel.from_pretrained("Sothay/gemma4-hscode-classifier",load_in_4bit=True,)# ---------- Inference with the authoritative lookup table (recommended) ----------3 unmodified linesrate_lookup = json.load(f)def predict_hs_code(description: str) -> dict:messages = [{"role": "system", "content": [{"type": "text", "text": "You are a customs compliance AI..."}]},{"role": "user", "content": [{"type": "text", "text": f"Description: {description}"}]},]inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")19 unmodified lines- **Dataset**: Custom Cambodian HS‑code dataset (`hs_code.csv`) with descriptions, codes, and official rates- Cleaned, deduplicated, split into 90/10 train/validation- Chat roles fixed to system/user/assistant (Gemma‑4 standard)- **Training config**: 2 epochs, effective batch size 8, learning rate 2e‑4, linear schedule, eval & save every epoch, best model loaded- **Hardware**: Google Colab T4 (16 GB) – peak memory ~10 GB thanks to QLoRA- **Accuracy**: Evaluated on held‑out examples (exact HS‑code match) – see model card for current numbers24 unmodified lines| File | Description ||------|-------------|| `adapter_model.safetensors` | LoRA adapter weights (few MB) || `tokenizer.json`, `tokenizer_config.json` | Tokenizer files || `hs_code_lookup.json` | Authoritative rate table for production inference || `README.md` | This file |> If you need a **merged, full‑precision model** (for vLLM, TGI, etc.), generate it locally with Unsloth:> ```python> model.save_pretrained_merged("merged_fp16", tokenizer, save_method="merged_16bit")3 unmodified lines## 🦙 Ollama / llama.cpp (GGUF)Export a quantized GGUF directly from the LoRA adapter:```pythonmodel.save_pretrained_gguf("gguf_model", tokenizer, quantization_method="q4_k_m")30 unmodified lines---**Author**: [Sothay](https://huggingface.co/Sothay)**Model card version**: 1.01234566 unmodified lines131415161718199 unmodified lines293031323334358 unmodified lines444546474849505152535455565758593 unmodified lines6364656667686970717273747519 unmodified lines959697989910010124 unmodified lines1261271281291301311321331341351361373 unmodified lines14114214314414514614730 unmodified lines178179180181---license: gemmapipeline_tag: text-generationlanguage:- en- km6 unmodified lines- unsloth- qlorabase_model:- unsloth/gemma-4-E4B-it---# Gemma‑4 HS Code Classifier (Cambodia Customs)9 unmodified linesGiven a plain‑English product description, the model generates:```textHS Code: 61091000Unit: PIECECustoms Duty: 25%Special Tax: 0%8 unmodified lines## 🚀 Quick start (in Colab or locally)This repository contains **only the LoRA adapter**, not the full model.Loading it will automatically download the base model (`unsloth/gemma-4-E4B-it`) and apply the adapter in 4-bit.```pythonfrom unsloth import FastModelmodel, tokenizer = FastModel.from_pretrained("Sothay/gemma4-hscode-classifier", # LoRA adapter on Hugging Faceload_in_4bit = True, # required – the adapter was trained in 4-bitmax_seq_length = 1024,)# ---------- Inference with the authoritative lookup table (recommended) ----------3 unmodified linesrate_lookup = json.load(f)def predict_hs_code(description: str) -> dict:system_prompt = ("You are a customs compliance AI. Classify the product description to its ""correct 8-digit HS code and output the corresponding trade rates (Customs Duty, ""Special Tax, VAT, Excise Tax) and unit.")messages = [{"role": "system", "content": [{"type": "text", "text": system_prompt}]},{"role": "user", "content": [{"type": "text", "text": f"Description: {description}"}]},]inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")19 unmodified lines- **Dataset**: Custom Cambodian HS‑code dataset (`hs_code.csv`) with descriptions, codes, and official rates- Cleaned, deduplicated, split into 90/10 train/validation- Chat roles fixed to system/user/assistant (Gemma‑4 standard)- **Training config**: 3 epochs, effective batch size 8, learning rate 2e‑4, linear schedule, eval & save every epoch, best model loaded- **Hardware**: Google Colab T4 (16 GB) – peak memory ~10 GB thanks to QLoRA- **Accuracy**: Evaluated on held‑out examples (exact HS‑code match) – see model card for current numbers24 unmodified lines| File | Description ||------|-------------|| `adapter_model.safetensors` | LoRA adapter weights (few MB) || `adapter_config.json` | Adapter configuration (references base model) || `tokenizer.json`, `tokenizer_config.json` | Tokenizer files || `hs_code_lookup.json` | Authoritative rate table for production inference || `README.md` | This file |> **Note**: Only the adapter is stored here – the full Gemma‑4 base model is automatically fetched from Unsloth when you call `FastModel.from_pretrained`.> If you need a **merged, full‑precision model** (for vLLM, TGI, etc.), generate it locally with Unsloth:> ```python> model.save_pretrained_merged("merged_fp16", tokenizer, save_method="merged_16bit")3 unmodified lines## 🦙 Ollama / llama.cpp (GGUF)Export a quantized GGUF directly from the loaded adapter:```pythonmodel.save_pretrained_gguf("gguf_model", tokenizer, quantization_method="q4_k_m")30 unmodified lines---**Author**: [Sothay](https://huggingface.co/Sothay)**Model card version**: 1.1
README.md+20-9