Update README
Browse files
README.md
CHANGED
@@ -11,12 +11,133 @@ language:
|
|
11 |
- en
|
12 |
---
|
13 |
|
14 |
-
# Uploaded
|
15 |
|
16 |
- **Developed by:** kmagai
|
17 |
- **License:** apache-2.0
|
18 |
-
- **Finetuned from model
|
19 |
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
- en
|
12 |
---
|
13 |
|
14 |
+
# Uploaded model
|
15 |
|
16 |
- **Developed by:** kmagai
|
17 |
- **License:** apache-2.0
|
18 |
+
- **Finetuned from model:** llm-jp/llm-jp-3-13b
|
19 |
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
## JSONL Output Process
|
25 |
+
|
26 |
+
### Model Inference Setup
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
30 |
+
import torch
|
31 |
+
from tqdm import tqdm
|
32 |
+
import json
|
33 |
+
|
34 |
+
# QLoRA config for 4-bit quantization
|
35 |
+
bnb_config = BitsAndBytesConfig(
|
36 |
+
load_in_4bit=True,
|
37 |
+
bnb_4bit_quant_type="nf4",
|
38 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
39 |
+
bnb_4bit_use_double_quant=False,
|
40 |
+
)
|
41 |
+
|
42 |
+
# Load model and tokenizer
|
43 |
+
model = AutoModelForCausalLM.from_pretrained(
|
44 |
+
model_name,
|
45 |
+
quantization_config=bnb_config,
|
46 |
+
device_map="auto",
|
47 |
+
token=HF_TOKEN
|
48 |
+
)
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token=HF_TOKEN)
|
50 |
+
```
|
51 |
+
|
52 |
+
### Input Data Processing
|
53 |
+
|
54 |
+
The script reads input data from a JSONL file (`elyza-tasks-100-TV_0.jsonl`). Each line contains a JSON object with task information:
|
55 |
+
|
56 |
+
```python
|
57 |
+
datasets = []
|
58 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
59 |
+
item = ""
|
60 |
+
for line in f:
|
61 |
+
line = line.strip()
|
62 |
+
item += line
|
63 |
+
if item.endswith("}"):
|
64 |
+
datasets.append(json.loads(item))
|
65 |
+
item = ""
|
66 |
+
```
|
67 |
+
|
68 |
+
### Generation Process
|
69 |
+
|
70 |
+
For each input in the dataset:
|
71 |
+
|
72 |
+
1. Format the prompt with instruction template
|
73 |
+
2. Tokenize the input
|
74 |
+
3. Generate response using the model
|
75 |
+
4. Decode the output
|
76 |
+
5. Create result object with task_id and output
|
77 |
+
|
78 |
+
```python
|
79 |
+
results = []
|
80 |
+
for data in tqdm(datasets):
|
81 |
+
input = data["input"]
|
82 |
+
prompt = f"""### Instruction
|
83 |
+
{input}
|
84 |
+
### Response:
|
85 |
+
"""
|
86 |
+
|
87 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
88 |
+
with torch.no_grad():
|
89 |
+
outputs = model.generate(
|
90 |
+
tokenized_input,
|
91 |
+
max_new_tokens=100,
|
92 |
+
do_sample=False,
|
93 |
+
repetition_penalty=1.2
|
94 |
+
)[0]
|
95 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
96 |
+
|
97 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
98 |
+
```
|
99 |
+
|
100 |
+
### Generation Parameters
|
101 |
+
|
102 |
+
- `max_new_tokens=100`: Maximum number of tokens to generate
|
103 |
+
- `do_sample=False`: Deterministic generation (same output every time)
|
104 |
+
- `repetition_penalty=1.2`: Penalize repetition in generated text
|
105 |
+
|
106 |
+
### Output Format
|
107 |
+
|
108 |
+
The generated responses are saved in a JSONL file with the following format:
|
109 |
+
|
110 |
+
```json
|
111 |
+
{"task_id": "task_1", "input": "input text", "output": "generated response"}
|
112 |
+
```
|
113 |
+
|
114 |
+
Required fields:
|
115 |
+
- `task_id`: Unique identifier for the task
|
116 |
+
- `output`: Response generated by the model
|
117 |
+
|
118 |
+
Optional fields:
|
119 |
+
- `input`: Input text (can be omitted in submission)
|
120 |
+
|
121 |
+
## Training Data Format
|
122 |
+
|
123 |
+
The training data should be provided in JSONL (JSON Lines) format, where each line represents a single JSON object containing the following fields:
|
124 |
+
|
125 |
+
```json
|
126 |
+
{
|
127 |
+
"instruction": "Task instruction text",
|
128 |
+
"input": "Input text (optional)",
|
129 |
+
"output": "Expected output text"
|
130 |
+
}
|
131 |
+
```
|
132 |
+
|
133 |
+
### Fields Description
|
134 |
+
|
135 |
+
- `instruction`: Task instruction that tells the model what to do
|
136 |
+
- `input`: (Optional) Input text that provides specific context for the instruction
|
137 |
+
- `output`: Expected output that represents the ideal response
|
138 |
+
|
139 |
+
### Example
|
140 |
+
|
141 |
+
```json
|
142 |
+
{"instruction": "以下の文章を要約してください。", "input": "人工知能(AI)は、人間の知能を模倣し、学習、推論、判断などを行うコンピュータシステムです。近年、機械学習や深層学習の発展により、画像認識、自然言語処理、ゲームなど様々な分野で人間に匹敵する、あるいは人間を超える性能を示しています。", "output": "AIは人間の知能を模倣するコンピュータシステムで、機械学習の発展により多くの分野で高い性能を示している。"}
|
143 |
+
{"instruction": "次の英文を日本語に翻訳してください。", "input": "Artificial Intelligence is transforming the way we live and work.", "output": "人工知能は私たちの生活と仕事の仕方を変革しています。"}
|