Views
No views yet
pip:1pip install transformers
2pip install tensorflow
3
4
5# Load the fine-tuned model and tokenizer
6from transformers import T5Tokenizer, TFT5ForConditionalGeneration
7
8model_id = "Ra-Is/medical-gen-small-CoT"
9model = TFT5ForConditionalGeneration.from_pretrained(model_id)
10tokenizer = T5Tokenizer.from_pretrained(model_id)
11
12# Prepare a sample input prompt
13input_prompt = ("A 35-year-old female presents with a 2-week history of "
14 "persistent cough, shortness of breath, and fatigue. She has "
15 "a history of asthma and has recently been exposed to a sick "
16 "family member with a respiratory infection. Chest X-ray shows "
17 "bilateral infiltrates. What is the likely diagnosis, and what "
18 "should be the treatment?")
19
20# Tokenize the input
21input_ids = tokenizer(input_prompt, return_tensors="tf").input_ids
22
23# Generate the output (diagnosis)
24outputs = model.generate(
25 input_ids,
26 max_length=512,
27 num_beams=5,
28 temperature=1,
29 top_k=50,
30 top_p=0.9,
31 do_sample=True, # Enable sampling
32 early_stopping=True
33 )
34
35# Decode and print the output
36generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
37print(generated_text)