Update README.md
Browse files
README.md
CHANGED
@@ -54,5 +54,50 @@ def format_instruction(sample):
|
|
54 |
### Response:
|
55 |
{sample[" çıktı"]}
|
56 |
"""```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
|
|
|
54 |
### Response:
|
55 |
{sample[" çıktı"]}
|
56 |
"""```
|
57 |
+
## Generate Output:
|
58 |
+
|
59 |
+
```python
|
60 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
61 |
+
|
62 |
+
model_id = "ardaorcun/finetuned_cosmos2603"
|
63 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
64 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,
|
65 |
+
device_map='auto',
|
66 |
+
load_in_8bit=True)
|
67 |
+
|
68 |
+
sampling_params = dict(do_sample=True, temperature=0.3, top_k=50, top_p=0.9)
|
69 |
+
|
70 |
+
pipe = pipeline("text-generation",
|
71 |
+
model=model,
|
72 |
+
tokenizer=tokenizer,
|
73 |
+
device_map="auto",
|
74 |
+
max_new_tokens=512,
|
75 |
+
return_full_text=True,
|
76 |
+
repetition_penalty=1.1
|
77 |
+
)
|
78 |
+
|
79 |
+
DEFAULT_SYSTEM_PROMPT = "Sen cevap vermeyi seven yardımcı bir dil modelisin.\n"
|
80 |
+
|
81 |
+
def format_instruction(sample):
|
82 |
+
return f"""{DEFAULT_SYSTEM_PROMPT}
|
83 |
+
### Input:
|
84 |
+
{sample["talimat"]}
|
85 |
+
|
86 |
+
### Context:
|
87 |
+
{sample["giriş"]}
|
88 |
+
|
89 |
+
### Response:
|
90 |
+
{sample["çıktı"]}"""
|
91 |
+
|
92 |
+
def generate_output(user_query, sys_prompt=DEFAULT_SYSTEM_PROMPT):
|
93 |
+
prompt = format_instruction({"talimat": user_query, "giriş": "", "çıktı": ""})
|
94 |
+
outputs = pipe(prompt,
|
95 |
+
**sampling_params
|
96 |
+
)
|
97 |
+
return outputs[0]["generated_text"]
|
98 |
+
|
99 |
+
user_query = "Türkiye'de kaç il var?"
|
100 |
+
response = generate_output(user_query)
|
101 |
+
print(response)```
|
102 |
|
103 |
|