Update README.md
Browse files
README.md
CHANGED
|
@@ -23,4 +23,38 @@ model = LLaMAForCausalLM.from_pretrained(
|
|
| 23 |
|
| 24 |
|
| 25 |
model = PeftModel.from_pretrained(model, "Aspik101/polish-alpaca7B-lora")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
model = PeftModel.from_pretrained(model, "Aspik101/polish-alpaca7B-lora")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_answer(question, model_version = model):
|
| 29 |
+
PROMPT =f'''Poniżej znajduje się instrukcja opisująca zadanie. Napisz odpowiedź, która odpowiednio rozwiąrze zadanie.
|
| 30 |
+
|
| 31 |
+
### Instruction:
|
| 32 |
+
{question}
|
| 33 |
+
|
| 34 |
+
### Response:
|
| 35 |
+
'''
|
| 36 |
+
|
| 37 |
+
inputs = tokenizer(
|
| 38 |
+
PROMPT,
|
| 39 |
+
return_tensors="pt",
|
| 40 |
+
)
|
| 41 |
+
input_ids = inputs["input_ids"].cuda()
|
| 42 |
+
|
| 43 |
+
generation_config = GenerationConfig(
|
| 44 |
+
temperature=0.2,
|
| 45 |
+
top_p=0.95,
|
| 46 |
+
repetition_penalty=1.15,
|
| 47 |
+
)
|
| 48 |
+
print("Generating...")
|
| 49 |
+
generation_output = model_version.generate(
|
| 50 |
+
input_ids=input_ids,
|
| 51 |
+
generation_config=generation_config,
|
| 52 |
+
return_dict_in_generate=True,
|
| 53 |
+
output_scores=True,
|
| 54 |
+
max_new_tokens=128,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
sentences = " ".join([tokenizer.decode(s) for s in generation_output.sequences])
|
| 58 |
+
print(sentences.split("Response:\n")[1])
|
| 59 |
+
|
| 60 |
```
|