Views
No views yet
meta-llama/Meta-Llama-3-8B-InstructSynTerm (ElenaSenger/SynTerm-fine-tuning)The model was trained with conversation-style prompts, so the same format should be used for inference.
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "ElenaSenger/DiSTER-Llama-3-8B-Instruct"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 device_map="auto",
10 torch_dtype="auto"
11)
12
13
14# Use the chat format as in SynTerm-fine-tuning
15prompt = (
16 '{"id": "test_0", "conversations": [\n'
17 ' {"from": "human", "value": "Text: We used dropout regularization and AdamW optimizer to train a CNN on MRI images."},\n'
18 ' {"from": "gpt", "value": "I\'ve read this text."},\n'
19 ' {"from": "human", "value": "What describes (technical or scientific) terms in the text, that are relevant to the domain medical-imaging?"},\n'
20 ' {"from": "gpt", "value": ""}\n'
21 ']}\n'
22)
23
24
25
26inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
27
28 with torch.no_grad():
29 outputs = model.generate(
30 **inputs,
31 max_new_tokens=128,
32 do_sample=True, # Enable sampling for temperature to take effect
33 temperature=0.1,
34 top_p=1.0
35 )
36 decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
37 print("=== Decoded output ===")
38 print(decoded)
39 # Print only the model's reply
40 reply = decoded[len(prompt):].strip()
41 print("\n=== Model reply only ===")
42 print(reply)