WorldDisasterLM-8B / worlddisasterlm /data /scenario_builder.py
drdeveloper88's picture
Add usage code example (from_pretrained + BitsAndBytes + multilingual) to README
3b9fcc7
Raw
History Blame Contribute Delete
12 kB
"""
Synthetic emergency scenario builder.
Generates multi-turn conversations, role-play scenarios, and cross-hazard
compound disaster samples to enrich training diversity.
"""
from worlddisasterlm.data.schemas import InstructionSample
COMPOUND_SCENARIOS = [
{
"scenario": "An earthquake of magnitude 7.2 struck a coastal city causing building collapses, "
"followed 45 minutes later by a tsunami warning.",
"region": "Pacific coastal city",
"event_type": "compound: earthquake + tsunami",
"severity": "critical",
"response": (
"Compound Disaster Response — Earthquake + Tsunami:\n\n"
"IMMEDIATE (0–15 min):\n"
"1. Issue tsunami warning and mandatory coastal evacuation order immediately.\n"
"2. Search and rescue operations for earthquake-trapped victims must start inland first.\n"
"3. Hospitals on high ground remain operational; coastal facilities evacuate patients.\n\n"
"SHORT-TERM (15 min – 6 hours):\n"
"4. Establish triage stations above tsunami inundation zone.\n"
"5. Account for all search and rescue teams before wave arrival.\n"
"6. Deploy helicopters for coastal cliff rescues post-wave.\n\n"
"CRITICAL NOTE: Aftershocks will compromise already-damaged structures. "
"Do not re-enter buildings until structural engineers clear them."
),
},
{
"scenario": "A category 4 hurricane is forecast to make landfall in 48 hours. "
"The region already has 30,000 displaced persons from last week's flooding.",
"region": "Caribbean island",
"event_type": "compound: hurricane + displaced persons",
"severity": "critical",
"response": (
"Compound Emergency — Hurricane Landfall with Pre-existing Displacement:\n\n"
"PRE-LANDFALL (48–24 hours):\n"
"1. Mandatory evacuation of all existing displacement camps in low-lying areas.\n"
"2. Identify inland strong buildings for mass shelter; assess capacity.\n"
"3. Pre-position 72-hour food and water supplies at inland shelters.\n"
"4. Coordinate with UNHCR and local government for camp-to-shelter transfers.\n\n"
"PRE-LANDFALL (24–0 hours):\n"
"5. All personnel secured; close airport; ban sea transport.\n"
"6. Emergency services on stand-by in hardened facilities.\n\n"
"POST-LANDFALL:\n"
"7. Damage assessment sweep before re-opening any displaced camp.\n"
"8. Restore access roads before relief convoy mobilization."
),
},
{
"scenario": "During a wildfire evacuation, a fuel tanker overturned on the primary "
"evacuation highway, blocking egress for 15,000 evacuees.",
"region": "Southern California",
"event_type": "compound: wildfire + infrastructure failure",
"severity": "critical",
"response": (
"Multi-Hazard Evacuation Disruption — Wildfire + Road Blockage:\n\n"
"1. Activate alternate evacuation routes immediately; publish via Emergency Alert System.\n"
"2. Dispatch hazmat team to fuel tanker — assess fire ignition risk before moving vehicle.\n"
"3. If tanker poses fire risk: keep 300m standoff; use bulldozer to open shoulder lane.\n"
"4. Coordinate law enforcement for contraflow on alternate highways.\n"
"5. Deploy CHP and National Guard for traffic management at choke points.\n"
"6. Air resources pivot to aerial evacuation for mobility-impaired stranded persons.\n"
"7. Communicate updated routes every 15 minutes via radio, app, and social media."
),
},
]
MULTILINGUAL_SAMPLES = [
{
"lang": "Nepali",
"instruction": "भूकम्पको बेला के गर्ने?",
"output": (
"भूकम्पको बेला:\n"
"१. तुरुन्त झुक्नुहोस्, ढाक्नुहोस् र समात्नुहोस् (Drop, Cover, Hold On)।\n"
"२. झ्याल, ऐना र भारी सामानबाट टाढा रहनुहोस्।\n"
"३. बाहिर हुनुहुन्छ भने खुला ठाउँमा जानुहोस् — भवन, रुख र बिजुलीका तारबाट टाढा।\n"
"४. हल्लाउन बन्द भएपछि चोटपटक जाँच गर्नुहोस् र सावधानीसाथ बाहिर निस्कनुहोस्।\n"
"५. परकम्पको लागि तयार रहनुहोस्।\n"
"गम्भीर घाइतेको लागि तुरुन्त आपतकालीन सेवा (१०१ वा स्थानीय नम्बर) मा फोन गर्नुहोस्।"
),
},
{
"lang": "Nepali",
"instruction": "बाढीको बेला के गर्ने?",
"output": (
"बाढीको बेला:\n"
"१. तुरुन्त अग्लो ठाउँमा जानुहोस् — निकासी आदेशको प्रतीक्षा नगर्नुहोस्।\n"
"२. बाढीको पानीमा नहिँड्नुहोस् वा गाडी नचलाउनुहोस् — ६ इन्च पानीले पनि गिराउन सक्छ।\n"
"३. बिजुलीका उपकरणहरू बन्द गर्नुहोस्।\n"
"४. स्थानीय अधिकारीको निकासी मार्ग पछ्याउनुहोस्।\n"
"५. आधिकारिक अलर्टको लागि रेडियो सुन्नुहोस्।\n"
"खतरामा परेमा तुरुन्त आपतकालीन सेवामा सम्पर्क गर्नुहोस्।"
),
},
{
"lang": "Nepali",
"instruction": "विपद् व्यवस्थापनको लागि आधारभूत तयारी के के गर्नुपर्छ?",
"output": (
"विपद् तयारीका आधारभूत कदमहरू:\n"
"१. परिवारको आपतकालीन योजना बनाउनुहोस् र अभ्यास गर्नुहोस्।\n"
"२. ७२ घण्टाको आपतकालीन किट तयार राख्नुहोस्: पानी, खाना, औषधि, कागजात।\n"
"३. निकासी मार्ग र नजिकको आश्रयस्थलको जानकारी राख्नुहोस्।\n"
"४. समुदायको पूर्व चेतावनी प्रणालीमा सहभागी हुनुहोस्।\n"
"५. विद्यालय, कार्यस्थल र समुदायमा नियमित अभ्यास गर्नुहोस्।\n"
"राष्ट्रिय विपद् जोखिम न्यूनीकरण तथा व्यवस्थापन प्राधिकरण (NDRRMA) को निर्देशिका पालना गर्नुहोस्।"
),
},
{
"lang": "Spanish",
"instruction": "¿Qué debo hacer durante un terremoto?",
"output": (
"Durante un terremoto:\n"
"1. Agáchese, cúbrase y sujétese (Drop, Cover, Hold On).\n"
"2. Aléjese de ventanas, espejos y objetos pesados.\n"
"3. Si está en el exterior, diríjase a un espacio abierto.\n"
"4. Después del sismo, verifique heridos y salga con cuidado.\n"
"5. Esté preparado para réplicas.\n"
"Llame al número de emergencias de su país para reportar heridos graves."
),
},
{
"lang": "French",
"instruction": "Quelles sont les étapes à suivre en cas d'inondation ?",
"output": (
"En cas d'inondation :\n"
"1. Montez immédiatement en hauteur – ne restez pas au niveau du sol.\n"
"2. N'essayez jamais de traverser des eaux en crue, même à pied.\n"
"3. Coupez l'électricité et le gaz si c'est sans danger.\n"
"4. Suivez les consignes d'évacuation des autorités locales.\n"
"5. Appelez les secours si vous êtes en danger immédiat.\n"
"Restez à l'écoute des alertes officielles."
),
},
{
"lang": "Arabic",
"instruction": "ما هي الخطوات الواجب اتخاذها أثناء الإعصار؟",
"output": (
"أثناء الإعصار:\n"
"١. ابق في الداخل بعيداً عن النوافذ والأبواب الزجاجية.\n"
"٢. اذهب إلى الطابق الأرضي أو الغرفة الداخلية دون نوافذ.\n"
"٣. لا تخرج لأن عين الإعصار تبدو هادئة لكنها مؤقتة.\n"
"٤. استمع إلى تعليمات الدفاع المدني عبر الراديو أو التليفزيون.\n"
"٥. ابتعد عن مجاري المياه والمناطق المنخفضة بعد مرور الإعصار."
),
},
{
"lang": "Hindi",
"instruction": "बाढ़ के दौरान क्या करें?",
"output": (
"बाढ़ के दौरान:\n"
"1. तुरंत ऊंची जगह पर जाएं।\n"
"2. बाढ़ के पानी में न चलें—6 इंच पानी भी गिरा सकता है।\n"
"3. बिजली के उपकरण बंद करें।\n"
"4. आधिकारिक निकासी मार्ग का पालन करें।\n"
"5. आपातकालीन अलर्ट के लिए रेडियो सुनें।\n"
"खतरे में होने पर तुरंत आपातकालीन सेवा को कॉल करें।"
),
},
]
def build_compound_scenarios() -> list[InstructionSample]:
samples: list[InstructionSample] = []
for scene in COMPOUND_SCENARIOS:
samples.append(
InstructionSample(
instruction="Provide a comprehensive emergency response plan for this compound disaster scenario.",
input=(
f"Scenario: {scene['scenario']}\n"
f"Region: {scene['region']}\n"
f"Event type: {scene['event_type']}\n"
f"Severity: {scene['severity']}"
),
output=scene["response"],
)
)
return samples
def build_multilingual_samples() -> list[InstructionSample]:
samples: list[InstructionSample] = []
for item in MULTILINGUAL_SAMPLES:
samples.append(
InstructionSample(
instruction=item["instruction"],
input="",
output=item["output"],
language=item["lang"],
)
)
return samples
def build_all_scenarios() -> list[InstructionSample]:
return build_compound_scenarios() + build_multilingual_samples()