modyfikacja funkcji testowej

This commit is contained in:
l.gabrysiak 2025-02-25 17:42:20 +01:00
parent 1a41ca184b
commit becb46b4ba
1 changed files with 7 additions and 2 deletions

9
hft.py
View File

@ -204,9 +204,14 @@ 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_embedding.weight.shape[0] - 1 # Tymczasowe rozwiązanie
source = source_mapper.get_source(source_idx)
return f"{answer}\n\nŹródło: {source if source else 'Opracowanie własne'}"
# Przykład użycia # Przykład użycia
question = "Ile dni urlopu przysługuje pracownikowi?" question = "Ile dni urlopu przysługuje pracownikowi?"
answer = generate_answer(question, model, tokenizer, source_mapper) answer = generate_answer(question, model, tokenizer, source_mapper)
print(answer) print("Pytanie:", question)
print("Odpowiedź:", answer)