Richard Neuschulz
commited on
Commit
•
9dba3d4
1
Parent(s):
e8c0226
first submission
Browse files- app.py +31 -0
- config.json +1 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
|
3 |
+
model_id = "seedboxai/KafkaLM-8x7B-German-V0.1-DPO"
|
4 |
+
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, trust_remote_code=True)
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
+
|
9 |
+
def generate_prompt(input):
|
10 |
+
prompt = ''
|
11 |
+
sys_prompt = "Du bist ein freundlicher und hilfsbereiter KI-Assistent. Du beantwortest Fragen faktenorientiert und präzise, ohne dabei relevante Fakten auszulassen."
|
12 |
+
|
13 |
+
prompt += f"<|system|>\n{sys_prompt.strip()}</s>\n"
|
14 |
+
prompt += f"<|user|>\n{input.strip()}</s>\n"
|
15 |
+
prompt += f"<|assistant|>\n"
|
16 |
+
|
17 |
+
return prompt.strip()
|
18 |
+
|
19 |
+
|
20 |
+
generate_text = transformers.pipeline(
|
21 |
+
model=model, tokenizer=tokenizer,
|
22 |
+
return_full_text=True,
|
23 |
+
task='text-generation',
|
24 |
+
temperature=0.5,
|
25 |
+
max_new_tokens=512,
|
26 |
+
top_p=0.95,
|
27 |
+
top_k=50,
|
28 |
+
do_sample=True,
|
29 |
+
)
|
30 |
+
|
31 |
+
print(generate_text(generate_prompt("Wer ist eigentlich dieser Kafka?")))
|
config.json
CHANGED
@@ -28,3 +28,4 @@
|
|
28 |
"use_cache": true,
|
29 |
"vocab_size": 32000
|
30 |
}
|
|
|
|
28 |
"use_cache": true,
|
29 |
"vocab_size": 32000
|
30 |
}
|
31 |
+
|