Dodanie testu na koniec treningu
This commit is contained in:
parent
5aef37828d
commit
bb183461ba
22
hft.py
22
hft.py
|
|
@ -192,7 +192,7 @@ trainer.train()
|
||||||
def generate_answer(question, model, tokenizer, source_mapper, max_length=200):
|
def generate_answer(question, model, tokenizer, source_mapper, max_length=200):
|
||||||
inputs = tokenizer(question, return_tensors="pt", truncation=True, max_length=512)
|
inputs = tokenizer(question, return_tensors="pt", truncation=True, max_length=512)
|
||||||
|
|
||||||
outputs = model.generate(
|
outputs = model.base_model.generate(
|
||||||
**inputs,
|
**inputs,
|
||||||
max_length=max_length,
|
max_length=max_length,
|
||||||
num_return_sequences=1,
|
num_return_sequences=1,
|
||||||
|
|
@ -205,3 +205,23 @@ def generate_answer(question, model, tokenizer, source_mapper, max_length=200):
|
||||||
# Pobierz źródło z ostatniego tokena
|
# Pobierz źródło z ostatniego tokena
|
||||||
last_token_id = outputs.sequences[0][-1].item()
|
last_token_id = outputs.sequences[0][-1].item()
|
||||||
source_idx = model.source_embeddi
|
source_idx = model.source_embeddi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Po zakończeniu treningu modelu
|
||||||
|
|
||||||
|
# Przygotowanie niezbędnych komponentów
|
||||||
|
model.eval() # Przełącz model w tryb ewaluacji
|
||||||
|
model = model.to("cuda" if torch.cuda.is_available() else "cpu") # Przenieś model na GPU, jeśli jest dostępne
|
||||||
|
|
||||||
|
# Przykładowe pytanie
|
||||||
|
question = "Ile dni urlopu przysługuje pracownikowi?"
|
||||||
|
|
||||||
|
# Generowanie odpowiedzi
|
||||||
|
answer = generate_answer(question, model, tokenizer, source_mapper)
|
||||||
|
|
||||||
|
# Wyświetlenie wyniku
|
||||||
|
print("Pytanie:", question)
|
||||||
|
print("Odpowiedź:", answer)
|
||||||
Loading…
Reference in New Issue