faisalshah012003 commited on
Commit
a13509e
·
verified ·
1 Parent(s): d91e90a

Update medical_simplifier.py

Browse files
Files changed (1) hide show
  1. medical_simplifier.py +11 -1
medical_simplifier.py CHANGED
@@ -32,7 +32,15 @@ class MedicalTextSimplifier:
32
  """Generate plain-language explanation using BioMedLM"""
33
  try:
34
  prompt = f"Explain the medical term '{term}' in simple language for a patient. Context: {context}\nExplanation:"
35
- result = self.pipe(prompt, max_length=100, do_sample=True, temperature=0.7, top_p=0.9)
 
 
 
 
 
 
 
 
36
  explanation = result[0]['generated_text'].split("Explanation:")[-1].strip()
37
  return explanation
38
  except Exception as e:
@@ -87,4 +95,6 @@ class MedicalTextSimplifier:
87
  simplified_text = simplified_text[:start] + annotated + simplified_text[end:]
88
  offset += len(annotated) - len(term)
89
 
 
 
90
  return simplified_text
 
32
  """Generate plain-language explanation using BioMedLM"""
33
  try:
34
  prompt = f"Explain the medical term '{term}' in simple language for a patient. Context: {context}\nExplanation:"
35
+ result = self.pipe(
36
+ prompt,
37
+ max_new_tokens=50, # Use max_new_tokens instead of max_length
38
+ do_sample=True,
39
+ temperature=0.7,
40
+ top_p=0.9,
41
+ truncation=True, # Explicitly enable truncation
42
+ pad_token_id=self.pipe.tokenizer.eos_token_id # Set pad token
43
+ )
44
  explanation = result[0]['generated_text'].split("Explanation:")[-1].strip()
45
  return explanation
46
  except Exception as e:
 
95
  simplified_text = simplified_text[:start] + annotated + simplified_text[end:]
96
  offset += len(annotated) - len(term)
97
 
98
+ print("\nSimplified text:")
99
+ print(simplified_text)
100
  return simplified_text