Chat2Scenario: Scenario Extraction From Dataset Through Utilization of Large Language Model
Yongqi Zhao Wenbo Xiao Tomislav Mihalj Jia Hu Arno Eichberger





    
Chat2Scenario: Scenario Extraction From Dataset Through Utilization of Large Language Model



This work was supported by the National Key R&D Program of China under Grant Nr. 2022YFE0117100, and by the FFG in the research project PECOP (FFG Projektnummer 893988), as part of the Bilateral Cooperation Austria - People's Republic of China / MOST 2nd Call program. Corresponding author: Wenbo Xiao (wenbo.xiao@student.tugraz.at)

    Yongqi Zhao
Institute of Automotive Engineering 

Graz University of Technology

Graz, Austria
Wenbo Xiao
Institute of Automotive Engineering 

Graz University of Technology

Graz, Austria
Tomislav Mihalj
Institute of Automotive Engineering 

Graz University of Technology

Graz, Austria
Jia Hu
College of Transportation Engineering 

Tongji University

Shanghai, China
Arno Eichberger
Institute of Automotive Engineering 

Graz University of Technology

Graz, Austria

    April 29, 2024
=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================




The advent of Large Language Models (LLM) provides new insights to validate Automated Driving Systems (ADS). In the herein-introduced work, a novel approach to extracting scenarios from naturalistic driving datasets is presented. A framework called Chat2Scenario is proposed leveraging the advanced Natural Language Processing (NLP) capabilities of LLM to understand and identify different driving scenarios. By inputting descriptive texts of driving conditions and specifying the criticality metric thresholds, the framework efficiently searches for desired scenarios and converts them into ASAM OpenSCENARIO[<https://www.asam.net/standards/detail/openscenario/>] and IPG CarMaker text files[<https://ipg-automotive.com/de/support/supportanfrage/faq/usage-of-user-inputs-from-a-file-in-a-maneuver-133/>]. This methodology streamlines the scenario extraction process and enhances efficiency. Simulations are executed to validate the efficiency of the approach. The framework is presented based on a user-friendly web app and is accessible via the following link: <https://github.com/ftgTUGraz/Chat2Scenario>.



Large Language Model, Scenario Extraction, Automated Driving Systems, Virtual Testing




§ INTRODUCTION
  It has been proven that mileage-based on-road testing is not sufficient for the validation of ADS, as Automated Vehicles (AV) must be driven billions of miles to demonstrate their reliability <cit.>. To increase testing efficiency, a scenario-based method was proposed in project PEGASUS[<https://www.pegasusprojekt.de/en/home>] aiming to expose ADS in virtual driving environments derived from the real world. However, this approach heavily relies on the measurements of real-world traffic and high-fidelity simulation platforms. Adequate measurement data of real-world traffic ensures a reliable data source; simulators provide an efficient alternative to guarantee safety, as long as it is close to reality.

In recent years, there have been intensive investigations into contributions related to high-quality, cost-effective dataset provision (cf. <cit.>) and the release of portable simulation platforms (cf. <cit.>). However, the availability of portable and publicly accessible automation tools for reconstructing the measurements within these simulation platforms has been limited. Karunakaran et al. <cit.> developed a tool for identifying and extracting lane change scenarios from LiDAR point clouds. Zhu et al. <cit.> proposed a framework for extracting ADS disengagement scenarios from AV road testing data. Montanari et al. <cit.> created a tool to extract concrete scenarios from test vehicle bus communication data based on maneuvers. Zhang et al. <cit.> introduced a toolkit to extract accident scenarios from traffic surveillance videos. However, these tools face several issues: 1) compatibility is limited to datasets that are either difficult to acquire at scale, not publicly accessible, or require extensive pre-processing; 2) the ability to extract only one type of scenario, resulting in a limited scope; 3) the inability to quantitatively evaluate the criticality of the generated scenarios; 4) the lack of open-source availability or user-friendly interfaces, making practical application laborious.



