File size: 4,235 Bytes
3b68d3e
 
305a28d
3b68d3e
 
 
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
 
305a28d
3b68d3e
 
 
305a28d
3b68d3e
 
 
 
 
 
305a28d
3b68d3e
305a28d
3b68d3e
 
 
 
 
 
 
 
 
 
 
305a28d
3b68d3e
 
 
 
 
305a28d
3b68d3e
305a28d
3b68d3e
 
 
 
 
 
 
 
 
 
 
 
305a28d
 
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
 
3b68d3e
 
305a28d
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
305a28d
3b68d3e
 
305a28d
3b68d3e
 
 
 
 
 
 
 
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
license: apache-2.0
language:

tr
base_model: unsloth/Llama-3.1-8B
tags:

llama-3.1

turkish-law

unsloth

qlora

text-generation

tr
datasets:

sinanelms/output_kanun_tokensli.json

Llama 3.1 8B - Türk Hukuk Uzmanı Modeli
Bu model, unsloth/Llama-3.1-8B temel modelinin, Türkçe hukuk metinlerini içeren sinanelms/output_kanun_tokensli.json veri seti üzerinde QLoRA yöntemiyle fine-tune edilmiş versiyonudur. Model, Türk hukukuyla ilgili sorulara bir yargıç veya uzman avukat perspektifinden, detaylı ve doğru cevaplar vermek üzere eğitilmiştir.

Eğitim, Unsloth kütüphanesi kullanılarak Google Colab ortamında bir NVIDIA A100-SXM4-80GB GPU üzerinde gerçekleştirilmiştir.

Model Açıklaması
Temel Model: unsloth/Llama-3.1-8B (4-bit quantize edilmiş)

Veri Seti: sinanelms/output_kanun_tokensli.json (353,386 eğitim örneği)

Dil: Türkçe

Uzmanlık Alanı: Türk Hukuku

Amaçlanan Kullanım: Hukuki metin anlama, soru-cevap, özetleme ve hukuki konularda asistanlık.

Nasıl Kullanılır?
Modeli kullanmak için transformers, torch ve unsloth kütüphanelerinin kurulu olması gerekmektedir. Aşağıdaki kod parçası, modeli nasıl yükleyeceğinizi ve streaming (akıcı) bir şekilde cevap üreteceğinizi gösterir.

from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
import torch

# Kendi model reponuzun adını buraya yazın
# Örnek: model_path = "Yusuf-c/Llama-3.1-8B-Turkish-Law-v1"
model_path = "kullanici-adiniz/repo-adiniz"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
    model_path,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

streamer = TextStreamer(tokenizer, skip_prompt=True)

# Llama 3.1 formatına uygun prompt
messages = [
    {
        "role": "system",
        "content": "Sen Türk hukuku konusunda uzmanlaşmış bir yapay zeka asistanısın. Sen bir yargıçsın, sorulan sorulara doğru ve detaylı bilgiler veriyorsun."
    },
    {
        "role": "user",
        "content": "Türk Borçlar Kanunu'na göre bir sözleşme nasıl kurulur?"
    }
]

prompt = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

# Akıcı (streaming) şekilde cevap üretimi
with torch.no_grad():
    _ = model.generate(
        **inputs,
        max_new_tokens=512,
        temperature=0.7,
        top_p=0.9,
        top_k=50,
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id,
        streamer=streamer,
    )


Prompt Formatı
Model, Llama 3.1'in chat formatı ile eğitilmiştir. En iyi sonuçları almak için aşağıdaki sistem mesajını kullanmanız önerilir:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

Sen Türk hukuku konusunda uzmanlaşmış bir yapay zeka asistanısın. Sen bir yargıçsın, sorulan sorulara doğru ve detaylı bilgiler veriyorsun.<|eot_id|><|start_header_id|>user<|end_header_id|>

{KULLANICI_SORUSU}<|eot_id|><|start_header_id|>assistant<|end_header_id|>


Eğitim Detayları
Eğitim, bellek verimliliği ve hız için Unsloth kütüphanesi ile optimize edilmiştir.

Eğitim Hiperparametreleri
Parametre

Değer

base_model

unsloth/Llama-3.1-8B

quantization

4-bit

lora_r

32

lora_alpha

64

lora_dropout

0.0

optimizer

adamw_8bit

learning_rate

1e-4

lr_scheduler_type

cosine

per_device_train_batch_size

1

gradient_accumulation_steps

32

effective_batch_size

32

num_train_epochs

1

max_seq_length

1024

Eğitim Sonuçları
Metrik

Değer

GPU

NVIDIA A100-SXM4-80GB

Eğitim Süresi

~606.5 dakika (~10.1 saat)

Toplam Adım

2,416

Final Train Loss

0.9524

Validation Loss

0.8216 (Adım 2208)

Veri Seti Boyutu

353,386 (Eğitim) / 7,212 (Doğrulama)

Kaynak Gösterme
Bu modeli veya çalışmayı kullanırsanız, lütfen aşağıdaki şekilde atıfta bulunun:

@misc{turkish_law_llama3_1_8b_2024,
    title={Llama 3.1 8B - Turkish Legal Expert},
    author={Your Name},
    year={2024},
    publisher={Hugging Face},
    journal={Hugging Face repository},
    howpublished={\url{[https://huggingface.co/your-username/your-repo-name](https://huggingface.co/your-username/your-repo-name)}}
}