初始化项目,由ModelHub XC社区提供模型

Model: kartikey31/txn-parser
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-08-09 01:23:21 +08:00
commit f70fa31854
39 changed files with 298378 additions and 0 deletions

152
gemma-3-270m/README.md Normal file
View File

@@ -0,0 +1,152 @@
---
license: apache-2.0
base_model: unsloth/gemma-3-270m-it
tags:
- text-generation
- lora
- qlora
- gguf
- transaction-parser
language:
- en
- hi
library_name: peft
---
# txn-parser / gemma-3-270m
QLoRA fine-tune of [`unsloth/gemma-3-270m-it`](https://huggingface.co/unsloth/gemma-3-270m-it) for
extracting structured transaction data (amount, currency, item, category,
type) from free-form Indian-English / code-switched speech and text.
This model lives in subfolder **`gemma-3-270m/`** of the
[`kartikey31/txn-parser`](https://huggingface.co/kartikey31/txn-parser) repo, alongside
sibling fine-tunes of other base models trained on the same data.
## What's in here
- `gemma-3-270m/adapters/` — PEFT LoRA adapter (rank 32). Load on top of the base model
with `peft.PeftModel.from_pretrained(base, "kartikey31/txn-parser", subfolder="gemma-3-270m/adapters")`.
- `gemma-3-270m/gguf/` — merged GGUF builds at multiple quantization levels
(file names follow `txn-parser-gemma-3-270m-<QUANT>.gguf`):
- [`gemma-3-270m/gguf/txn-parser-gemma-3-270m-F16.gguf`](https://huggingface.co/kartikey31/txn-parser/resolve/main/gemma-3-270m/gguf/txn-parser-gemma-3-270m-F16.gguf) (542.8 MB)
- [`gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q4_K_M.gguf`](https://huggingface.co/kartikey31/txn-parser/resolve/main/gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q4_K_M.gguf) (253.1 MB)
- [`gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q5_K_M.gguf`](https://huggingface.co/kartikey31/txn-parser/resolve/main/gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q5_K_M.gguf) (260.0 MB)
- [`gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q6_K.gguf`](https://huggingface.co/kartikey31/txn-parser/resolve/main/gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q6_K.gguf) (283.0 MB)
- [`gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q8_0.gguf`](https://huggingface.co/kartikey31/txn-parser/resolve/main/gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q8_0.gguf) (291.5 MB)
## Training data
- 93,348 teacher-labeled examples (`data/distill/train.jsonl`)
- 300 held-out eval examples (`data/distill/eval.jsonl`)
- Validator-gated: every row's `output` passes the project's grammar +
amount-parser semantic validator.
## Training config
| Knob | Value |
|---|---|
| Base model | `unsloth/gemma-3-270m-it` |
| Method | QLoRA (4-bit) via Unsloth |
| LoRA rank | 32 (alpha 64, dropout 0.0) |
| Epochs | 2 |
| Batch size (train) | 64 |
| Grad accumulation | 1 |
| Eval batch size | 4 |
| Max seq length | 1024 |
| Learning rate | 2e-4 (warmup 3%) |
| Started | |
| Finished | |
## System prompt (use this EXACTLY)
The model was trained with one specific system prompt and Gemma/Smol/Qwen
chat template. If you paraphrase the prompt or skip the chat template,
quality degrades quickly. Copy-paste this verbatim into your inference
client (no leading/trailing whitespace, no edits):
```text
You convert voice-transcribed transaction descriptions into structured JSON.
Output ONLY a JSON object with this schema, no other text:
{"transactions":[{"amount":<number>,"currency":"INR"|"USD","item":"<lowercase singular noun phrase>","category":"<enum>","type":"expense"|"income"}]}
Categories: Food, Drinks, Groceries, Transport, Shopping, Entertainment, Bills, Health, Education, Personal, Gifts, Income, Other.
Rules:
- Currency defaults to INR. Use USD only when the input explicitly says "dollars" or contains "$".
- Amounts: "k" = ×1000, "hazaar" = ×1000, "sau" = ×100, "lakh" = ×100000. Convert number-words ("five hundred") to digits.
- type is "expense" by default; "income" only for explicit salary, cashback, refund, gift received, payment received.
- For disfluencies and corrections ("500 wait no 600"), output the CORRECTED amount only.
- For ambiguous items ("that thing", "stuff"), use item "unspecified" and category "Other".
- Item field: lowercase singular noun phrase ("uber ride", "beer", "chai" — not "Beers" or "Uber").
- Multi-transaction inputs become multiple array entries in spoken order.
- Category heuristics: uber/ola/auto/petrol/bus/metro → Transport; beer/wine/chai/coffee/juice → Drinks; rent/electricity/wifi/recharge/gas → Bills; movie/netflix/concert → Entertainment; doctor/medicine/hospital → Health.
```
Source of truth: [`scripts/_lib.py`](https://github.com/kartikeychoudhary/txn-parser/blob/main/scripts/_lib.py)
constant `SYSTEM_PROMPT`. Don't retype it — pull from `_lib.py` or this README.
## Download a single GGUF
```bash
huggingface-cli download kartikey31/txn-parser \
gemma-3-270m/gguf/txn-parser-gemma-3-270m-Q4_K_M.gguf \
--local-dir .
```
## Inference (Python, llama-cpp-python)
```python
from llama_cpp import Llama
SYSTEM_PROMPT = '''You convert voice-transcribed transaction descriptions into structured JSON.
Output ONLY a JSON object with this schema, no other text:
{"transactions":[{"amount":<number>,"currency":"INR"|"USD","item":"<lowercase singular noun phrase>","category":"<enum>","type":"expense"|"income"}]}
Categories: Food, Drinks, Groceries, Transport, Shopping, Entertainment, Bills, Health, Education, Personal, Gifts, Income, Other.
Rules:
- Currency defaults to INR. Use USD only when the input explicitly says "dollars" or contains "$".
- Amounts: "k" = ×1000, "hazaar" = ×1000, "sau" = ×100, "lakh" = ×100000. Convert number-words ("five hundred") to digits.
- type is "expense" by default; "income" only for explicit salary, cashback, refund, gift received, payment received.
- For disfluencies and corrections ("500 wait no 600"), output the CORRECTED amount only.
- For ambiguous items ("that thing", "stuff"), use item "unspecified" and category "Other".
- Item field: lowercase singular noun phrase ("uber ride", "beer", "chai" — not "Beers" or "Uber").
- Multi-transaction inputs become multiple array entries in spoken order.
- Category heuristics: uber/ola/auto/petrol/bus/metro → Transport; beer/wine/chai/coffee/juice → Drinks; rent/electricity/wifi/recharge/gas → Bills; movie/netflix/concert → Entertainment; doctor/medicine/hospital → Health.'''
llm = Llama(
model_path="txn-parser-gemma-3-270m-Q4_K_M.gguf",
n_gpu_layers=-1, n_ctx=2048,
)
out = llm.create_chat_completion(
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "200 ka samosa"},
],
temperature=0.0,
)
print(out["choices"][0]["message"]["content"])
```
## Inference (CLI, llama.cpp)
```bash
./llama-cli -m txn-parser-gemma-3-270m-Q4_K_M.gguf \
--grammar-file scripts/grammar.gbnf \
--system-prompt "$(cat system_prompt.txt)" \
-p "200 ka samosa" -n 256
```
## Reproduce
```bash
git clone https://github.com/kartikeychoudhary/txn-parser.git
cd txn-parser && bash setup.sh
python scripts/train_and_publish.py --only gemma-3-270m
```
---
*Auto-published by `scripts/train_and_publish.py` on 2026-05-22T21:33:31.274220+00:00.*

View File

@@ -0,0 +1,210 @@
---
base_model: unsloth/gemma-3-270m-it-unsloth-bnb-4bit
library_name: peft
pipeline_tag: text-generation
tags:
- base_model:adapter:unsloth/gemma-3-270m-it-unsloth-bnb-4bit
- lora
- sft
- transformers
- trl
- unsloth
---
# Model Card for Model ID
<!-- Provide a quick summary of what the model is/does. -->
## Model Details
### Model Description
<!-- Provide a longer summary of what this model is. -->
- **Developed by:** [More Information Needed]
- **Funded by [optional]:** [More Information Needed]
- **Shared by [optional]:** [More Information Needed]
- **Model type:** [More Information Needed]
- **Language(s) (NLP):** [More Information Needed]
- **License:** [More Information Needed]
- **Finetuned from model [optional]:** [More Information Needed]
### Model Sources [optional]
<!-- Provide the basic links for the model. -->
- **Repository:** [More Information Needed]
- **Paper [optional]:** [More Information Needed]
- **Demo [optional]:** [More Information Needed]
## Uses
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
### Direct Use
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
[More Information Needed]
### Downstream Use [optional]
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
[More Information Needed]
### Out-of-Scope Use
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
[More Information Needed]
## Bias, Risks, and Limitations
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
[More Information Needed]
### Recommendations
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
## How to Get Started with the Model
Use the code below to get started with the model.
[More Information Needed]
## Training Details
### Training Data
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
[More Information Needed]
### Training Procedure
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
#### Preprocessing [optional]
[More Information Needed]
#### Training Hyperparameters
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
#### Speeds, Sizes, Times [optional]
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
[More Information Needed]
## Evaluation
<!-- This section describes the evaluation protocols and provides the results. -->
### Testing Data, Factors & Metrics
#### Testing Data
<!-- This should link to a Dataset Card if possible. -->
[More Information Needed]
#### Factors
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
[More Information Needed]
#### Metrics
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
[More Information Needed]
### Results
[More Information Needed]
#### Summary
## Model Examination [optional]
<!-- Relevant interpretability work for the model goes here -->
[More Information Needed]
## Environmental Impact
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
- **Hardware Type:** [More Information Needed]
- **Hours used:** [More Information Needed]
- **Cloud Provider:** [More Information Needed]
- **Compute Region:** [More Information Needed]
- **Carbon Emitted:** [More Information Needed]
## Technical Specifications [optional]
### Model Architecture and Objective
[More Information Needed]
### Compute Infrastructure
[More Information Needed]
#### Hardware
[More Information Needed]
#### Software
[More Information Needed]
## Citation [optional]
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
**BibTeX:**
[More Information Needed]
**APA:**
[More Information Needed]
## Glossary [optional]
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
[More Information Needed]
## More Information [optional]
[More Information Needed]
## Model Card Authors [optional]
[More Information Needed]
## Model Card Contact
[More Information Needed]
### Framework versions
- PEFT 0.19.1

View File

@@ -0,0 +1,52 @@
{
"alora_invocation_tokens": null,
"alpha_pattern": {},
"arrow_config": null,
"auto_mapping": {
"base_model_class": "Gemma3ForCausalLM",
"parent_library": "transformers.models.gemma3.modeling_gemma3",
"unsloth_fixed": true
},
"base_model_name_or_path": "unsloth/gemma-3-270m-it-unsloth-bnb-4bit",
"bias": "none",
"corda_config": null,
"ensure_weight_tying": false,
"eva_config": null,
"exclude_modules": null,
"fan_in_fan_out": false,
"inference_mode": true,
"init_lora_weights": true,
"layer_replication": null,
"layers_pattern": null,
"layers_to_transform": null,
"loftq_config": {},
"lora_alpha": 64,
"lora_bias": false,
"lora_dropout": 0.0,
"lora_ga_config": null,
"megatron_config": null,
"megatron_core": "megatron.core",
"modules_to_save": null,
"peft_type": "LORA",
"peft_version": "0.19.1",
"qalora_group_size": 16,
"r": 32,
"rank_pattern": {},
"revision": null,
"target_modules": [
"v_proj",
"down_proj",
"gate_proj",
"k_proj",
"o_proj",
"q_proj",
"up_proj"
],
"target_parameters": null,
"task_type": "CAUSAL_LM",
"trainable_token_indices": null,
"use_bdlora": null,
"use_dora": false,
"use_qalora": false,
"use_rslora": false
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:45b973b84902da8d42103cebe35f1fd7ccd477e0ac8b65edd5cc01e86962f015
size 30409120

View File

@@ -0,0 +1,50 @@
{# Unsloth Chat template fixes #}
{{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
{%- if messages[0]['content'] is string -%}
{%- set first_user_prefix = messages[0]['content'] + '
' -%}
{%- else -%}
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
' -%}
{%- endif -%}
{%- set loop_messages = messages[1:] -%}
{%- else -%}
{%- set first_user_prefix = "" -%}
{%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_messages -%}
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif -%}
{%- if (message['role'] == 'assistant') -%}
{%- set role = "model" -%}
{%- else -%}
{%- set role = message['role'] -%}
{%- endif -%}
{{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
{%- if message['content'] is string -%}
{{ message['content'] | trim }}
{%- elif message['content'] is iterable -%}
{%- for item in message['content'] -%}
{%- if item['type'] == 'image' -%}
{{ '<start_of_image>' }}
{%- elif item['type'] == 'text' -%}
{{ item['text'] | trim }}
{%- endif -%}
{%- endfor -%}
{%- elif message['content'] is defined -%}
{{ raise_exception("Invalid content type") }}
{%- endif -%}
{{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model
'}}
{%- endif -%}
{# Copyright 2025-present Unsloth. Apache 2.0 License. #}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:daab2354f8a74e70d70b4d1f804939b68a8c9624dd06cb7858e52dd8970e9726
size 33384567

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
size 4689074

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:68d695f4376c7e60e1ebbffd39ec241e4ba713fe0214fd0a807e1aef7d303cbb
size 542835136

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b712099c6e1a1d96c02925983b5552297686054dfd38055d126596587168f95a
size 253114816

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8f6998034ce51ce7227621930e95b0970a667e2eedb8aec04a18745ee9bbbffb
size 260026816

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44d85853e661a49e49be8177577431c98e2940951c98239b6e80b855fa3391c8
size 282974656

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:63f2d561d816946561952bacb8f076d60e622cf36995c5fd988a930475da95d7
size 291545536