1from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
2from peft import PeftModel
3
4base_id = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
5adpt_id = "salakash/SamKash-Tolstoy" # replace with your repo path
6
7tok = AutoTokenizer.from_pretrained(base_id, use_fast=True)
8
9# CPU (float32) or Apple M-series (MPS, float16)
10import torch
11device = "mps" if torch.backends.mps.is_available() else "cpu"
12dtype = torch.float16 if device == "mps" else torch.float32
13
14base = AutoModelForCausalLM.from_pretrained(base_id, dtype=dtype)
15base.to(device)
16
17model = PeftModel.from_pretrained(base, adpt_id)
18model.config.use_cache = True # inference = OK to re-enable KV cache
19
20gen = pipeline("text-generation", model=model, tokenizer=tok, device=-1)
21out = gen(
22 "Write a reflective paragraph about conscience and fate in an aristocratic household.",
23 max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9
24)[0]["generated_text"]
25print(out)
26
27
28
29
30## Model Details
31
32### Model Description
33
34- **Developed by:** Samiya Kashif & Kashif Salahuddin
35- **Funded by:** Self-funded (individual project)
36- **Shared by:** Samiya Kashif & Kashif Salahuddin
37- **Model type:** LoRA (PEFT) adapter for a decoder-only causal language model (Qwen-family, 1.5B params base)
38- **Language(s) (NLP):** English
39- **License:** Apache 2.0
40- **Finetuned from model:** deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
41
42### Model Sources [optional]
43
44<!-- Provide the basic links for the model. -->
45
46- **Repository:** salakash/SamKash-Tolstoy
47- **Paper :https://medium.com/@kashsala/building-samkash-tolstoy-a-tiny-lora-llm-that-lives-and-breathes-russian-literature-ca959747af4a
48- **Demo:**
49
50## Attribution & Basics
51
52- **Funded by:** Self-funded (individual project)
53- **Shared by:** Samiya Kashif & Kashif Salahuddin (SamKash)
54- **Model type:** LoRA (PEFT) adapter for a decoder-only causal language model (Qwen-family base, 1.5B params)
55- **Language(s) (NLP):** English (`en`) — trained on English texts/metadata tagged as *Russian Literature* from Project Gutenberg
56- **License:** `other` for the adapters (base model license applies separately)
57- **Finetuned from model:** `deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B`
58
59---
60
61## Uses
62
63### Direct Use
64- Stylized long-form **generation** in the voice and conventions of 19th-century **Russian literature**.
65- Brainstorming themes, motifs, and character interiority.
66- Style-transfer scaffolding (draft → “make it sound like 19th-century Russian prose”).
67
68### Downstream Use
69- As a component in a creative-writing assistant or editor plugin.
70- Further **instruction tuning (SFT)** for tasks like summarization, theme extraction, or literature Q&A.
71- Educational demos of domain-adaptive pretraining (DAPT) using LoRA/PEFT.
72
73### Out-of-Scope Use
74- Factual or safety-critical tasks (medical, legal, financial advice).
75- Producing or implying authorship of genuine Tolstoy text.
76- Modern colloquial dialogue or code generation (not optimized for these).
77
78---
79
80## Bias, Risks, and Limitations
81
82- **Stylistic bias:** Strong tilt toward 19th-century Russian prose (long sentences, moral reflection).
83- **Content bias:** Public-domain texts may reflect **outdated social views**.
84- **Hallucination:** As a generative model, it can invent details; don’t use for factual claims.
85- **Language scope:** Focused on English; performance on other languages is not guaranteed.
86
87### Recommendations
88- Keep a **human in the loop** for editing and intent verification.
89- Avoid representing outputs as genuine text by historical authors.
90- For classroom settings, clearly label generated content as synthetic.
91
92---
93
94## How to Get Started with the Model
95
96```python
97import torch
98from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
99from peft import PeftModel
100
101base_id = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
102adpt_id = "salakash/SamKash-Tolstoy" # or local folder
103
104device = "mps" if torch.backends.mps.is_available() else "cpu"
105dtype = torch.float16 if device == "mps" else torch.float32
106
107tok = AutoTokenizer.from_pretrained(base_id, use_fast=True)
108base = AutoModelForCausalLM.from_pretrained(base_id, dtype=dtype)
109base.to(device)
110
111model = PeftModel.from_pretrained(base, adpt_id)
112model.config.use_cache = True # inference
113
114gen = pipeline("text-generation", model=model, tokenizer=tok, device=-1)
115print(gen(
116 "Write a reflective paragraph about conscience and fate in an aristocratic household.",
117 max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9
118)[0]["generated_text"])