Sothay commited on
Commit
077b045
·
verified ·
1 Parent(s): d9f2d17

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -9
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
- - google/gemma-4-12B-it
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: 6105.10.00
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": "You are a customs compliance AI..."}]},
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**: 2 epochs, effective batch size 8, learning rate 2e‑4, linear schedule, eval & save every epoch, best model loaded
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 LoRA adapter:
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.0
 
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