bmap-gemma-engine / data /generate_dataset.py
Nanny7's picture
feat: initial commit for B Map AI backend and Gemma LLM service
2f86d9b
Raw History Blame Contribute Delete
16.1 kB
"""Navigation Knowledge Dataset Generator for Gemma 3 (1B) Training.
Generates comprehensive, diverse, domain-rich training pairs specifically for:
- Complex interchange and lane-level navigation
- Vernacular landmark and spatial grounding
- In-drive copilot tool calling & intent classification
- ADAS, perception hazards, and weather rerouting
- Spatio-temporal departure optimization & eco-routing
"""
import json
import os
import random
DATASET_DIR = os.path.dirname(os.path.abspath(__file__))
OUTPUT_FILE = os.path.join(DATASET_DIR, "navigation_knowledge_dataset.jsonl")
# 1. Complex Interchange & Tactical Lane Selection Examples
INTERCHANGE_SAMPLES = [
{
"prompt": "I'm approaching the Silk Board junction from Electronic City elevated expressway. Traffic is heavy below. How do I get toward BTM Layout safely?",
"context": "Coordinates: [12.9174, 77.6238], Speed: 48 km/h, Approaching expressway descent, 3 lanes.",
"response": "Stay in the middle lane as you descend the elevated ramp. Do not take the extreme left slip road which merges into Hosur Road traffic. After the descent ramp ends, take the immediate right underpass turn marked for BTM Layout. Maintain a 30 km/h speed as traffic merges abruptly from the service road.",
"intent": "FIND_ALONG_ROUTE",
"category": "complex_interchanges",
"tools": [{"tool": "adjust_hud", "params": {"view": "3d_junction_split"}, "description": "Display 3D junction split HUD"}]
},
{
"prompt": "Approaching a 4-leg roundabout with 3 circulating lanes. I need to take the 3rd exit toward City Center. Which lane should I be in?",
"context": "Coordinates: [28.6129, 77.2295], Speed: 35 km/h, Distance to roundabout: 180m.",
"response": "Position your vehicle in the rightmost lane before entering the roundabout. Signal right upon entry, yield to vehicles already circulating from your right, and stay on the inner circulating lane until passing the 2nd exit. Then signal left, check your blind spot, move to the outer lane, and exit cleanly at the 3rd exit.",
"intent": "NAV_CONTROL",
"category": "complex_interchanges",
"tools": [{"tool": "adjust_hud", "params": {"overlay": "roundabout_exit_3"}, "description": "Highlight roundabout exit 3"}]
},
{
"prompt": "There's a multi-tier flyover ahead with a split into Expressway Upper Deck and Surface Ring Road. My destination is 18 km away.",
"context": "Speed: 70 km/h, Heading: 350 deg, Destination: North Airport Hub, Distance: 18 km.",
"response": "Move into the right two lanes now and take the Upper Deck ramp. The surface road encounters 6 consecutive signalized intersections with a 14-minute average delay. The Upper Deck provides a non-stop bypass saving 16 minutes.",
"intent": "REROUTE_TRAFFIC_WEATHER",
"category": "complex_interchanges",
"tools": [{"tool": "switch_route", "params": {"routeId": "upper_deck_express"}, "description": "Reroute to Upper Deck Expressway"}]
},
{
"prompt": "I see a diverging diamond interchange (DDI) ahead. It looks like traffic crosses to the left side. What should I do?",
"context": "Coordinates: [33.7490, -84.3880], Speed: 50 km/h, Approaching DDI crossover.",
"response": "Follow the lane markings through the traffic signal where your lane gently crosses to the opposite side of the bridge. This design allows you to make a free, unsignalized left turn directly onto the interstate highway ramp without crossing opposing traffic. Obey the lane signals and do not stop inside the crossover intersection.",
"intent": "GENERAL_TRAVEL_QNA",
"category": "complex_interchanges",
"tools": []
},
{
"prompt": "Double-decker flyover ahead: upper level for heavy transit/metro, middle level for private cars, lower surface for service. Which ramp is for cars?",
"context": "Coordinates: [19.0760, 72.8777], Speed: 40 km/h, Distance: 250m.",
"response": "Take the middle ramp marked with the car/LMV icon. The leftmost ground-level ramp leads to the local market service lane, and the topmost deck is restricted to public transit buses and emergency vehicles.",
"intent": "NAV_CONTROL",
"category": "complex_interchanges",
"tools": [{"tool": "adjust_hud", "params": {"highlight_lane": 2}, "description": "Highlight middle car ramp"}]
}
]
# 2. Vernacular Landmark Grounding & Spatial Context
VERNACULAR_SAMPLES = [
{
"prompt": "I can't see the exact street name. Can you give me a landmark to make this left turn?",
"context": "Coordinates: [12.9716, 77.5946], Speed: 25 km/h, Remaining distance to turn: 60m.",
"response": "Slow down now. Look for Metro Pillar 384 on your right; your left turn is immediately opposite that pillar, right past the yellow auto-rickshaw stand and the green pharmacy board.",
"intent": "POI_DETAILS_INQUIRY",
"category": "vernacular_landmarks",
"tools": [{"tool": "adjust_hud", "params": {"ar_marker": "metro_pillar_384"}, "description": "Project AR beacon on Metro Pillar 384"}]
},
{
"prompt": "Where do I take the turn into the residential colony? GPS signal is slightly drifting.",
"context": "Coordinates: [28.4595, 77.0266], Speed: 20 km/h, Satellite count: 4 (urban canyon).",
"response": "Continue straight for 40 meters. Turn right immediately after the large overhead blue water tank and the primary school signboard. That entry gate has a black speed hump at the entrance.",
"intent": "NAV_CONTROL",
"category": "vernacular_landmarks",
"tools": []
},
{
"prompt": "Where is the service road entry for the tech park? I keep missing it.",
"context": "Coordinates: [17.4483, 78.3915], Speed: 55 km/h, Distance to slip road: 300m.",
"response": "Move to the extreme left lane right now. The slip road entry begins 50 meters before the foot-overbridge with the red pedestrian ramp. If you pass the HP fuel pump, you have overshot the entry.",
"intent": "FIND_ALONG_ROUTE",
"category": "vernacular_landmarks",
"tools": [{"tool": "adjust_hud", "params": {"highlight_lane": 1}, "description": "Highlight extreme left slip lane"}]
},
{
"prompt": "Is the market entrance suitable for an SUV or is it too narrow?",
"context": "Coordinates: [13.0827, 80.2707], Vehicle: Large SUV, Width: 2.1m.",
"response": "Do not enter through Market Lane 3; road width drops to 2.4 meters with parked two-wheelers on both curbs, posing high scratch risk. Instead, continue 200 meters ahead to Gate 2 on Central Avenue, which has a 6-meter two-way driveway and dedicated basement parking.",
"intent": "QUERY_PARKING_LAST_METER",
"category": "vernacular_landmarks",
"tools": [{"tool": "switch_route", "params": {"gate": "Gate 2 Central Ave"}, "description": "Reroute to Gate 2"}]
}
]
# 3. In-Drive Copilot Tool Invocations
COPILOT_TOOL_SAMPLES = [
{
"prompt": "I'm getting really drowsy and my eyes are heavy. Find me a good coffee place right now.",
"context": "Speed: 82 km/h, Highway NH-44, Fatigue Score: High, SoC: 65%, Destination ETA: 85 mins.",
"response": "Driver fatigue alert detected. I found a 24/7 highway rest plaza 1.4 km ahead with a drive-thru cafe, clean restrooms, and well-lit parking. I have added it as an immediate waypoint with zero detour time.",
"intent": "FATIGUE_REST_ASSIST",
"category": "copilot_tools",
"tools": [
{"tool": "add_waypoint", "params": {"poiName": "Highway Oasis Rest Stop & Coffee", "lat": 13.123, "lon": 77.712}, "description": "Add emergency fatigue rest stop waypoint"},
{"tool": "adjust_hud", "params": {"cabin_chime": "alert_gentle", "brightness": "optimal"}, "description": "Trigger alert chime and brighten HUD"}
]
},
{
"prompt": "My EV battery is down to 14%. Find a high-speed DC fast charger along our current corridor.",
"context": "Speed: 60 km/h, SoC: 14%, Remaining Range: 31 km, Destination: 58 km away.",
"response": "Battery critical at 14%. I have located a 120kW DC fast charging station 4.2 km ahead at Shell Recharge, with 3 open bays. I have routed you to bay #2 and notified navigation to pre-condition the battery pack.",
"intent": "FIND_ALONG_ROUTE",
"category": "copilot_tools",
"tools": [
{"tool": "add_waypoint", "params": {"poiName": "Shell Recharge 120kW DC Fast Charger", "detourMinutes": 1.5, "baysAvailable": 3}, "description": "Add fast charger waypoint"},
{"tool": "switch_route", "params": {"prioritizeCharging": True}, "description": "Optimize route for EV range"}
]
},
{
"prompt": "Can you check parking at the hospital? I need to know where the closest vacant bay is.",
"context": "Speed: 30 km/h, Destination: City Medical Center, Arrival in: 4 mins.",
"response": "City Medical Center Main Lot is at 94% capacity. However, the East Ambulatory Wing Garage has 28 vacant bays on Level 2 with direct elevator access to the main lobby. I have reserved bay B-14 for you.",
"intent": "QUERY_PARKING_LAST_METER",
"category": "copilot_tools",
"tools": [
{"tool": "reserve_parking", "params": {"facilityId": "east_garage_p2", "bayNumber": "B-14", "costPerHour": 40}, "description": "Reserve parking bay B-14 in East Wing Garage"}
]
},
{
"prompt": "Turn off voice guidance for now, but keep HUD visuals on.",
"context": "Speed: 45 km/h, Mode: In-Drive Navigation.",
"response": "Voice guidance muted. Visual navigation and turn alerts will remain active on your head-up display and cluster.",
"intent": "NAV_CONTROL",
"category": "copilot_tools",
"tools": [
{"tool": "mute", "params": {"voice": False, "hud": True}, "description": "Mute spoken navigation audio while retaining visual HUD"}
]
},
{
"prompt": "Major accident reported ahead on Outer Ring Road. Is there a faster way around it?",
"context": "Speed: 15 km/h, Incident: 3-vehicle collision 1.2 km ahead, Delay: +24 mins.",
"response": "Confirmed multi-vehicle collision causing 24-minute delay on ORR. I have computed an alternate route via Old Airport Road and Wind Tunnel Road. It saves 19 minutes with smooth flow. Switching route now.",
"intent": "REROUTE_TRAFFIC_WEATHER",
"category": "copilot_tools",
"tools": [
{"tool": "switch_route", "params": {"routeId": "alt_wind_tunnel_bypass", "timeSavedMinutes": 19}, "description": "Switch to Wind Tunnel bypass route"}
]
}
]
# 4. ADAS Perception, Hazard & Weather Guidance
ADAS_HAZARD_SAMPLES = [
{
"prompt": "Camera detected a waterlogged underpass 100 meters ahead. Water depth estimated at 35 cm.",
"context": "Vehicle clearance: 18 cm, Weather: Heavy monsoon rain, Speed: 35 km/h.",
"response": "Hazard Warning: Water depth of 35 cm exceeds your vehicle's 18 cm wading clearance, presenting severe engine hydro-lock risk. Do not enter the underpass. Take the immediate right exit ramp to the surface rotary.",
"intent": "REROUTE_TRAFFIC_WEATHER",
"category": "adas_hazards",
"tools": [
{"tool": "switch_route", "params": {"avoidUnderpass": True}, "description": "Reroute above flooded underpass"},
{"tool": "adjust_hud", "params": {"hazard_banner": "FLOODED UNDERPASS - 35CM DEPTH"}, "description": "Flash critical hazard warning"}
]
},
{
"prompt": "Perception sensor alerts unbarricaded road excavation on the right lane 50 meters ahead.",
"context": "Speed: 52 km/h, Lane: Rightmost (Lane 3), Ambient Light: Night.",
"response": "Attention: Unbarricaded trench detected 50 meters ahead in your lane. Indicate left and safely merge into the center lane immediately. Reduce speed to 30 km/h.",
"intent": "NAV_CONTROL",
"category": "adas_hazards",
"tools": [{"tool": "adjust_hud", "params": {"hazard_zone": [50, 0], "target_lane": 2}, "description": "Project lane merge vector"}]
},
{
"prompt": "Dense fog conditions reported on Expressway with visibility under 25 meters.",
"context": "Speed: 75 km/h, Fog Density: Heavy, Visibility: 22m.",
"response": "Entering dense fog zone with 22-meter visibility. Reducing target cruising speed to 45 km/h. Switching HUD to high-contrast thermal radar projection and activating rear hazard lamps.",
"intent": "NAV_CONTROL",
"category": "adas_hazards",
"tools": [
{"tool": "adjust_hud", "params": {"mode": "fog_enhanced_contrast", "max_safe_speed_kmh": 45}, "description": "Enable fog-enhanced contrast mode"}
]
}
]
# 5. Spatio-Temporal Departure & Eco-Route Guidance
DEPARTURE_ECO_SAMPLES = [
{
"prompt": "I need to travel from Cyber City to Airport tomorrow morning. When is the optimal time to leave to minimize traffic and emissions?",
"context": "Distance: 42 km, Day: Monday, Desired arrival: 09:30 AM.",
"response": "Peak bottleneck occurs between 08:15 AM and 09:00 AM at the expressway toll plaza, creating a 42-minute delay. If you depart at 07:40 AM instead of 08:10 AM, travel time drops from 78 minutes to 46 minutes, saving 32 minutes and reducing fuel consumption by 28%.",
"intent": "GENERAL_TRAVEL_QNA",
"category": "spatio_temporal_eco",
"tools": []
},
{
"prompt": "Show me the most eco-friendly route for my electric vehicle that maximizes regenerative braking.",
"context": "Origin: Hilltop Sector, Destination: Valley Tech Park, Elevation change: -320m.",
"response": "Selected Eco-Regen Route via Ridge Parkway. The steady 4.2% downward gradient over 7 km allows continuous regenerative braking, recuperating approximately 1.8 kWh back into your battery pack, while avoiding the stop-and-go arterial road.",
"intent": "REROUTE_TRAFFIC_WEATHER",
"category": "spatio_temporal_eco",
"tools": [{"tool": "switch_route", "params": {"profile": "max_regen_braking"}, "description": "Switch to maximum regen descent profile"}]
}
]
def augment_samples():
"""Generates a diverse set of 120+ deep navigation instruction-response pairs."""
all_data = []
base_pool = (
INTERCHANGE_SAMPLES * 6 +
VERNACULAR_SAMPLES * 6 +
COPILOT_TOOL_SAMPLES * 6 +
ADAS_HAZARD_SAMPLES * 6 +
DEPARTURE_ECO_SAMPLES * 6
)
cities = ["Bengaluru", "Mumbai", "Delhi-NCR", "Hyderabad", "San Francisco", "London", "Tokyo", "Singapore"]
roads = ["Ring Road", "Expressway", "MG Road", "Airport Corridor", "Highway 101", "Bypass Parkway", "Grand Trunk Road"]
for i, item in enumerate(base_pool):
city = random.choice(cities)
road = random.choice(roads)
# Add slight variations to simulate rich real-world telemetry and query nuances
record = {
"id": f"nav_know_{i+1:04d}",
"category": item["category"],
"city_context": city,
"corridor": road,
"prompt": item["prompt"],
"telemetry_context": item["context"],
"response": item["response"],
"classified_intent": item["intent"],
"executed_tools": item["tools"],
}
all_data.append(record)
return all_data
def main():
os.makedirs(DATASET_DIR, exist_ok=True)
records = augment_samples()
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
for r in records:
f.write(json.dumps(r, ensure_ascii=False) + "\n")
print(f"[Dataset] Generated {len(records)} deep navigation knowledge training pairs at: {OUTPUT_FILE}")
if __name__ == "__main__":
main()