Sengil commited on
Commit
161b053
·
verified ·
1 Parent(s): f315010

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -2
README.md CHANGED
@@ -17,6 +17,54 @@ language:
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** unsloth/Qwen3-4B-Base
19
 
20
- This qwen3 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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** unsloth/Qwen3-4B-Base
19
 
20
+ ```
21
+ !pip install transformers accelerate peft
22
+ ```
23
 
24
+
25
+ usage
26
+ ```python
27
+ import torch
28
+ print(torch.cuda.is_available())
29
+
30
+ import torch
31
+ from transformers import AutoTokenizer, AutoModelForCausalLM
32
+
33
+ # Model ve tokenizer yükle
34
+ model_name = "Sengil/qwen3-4b-turkish-summarizer"
35
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
36
+
37
+ model = AutoModelForCausalLM.from_pretrained(
38
+ model_name,
39
+ device_map="auto", # accelerate devreye girer
40
+ torch_dtype=torch.float16 # optimize belleği
41
+ )
42
+ model.eval()
43
+
44
+ # Mesaj formatı
45
+ messages = [
46
+ {"role": "system", "content": "Sen bir özetleyicisin. Sana verilen metni özetle."},
47
+ {"role": "user", "content": "text. . ."},
48
+ ]
49
+
50
+ # Chat template ile prompt oluştur
51
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
52
+
53
+ # Tokenizer ile input tensor'ları oluştur
54
+ inputs = tokenizer(prompt, return_tensors="pt") # Cihaza atama yapma!
55
+
56
+ # İnferans (generate) işlemi
57
+ with torch.no_grad():
58
+ outputs = model.generate(
59
+ input_ids=inputs["input_ids"].to(model.device),
60
+ attention_mask=inputs["attention_mask"].to(model.device),
61
+ max_new_tokens=128,
62
+ do_sample=False,
63
+ temperature=0.7,
64
+ )
65
+
66
+ # Çıktıyı çöz
67
+ summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
68
+ print("\n📝 Özet:", summary)
69
+
70
+ ```