Views
No views yet
pip install torch==2.5.1 transformers==4.53.2 accelerate==1.8.11import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
3
4model_id = "nllg/TikZilla-8B-RL"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13eos_token_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
14pad_token_id = tokenizer.pad_token_id or tokenizer.eos_token_id or eos_token_id
15
16gen_config = GenerationConfig(
17 do_sample=True,
18 temperature=1.0,
19 top_p=0.9,
20 max_new_tokens=2048,
21 eos_token_id=eos_token_id,
22 pad_token_id=pad_token_id,
23)
24
25your_input_description = "A scientific line plot showing two curves. The x-axis is labeled 'Time' ranging from 0 to 100, and the y-axis is labeled 'Value' ranging from 0 to 1. The first curve is a blue solid line that gradually increases from near 0 and levels off around 0.9. The second curve is a red dashed line that rises to a peak around the middle of the plot and then decreases. A legend in the upper right labels the blue line as 'Model A' and the red dashed line as 'Model B'. The background is white with light gray grid lines."
26
27messages = [
28 {
29 "role": "user",
30 "content": (
31 "Generate a complete LaTeX document that contains a TikZ figure according to the following requirements:\n"
32 + your_input_description +
33 "\nWrap your code using \\documentclass[tikz]{standalone}, and include \\begin{document}...\\end{document}. "
34 "Only output valid LaTeX code with no extra text."
35 ),
36 }
37]
38
39text = tokenizer.apply_chat_template(
40 messages,
41 tokenize=False,
42 add_generation_prompt=True,
43)
44
45inputs = tokenizer([text], return_tensors="pt").to(model.device)
46output_ids = model.generate(**inputs, generation_config=gen_config)
47response_ids = output_ids[0][len(inputs["input_ids"][0]):]
48output = tokenizer.decode(response_ids, skip_special_tokens=True)
49
50print(output)