pankajpandey-dev commited on
Commit
3a11eb4
·
verified ·
1 Parent(s): a02dccb

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +51 -121
README.md CHANGED
@@ -1,144 +1,74 @@
1
  ---
2
  license: apache-2.0
3
- language:
4
- - hi
5
- - en
6
- base_model: Qwen/Qwen3.5-9B
7
- pipeline_tag: text-generation
8
  library_name: transformers
9
- tags:
10
- - hindi
11
- - qwen3_5
12
- - qwen3.5
13
- - unsloth
14
- - lora
15
- - instruction-tuning
16
- - conversational
17
- - india
18
  datasets:
19
  - ai4bharat/indic-instruct-data-v0.1
20
  - CohereForAI/aya_dataset
 
 
 
 
 
21
  ---
 
22
 
23
- # 🇮🇳 Qwen3.5-9B-Hindi-Instruct
24
-
25
- **Native Hindi answers, instantly — no English "thinking detour."**
26
-
27
- Base Qwen3.5-9B knows Hindi, but ask it a simple Hindi question and it burns hundreds of tokens on an English chain-of-thought before answering — and its answers code-switch into English. This fine-tune fixes both: it responds **immediately, in pure Devanagari Hindi**, and follows instructions tightly (ask for तीन उपाय, get exactly 3).
28
-
29
- Part of the 🇮🇳 Hindi LLM Series — small models fine-tuned for Hindi, quantized for edge/CPU use, trained on rented cloud GPUs for under $10 per run.
30
-
31
- ## Before / After
32
-
33
- Same prompt: `स्वस्थ रहने के तीन उपाय बताइए।`
34
-
35
- **Base Qwen3.5-9B** (400 tokens later, still hasn't answered):
36
- ```
37
- Thinking Process:
38
- 1. **Analyze the Request:**
39
- * Language: Hindi (Devanagari script).
40
- * Task: Provide three ways to stay healthy...
41
- 2. **Identify Key Health Advice:**
42
- * Healthy eating (balanced diet)...
43
- ```
44
-
45
- **This model** (first tokens):
46
- ```
47
- स्वस्थ रहने के लिए, सही आहार का सेवन करना जरूरी है, नियमित व्यायाम
48
- करना चाहिए और पर्याप्त नींद लेनी चाहिए।
49
- ```
50
-
51
- ## Pipeline
52
-
53
- ```
54
- Qwen/Qwen3.5-9B (instruct, hybrid-thinking)
55
- |
56
- v
57
- SFT + LoRA (r=16, bf16) with Unsloth
58
- - response-only loss, masked on "<|im_start|>assistant\n"
59
- - trained WITH empty <think> blocks -> answers directly
60
- |
61
- v
62
- qwen3.5-9b-hindi-instruct (this repo, merged 16-bit)
63
- ```
64
-
65
- ## Training data — 12,912 pairs from 4 sources
66
-
67
- | Source | Pairs | Why |
68
- |---|---|---|
69
- | Anudesh (hi) | 5,000 | Native real-user Hindi prompts |
70
- | Dolly (hi, IndicTrans2-translated) | 4,000 | Task diversity; kept only chrF++ >= 55 rows |
71
- | wikiHow (hi) | 3,000 | Native long-form step-by-step answers |
72
- | Aya (Hindi) | 912 | Human-written by native speakers |
73
 
74
- Cleaning: cross-source dedup, length bounds, Latin-script ratio filter, percent-encoding repair on wikiHow (465 dropped for length, 339 duplicates, 61 excessive Latin script).
 
75
 
76
- ## Evaluation (vs base, same 25 Hindi prompts)
 
 
 
 
 
77
 
78
- | Behavior | Base Qwen3.5-9B | This model |
79
- |---|---|---|
80
- | English "thinking" before Hindi answer | Always | Never |
81
- | Code-switching in answers | Frequent | Not observed |
82
- | "तीन बताइए" -> exactly 3 items | Unreliable | Yes |
83
- | Formats (letter/essay/message) | Verbose, meta-commentary | Direct, correct format |
84
 
85
- Manual 25-prompt eval (essays, formal letters, lists, single-sentence QA, recipes) — honest and small, not a benchmark.
 
 
86
 
87
- ## Usage
88
 
 
89
  ```python
90
  from transformers import AutoModelForCausalLM, AutoTokenizer
91
-
92
- model_id = "pankajpandey-dev/qwen3.5-9b-hindi-instruct"
93
- tok = AutoTokenizer.from_pretrained(model_id)
94
- model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="bfloat16", device_map="auto")
95
-
96
- msgs = [{"role": "user", "content": "दीपावली पर एक छोटा निबंध लिखिए।"}]
97
- text = tok.apply_chat_template(msgs, add_generation_prompt=True, tokenize=False)
98
- out = model.generate(**tok(text, return_tensors="pt").to(model.device), max_new_tokens=400, temperature=0.7)
99
- print(tok.decode(out[0], skip_special_tokens=True))
100
  ```
 
101
 
102
- For CPU: use the [GGUF repo](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-GGUF) (Q4_K_M = 5.4 GB).
103
-
104
- ### ⚠️ Non-thinking is baked in
105
- The chat template always emits a closed empty <think> block — the model answers directly. This is intentional: llama.cpp defines enable_thinking=true by default, which would otherwise re-trigger the base model's English chain-of-thought. Need thinking mode? Use the base model.
106
-
107
- ## Training details
 
 
 
108
 
109
- - **Hardware:** 1x NVIDIA L40S (48 GB), Lightning.ai total ~ **$9**
110
- - **Method:** Unsloth, LoRA r=16/alpha=16, bf16, q/k/v/o + gate/up/down (29M params, 0.31%)
111
- - **Recipe:** 2 epochs, LR 1e-4 cosine, warmup 3%, effective batch 16, max_seq_len 2048
112
- - **Loss:** response-only, final train loss 0.94
113
- - Vision layers untouched (text-only fine-tune, vision untested)
114
 
115
- Two findings for other Qwen3.5 fine-tuners:
116
- 1. convert_hf_to_gguf.py fails on Unsloth-saved checkpoints with "Tokenizer class TokenizersBackend does not exist" fix: set "tokenizer_class": "PreTrainedTokenizerFast" in tokenizer_config.json.
117
- 2. Patching the template default to non-thinking is not enough for GGUF: **llama.cpp defines enable_thinking=true itself**. Hard-bake the closed think block into both branches.
118
 
119
- ## Limitations (honest)
 
120
 
121
- - Factual reliability in long-form Hindi is imperfect — a **native Hindi instruction-follower**, not an encyclopedia.
122
- - Occasional translationese from the Dolly subset.
123
- - Trained single-turn; multi-turn works but wasn't the focus.
124
- - Thinking mode intentionally disabled. Not additionally safety-tuned.
125
-
126
- ## License & data notes
127
-
128
- Weights: **Apache 2.0**. Data: Anudesh responses were Llama-2-70B-generated (Llama 2 terms), Dolly-hi is CC-BY-SA-3.0-derived, wikiHow from hi.wikihow.com, Aya Apache 2.0.
129
-
130
- ## Related
131
-
132
- [GGUF quants](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-GGUF) · [LoRA adapter](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-lora) · [🇮🇳 Hindi LLM Series](https://huggingface.co/pankajpandey-dev)
133
-
134
- ## Citation
135
 
136
- ```bibtex
137
- @misc{pandey2026qwen35hindi,
138
- title = {Qwen3.5-9B-Hindi-Instruct},
139
- author = {Pankaj Pandey},
140
- year = {2026},
141
- publisher = {Hugging Face},
142
- howpublished = {https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct}
143
- }
144
- ```
 
1
  ---
2
  license: apache-2.0
3
+ language: [hi, en]
4
+ base_model: unsloth/Qwen3.5-9B
 
 
 
5
  library_name: transformers
6
+ pipeline_tag: text-generation
 
 
 
 
 
 
 
 
7
  datasets:
8
  - ai4bharat/indic-instruct-data-v0.1
9
  - CohereForAI/aya_dataset
10
+ tags: [hindi, qwen3.5, unsloth, lora, instruct, india]
11
+ widget:
12
+ - text: "स्वस्थ रहने के तीन उपाय बताइए।"
13
+ - text: "दीपावली पर एक छोटा निबंध लिखिए।"
14
+ - text: "चाय बनाने की विधि चरणों में बताइए।"
15
  ---
16
+ # Qwen3.5-9B Hindi Instruct 🇮🇳
17
 
18
+ **Qwen3.5-9B fine-tuned to answer directly in fluent, native Hindi — no English code-switching, no English "thinking" detours.** Runs on a laptop CPU via the [GGUF version](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-GGUF) (~5.7 GB).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ ## Why this exists
21
+ Base Qwen3.5-9B knows Hindi, but ask it a Hindi question and it burns hundreds of tokens *thinking in English* inside its think block before answering — and its answers code-switch. This fine-tune closes the think block immediately and replies in pure Devanagari, following instructions tightly.
22
 
23
+ ## Examples (from the release eval)
24
+ > **प्रश्न:** ऑनलाइन ठगी से बचने के तीन उपाय बताइए।
25
+ >
26
+ > **उत्तर:** आपके पास केवल एक कार्ड वाला खाता होना चाहिए (कभी भी अपने पूरे खाते को न दें)।
27
+ ऐसे फिशिंग ईमेल (जिनमें आपसे पैसा माँगा जाए) पर ध्यान न दें।
28
+ सभी ऑनलाइन लेनदेन की जांच करें।
29
 
30
+ > **प्रश्न:** 'ईमानदारी सबसे अच्छी नीति है' पर तीन वाक्य लिखिए।
31
+ >
32
+ > **उत्तर:** सच्चाई हमेशा सफलता लाती है। सत्य हमेशा सच्चाई से बढ़कर होता है। ईमानदारी सबसे अच्छी नीति है और ईमानदार��� हमेशा हमारे साथ रहती है।
 
 
 
33
 
34
+ > **प्रश्न:** मोबाइल फोन के दो लाभ और दो हानियाँ बताइए।
35
+ >
36
+ > **उत्तर:** संचार की सुविधा और जानकारी तक पहुंच, पर्यावरण पर प्रभाव, समय बर्बाद करना, अधिकारियों की जिम्मेदारी, संपर्क में आए व्यक्ति का समय बर्बाद करना, सामाजिक रूप से निर्लक्षी बनना
37
 
 
38
 
39
+ ## Quickstart
40
  ```python
41
  from transformers import AutoModelForCausalLM, AutoTokenizer
42
+ m = AutoModelForCausalLM.from_pretrained("pankajpandey-dev/qwen3.5-9b-hindi-instruct", torch_dtype="bfloat16", device_map="auto")
43
+ t = AutoTokenizer.from_pretrained("pankajpandey-dev/qwen3.5-9b-hindi-instruct")
44
+ msgs = [{"role": "user", "content": "जल संरक्षण के पाँच तरीके बताइए।"}]
45
+ text = t.apply_chat_template(msgs, add_generation_prompt=True, tokenize=False)
46
+ out = m.generate(**t(text=text, return_tensors="pt").to(m.device),
47
+ max_new_tokens=400, repetition_penalty=1.1)
48
+ print(t.decode(out[0], skip_special_tokens=True))
 
 
49
  ```
50
+ Use `repetition_penalty=1.1` (set in this repo's generation_config) — long letter/essay outputs can loop without it. The chat template opens a think block; this model closes it immediately — strip `<think>...</think>` from output if present.
51
 
52
+ ## Training recipe (fully reproducible)
53
+ | | |
54
+ |---|---|
55
+ | Base | unsloth/Qwen3.5-9B (bf16) |
56
+ | Method | LoRA r=16, alpha=16, response-only loss (Unsloth) |
57
+ | Data | 12,912 Hindi pairs — anudesh 5,000 · dolly-hi 4,000 (chrF++ >= 55) · wikiHow-hi 3,000 · Aya-hi 912 |
58
+ | Schedule | 2 epochs, LR 1e-4 cosine, effective batch 16, seq 2048 |
59
+ | Hardware | 1x NVIDIA L40S (48 GB), ~135 min |
60
+ | Final train loss | 0.938 |
61
 
62
+ Data deduplicated across sources, filtered for length and Latin-script ratio. wikiHow adds long-form step-by-step answers; Aya adds human-written originals.
 
 
 
 
63
 
64
+ ## Limitations
65
+ Parts of the data are machine-translated (dolly) or model-generated (anudesh via Llama-2-70B), so occasional unnatural phrasing or factual errors occur. Long formal-letter outputs may repeat without repetition_penalty=1.1. No additional safety tuning. Knowledge cutoff follows base Qwen3.5.
 
66
 
67
+ ## Licensing
68
+ Weights: Apache 2.0. Data licenses apply to data, not weights: dolly-hi CC-BY-SA 3.0-derived; anudesh generated by Llama-2-70B (Llama 2 license); Aya Apache 2.0.
69
 
70
+ ---
71
+ ## 🇮🇳 About the Hindi LLM Series
72
+ Weekly open releases making small LLMs speak fluent, native Hindi — trained on free/low-cost GPUs, shipped as GGUF for laptops and edge devices. Built by [pankajpandey-dev](https://huggingface.co/pankajpandey-dev) *(contact links on profile)*.
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ **This release:** [Model](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct) · [GGUF](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-GGUF) · [LoRA](https://huggingface.co/pankajpandey-dev/qwen3.5-9b-hindi-instruct-lora) · **Series:** [🇮🇳 Hindi LLM Collection](https://huggingface.co/pankajpandey-dev)