Views
No views yet
meta-llama/Llama-3.1-8B-Instructmedkit/simsamufr)transformers library. Make sure you are logged into your Hugging Face account and have accepted the Llama 3.1 license terms.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Ensure you have logged in to Hugging Face CLI
5# huggingface-cli login
6
7model_id = "Imed-Ghebriout/Llama-3.1-8B-Instruct-LoRA-SimSAMU"
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 torch_dtype=torch.bfloat16,
12 device_map="auto"
13)
14
15# A shortened example transcript
16transcript = "medecin: bonjour docteur DETOURET au SAMU 93 vous appelez pour votre grand père c'est ça ?\npatient: oui c'est bien ça\nmedecin: d'accord vous êtes avec lui là ou pas ?\npatient: non non j'arrive là devant l'immeuble et je vois il y a de la fumée partout.\nmedecin: il y a des secours sur place monsieur ?\npatient: non non, il y a personne.\nmedecin: donc votre grand père il est à quel étage ?\npatient: il est au deuxième étage.\nmedecin: il peut se déplacer lui ou pas ?\npatient: bah je sais pas je suis pas encore rentré."
17
18# A shortened example of the system prompt
19system_prompt = """Vous êtes un médecin urgentiste. Votre tâche est de résumer le dialogue médical suivant sous la forme d’un compte rendu clinique précis et structuré.
20Format du compte rapport clinique:
211-Motif principal de l’appel:
222-Contexte de l’appel:
233-Contexte du patient:
244-Traitement habituel:
255-Antécédents médicaux:
266-Symptômes du patient:
277-Histoire de la maladie actuelle:
288-Hypothèses diagnostiques:
299-Plan de traitement:
3010-Décision d’orientation:"""
31
32messages = [
33 {
34 "role": "system",
35 "content": system_prompt,
36 },
37 {
38 "role": "user",
39 "content": f"Dialogue médical:\n{transcript}\n---"
40 },
41]
42
43input_ids = tokenizer.apply_chat_template(
44 messages,
45 add_generation_prompt=True,
46 return_tensors="pt"
47).to(model.device)
48
49terminators = [
50 tokenizer.eos_token_id,
51 tokenizer.convert_tokens_to_ids("<|eot_id|>")
52]
53
54outputs = model.generate(
55 input_ids,
56 max_new_tokens=512,
57 eos_token_id=terminators,
58 do_sample=True,
59 temperature=0.6,
60 top_p=0.9,
61)
62
63response = outputs[0][input_ids.shape[-1]:]
64summary = tokenizer.decode(response, skip_special_tokens=True)
65print(summary)