Views
No views yet
Age, Diagnosis, LengthOfStay, ComorbidityCount, HadSurgery, etc.) are converted into a sequential natural language prompt format.gpt2-medium).[BOS] Age: 68; Diagnosis: CHF; LOS: 5; Comorbidities: 3; Surgery: Yes; --> Patient is elderly with CHF. A 5-day stay indicates stability. However, multiple comorbidities pose high risk. Readmission: 1 [EOS]Race or InsuranceType and Readmission_30d). Use with extreme caution in predictive tasks.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load the model and tokenizer
5model_name = "your-username/HealthcareReadmissionGPT" # Replace with actual HuggingFace path
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name)
8
9# Example structured prompt (must match training format)
10prompt_text = "Age: 79; Race: Black; Diagnosis: Lung Cancer; LOS: 13; Comorbidities: 4; Surgery: Yes; --> Patient is elderly with complex cancer and long LOS. Multiple..."
11
12# Encode the prompt
13input_ids = tokenizer.encode(prompt_text, return_tensors='pt')
14
15# Generate the continuation text (up to 50 new tokens)
16output = model.generate(
17 input_ids,
18 max_length=len(input_ids[0]) + 50,
19 num_return_sequences=1,
20 do_sample=True,
21 temperature=0.7,
22 pad_token_id=tokenizer.eos_token_id # Important for GPT-like models
23)
24
25# Decode and print the result
26generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
27
28print(f"--- Input Prompt ---\n{prompt_text}\n")
29print(f"--- Generated Assessment ---\n{generated_text}")
30# Expected last token sequence: ... Readmission: 1