Update README.md
Browse files
README.md
CHANGED
|
@@ -5,17 +5,171 @@ tags:
|
|
| 5 |
- transformers
|
| 6 |
- unsloth
|
| 7 |
- qwen2
|
|
|
|
|
|
|
| 8 |
license: apache-2.0
|
| 9 |
language:
|
| 10 |
- en
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
#
|
| 14 |
|
| 15 |
-
|
| 16 |
-
- **License:** apache-2.0
|
| 17 |
-
- **Finetuned from model :** unsloth/qwen2.5-coder-7b-bnb-4bit
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
| 5 |
- transformers
|
| 6 |
- unsloth
|
| 7 |
- qwen2
|
| 8 |
+
- diagram
|
| 9 |
+
- text-to-diagram
|
| 10 |
license: apache-2.0
|
| 11 |
language:
|
| 12 |
- en
|
| 13 |
+
datasets:
|
| 14 |
+
- huytd189/pintora-instruct
|
| 15 |
+
- huytd189/pintora-edit-instruct
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# Pintora-Coder-7B
|
| 19 |
|
| 20 |
+
## Introduction
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
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.
|
| 23 |
+
|
| 24 |
+
## Training Details
|
| 25 |
+
|
| 26 |
+
The model has been trained in the following steps:
|
| 27 |
+
|
| 28 |
+
1. Continued Pretraining with the [pintora-instruct](https://huggingface.co/datasets/huytd189/pintora-instruct) dataset
|
| 29 |
+
2. Instruction Fine-tuned with the [pintora-edit-instruct](https://huggingface.co/datasets/huytd189/pintora-edit-instruct) dataset
|
| 30 |
+
|
| 31 |
+
## Examples
|
| 32 |
+
|
| 33 |
+
**Example 1: Generate diagram from scratch**
|
| 34 |
+
|
| 35 |
+
Instruction:
|
| 36 |
+
|
| 37 |
+
```
|
| 38 |
+
Create a component diagram for a platform to buy and sell games between users.
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
Output code:
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
componentDiagram
|
| 45 |
+
|
| 46 |
+
package "Services" {
|
| 47 |
+
[Game Service]
|
| 48 |
+
[User Service]
|
| 49 |
+
}
|
| 50 |
+
database "Storage" {
|
| 51 |
+
[Games Table]
|
| 52 |
+
[Users Table]
|
| 53 |
+
}
|
| 54 |
+
[Game Service] --> [Games Table]
|
| 55 |
+
[User Service] --> [Users Table]
|
| 56 |
+
[Game Service] --> [User Service] : for authentication
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Preview:
|
| 60 |
+
|
| 61 |
+

|
| 62 |
+
|
| 63 |
+
**Example 2: Edit existing diagram**
|
| 64 |
+
|
| 65 |
+
Instruction:
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
Add shopping cart and checkout service to this component diagram
|
| 69 |
+
|
| 70 |
+
componentDiagram
|
| 71 |
+
|
| 72 |
+
package "Services" {
|
| 73 |
+
[Game Service]
|
| 74 |
+
[User Service]
|
| 75 |
+
}
|
| 76 |
+
database "Storage" {
|
| 77 |
+
[Games Table]
|
| 78 |
+
[Users Table]
|
| 79 |
+
}
|
| 80 |
+
[Game Service] --> [Games Table]
|
| 81 |
+
[User Service] --> [Users Table]
|
| 82 |
+
[Game Service] --> [User Service] : for authentication
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Output code:
|
| 86 |
+
|
| 87 |
+
```
|
| 88 |
+
componentDiagram
|
| 89 |
+
package "Services" {
|
| 90 |
+
[Game Service]
|
| 91 |
+
[User Service]
|
| 92 |
+
[Shopping Cart Service]
|
| 93 |
+
[Checkout Service]
|
| 94 |
+
}
|
| 95 |
+
database "Storage" {
|
| 96 |
+
[Games Table]
|
| 97 |
+
[Users Table]
|
| 98 |
+
[Cart Items Table]
|
| 99 |
+
[Orders Table]
|
| 100 |
+
}
|
| 101 |
+
[Game Service] --> [Games Table]
|
| 102 |
+
[User Service] --> [Users Table]
|
| 103 |
+
[Shopping Cart Service] --> [Cart Items Table]
|
| 104 |
+
[Checkout Service] --> [Cart Items Table]
|
| 105 |
+
[Checkout Service] --> [Orders Table]
|
| 106 |
+
[Game Service] --> [User Service] : for authentication
|
| 107 |
+
[Shopping Cart Service] --> [User Service] : for authentication
|
| 108 |
+
[Checkout Service] --> [User Service] : for authentication
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
Preview:
|
| 112 |
+
|
| 113 |
+

|
| 114 |
+
|
| 115 |
+
## Running
|
| 116 |
+
|
| 117 |
+
```python
|
| 118 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 119 |
+
import torch
|
| 120 |
+
|
| 121 |
+
# Load model
|
| 122 |
+
model_name = "huytd189/pintora-coder-7b"
|
| 123 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 124 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 125 |
+
|
| 126 |
+
# Prompt template
|
| 127 |
+
edit_prompt = """Pintora Diagram Edit Instruction
|
| 128 |
+
|
| 129 |
+
### Instruction:
|
| 130 |
+
{}
|
| 131 |
+
|
| 132 |
+
{}
|
| 133 |
+
|
| 134 |
+
### Response:
|
| 135 |
+
{}"""
|
| 136 |
+
|
| 137 |
+
# Example 1: Generate from scratch
|
| 138 |
+
inputs = tokenizer([
|
| 139 |
+
edit_prompt.format(
|
| 140 |
+
"Create a component diagram for a platform to buy and sell games between users.",
|
| 141 |
+
"",
|
| 142 |
+
""
|
| 143 |
+
)
|
| 144 |
+
], return_tensors="pt").to("cuda")
|
| 145 |
+
|
| 146 |
+
outputs = model.generate(**inputs, max_new_tokens=512, use_cache=True)
|
| 147 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
|
| 148 |
+
|
| 149 |
+
print("\n" + "="*80 + "\n")
|
| 150 |
+
|
| 151 |
+
# Example 2: Edit existing diagram
|
| 152 |
+
inputs = tokenizer([
|
| 153 |
+
edit_prompt.format(
|
| 154 |
+
"Add shopping cart and checkout service to this component diagram",
|
| 155 |
+
"""componentDiagram
|
| 156 |
+
|
| 157 |
+
package "Services" {
|
| 158 |
+
[Game Service]
|
| 159 |
+
[User Service]
|
| 160 |
+
}
|
| 161 |
+
database "Storage" {
|
| 162 |
+
[Games Table]
|
| 163 |
+
[Users Table]
|
| 164 |
+
}
|
| 165 |
+
[Game Service] --> [Games Table]
|
| 166 |
+
[User Service] --> [Users Table]
|
| 167 |
+
[Game Service] --> [User Service] : for authentication""",
|
| 168 |
+
""
|
| 169 |
+
)
|
| 170 |
+
], return_tensors="pt").to("cuda")
|
| 171 |
+
|
| 172 |
+
outputs = model.generate(**inputs, max_new_tokens=512, use_cache=True)
|
| 173 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
|
| 174 |
+
```
|
| 175 |
|
|
|