File size: 4,086 Bytes
d02c928 dcb3d7e d02c928 dcb3d7e d02c928 dcb3d7e d02c928 dcb3d7e d02c928 dcb3d7e d2188ee dcb3d7e d2188ee dcb3d7e d02c928 |
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 |
---
base_model: unsloth/qwen2.5-coder-7b-bnb-4bit
tags:
- text-generation-inference
- transformers
- unsloth
- qwen2
- diagram
- text-to-diagram
license: apache-2.0
language:
- en
datasets:
- huytd189/pintora-instruct
- huytd189/pintora-edit-instruct
---
# Pintora-Coder-7B
## Introduction
Pintora-Coder-7B is a fine-tuned version of [Qwen2.5-Coder-7B](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) to support the [Pintora](https://github.com/hikerpig/pintora) diagram language.
The model supports the following features:
1. Generate diagrams from scratch.
2. Edit existing diagrams.
## Training Details
The model has been trained in the following steps:
1. Continued pretraining with the [pintora-instruct](https://huggingface.co/datasets/huytd189/pintora-instruct) dataset.
2. Instruction fine-tuned with the [pintora-edit-instruct](https://huggingface.co/datasets/huytd189/pintora-edit-instruct) dataset.
## Examples
**Example 1: Generate diagram from scratch**
Instruction:
```
Create a component diagram for a platform to buy and sell games between users.
```
Output code:
```
componentDiagram
package "Services" {
[Game Service]
[User Service]
}
database "Storage" {
[Games Table]
[Users Table]
}
[Game Service] --> [Games Table]
[User Service] --> [Users Table]
[Game Service] --> [User Service] : for authentication
```
Preview:

**Example 2: Edit existing diagram**
Instruction:
```
Add shopping cart and checkout service to this component diagram
componentDiagram
package "Services" {
[Game Service]
[User Service]
}
database "Storage" {
[Games Table]
[Users Table]
}
[Game Service] --> [Games Table]
[User Service] --> [Users Table]
[Game Service] --> [User Service] : for authentication
```
Output code:
```
componentDiagram
package "Services" {
[Game Service]
[User Service]
[Shopping Cart Service]
[Checkout Service]
}
database "Storage" {
[Games Table]
[Users Table]
[Cart Items Table]
[Orders Table]
}
[Game Service] --> [Games Table]
[User Service] --> [Users Table]
[Shopping Cart Service] --> [Cart Items Table]
[Checkout Service] --> [Cart Items Table]
[Checkout Service] --> [Orders Table]
[Game Service] --> [User Service] : for authentication
[Shopping Cart Service] --> [User Service] : for authentication
[Checkout Service] --> [User Service] : for authentication
```
Preview:

## Running
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model
model_name = "huytd189/pintora-coder-7b"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
# Prompt template
edit_prompt = """Pintora Diagram Edit Instruction
### Instruction:
{}
{}
### Response:
{}"""
# Example 1: Generate from scratch
inputs = tokenizer([
edit_prompt.format(
"Create a component diagram for a platform to buy and sell games between users.",
"",
""
)
], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=512, use_cache=True)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
print("\n" + "="*80 + "\n")
# Example 2: Edit existing diagram
inputs = tokenizer([
edit_prompt.format(
"Add shopping cart and checkout service to this component diagram",
"""componentDiagram
package "Services" {
[Game Service]
[User Service]
}
database "Storage" {
[Games Table]
[Users Table]
}
[Game Service] --> [Games Table]
[User Service] --> [Users Table]
[Game Service] --> [User Service] : for authentication""",
""
)
], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=512, use_cache=True)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
```
|