jetbabareal commited on
Commit
6932f64
·
verified ·
1 Parent(s): ee92b71

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -5
README.md CHANGED
@@ -1,7 +1,6 @@
1
  ---
2
  language:
3
  - tr
4
- - en
5
  tags:
6
  - text-generation
7
  - custom-architecture
@@ -154,6 +153,9 @@ def generate_text(prompt, max_new_tokens=60, temperature=0.5, top_k=20):
154
  full_prompt = f"Kullanıcı: {prompt}\nModel: "
155
  input_ids = tokenizer.encode(full_prompt)
156
  idx = torch.tensor(input_ids, dtype=torch.long, device=device).unsqueeze(0)
 
 
 
157
 
158
  for _ in range(max_new_tokens):
159
  idx_cond = idx[:, -config.block_size:]
@@ -165,17 +167,33 @@ def generate_text(prompt, max_new_tokens=60, temperature=0.5, top_k=20):
165
  logits[logits < v[:, [-1]]] = -float('Inf')
166
  probs = F.softmax(logits, dim=-1)
167
  idx_next = torch.multinomial(probs, num_samples=1)
168
- if idx_next.item() == tokenizer.eos_id(): break
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  idx = torch.cat((idx, idx_next), dim=1)
170
 
171
- response_ids = idx[0][len(input_ids):].tolist()
172
- response = tokenizer.decode(response_ids)
173
- return response
174
 
175
  # --- ÖRNEK KULLANIM / EXAMPLE USAGE ---
176
  soru = "Nasılsın?"
177
  cevap = generate_text(soru)
178
  print(f"Soru: {soru}\nCevap: {cevap}")
 
 
 
 
179
  ```
180
 
181
  ---
 
1
  ---
2
  language:
3
  - tr
 
4
  tags:
5
  - text-generation
6
  - custom-architecture
 
153
  full_prompt = f"Kullanıcı: {prompt}\nModel: "
154
  input_ids = tokenizer.encode(full_prompt)
155
  idx = torch.tensor(input_ids, dtype=torch.long, device=device).unsqueeze(0)
156
+
157
+
158
+ generated_ids = []
159
 
160
  for _ in range(max_new_tokens):
161
  idx_cond = idx[:, -config.block_size:]
 
167
  logits[logits < v[:, [-1]]] = -float('Inf')
168
  probs = F.softmax(logits, dim=-1)
169
  idx_next = torch.multinomial(probs, num_samples=1)
170
+
171
+
172
+ generated_ids.append(idx_next.item())
173
+
174
+
175
+ decoded_so_far = tokenizer.decode(generated_ids)
176
+ if "Kullanıcı:" in decoded_so_far or "Model:" in decoded_so_far:
177
+
178
+ generated_ids = generated_ids[:-1]
179
+ break
180
+
181
+ if idx_next.item() == tokenizer.eos_id():
182
+ break
183
+
184
  idx = torch.cat((idx, idx_next), dim=1)
185
 
186
+ response = tokenizer.decode(generated_ids)
187
+ return response.strip()
 
188
 
189
  # --- ÖRNEK KULLANIM / EXAMPLE USAGE ---
190
  soru = "Nasılsın?"
191
  cevap = generate_text(soru)
192
  print(f"Soru: {soru}\nCevap: {cevap}")
193
+
194
+ soru = "En sevdiğin renk ne?"
195
+ cevap = generate_text(soru)
196
+ print(f"Soru: {soru}\nCevap: {cevap}")
197
  ```
198
 
199
  ---