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