Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "anthonym21/pinescript-v5-instructions-merged"
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
13def generate_pinescript(prompt, max_tokens=1024):
14 formatted = f"### Human: {prompt}\n### Assistant:"
15 inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
16
17 outputs = model.generate(
18 **inputs,
19 max_new_tokens=max_tokens,
20 temperature=0.7,
21 top_p=0.9,
22 do_sample=True,
23 pad_token_id=tokenizer.eos_token_id,
24 )
25
26 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
27 return response.split("### Assistant:")[-1].strip()
28
29# Example
30code = generate_pinescript("Write a PineScript v5 RSI indicator with overbought/oversold zones")
31print(code)| Prompt | Description |
|---|---|
| "Write a PineScript v5 indicator that shows RSI with dynamic overbought/oversold levels" | RSI with adaptive levels |
| "Create a MACD crossover strategy with stop loss and take profit" | Complete trading strategy |
| "Write a Bollinger Bands indicator with squeeze detection" | Volatility indicator |
| "Create a multi-timeframe moving average indicator" | MTF analysis tool |
| Parameter | Value |
|---|---|
| Epochs | 3 |
| Batch Size | 2 |
| Gradient Accumulation | 8 |
| Learning Rate | 2e-4 |
| LoRA r | 64 |
| LoRA alpha | 128 |
| Max Seq Length | 4096 |
| Quantization | 4-bit (nf4) |
1@misc{pinescript-v5-instructions-merged,
2 author = {Anthony Maio},
3 title = {PineScript v5 Code Generator},
4 year = {2025},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/anthonym21/pinescript-v5-instructions-merged}
7}