File size: 7,077 Bytes
24a076d
76b13c4
1c68f1c
8a0adac
a95cdff
 
 
 
1c68f1c
8a0adac
 
 
1c68f1c
8a0adac
 
 
24a076d
 
8a0adac
24a076d
8a0adac
24a076d
8a0adac
24a076d
8a0adac
24a076d
8a0adac
 
 
 
 
76b13c4
8a0adac
6af6684
08344d8
24a076d
8a0adac
24a076d
8a0adac
24a076d
8a0adac
 
 
 
 
 
 
 
24a076d
8a0adac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a076d
a95cdff
8a0adac
1c68f1c
 
 
8a0adac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a95cdff
 
8a0adac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76b13c4
8a0adac
 
76b13c4
8a0adac
 
 
 
 
 
 
 
 
 
24a076d
8a0adac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---
license: mit
base_model: meta-llama/Llama-3.2-3B-Instruct
model_name: NovelCrafter-LoRA
tags:
- text-generation
- lora
- peft
- creative-writing
- fine-tuned
- academic
- research
library_name: peft
pipeline_tag: text-generation
language:
- en
---

# NovelCrafter-LoRA: A Fine-Tuned Language Model for Creative Writing

## Model Description

**NovelCrafter-LoRA** is a Low-Rank Adaptation (LoRA) fine-tuned model designed to assist with creative and literary text generation. This adapter is trained on top of Meta's Llama 3.2 Instruct model family and is optimized for generating coherent, stylistically rich narrative text.

### Model Summary

| Property | Value |
|----------|-------|
| **Model Type** | LoRA Adapter (PEFT) |
| **Base Model** | `meta-llama/Llama-3.2-3B-Instruct` (GPU) / `meta-llama/Llama-3.2-1B-Instruct` (CPU) |
| **Language** | English |
| **License** | MIT License |
| **Fine-tuning Method** | LoRA (Low-Rank Adaptation) |
| **Training Steps** | 19 |
| **Last Updated** | 2026-01-20 |

## Technical Specifications

### LoRA Configuration

| Parameter | Value |
|-----------|-------|
| **Rank (r)** | 8 |
| **Alpha** | 32 |
| **Dropout** | 0.05 |
| **Target Modules** | `q_proj`, `v_proj` |
| **Bias** | None |
| **Task Type** | Causal Language Modeling |

### Training Configuration

| Parameter | Value |
|-----------|-------|
| **Batch Size** | 1 (per device) |
| **Gradient Accumulation Steps** | 8 |
| **Learning Rate** | 5e-5 |
| **Warmup Steps** | 100 |
| **Optimizer** | AdamW (torch) |
| **Epochs per Training Unit** | 3 |

## How to Use

### Installation

First, install the required dependencies:

```bash
pip install transformers peft torch accelerate
```

### Loading the Model

#### Option 1: Using PEFT (Recommended)

```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

# Choose base model based on your hardware
# GPU (recommended): meta-llama/Llama-3.2-3B-Instruct
# CPU: meta-llama/Llama-3.2-1B-Instruct
BASE_MODEL = "meta-llama/Llama-3.2-3B-Instruct"
ADAPTER_REPO = "a-01a/novelCrafter"

# Load base model
model = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL,
    torch_dtype=torch.float16,  # Use float32 for CPU
    device_map="auto",
)

# Load LoRA adapter
model = PeftModel.from_pretrained(model, ADAPTER_REPO)

# Load tokenizer from adapter repo (includes custom chat template)
tokenizer = AutoTokenizer.from_pretrained(ADAPTER_REPO)

print("Model loaded successfully!")
```

#### Option 2: Merging Adapter into Base Model

```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

BASE_MODEL = "meta-llama/Llama-3.2-3B-Instruct"
ADAPTER_REPO = "a-01a/novelCrafter"

# Load and merge
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float16)
model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
model = model.merge_and_unload()  # Merge LoRA weights into base model

tokenizer = AutoTokenizer.from_pretrained(ADAPTER_REPO)
```

### Generating Text

```python
def generate_text(prompt, max_new_tokens=512):
    '''Generate text using the fine-tuned model.'''
    messages = [
        {
            "role": "system",
            "content": "You are a skilled creative writing assistant. Write engaging, "
                       "descriptive prose with attention to character development and narrative flow."
        },
        {
            "role": "user",
            "content": prompt
        }
    ]
    
    # Apply chat template
    formatted_prompt = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True
    )
    
    # Tokenize
    inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
    
    # Generate
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=max_new_tokens,
            temperature=0.7,
            top_p=0.9,
            do_sample=True,
            pad_token_id=tokenizer.eos_token_id,
        )
    
    # Decode and return
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response.split("assistant")[-1].strip()

# Example usage
result = generate_text(
    "Write an opening paragraph for a mystery novel set in Victorian London."
)
print(result)
```

### Using with Transformers Pipeline

```python
from transformers import pipeline

generator = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device_map="auto",
)

output = generator(
    "Once upon a time in a distant kingdom,",
    max_new_tokens=200,
    temperature=0.7,
)[0]["generated_text"]

print(output)
```

## Intended Use

### Primary Use Cases

- **Creative Writing Assistance**: Generating narrative prose, story continuations, and creative text
- **Academic Research**: Studying fine-tuning techniques for creative text generation
- **Educational Purposes**: Learning about LoRA adapters and PEFT methods

### Out-of-Scope Uses

This model is **NOT** intended for:

- Commercial applications without proper licensing
- Generating misleading or deceptive content
- Any application that violates ethical guidelines
- Production systems without human oversight

## Limitations and Biases

- The model may generate repetitive or incoherent text for very long outputs
- Quality depends heavily on the prompt structure and specificity
- May exhibit biases present in the base model and training data
- Not optimized for factual accuracy or real-world knowledge tasks
- Performance varies based on the base model variant used

## Ethical Considerations

⚠️ **ACADEMIC AND RESEARCH USE ONLY**

This model is released strictly for academic research and educational purposes. By using this model, you agree to:

1. **Non-Commercial Use**: This model may not be used for commercial purposes without explicit written permission.

2. **Responsible Use**: Users must ensure generated content does not cause harm, spread misinformation, or violate any laws.

3. **Attribution**: Any academic publications or research using this model should provide appropriate citation.

4. **No Malicious Use**: The model must not be used to generate harmful, abusive, or illegal content.

5. **Human Oversight**: All generated content should be reviewed by humans before any public distribution.

6. **Compliance**: Users must comply with the base model's (Meta Llama) license terms and acceptable use policy.

## Citation

If you use this model in your research, please cite:

```bibtex
@misc{NovelCrafter-lora-2025,
  title={NovelCrafter-LoRA: A Fine-Tuned Language Model for Creative Writing},
  author={a-01a},
  year={2025},
  publisher={Hugging Face},
  url={https://huggingface.co/a-01a/novelCrafter}
}
```

## Contact

For questions, issues, or collaboration inquiries, please open an issue on the Hugging Face repository.

---

**Disclaimer**: This model is provided "as-is" without warranty of any kind. The authors are not responsible for any misuse or harm caused by the use of this model.