Instructions to use Maikobi/RARE_baseline_model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Maikobi/RARE_baseline_model with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Maikobi/RARE_baseline_model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update handler.py
Browse files- handler.py +14 -19
handler.py
CHANGED
|
@@ -229,19 +229,15 @@ class EndpointHandler():
|
|
| 229 |
knowledge_section = ""
|
| 230 |
|
| 231 |
return f"""{knowledge_section}Question: {question}
|
| 232 |
-
|
| 233 |
[REASONING]
|
| 234 |
I need to provide a comprehensive, evidence-based medical answer by:
|
| 235 |
-
|
| 236 |
1. **Medical Analysis**: What are the key medical concepts, conditions, or treatments involved?
|
| 237 |
2. **Evidence Review**: What does the current medical literature and provided knowledge indicate?
|
| 238 |
3. **Safety Considerations**: Are there any contraindications, warnings, or safety concerns I must address?
|
| 239 |
4. **Completeness Check**: Have I covered mechanism, treatment options, prognosis, and patient guidance?
|
| 240 |
5. **Clinical Context**: What would be most helpful for healthcare decision-making?
|
| 241 |
-
|
| 242 |
Let me work through this systematically using the medical evidence:
|
| 243 |
[/REASONING]
|
| 244 |
-
|
| 245 |
Answer:"""
|
| 246 |
|
| 247 |
def generate_rare_answer(self, question: str, retrieved_docs: List[Tuple[str, float]] = None, show_reasoning: bool = None) -> Dict[str, str]:
|
|
@@ -403,31 +399,30 @@ Answer:"""
|
|
| 403 |
return True
|
| 404 |
|
| 405 |
def correct_answer(self, question: str, wrong_answer: str, retrieved_docs: List[Tuple[str, float]] = None, error_type: str = "unknown") -> str:
|
| 406 |
-
"""TASK 3: Enhanced correction with error-type-specific prompts"""
|
| 407 |
if not hasattr(self, 'correction_model') or not self.correction_model:
|
| 408 |
return wrong_answer
|
| 409 |
|
| 410 |
try:
|
| 411 |
-
# Error-type-specific correction prompts
|
| 412 |
correction_prompts = {
|
| 413 |
-
"incomplete": f"Complete the missing information in this medical answer: Question: {question}
|
| 414 |
-
"factual_error": f"Correct the factual inaccuracies in this medical answer: Question: {question}
|
| 415 |
-
"
|
| 416 |
-
"
|
| 417 |
-
"
|
| 418 |
-
"
|
| 419 |
-
"
|
|
|
|
| 420 |
}
|
| 421 |
|
| 422 |
-
# Use error-type-specific prompt
|
| 423 |
-
|
| 424 |
|
| 425 |
-
# Add evidence if available
|
| 426 |
if retrieved_docs:
|
| 427 |
evidence = "\n".join([doc for doc, _ in retrieved_docs[:2]])
|
| 428 |
-
input_text =
|
| 429 |
-
else:
|
| 430 |
-
input_text = f"{base_prompt}\n\nProvide the corrected answer:"
|
| 431 |
|
| 432 |
inputs = self.correction_tokenizer(
|
| 433 |
input_text,
|
|
|
|
| 229 |
knowledge_section = ""
|
| 230 |
|
| 231 |
return f"""{knowledge_section}Question: {question}
|
|
|
|
| 232 |
[REASONING]
|
| 233 |
I need to provide a comprehensive, evidence-based medical answer by:
|
|
|
|
| 234 |
1. **Medical Analysis**: What are the key medical concepts, conditions, or treatments involved?
|
| 235 |
2. **Evidence Review**: What does the current medical literature and provided knowledge indicate?
|
| 236 |
3. **Safety Considerations**: Are there any contraindications, warnings, or safety concerns I must address?
|
| 237 |
4. **Completeness Check**: Have I covered mechanism, treatment options, prognosis, and patient guidance?
|
| 238 |
5. **Clinical Context**: What would be most helpful for healthcare decision-making?
|
|
|
|
| 239 |
Let me work through this systematically using the medical evidence:
|
| 240 |
[/REASONING]
|
|
|
|
| 241 |
Answer:"""
|
| 242 |
|
| 243 |
def generate_rare_answer(self, question: str, retrieved_docs: List[Tuple[str, float]] = None, show_reasoning: bool = None) -> Dict[str, str]:
|
|
|
|
| 399 |
return True
|
| 400 |
|
| 401 |
def correct_answer(self, question: str, wrong_answer: str, retrieved_docs: List[Tuple[str, float]] = None, error_type: str = "unknown") -> str:
|
| 402 |
+
"""TASK 3: Enhanced correction with error-type-specific prompts matching T5 training format"""
|
| 403 |
if not hasattr(self, 'correction_model') or not self.correction_model:
|
| 404 |
return wrong_answer
|
| 405 |
|
| 406 |
try:
|
| 407 |
+
# Error-type-specific correction prompts - EXACT MATCH to T5 training data format
|
| 408 |
correction_prompts = {
|
| 409 |
+
"incomplete": f"Complete the missing information in this medical answer: Question: {question} Incorrect Answer: {wrong_answer} Error Type: incomplete Error Explanation: Missing key details about treatment options and potential side effects. Provide the correct answer:",
|
| 410 |
+
"factual_error": f"Correct the factual inaccuracies in this medical answer: Question: {question} Incorrect Answer: {wrong_answer} Error Type: factual_error Error Explanation: Contains medical inaccuracies that need correction. Provide the correct answer:",
|
| 411 |
+
"format_mismatch": f"Reformat this answer to properly address the medical question: Question: {question} Incorrect Answer: {wrong_answer} Error Type: format_mismatch Error Explanation: The generated answer does not address the original question. Provide the correct answer:",
|
| 412 |
+
"too_short": f"Complete the missing information in this medical answer: Question: {question} Incorrect Answer: {wrong_answer} Error Type: too_short Error Explanation: Answer is too brief and lacks sufficient detail. Provide the correct answer:",
|
| 413 |
+
"contradiction": f"Fix the contradictory information in this medical answer: Question: {question} Incorrect Answer: {wrong_answer} Error Type: contradiction Error Explanation: Contains contradictory medical information. Provide the correct answer:",
|
| 414 |
+
"dangerous": f"Rewrite this answer to remove dangerous medical advice: Question: {question} Incorrect Answer: {wrong_answer} Error Type: dangerous Error Explanation: Contains potentially harmful medical advice. Provide the correct answer:",
|
| 415 |
+
"too_verbose": f"Make this medical answer more concise while keeping key information: Question: {question} Incorrect Answer: {wrong_answer} Error Type: too_verbose Error Explanation: Answer is unnecessarily long and verbose. Provide the correct answer:",
|
| 416 |
+
"unknown": f"Improve this medical answer: Question: {question} Incorrect Answer: {wrong_answer} Error Type: unknown Error Explanation: General improvement needed. Provide the correct answer:"
|
| 417 |
}
|
| 418 |
|
| 419 |
+
# Use error-type-specific prompt that matches T5 training format
|
| 420 |
+
input_text = correction_prompts.get(error_type, correction_prompts["unknown"])
|
| 421 |
|
| 422 |
+
# Add evidence if available (append context like in training data)
|
| 423 |
if retrieved_docs:
|
| 424 |
evidence = "\n".join([doc for doc, _ in retrieved_docs[:2]])
|
| 425 |
+
input_text = input_text.replace("Provide the correct answer:", f"Context: {evidence} Provide the correct answer:")
|
|
|
|
|
|
|
| 426 |
|
| 427 |
inputs = self.correction_tokenizer(
|
| 428 |
input_text,
|