Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3from textwrap import dedent
4
5model_id = "VibrantVista/Dickens_Charles"
6author_name = "Dickens, Charles"
7book_title = "A Tale of Two Cities"
8plot = "The weather was very rainy and cold." # Replace with your own plot
9
10tokenizer = AutoTokenizer.from_pretrained(model_id)
11model = AutoModelForCausalLM.from_pretrained(
12 model_id,
13 torch_dtype=torch.bfloat16,
14 device_map="auto"
15)
16
17# Strict Prompt Format used in Training
18prompt = dedent(f"""\
19# Style Target
20Author: {author_name}
21Title: {book_title}
22
23Task: Write an original, polished literary short story between 1,200 and 1,500 words about {plot} in this style.
24Constraints:
25- Do NOT mention the author or title in the story text.
26- Final line must be exactly: THE END.
27
28Story:
29""")
30
31messages = [
32 {"role": "user", "content": prompt}
33]
34
35inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
36
37# Using optimized parameters for creative writing
38outputs = model.generate(
39 inputs,
40 max_new_tokens=2200,
41 temperature=0.9,
42 top_p=0.95,
43 min_p=0.05,
44 repetition_penalty=1.05
45)
46
47print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))1@misc{liu2025capturingclassicauthorialstyle,
2 title={Capturing Classic Authorial Style in Long-Form Story Generation with GRPO Fine-Tuning},
3 author={Jinlong Liu and Mohammed Bahja and Venelin Kovatchev and Mark Lee},
4 year={2025},
5 eprint={2512.05747},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2512.05747},
9}