Views
No views yet
| hellaswag acc_norm | arc_challenge acc_norm | m_mmlu 5-shot acc | Average |
|---|---|---|---|
| 0.7915 | 0.5606 | 0.6939 | 0.682 |
!pip install transformers torch sentencepiece1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3device = "cpu" # if you want to use the gpu make sure to have cuda toolkit installed and change this to "cuda"
4
5model = AutoModelForCausalLM.from_pretrained("MoxoffSpA/Moxoff-Phi3Mini-KTO")
6tokenizer = AutoTokenizer.from_pretrained("MoxoffSpA/Moxoff-Phi3Mini-KTO")
7
8question = """Quanto è alta la torre di Pisa?"""
9context = """
10La Torre di Pisa è un campanile del XII secolo, famoso per la sua inclinazione. Alta circa 56 metri.
11"""
12
13prompt = f"Domanda: {question}, contesto: {context}"
14
15messages = [
16 {"role": "user", "content": prompt}
17]
18
19encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
20
21model_inputs = encodeds.to(device)
22model.to(device)
23
24generated_ids = model.generate(
25 model_inputs, # The input to the model
26 max_new_tokens=128, # Limiting the maximum number of new tokens generated
27 do_sample=True, # Enabling sampling to introduce randomness in the generation
28 temperature=0.1, # Setting temperature to control the randomness, lower values make it more deterministic
29 top_p=0.95, # Using nucleus sampling with top-p filtering for more coherent generation
30 eos_token_id=tokenizer.eos_token_id # Specifying the token that indicates the end of a sequence
31)
32
33decoded_output = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
34trimmed_output = decoded_output.strip()
35print(trimmed_output)