Based on the aforementioned issues, the Chat2Scenario framework is introduced. This framework incorporates the latest OpenAI LLM, gpt-4-1106-preview[<https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo>], to extract concrete scenarios from naturalistic driving datasets. In this work, the highD dataset (refer to <cit.>), comprising vehicle trajectories on German highways collected via drones, is employed. This approach is advantageous not only because addresses the issue of limited data sources but also due to the minimal requirement for pre-processing. Datasets in the same format from various locations (e.g., intersection <cit.>, roundabout <cit.>, highway exits <cit.>, university campus[<https://levelxdata.com/unid-dataset/>]) are also publicly available and can be potentially integrated into this tool.

















Subsequently, the OpenAI LLM is leveraged to interpret scenarios described in natural language, thereby broadening the range of searchable scenario types. Next, several metrics are provided to quantify the criticality of generated scenarios. Finally, the tool is delivered as a user-friendly and practical web app (see Fig. <ref>) to enhance usability. The contributions of this work are summarized as follows:


    
  * The OpenAI LLM is utilized to enhance scenario searching efficiency and expand the searchable scenario types.
    
  * Criticality metrics-based scenario filtering criterion is provided to promote the searching accuracy.
    
  * A practical and shareable web app is released to connect the naturalistic driving dataset and the simulation platform for ADS validation.


The presented framework would be useful to facilitate the process of the ADS function test. The outcome should also provide new insight for the ADS testing engineers to simplify the search and analysis of complex datasets.



§ TERMINOLOGY AND DATASET FORMAT



 §.§ Definition of Activity and Event

An Activity is defined as the minimal unit in a scenario's dynamics, representing the temporal progression of state variables, where its end signifies the commencement of the subsequent activity <cit.>. An Event indicates the time instant when a transition of state occurs, such that before and after an event, the state corresponds to two different activities <cit.>. The concepts of Event and Activity are visualized in Fig. <ref>.





 §.§ Dataset Format

The highD dataset comprises multiple recordings, each encapsulated within a CSV file. Each file encompasses a suite of vehicle trajectories, providing comprehensive details such as the data frame, vehicle ID, position, velocity, acceleration, and the current lane ID for each respective trajectory, as depicted in Tab. <ref>. The global coordinate system's origin is positioned at the upper left corner, with the horizontal and vertical axes defined as the x-axis and y-axis, respectively. Lanes within this system are sequentially numbered starting from 1, as depicted in Fig. <ref>. 

























































§ METHODOLOGY

In Fig. <ref>, it is illustrated the workflow of Chat2Scenario system. This process begins with the user uploading a dataset to the Chat2Scenario web app and entering a scenario description along with the criticality metric and threshold. LLM subsequently interprets the descriptive text of the scenario. Based on the LLM response, scenarios matching the requirements are added to the scenario pool, where their criticality is analyzed. Scenarios not meeting the threshold criteria are excluded. Finally, the selected scenarios are converted into ASAM OpenSCENARIO and IPG CarMaker text. These scenarios can be visualized via the web app. Each module in the flowchart is detailed in this section.



 §.§ Chat2Scenario Web App

The shareable web app depicted in Fig. <ref> is developed using the Python programming language and leverages the Streamlit[<https://docs.streamlit.io/library>] library. It offers a user-friendly interface that enables users to configure parameters and visually explore selected scenarios with ease.





 §.§ Scenario Understanding

In the scenario understanding module, the NLP capabilities of LLM are utilized to identify and categorize the dynamic behaviors and positions of vehicles within driving scenarios. A key factor in this process is the strategic prompt engineering, which directs the LLM to generate precise and relevant responses. In this study, the prompts provided to the LLM integrate a scenario classification model. This integration allows the LLM to interpret scenario narratives and accurately align semantic labels with a well-structured framework, transforming unstructured text into structured scenario data. Further details on the scenario classification model and the interface and the prompt engineering are elaborated in subsequent sections.



  §.§.§ Scenario Classification Model

In Fig. <ref>, the classification model for highway traffic scenarios is illustrated. This model categorizes the information into two primary sections: vehicle activity and target vehicle's position w.r.t. the ego vehicle. Vehicle activity is subdivided into longitudinal and lateral activities. Longitudinal activity pertains to velocity, with three possible states: Keep velocity, Acceleration, or Deceleration <cit.>. Lateral activity relates to the vehicle's interaction with traffic lanes, comprising Follow lane, Lane change left, or Lane change right.

The relative position of the target vehicle concerning the ego vehicle is crucial for resolving ambiguities in scenarios. For instance, consider an unspecified scenario where the ego vehicle follows the lane, and a target vehicle changes lane to the right. This situation could correspond to any scenarios depicted in Fig. <ref> - <ref>. However, if it is specified that the target vehicle begins in the left adjacent lane and ends up in front of the ego vehicle within the same lane, only the scenario in Fig. <ref> satisfies these conditions.



Target vehicles position w.r.t. ego vehicle is categorized as being in the Same Lane, Adjacent Lane, or Lane Next to Adjacent Lane. The presence of vehicles in the same or adjacent lanes is significant for the decision-making of the AV and is thus included <cit.>. Vehicles in the lane next to the adjacent lane are also considered due to their potential to merge into the ego vehicle's lane <cit.>. Vehicles in other lanes are excluded from consideration as they are unlikely to interact with the ego vehicle. Regarding the Same Lane, target vehicles are either Behind or in Front of the ego vehicle. As for the Adjacent lane, the target vehicles are situated in the Left or Right adjacent lane. The categorization is analogous for vehicles in the Lane Next to Adjacent Lane.



  §.§.§ Prompt Engineering of LLM




Prompt engineering refers to the strategic formulation of input queries to effectively guide the LLM's responses, optimizing for more accurate, relevant, and useful outputs. Informed by the six strategies from OpenAI's prompt engineering guide[<https://platform.openai.com/docs/guides/prompt-engineering>], a structured prompt for LLM optimization is proposed, as depicted in Figure <ref>. The prompt consists of five segments. The first segment, Fig. <ref>, delineates the role of the LLM as an advanced AI tool for scenario analysis, specially tasked with interpreting driving scenarios following a pre-established classification model shown in Fig. <ref>. This structured approach is designed to minimize response variability, thereby simplifying the subsequent processing. 

In Fig. <ref>, the user is required to provide a detailed description of the driving scenario as 'descriptive_text_of_scenario'. This input serves as the contextual basis for the LLM's analytical extraction.  

The details of the task are articulated in Fig. <ref>, which sets forth the expected structured response from the LLM. It is necessary to use curly braces '{}' and square brackets '[]' to systematically encapsulate the identified attributes of the scenario. In instances involving several target vehicles, the response employs a numbering system with '#' and a sequential numeral to organize the data. This structured format is imperative for the automated parsing of scenario data, thus optimizing programming efficiency.

An application of this framework is demonstrated in Fig. <ref>, providing an example of how the LLM should process a specific driving situation. It depicts an instance in which the ego vehicle maintains its velocity and lane position while another vehicle executes lane changes and accelerations. The subsequent subprompt in Fig. <ref> reinforces the analytical task, guaranteeing precision and uniformity in the results.



 §.§ Scenario Searching

The primary objective of scenario searching is to evaluate the congruence between vehicle trajectories in the datasets and the LLM's responses. This congruence assessment hinges on the identified activities of both the ego and target vehicles, as well as their relative positional relationships. The methodologies are expounded upon in the following sections.



  §.§.§ Activity Identification

The distinction between sub-categories of longitudinal activities A_lon depends on the comparison of longitudinal acceleration a_lon with a predefined acceleration threshold a_lon^thr <cit.>. This comparison must satisfy the following equation:

    A_lon(a_lon) = 
    Deceleration,    a_lon < -a_lon^thr, 
    Acceleration,    a_lon > a_lon^thr, 
    Keep velocity,   otherwise.


The variation in lane ID, denoted as (ΔL), indicates lateral activities A_lat and helps in identifying lane changes. Additionally, the vehicle's longitudinal velocity (v_lon), in relation to the x-axis, determines the direction of the change, whether left or right. This is quantified by the following equation:

    A_lat = 
    Follow lane,    Δ L = 0, 
    Lane change right,     (Δ L > 0  and  v_lon > 0)  or 
        (Δ L < 0  and  v_lon < 0),
    Lane change left,     (Δ L < 0 and v_lon > 0) or
       (Δ L > 0 and v_lon < 0).




  §.§.§ Position Identification

The relative position of the target vehicle w.r.t. the ego vehicle, denoted as P_tgt^ego, can be determined by the absolute value of the lane ID difference between the target and ego vehicles, given by Δ L_ego^tgt, which is the modulus of the difference in lane IDs, L_tgt - L_ego, and the position difference along the x-axis, Δ x.

For situations where v_lon < 0, the position P_tgt^ego should satisfy the following conditions:


    P_tgt^ego =
    {[                                         Front,                  Δ L_ego^tgt = 0  and Δ x < 0,;                                        Behind,                  Δ L_ego^tgt = 0  and Δ x > 0,;                            Left adjacent lane,                               Δ L_ego^tgt = 1,;                           Right adjacent lane,                              Δ L_ego^tgt = -1,;   [    Lane next to the; left adjacent lane, ]                               Δ L_ego^tgt = 2,; [     Lane next to the; right adjacent lane, ]                              Δ L_ego^tgt = -2.;                                                ].


Similarly, when v_lon > 0, the position P_tgt^ego is defined by:

    P_tgt^ego =
    {[                                         Front,                  Δ L_ego^tgt = 0  and Δ x > 0,;                                        Behind,                  Δ L_ego^tgt = 0  and Δ x < 0,;                            Left adjacent lane,                              Δ L_ego^tgt = -1,;                           Right adjacent lane,                               Δ L_ego^tgt = 1,;   [    Lane next to the; left adjacent lane, ]                              Δ L_ego^tgt = -2,; [     Lane next to the; right adjacent lane, ]                               Δ L_ego^tgt = 2.;                                                ].




 §.§ Criticality Analysis


The scenario pool may encompass a multitude of scenarios that correspond to the input descriptive text. To quantitatively ascertain the scenarios most pertinent to the testing task, their criticalities must be evaluated. Consequently, this study incorporates some metrics summarized by Westhofen et al. <cit.> for assessing scenario criticality. 



A further consideration is determining which scenes within a scenario warrant criticality analysis. In this work, criticality is computed exclusively for the scenario segments where both the ego and target vehicles' activities and their relative positions are satisfied. For example, in the scenario depicted in Fig. <ref>, criticality is assessed from t_1 to t_2, as shown in Fig. <ref>. The criticality metrics utilized in Chat2Scenario are cataloged in Table <ref>. 





 §.§ Simulatable Format Generation

The Chat2Scenario platform facilitates the generation of scenarios in two formats: ASAM OpenSCENARIO and IPG CarMaker text. 


  §.§.§ ASAM OpenSCENARIO

The OpenSCENARIO files, generated using the scenariogeneration[<https://github.com/pyoscx/scenariogeneration>] Python package, are compatible with multiple simulators, including Esmini <cit.> and CARLA <cit.>. The XML schema is utilized for defining the scenarios in OpenSCENARIO. In this work, scenarios are reconstructed in Esmini based on vehicular trajectories. This process involves specifying a Vertex for each timestamp, illustrated in Fig. <ref>. For each Vertex, the vehicle's WorldPosition is delineated, with coordinates (x, y, z) derived directly from the dataset. Regarding the attitude, the heading angle (h) is constrained to 0 or π radians, reflecting the road's alignment with the x-axis. Both pitch (p) and roll (r) angles are set to 0 radians by default. 





  §.§.§ IPG CarMaker Text

The IPG CarMaker text format is tailored to incorporate real-world measurements of vehicle maneuvers into the CarMaker simulation environment. As depicted in Fig. <ref>, the format begins with a timestamp in the first column. Successive columns record the vehicle's global position coordinates - longitudinal (x) and lateral (y) positions. The initial row captures the vehicle's position at the scene's start, with a timestamp of zero and 162 as the vehicle's identifier. In scenarios with multiple vehicles, their data are adjacently aligned, employing unique identifiers for each. Notably, this format is applied solely to non-ego vehicles. Regarding the ego vehicle, the trajectory is defined on the road network through the edition of UserPath.Nodes. More details are available in the IPGRoad document <cit.>.





§ RESULT AND DISCUSSION




 §.§ Qualitative Evaluation




The framework Chat2Scenario is validated through the extraction of three typical driving scenarios: following, cut-in, and cut-out scenarios. These scenarios are pivotal in testing ADS due to their frequency of occurrence and potential risk in daily driving. The following scenario tests the ADS capability to maintain safe following distances and respond to varying speeds of traffic. The cut-in and cut-out scenarios are critical for evaluating an ADS's lane-changing and overtaking strategies, as they involve the ego vehicle's reaction to other vehicles. These scenarios are successfully extracted from the dataset and reconstructed in Esmini and CarMaker, as detailed in Tab.<ref>. 



 §.§ Quantitative Evaluation


In the highD dataset, ground truth labels for various scenarios are absent. To address this gap, semantic labels are manually generated through an analysis facilitated by a MATLAB-based visualization tool[<https://github.com/RobertKrajewski/highD-dataset>]. Given the intensive nature of the work, only one file - track #36, which lasts about 27 minutes - is randomly selected from a total of 60 files for detailed analysis. In the labeling process, human driving experiences are used, but the vehicle's longitudinal activities are excluded due to the difficulty of manual identification from animated data. The quality of these labels is further verified by an independent reviewer. The effectiveness of the Chat2Scenario tool is assessed by comparing its outputs with the ground truth of track #36, and the results are presented in Tab. <ref>. 



For the following scenario, a promising level of precision is demonstrated; however, this is mitigated by a significant rate of false negative, which can be attributed to the exclusion of scenarios that fall below the predefined duration threshold. In terms of the cut-in and cut-out scenarios, the values across all metrics indicate a robust competence in effectively identifying these scenarios. Overall, the capabilities of Chat2Scenario for scenario identification are substantiated by the quantitative metrics presented in the table.



§ CONCLUSION AND FUTURE WORK


This paper has introduced Chat2Scenario, a publicly accessible web app that advances the extraction of concrete scenarios from naturalistic driving datasets. The platform interprets scenario descriptions in natural language and evaluates their criticality with precision, thereby streamlining the scenario generation process. The validity and the practicality of Chat2Scenario are substantiated through simulations in Esmini and CarMaker.

Comprehensive validation of the framework is to be primarily focused upon in future work to ensure its robustness and reliability. Additionally, the expansion of dataset diversity and the refinement of criticality metrics for customized evaluation are also planned.



§ ACKNOWLEDGMENT


The authors would like to thank Dr. Hexuan Li for the discussion during the conception phase, Faris Orucevic for the technical support about CarMaker, and Zhengyu Wang for generating the ground truth labels.

ieeetr

