Traffic question and answer method, device and equipment based on large language model and medium
By pre-constructing a knowledge graph in the field of traffic safety and dividing the question text into sub-question texts, the existing question-and-answer methods have solved the problem with poor accuracy in the transportation field, and achieved higher question-and-answer accuracy and reliability.
Patent Information
- Application Number
- CN202411981898.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-27
AI Technical Summary
The existing question-and-answer methods have poor answer accuracy in the field of transportation, and there are problems such as inaccurate knowledge 'illusion' problems and inaccurate target retrieval and excessive redundant information.
By pre-constructing a traffic safety knowledge graph, the problem text is divided into multiple sub-question texts, the target entity with the highest similarity corresponding to the sub-question text and the target sub-graph of the first-order relationship, and the information is input into the large language model to improve the accuracy of question and answer.
By dividing the question text into sub-question text and combining the traffic safety knowledge graph, the accuracy of the question and answer is significantly improved, ensuring the reliability of the sub-answer text and the target answer text.
Smart Images

Figure CN120045655A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of natural language processing, and in particular, to a traffic question-answering method, device, equipment and medium based on a large language model. Background Art
[0002] The breakthrough of the large language model technology LLM has made it possible for natural and efficient interaction in the transportation industry, especially showing efficient anthropomorphic interaction capabilities in professional knowledge consultation and answering. Since the basic large language model often does not have knowledge in vertical industry fields, in order to improve the reliability of question answering, researchers generally adopt the Retrieval Augmented Generation (RAG) technology, which recalls the domain knowledge most relevant to the user's question and transmits it to the context window, so as to improve the large model's perception ability of professional domain knowledge.
[0003] However, the LLM and RAG technologies themselves have capacity defects. Among them, the LLM inevitably has the problem of knowledge "hallucination", which greatly reduces the application reliability in large-scale real scenarios. In addition, the RAG technology generally recalls similar segments through vector similarity, which is prone to problems such as inaccurate target retrieval and excessive redundant information. And the context window size of the LLM itself is limited, which may cause the problem that the most relevant knowledge cannot be transmitted due to excessive redundant information, resulting in unreliable answer effects. Summary of the Invention
[0004] This application provides a traffic question-answering method, device, equipment and medium based on a large language model to solve the problem of poor answer accuracy of existing question-answering methods.
[0005] In a first aspect, this application provides a traffic question-answering method based on a large language model, and the method includes:
[0006] Obtain the question text, and divide the question text into multiple sub-question texts; for the multiple sub-question texts, determine the target entity with the highest similarity corresponding to the sub-question text in a pre-constructed traffic safety knowledge graph; determine the target sub-graph in the traffic safety knowledge graph that has a first-order relationship with the target entity;
[0007] For the multiple sub-question texts, input the sub-question texts, the entities and relationships in the corresponding target sub-graph, and traffic long text data into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model;
[0008] Input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and determine the target answer text corresponding to the question text based on the large language model.
[0009] The above technical solution has the following advantages or beneficial effects:
[0010] In this application, a traffic safety knowledge graph is pre-constructed. After dividing the problem text into multiple sub-problem texts, for the multiple sub-problem texts, the target entity with the highest similarity corresponding to the sub-problem text in the traffic safety knowledge graph is determined; and the target sub-graph with a first-order relationship with the target entity is determined. Among them, the sub-problem text and each entity in the traffic safety knowledge graph are respectively converted into semantic vectors through the open-source embedding model embed; then the target entity with the highest similarity corresponding to the sub-problem text is determined through the similarity of the semantic vectors. Then, for the multiple sub-problem texts, the sub-problem text, the entities and relationships in the corresponding target sub-graph, and the traffic long text data are input into the large language model, and the sub-answer text corresponding to the sub-problem text is determined based on the large language model. Finally, the problem text, the multiple sub-problem texts, and the corresponding sub-answer texts are input into the large language model, and the target answer text corresponding to the problem text is determined based on the large language model. This application divides the problem text into multiple sub-problem texts, combines the traffic safety knowledge graph and the traffic long text data, and determines the sub-answer text corresponding to the sub-problem text based on the large language model. Thus, the accuracy of the determined sub-answer text is ensured. Furthermore, by combining the problem text, the multiple sub-problem texts, and the corresponding sub-answer texts, the target answer text corresponding to the problem text is determined based on the large language model. Thus, the accuracy of the determined target answer text is ensured.
[0011] In an alternative implementation, the process of determining the sub-answer text corresponding to the sub-problem text based on the large language model includes:
[0012] According to the preset number of text block characters and the number of overlapping characters between adjacent text blocks, the traffic long text data is divided into each text block;
[0013] For the multiple sub-problem texts, the target text block with the highest similarity corresponding to the sub-problem text is determined;
[0014] The sub-problem text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block are input into the large language model, and the sub-answer text corresponding to the sub-problem text is determined based on the large language model.
[0015] The above technical solution has the following advantages or beneficial effects:
[0016] In this application, first, according to the preset number of characters in the text block and the number of overlapping characters between adjacent text blocks, the traffic long text data is divided into each text block; then, for multiple sub-question texts, the target text block with the highest similarity corresponding to the sub-question text is determined. Among them, the sub-question text and each text block are respectively converted into semantic vectors through the open-source embedding model embed; then, the target text block with the highest similarity corresponding to the sub-question text is determined through the similarity of the semantic vectors. Furthermore, the sub-question text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block are input into the large language model, and the sub-answer text corresponding to the sub-question text is determined based on the large language model. Thereby, the accuracy of determining the sub-answer text corresponding to the sub-question text is improved.
[0017] In an alternative embodiment, the process of determining the sub-answer text corresponding to the sub-question text based on the large language model includes:
[0018] For the multiple sub-question texts, determine the sub-answer text corresponding to the previous sub-question text of the sub-question text; input the sub-question text, the entities and relationships in the corresponding target sub-graph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model.
[0019] The above technical solution has the following advantages or beneficial effects:
[0020] In this application, the question text is obtained and divided into multiple sub-question texts. There is a sequential order among the multiple sub-question texts, and the sequential order of the multiple sub-question texts is related to the context association relationship of the semantics of the multiple sub-question texts. The sub-answer text corresponding to each sub-question text is determined in sequence according to the sequential order. For the first sub-question text, input the sub-question text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model. For the sub-question texts other than the first sub-question text, input the sub-question text, the entities and relationships in the corresponding target sub-graph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model. Thereby, the accuracy of determining the sub-answer text corresponding to the sub-question text is further improved.
[0021] In an alternative embodiment, the training process of the large language model includes:
[0022] Perform data tokenization processing on each sample traffic safety Q&A pair data to obtain each tokenized Q&A pair data;
[0023] For each of the tokenized Q&A pair data, input the tokenized Q&A pair data into the large language model to be trained, and based on the generative pre-training model and the low-rank adaptation network in the large language model, extract the semantic vectors of the tokenized Q&A pair data respectively; determine the predicted answer text based on the semantic vectors; determine the loss value according to the predicted answer text and the answer text label in the tokenized Q&A pair data; and train the large language model according to the loss value.
[0024] The above technical solution has the following advantages or beneficial effects:
[0025] In this application, when training the large language model, first perform data tokenization processing on each sample traffic safety Q&A pair data to obtain each tokenized Q&A pair data; wherein, each sample traffic safety Q&A pair data includes at least one of road information retrieval Q&A pair data, safety hazard information Q&A pair data, road design specification Q&A pair data, road hazard measure Q&A pair data, and hazard disposal reasoning Q&A pair data. Then, for each tokenized Q&A pair data, input the tokenized Q&A pair data into the large language model to be trained, and based on the generative pre-training model and the low-rank adaptation network in the large language model, extract the semantic vectors of the tokenized Q&A pair data respectively; determine the predicted answer text based on the semantic vectors; determine the loss value according to the predicted answer text and the answer text label in the tokenized Q&A pair data; and train the large language model according to the loss value. The answer text label is the answer data in the tokenized Q&A pair data. This application combines sample traffic safety Q&A pair data to train the large language model, so that the large language model has the ability to accurately answer questions in the field of traffic safety.
[0026] In an optional implementation manner, training the large language model according to the loss value includes:
[0027] During the training process, the parameters of the generative pre-training model are fixed, and the model parameters of the low-rank adaptation network are updated according to the loss value.
[0028] The above technical solution has the following advantages or beneficial effects:
[0029] In order to improve the training efficiency of the large language model, this application trains the large language model by means of fine-tuning the large language model. Specifically, during the training process, the parameters of the generative pre-training model are fixed, and the model parameters of the low-rank adaptation network are updated according to the loss value. The parameters of the generative pre-training model are pre-trained by an open-source large language model, and the low-rank adaptation network is a network structure added to the large language model in this application.
[0030] In an optional implementation manner, the process of pre-building a traffic safety knowledge graph includes:
[0031] For each of the above text blocks, input the text block and the entity relationship extraction prompt statement into the large language model, and based on the large language model, determine each entity in the text block and the relationship between entities.
[0032] Input the fusion standardized prompt statement and each entity in each text block and the relationship between entities into the large language model, and based on the large language model, determine each entity in the traffic long text data and the relationship between entities; construct the traffic safety knowledge graph based on the relationship between each entity in the traffic long text data and the relationship between entities.
[0033] The above technical solution has the following advantages or beneficial effects:
[0034] In this application, according to the preset number of characters in the text block and the number of overlapping characters between adjacent text blocks, the traffic long text data is divided into each text block; then for each text block, input the text block and the entity relationship extraction prompt statement into the large language model, and based on the large language model, determine each entity in the text block and the relationship between entities; then input the fusion standardized prompt statement and each entity in each text block and the relationship between entities into the large language model, and based on the large language model, determine each entity in the traffic long text data and the relationship between entities; finally, construct the traffic safety knowledge graph based on the relationship between each entity in the traffic long text data and the relationship between entities. This provides a basis for subsequently determining the target entity with the highest similarity corresponding to the sub-question text in the traffic safety knowledge graph.
[0035] In a second aspect, this application provides a traffic question and answer device based on a large language model, and the device includes:
[0036] A first determination module, configured to obtain a question text, divide the question text into multiple sub-question texts; for the multiple sub-question texts, determine the target entity with the highest similarity corresponding to the sub-question text in the pre-constructed traffic safety knowledge graph; determine the target sub-graph having a first-order relationship with the target entity in the traffic safety knowledge graph;
[0037] A second determination module, configured to for the multiple sub-question texts, input the sub-question text, the entities and relationships in the corresponding target sub-graph, and the traffic long text data into the large language model, and based on the large language model, determine the sub-answer text corresponding to the sub-question text;
[0038] A third determination module, configured to input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and based on the large language model, determine the target answer text corresponding to the question text.
[0039] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus;
[0040] The memory is used to store a computer program;
[0041] The processor is configured to implement the described method when executing the program stored on the memory.
[0042] In a fourth aspect, the present application provides a computer-readable storage medium, in which a computer program is stored, and the computer program implements the described method when executed by a processor.
[0043] In a fifth aspect, the present application provides a computer program product, which includes an executable program, and the executable program implements the described method when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0045] Figure 1 It is a schematic diagram of the traffic question-answering process based on a large language model provided by the present application;
[0046] Figure 2 It is a schematic diagram of the process for determining the sub-answer text corresponding to the sub-question text provided by the present application for the first time;
[0047] Figure 3 It is a schematic diagram of the process for determining the sub-answer text corresponding to the sub-question text provided by the present application for the second time;
[0048] Figure 4 It is a schematic diagram of the training process of the large language model provided by the present application;
[0049] Figure 5 It is a schematic diagram of the process for pre-constructing a traffic safety knowledge graph provided by the present application;
[0050] Figure 6 It is a schematic diagram of the traffic safety knowledge graph construction and question-answering framework provided by the present application;
[0051] Figure 7 It is an architecture diagram of the traffic safety large language model TraSecLLM provided by the present application;
[0052] Figure 8Schematic diagram of the TraSecKG construction process provided by this application;
[0053] Figure 9 Flowchart of the chain of thought question answering based on TraSecKG provided by this application;
[0054] Figure 10 Schematic diagram of the structure of the traffic question answering device based on the large language model provided by this application;
[0055] Figure 11 Schematic diagram of the structure of the electronic device provided by this application. Detailed implementation manners
[0056] To make the objectives and implementation manners of this application clearer, the following will clearly and completely describe the exemplary implementation manners of this application with reference to the accompanying drawings in the exemplary embodiments of this application. Obviously, the described exemplary embodiments are only a part rather than all of the embodiments of this application.
[0057] It should be noted that the brief description of the terms in this application is only for facilitating the understanding of the subsequent described implementation manners, rather than intending to limit the implementation manners of this application. Unless otherwise specified, these terms should be understood in their ordinary and general meanings.
[0058] The terms "first", "second", "third", etc. in the specification, claims and the above accompanying drawings of this application are used to distinguish similar or like objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that such terms used can be interchanged under appropriate circumstances.
[0059] The terms "comprising" and "having" and any variations thereof are intended to cover but not be exclusive of inclusion. For example, a product or device comprising a series of components does not necessarily have to be limited to all the components clearly listed, but may include other components not clearly listed or inherent to these products or devices.
[0060] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or a combination of hardware or / and software code that can perform the functions related to this element.
[0061] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of this application, rather than to limit them; although this application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of this application.
[0062] For the sake of convenience in explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. According to the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, so that those skilled in the art can better use the embodiments and various different modified embodiments suitable for specific usage considerations.
[0063] The breakthrough of large language model technology has made it possible for natural and efficient interaction in the transportation industry, especially showing efficient anthropomorphic interaction capabilities in professional knowledge consultation and answering. Since the basic large language models often do not have knowledge in vertical industry fields, in order to improve the reliability of question answering, researchers generally adopt the Retrieval Augmented Generation (RAG) technology, which recalls the domain knowledge most relevant to the user's question and transfers it to the context window, so as to improve the large model's perception ability of professional domain knowledge.
[0064] However, there are capacity defects in the LLM and RAG technologies themselves. Among them, the LLM inevitably has the problem of knowledge "hallucination", which greatly reduces the application reliability in large-scale real-world scenarios. In addition, the RAG technology generally recalls similar segments through vector similarity, which is prone to problems such as inaccurate target retrieval and excessive redundant information. And the context window size of the LLM itself is limited, which may cause the problem that the most relevant knowledge cannot be transmitted due to excessive redundant information, resulting in unreliable answer effects. To solve this kind of unreliable information retrieval problem, a reliable solution idea is knowledge-based question answer (KBQA), which retrieves a small number of entities and relationships most relevant to the question in the knowledge graph, and then can solve the problems of limited retrieval accuracy and context length. However, traditional KBQA often has problems such as too high complexity, inaccurate knowledge extraction, and imprecise semantics in the process of defining knowledge. The development of LLM technology provides a new direction for large-scale text knowledge extraction.
[0065] Therefore, this application proposes a large model-based traffic safety knowledge graph construction and question answering technology. By embedding the data characteristics of the traffic safety field into the large model, a knowledge graph construction process based on the large model is designed, and finally, accurate answers to complex questions are realized through the chain of thought technology, which can ensure accurate and reliable question answering in traffic safety applications.
[0066] This application proposes a technology for constructing a traffic safety knowledge graph and answering questions based on a large language model (LLM). Considering that directly applying the LLM to achieve knowledge retrieval-enhanced interactive question answering often has problems such as inaccurate information retrieval and excessive redundant information in the context prompt, which easily leads to "hallucinations" in the question answering effect, a technology for constructing a traffic safety knowledge graph and accurate question answering based on the LLM is proposed to improve the retrieval accuracy of key information and reduce the possibility of large model reply hallucinations. First, a fine-tuned large model TraSec-LLM that integrates traffic safety domain knowledge is proposed. Professional domain knowledge such as hazard information, measure recommendations, and road regulations in the traffic safety domain is embedded into the LLM, and TraSec-LLM is fine-tuned based on LLaMA2-7B through low-rank adaptation technology. Secondly, to effectively organize data information in the traffic safety domain, a knowledge graph construction process based on large model technology is proposed. TraSec-LLM is used to extract entity relationships and standardize patterns from text information in the traffic safety domain, and a traffic safety knowledge graph network TraSecKG is constructed. Finally, a complex question answering technology based on the chain of thought technique is proposed. Complex questions are decomposed into multiple coherent sub-questions by the large model, and then separate graph subgraph recalls and similar text recalls are implemented for each sub-question. TraSec-LLM is used to answer the sub-questions separately, and finally the large model summarizes the answers to all sub-questions to form the final question answering result.
[0067] This application proposes a knowledge embedding training framework for the traffic safety domain based on low-rank adaptation technology, and constructs a large model TraSec-LLM for the traffic safety domain. A knowledge graph construction technology for the safety domain based on large model technology is proposed, and prompt statements for entity relationship extraction and pattern standardization are designed, and a traffic safety domain graph TraSec-KG is constructed. A complex question answering technology based on the integration of chain of thought reasoning is proposed. Complex questions are decomposed into sub-questions, and then accurate replies to the sub-questions are achieved through subgraph and text block association recalls. Finally, the final reply result is formed by summarizing the answers to all sub-questions.
[0068] Figure 1 The following are the steps of the traffic question answering process based on the large language model provided in this application:
[0069] S101: Obtain the question text, and divide the question text into multiple sub-question texts; for the multiple sub-question texts, determine the target entity with the highest similarity in the pre-constructed traffic safety knowledge graph corresponding to the sub-question text; determine the target subgraph in the traffic safety knowledge graph that has a first-order relationship with the target entity;
[0070] S102: For the multiple sub-question texts, input the sub-question texts, the entities and relationships in the corresponding target sub-graphs, and the traffic long-text data into a large language model, and determine the sub-answer texts corresponding to the sub-question texts based on the large language model;
[0071] S103: Input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and determine the target answer text corresponding to the question text based on the large language model.
[0072] The question-answering method based on a large language model provided by this application is applied to an electronic device, which can be a device such as a PC, a computer, a server, etc.
[0073] The electronic device obtains the question text, and the question text can be divided into multiple sub-question texts through a task decomposition prompt statement. Optionally, input the question text and the task decomposition prompt statement into the large language model, and divide the question text into multiple sub-question texts based on the large language model. A traffic safety knowledge graph is pre-constructed in the electronic device. After obtaining multiple sub-question texts, for the multiple sub-question texts, first determine the similarity between the sub-question text and each entity in the traffic safety knowledge graph, and determine the entity with the highest similarity as the target entity corresponding to the sub-question text. Optionally, convert the sub-question text and each entity in the traffic safety knowledge graph into semantic vectors through an open-source embedding model embed; then determine the target entity with the highest similarity corresponding to the sub-question text through the similarity of the semantic vectors. Then determine the target sub-graph in the traffic safety knowledge graph that has a first-order relationship with the target entity. The first-order relationship refers to the relationship directly connected to the target entity. The target sub-graph includes multiple entities and the relationships between the multiple entities.
[0074] For the multiple sub-question texts, input the sub-question texts, the entities and relationships in the corresponding target sub-graphs, and the traffic long-text data into the large language model, and determine the sub-answer texts corresponding to the sub-question texts based on the large language model. The traffic long-text data is, for example, data such as traffic-related specification materials. Finally, input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and determine the target answer text corresponding to the question text based on the large language model.
[0075] In this application, a traffic safety knowledge graph is pre-constructed. After dividing the problem text into multiple sub-problem texts, for the multiple sub-problem texts, the target entity with the highest similarity corresponding to the sub-problem text in the traffic safety knowledge graph is determined; and the target sub-graph with a first-order relationship with the target entity is determined. Among them, the sub-problem text and each entity in the traffic safety knowledge graph are respectively converted into semantic vectors through the open-source embedding model embed; then the target entity with the highest similarity corresponding to the sub-problem text is determined through the similarity of the semantic vectors. Then, for the multiple sub-problem texts, the sub-problem text, the entities and relationships in the corresponding target sub-graph, and the traffic long text data are input into the large language model, and the sub-answer text corresponding to the sub-problem text is determined based on the large language model. Finally, the problem text, the multiple sub-problem texts, and the corresponding sub-answer texts are input into the large language model, and the target answer text corresponding to the problem text is determined based on the large language model. This application divides the problem text into multiple sub-problem texts, combines the traffic safety knowledge graph and the traffic long text data, and determines the sub-answer text corresponding to the sub-problem text based on the large language model. Thus, the accuracy of the determined sub-answer text is ensured. Furthermore, by combining the problem text, the multiple sub-problem texts, and the corresponding sub-answer texts, the target answer text corresponding to the problem text is determined based on the large language model. Thus, the accuracy of the determined target answer text is ensured.
[0076] Figure 2 FIG. 4 is a schematic diagram of the process for determining the sub-answer text corresponding to the sub-problem text provided in the first embodiment of the present application, including the following steps:
[0077] S201: Divide the traffic long text data into respective text blocks according to the preset number of text block characters and the number of overlapping characters between adjacent text blocks;
[0078] S202: For the multiple sub-problem texts, determine the target text block with the highest similarity corresponding to the sub-problem text;
[0079] S203: Input the sub-problem text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block into the large language model, and determine the sub-answer text corresponding to the sub-problem text based on the large language model.
[0080] In this application, first, according to the preset number of characters in a text block and the number of overlapping characters between adjacent text blocks, the traffic long text data is divided into individual text blocks; then, for multiple sub-question texts, the target text block with the highest similarity corresponding to the sub-question text is determined. Among them, the sub-question text and each text block are respectively converted into semantic vectors through the open-source embedding model embed; then, the target text block with the highest similarity corresponding to the sub-question text is determined through the similarity of the semantic vectors. Furthermore, the sub-question text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block are input into the large language model, and the sub-answer text corresponding to the sub-question text is determined based on the large language model. Thus, the accuracy of determining the sub-answer text corresponding to the sub-question text is improved.
[0081] Figure 3 FIG. 4 is a schematic diagram of the process for providing the second sub-answer text corresponding to the sub-question text in this application, including the following steps:
[0082] S301: According to the preset number of characters in a text block and the number of overlapping characters between adjacent text blocks, divide the traffic long text data into individual text blocks;
[0083] S302: For the multiple sub-question texts, determine the target text block with the highest similarity corresponding to the sub-question text;
[0084] S303: For the multiple sub-question texts, determine the sub-answer text corresponding to the previous sub-question text of the sub-question text; input the sub-question text, the entities and relationships in the corresponding target sub-graph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model.
[0085] In this application, the question text is obtained and divided into multiple sub-question texts. There is a sequential order among the multiple sub-question texts, and the sequential order of the multiple sub-question texts is related to the context association relationship of the semantics of the multiple sub-question texts. The sub-answer texts corresponding to each sub-question text are determined sequentially in the order. For the first sub-question text, input the sub-question text, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model. For sub-question texts other than the first sub-question text, input the sub-question text, the entities and relationships in the corresponding target sub-graph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model. Thus, the accuracy of determining the sub-answer text corresponding to the sub-question text is further improved.
[0086] Figure 4Schematic diagram of the training process of the large language model provided by this application, including the following steps:
[0087] S401: Perform data tokenization on each sample traffic safety Q&A pair data to obtain each tokenized Q&A pair data;
[0088] S402: For each of the tokenized Q&A pair data, input the tokenized Q&A pair data into the large language model to be trained. Based on the generative pre-training model and the low-rank adaptation network in the large language model, extract the semantic vectors of the tokenized Q&A pair data respectively; determine the predicted answer text based on the semantic vectors; determine the loss value according to the predicted answer text and the answer text label in the tokenized Q&A pair data; train the large language model according to the loss value.
[0089] Each of the sample traffic safety Q&A pair data includes at least one of road information retrieval Q&A pair data, safety hazard information Q&A pair data, road design specification Q&A pair data, road hazard measure Q&A pair data, and hazard disposal reasoning Q&A pair data.
[0090] In this application, when training the large language model, first perform data tokenization on each sample traffic safety Q&A pair data to obtain each tokenized Q&A pair data; then for each tokenized Q&A pair data, input the tokenized Q&A pair data into the large language model to be trained. Based on the generative pre-training model and the low-rank adaptation network in the large language model, extract the semantic vectors of the tokenized Q&A pair data respectively; determine the predicted answer text based on the semantic vectors; determine the loss value according to the predicted answer text and the answer text label in the tokenized Q&A pair data; train the large language model according to the loss value. The answer text label is the answer data in the tokenized Q&A pair data. This application trains the large language model in combination with the sample traffic safety Q&A pair data, so that the large language model has the ability to accurately answer questions in the field of traffic safety.
[0091] In an optional implementation manner, training the large language model according to the loss value includes:
[0092] During the training process, the parameters of the generative pre-training model are fixed, and the model parameters of the low-rank adaptation network are updated according to the loss value.
[0093] To improve the efficiency of large language model training, this application trains the large language model by fine-tuning the large language model. Specifically, during the training process, the parameters of the generative pre-trained model are fixed, and the model parameters of the low-rank adaptation network are updated according to the loss value. The parameters of the generative pre-trained model are pre-trained by an open-source large language model, and the low-rank adaptation network is a network structure added to the large language model in this application.
[0094] Figure 5 The following is a schematic diagram of the process of pre-constructing a traffic safety knowledge graph provided by this application, including the following steps:
[0095] S501: For each of the text blocks, input the text block and the entity relationship extraction prompt statement into the large language model, and determine each entity in the text block and the relationship between entities based on the large language model;
[0096] S502: Input the fusion normalization prompt statement and each entity in each text block and the relationship between entities into the large language model, and determine each entity in the traffic long text data and the relationship between entities based on the large language model; construct the traffic safety knowledge graph based on the relationship between each entity in the traffic long text data and the relationship between entities.
[0097] In this application, according to the preset number of characters in the text block and the number of overlapping characters in adjacent text blocks, the traffic long text data is divided into each text block; then for each text block, input the text block and the entity relationship extraction prompt statement into the large language model, and determine each entity in the text block and the relationship between entities based on the large language model; then input the fusion normalization prompt statement and each entity in each text block and the relationship between entities into the large language model, and determine each entity in the traffic long text data and the relationship between entities based on the large language model; finally, construct the traffic safety knowledge graph based on the relationship between each entity in the traffic long text data and the relationship between entities. This provides a basis for subsequently determining the target entity with the highest similarity corresponding to the sub-question text in the traffic safety knowledge graph.
[0098] The following will provide a detailed description of the question-answering process based on the large language model provided by this application with reference to the accompanying drawings.
[0099] Figure 6 The following is a schematic diagram of the traffic safety knowledge graph construction and question-answering framework provided by this application, including:
[0100] S01: Fine-tune the large language model TraSec-LLM in the traffic safety field;
[0101] S02: Construct the traffic safety knowledge graph TraSecKG based on TraSec-LLM;
[0102] S03: Implement complex traffic safety knowledge Q&A based on TraSecKG and chain of thought.
[0103] The purpose of this application is to provide a traffic safety knowledge graph construction and Q&A technology based on large language model technology, which is used to improve the Q&A hallucination problem caused by the limited recall accuracy of associated information in knowledge retrieval enhanced Q&A of large language models. Specifically, a traffic safety knowledge graph construction and Q&A technology related to this application.
[0104] S01: Fine-tune the large language model TraSec-LLM in the field of traffic safety.
[0105] The TraSecLLM large model takes LLaMA as the base and uses the LoRA (low rank adaptation) fine-tuning method to inject background knowledge in the field of traffic safety into the basic large model, forming a dialogue large model TraSecLLM for the traffic safety industry.
[0106] Figure 7 This is the architecture diagram of the traffic safety large language model TraSecLLM provided by this application. The LlaMA2-7B pre-trained weights are the weights of the generative pre-trained model. The upsampling matrix A and the downsampling matrix B are low-rank adaptation networks. The construction of traffic safety knowledge Prompt includes road information retrieval Q&A pairs, safety hazard information Q&A pairs, road design specification Q&A pairs, road hazard measure Q&A pairs, and hazard disposal reasoning Q&A pairs. Based on the construction of traffic safety knowledge Prompt, generate traffic safety text sequence tokens {x 1 …x m …}, traffic safety text sequence tokens {x 1 …x m …} are respectively input into the generative pre-trained model and the low-rank adaptation network. Based on the generative pre-trained model and the low-rank adaptation network, extract the semantic vectors of the traffic safety text sequence respectively; based on the semantic vectors, determine the traffic safety prediction text sequence token data {o m+1 …x m+n}.
[0107] LoRA is a novel technology that can solve the problem of efficiently fine-tuning large language models. By freezing the weights of the pre-trained model and injecting trainable layers (rank decomposition matrices) into each Transformer block, LoRA can greatly reduce the number of training parameters and memory requirements.
[0108] First, prepare traffic safety Q&A pair data, mainly including road information retrieval Q&A pairs, safety hazard information Q&A pairs, road design specification Q&A pairs, road hazard measure Q&A pairs, and hazard disposal reasoning Q&A pair data, as shown in Table 1 below.
[0109] Table 1: Data of Traffic Safety Q&A Pairs
[0110]
[0111] Q1: How many lanes are there on Songling Road in Qingdao?
[0112] A1: As a longitudinal main road on the east side of Laoshan District, Songling Road is designed with eight lanes in both directions.
[0113] ## Q&A Pairs of Potential Safety Hazard Information
[0114] Q2: What potential safety hazards should pedestrians pay attention to when crossing the road?
[0115] A2: When crossing the road, pedestrians need to observe traffic signals and strictly abide by the instructions of traffic lights, stop at red lights and go at green lights, and never run a red light; observe oncoming vehicles. When crossing the road, look left and right for oncoming vehicles, especially pay attention to avoiding turning vehicles as turning vehicles may have blind spots; choose a safe passage: try to cross the road through pedestrian crossings, overpasses or underground passages and other crossing facilities, and avoid directly crossing the motor vehicle lane, etc.
[0116] ## Q&A Pairs of Road Design Specifications
[0117] Q3: How many grades are there for highways?
[0118] A3: Highways are divided into five technical grades: expressways, first-class highways, second-class highways, third-class highways and fourth-class highways.
[0119] ## Q&A Pairs of Road Hazard Measures
[0120] Q4: How to handle the lack or inadequacy of traffic safety facilities?
[0121] A4: Improve traffic signs and markings, and set traffic signs and markings in accordance with national standards; add safety facilities, such as warning lights, deceleration devices, rearview mirrors and other safety facilities; conduct regular maintenance and regularly check whether the functions of traffic facilities are normal.
[0122] ## Q&A Pairs of Hazard Disposal Reasoning
[0123] Q5: Traffic congestion frequently occurs in the XX section, causing serious potential safety hazards. Please analyze the possible reasons and propose corresponding disposal measures.
[0124] A5: The traffic flow in the XX section is too large, the signal timing is unreasonable, and there are defects in the road design. In addition, frequent traffic accidents due to poor visibility, slippery road surface, etc. affect the traffic efficiency. Suggested disposal measures include: optimizing traffic signal control, increasing lanes or improving road design, strengthening traffic law enforcement publicity, establishing an emergency response mechanism, etc.
[0125] Secondly, tokenize each Q-A pair sequence data into {x 1:m , y m+1:m+n}. After receiving the input data x 1:m , the LLaMA2 model outputs the prediction result o m+1:m+n through the forward propagation of the model. Then, by minimizing the error between the predicted value o m+1:m+n and the true value y m+1:m+n , a trained model can be obtained.
[0126] This application is fine-tuned based on the open-source large model LLaMA2-7B, and the parameters to be updated are represented as follows:
[0127] W 1 = W 0 + ΔW;
[0128] Among them, W 1 is the weight parameter of the fine-tuned TraSec-LLM model in this application, W 0 is the initialization parameter of the base model LLaMA-7B, and ΔW is the parameter to be fine-tuned and updated. To achieve lightweight model fine-tuning, W 0 can be frozen and only ΔW needs to be updated.
[0129] Assume that the pre-training matrix of LLaMA2-7B is Then the process of updating the fine-tuned model parameters can be expressed as:
[0130] (Predicted answer and labeled answer).
[0131] Among them, the rank r << min(d, k). Then, the model training process can be completed through minimizing optimization by error backpropagation.
[0132] Finally, embed the corpus features in the traffic safety field into the large language model TraSec-LLM through the low-rank adaptation LoRA technology. It should be noted that the LoRA technology allows the model to quickly adapt to new data features without losing the existing knowledge.
[0133] S02: Construct the traffic safety knowledge graph TraSecKG based on TraSec-LLM.
[0134] Figure 8 is the schematic diagram of the TraSecKG construction process provided by this application. As Figure 8 shown, perform text chunking on the text materials, extract entity relationships based on TraSec-LLM, and then perform pattern fusion based on TraSec-LLM to obtain TraSecKG.
[0135] Entity relation extraction includes:
[0136] Step 1: Extract entities from text chunks;
[0137] Step 2: Extract entity pairs with high correlation and their relationships from the entity list.
[0138] Schema fusion includes:
[0139] Step 1: Provide a textual definition of the relationship for all triples {source entity, target entity, relationship};
[0140] Step 2: Select the most appropriate relationship and refine the knowledge graph into a canonical form, eliminate redundancy and ambiguity, and merge similar schemas to standardize the triples.
[0141] To achieve accurate question answering for knowledge and complex problems in the field of traffic safety, this application proposes to construct a traffic safety knowledge graph to achieve structured organization of traffic safety knowledge and support accurate and efficient question answering.
[0142] The construction process of TraSecKG is divided into three steps, including text chunking, entity relation extraction, and schema fusion.
[0143] Text chunking.
[0144] Due to the limited context window of the large model, it is first necessary to divide the original long text materials into text chunks of appropriate size, and then each text chunk is separately handed over to the TraSec-LLM large model for processing.
[0145] Assume that the total length of a long text Doc in the field of traffic safety is a, the size of each block is b (the number of characters in the text block), and the overlapping size of adjacent blocks is c (the number of overlapping characters in adjacent text blocks, c < b). Then the total number of chunks chunks is:
[0146]
[0147] According to the practical demonstration of GraphRAG, longer text chunks require fewer large model calls for extraction, have higher efficiency and lower cost, but there will be a problem of decreased recall rate in a longer LLM context window, that is, the extraction instances are insufficient and there are omissions. In the case of single-round extraction (i.e., zero collection), on the sample dataset, the instances extracted using blocks of size 600 are almost twice as many as those using 2400 blocks.
[0148] This application defines the size of each chunk Chunk as 600 and the overlapping size of adjacent Chunks as 200. Therefore, a text with a length of 5000 can be divided into 13 chunks.
[0149] Entity relation extraction.
[0150] Entities and relations are then extracted from each text block, i.e., instances of nodes and edges in the graph. This process is to extract structured information from the text, especially to identify entities and their relations. By optimizing hints and multiple rounds of collection, complex information can be extracted from large amounts of text.
[0151] By designing entity and relationship extraction prompts, TraSec-LLM can extract instances of entity nodes and relationship edges for traffic safety text blocks. The detailed prompts are shown in Table 2.
[0152] Table 2: TraSecKG entity and relation extraction prompts
[0153]
[0154]
[0155] Mode fusion.
[0156] Since there may be duplicate entities or relations in the triples generated from different blocks, in order to build a complete, concise, high-quality graph, a pattern fusion standardization prompt is designed to enable TraSec-LLM to standardize the entity and relationship lists extracted from different blocks. Specifically, it provides a natural language definition for each relationship and then unifies the semantically equivalent entities and relationships. Table 3 shows the TraSecKG pattern fusion standardization prompt. Entity and relationship semantic disambiguation and redundancy elimination are achieved through pattern fusion, and high-quality TraSecKG is produced for accurate knowledge question answering.
[0157] Table 3: TraSecKG pattern fusion standardization prompt
[0158]
[0159] S03: Implement complex traffic safety knowledge question and answer based on TraSecKG and thinking chain.
[0160] Considering that traditional knowledge question-answering often has the problem of hallucination when directly searching for similar fragments in text vectors to answer, in order to improve the accuracy of question-answering of complex questions in the field of traffic safety, this application proposes a safe question-answering strategy based on thought chain reasoning based on the constructed TraSecKG, guiding the large model to retrieve the related subgraphs of complex questions in sequence through an explainable logical chain, and achieve accurate answers.
[0161] Figure 9 The TraSecKG-based thinking chain question-answering flowchart provided for this application is mainly divided into four stages:
[0162] Phase 1: Problem Step-by-Step Decomposition. First, use the TraSec-LLM large model to decompose the user's question (Query) into multiple sub-questions. The decomposition logic can either directly let the TraSec-LLM large model decompose in a step-by-step derivation manner or be defined by the user in advance with a complex problem reasoning logic template. Then, TraSec-LLM extracts slots and decomposes the problem by matching the template through calculating the similarity between the Query and TraSec-LLM. Assume that the original problem can be decomposed into k sub-questions by the large model, denoted as Q = {q 1 ,q 2 ,…,q k}.
[0163] Phase 2: Knowledge Retrieval and Reasoning. For the sub-question q i , retrieve and recall the most relevant sub-graph g i and the most similar text block d i from TraSecKG and the original text respectively, so as to obtain the associated reasoning information set {g i ,d i} of the sub-question.
[0164] Among them, the most relevant sub-graph is matched according to the similarity between the problem and the nodes in TraSecKG. The matching function is defined as, f 1 (q i ,v i ) = similarity(embed(q i ),embed(v i ));
[0165] Among them, the function embed(·) uses the bge-m3 open-source embedding model, and the similarity function is used to calculate the similarity between the encoded vectors. v i represents the node information in TraSecKG.
[0166] Among them, the most similar text is obtained by using the similarity function to find the most relevant text. The matching function is defined as: f 2 (q i ,d i ) = similarity(embed(q i ),embed(d i ));
[0167] Among them, the function embed(·) uses the bge-m3 open-source embedding model, and the similarity function is used to calculate the similarity between the encoded vectors.
[0168] Phase 3: Result response generation. For each sub-question, use TraSec-LLM to generate the result response, that is, uniformly pass the question, context-related information, and the result of the large model's previous response to the large model to let it generate the result response.
[0169] a i = TraSec-LLM(q i ,g i ,d i ,a i-1 ), i ≥ 2;
[0170] a 1 = TraSec-LLM(q 0 ,g 0 ,d 0 ), i = 1;
[0171] Phase 4: Comprehensive answer generation. After obtaining the answer set A = {a 1 ,a 2 ,…,a k} of all sub-questions, finally perform answer reduction and merging, that is, pass the original question, the decomposed question set, and the decomposed answer set as context to the TraSec-LLM large model, and prompt it to summarize and output the final answer,
[0172] Result = TraSec-LLM(Query, Q, A).
[0173] As Figure 9 shown, for example, the questions are: Generally, how many grades is a highway divided into according to regulations? What is the design speed specification for each grade? If a railway is adjacent to a highway in parallel, is it feasible that the distance between the subway land boundary and the highway land boundary is 25m?
[0174] The questions in Phase 1 are gradually decomposed into:
[0175] Q1: What are the grades of highways divided according to national regulations?
[0176] Q2: What is the design speed for each grade of highway according to the grade division?
[0177] Q3: When a highway is adjacent to other roads, there are specifications. If a railway is adjacent to a highway in parallel, what is the range of the distance between the subway land boundary and the highway land boundary?
[0178] Q4: If a railway is adjacent to a highway in parallel, is it in compliance with the specification that the distance between the subway land boundary and the highway land boundary is 25 meters?
[0179] The knowledge retrieval and reasoning in Phase 2 are:
[0180] Q1 ==> {E1: Highway, E2: Grade}{R1: Grade to which the highway belongs};
[0181] Q2 ==> {EI: Highway, E2: Grade, E3: Design Speed}{R1: Grade to which the highway belongs, R2: Design speed of the highway};
[0182] Q3 ==> {E1: Highway, E2: Other roads, E3: Range of boundary spacing}{R1: Intersection method, R2: Design range of the spacing between associated roads};
[0183] {Railway, Expressway, Parallel and adjacent, Boundary spacing ≥ 30 meters};
[0184] {Railway, First-class and second-class highways, Parallel and adjacent, Boundary spacing ≥ 15 meters};
[0185] {Railway, Third-class and fourth-class highways, Parallel and adjacent, Boundary spacing ≥ 5 meters};
[0186] Q4 ==> {[E1 - Expressway, E2 - Subway, R1 - Parallel and adjacent], Whether the boundary spacing of 25m is reasonable};
[0187] 25 meters does not meet the minimum spacing of 30 meters and is unreasonable.
[0188] The result response for Phase 3 is generated as:
[0189] A1: Highways are divided into five technical grades: expressways, first-class highways, second-class highways, third-class highways, and fourth-class highways;
[0190] A2: The speed of expressways shall not be less than 100 km / h, and 80 km / h may be adopted under topographical and geological constraints;
[0191] The design speed of first-class highways should preferably be 80 km / h, and 60 km / h may be adopted under topographical and geological constraints;
[0192] The design speed of second-class highways should preferably be 80 km / h, and 60 km / h or 40 km / h may be adopted under topographical and geological constraints;
[0193] The design speed of third-class highways should preferably be 40 km / h, and 30 km / h may be adopted under topographical and geological constraints;
[0194] The design speed of fourth-class highways should preferably be 30 km / h, and 20 km / h may be adopted under topographical and geological constraints;
[0195] A3: If the railway is parallel and adjacent to the expressway, the boundary spacing shall be ≥ 30 meters; if the railway is parallel and adjacent to first- and second-class highways, the boundary spacing shall be ≥ 15 meters; if the railway is parallel and adjacent to third- and fourth-class highways, the boundary spacing shall be ≥ 5 meters;
[0196] A4: It does not meet the 30-meter specification.
[0197] The comprehensive answer for Stage 4 is generated as follows:
[0198] Highways are generally divided into five grades, namely expressways, first-class, second-class, third-class, and fourth-class highways. Among them, the design speed of expressways should not be less than 100 km / h, the speed range of first-class highways is 80 - 60 km / h, the speed range of second-class highways is 80 - 40 km / h, the speed range of third-class highways is 40 - 30 km / h, and the speed range of fourth-class highways is 30 - 20 km / h. When a railway is adjacent to a highway in parallel, the distance between the boundary of the subway land and the boundary of the expressway land should not be less than 30 meters according to regulations. Therefore, a range of 25 meters does not meet the specifications.
[0199] Figure 10 The following is a schematic structural diagram of a traffic Q&A device based on a large language model provided for this application. The device includes:
[0200] The first determination module 21 is used to obtain the question text, divide the question text into multiple sub-question texts; for the multiple sub-question texts, determine the target entity with the highest similarity in the pre-constructed traffic safety knowledge graph corresponding to the sub-question text; determine the target sub-graph in the traffic safety knowledge graph that has a first-order relationship with the target entity;
[0201] The second determination module 22 is used to, for the multiple sub-question texts, input the sub-question texts, the entities and relationships in the corresponding target sub-graph, and the traffic long text data into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model;
[0202] The third determination module 23 is used to input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and determine the target answer text corresponding to the question text based on the large language model.
[0203] In an alternative embodiment, the second determination module 22 is specifically configured to divide the traffic long text data into respective text blocks according to the preset number of characters in a text block and the number of overlapping characters in adjacent text blocks; for the multiple sub-question texts, determine the target text block with the highest similarity corresponding to the sub-question text; input the sub-question texts, the entities and relationships in the corresponding target sub-graph, and the corresponding target text block into the large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model.
[0204] In an alternative embodiment, the second determination module 22 is specifically configured to, for the multiple sub-question texts, determine the sub-answer text corresponding to the previous sub-question text of the sub-question text; input the sub-question text, the entities and relationships in the corresponding target sub-graph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into a large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model.
[0205] In an alternative embodiment, the device further includes:
[0206] A training module 24, configured to perform data tokenization processing on each sample traffic safety question-and-answer pair data to obtain each tokenized question-and-answer pair data; for each tokenized question-and-answer pair data, input the tokenized question-and-answer pair data into a large language model to be trained, and respectively extract the semantic vectors of the tokenized question-and-answer pair data based on the generative pre-training model and the low-rank adaptation network in the large language model; determine a predicted answer text based on the semantic vectors; determine a loss value according to the predicted answer text and the answer text label in the tokenized question-and-answer pair data; and train the large language model according to the loss value.
[0207] In an alternative embodiment, the training module 24 is specifically configured to, during training, keep the parameters of the generative pre-training model fixed and update the model parameters of the low-rank adaptation network according to the loss value.
[0208] In an alternative embodiment, the device further includes:
[0209] A graph construction module 25, configured to, for each text block, input the text block and the entity relationship extraction prompt statement into the large language model, and determine each entity in the text block and the relationships between the entities based on the large language model; input the fusion normalization prompt statement and each entity in each text block and the relationships between the entities into the large language model, and determine each entity in the traffic long text data and the relationships between the entities based on the large language model; and construct a traffic safety knowledge graph based on each entity in the traffic long text data and the relationships between the entities.
[0210] The present application also provides an electronic device, as Figure 11 shown, including: a processor 31, a communication interface 32, a memory 33, and a communication bus 34, where the processor 31, the communication interface 32, and the memory 33 communicate with each other through the communication bus 34;
[0211] The memory 33 stores a computer program, and when the program is executed by the processor 31, the processor 31 is caused to execute any of the above method steps.
[0212] The communication bus mentioned in the above-mentioned electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, only a thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0213] The communication interface 32 is used for communication between the above-mentioned electronic device and other devices.
[0214] The memory may include a Random Access Memory (RAM), and may also include a Non-Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located far from the aforementioned processor.
[0215] The above-mentioned processor may be a general-purpose processor, including a central processing unit, a Network Processor (NP), etc.; it may also be a Digital Signal Processing (DSP), an application-specific integrated circuit, a field-programmable gate array, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0216] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program executable by an electronic device. When the program runs on the electronic device, it enables the electronic device to execute any of the above method steps.
[0217] This application provides a computer program product. The computer program product includes an executable program that implements the above-mentioned method when executed by a processor.
[0218] Although the preferred embodiments of this application have been described, those skilled in the art can make additional changes and modifications once they know the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of this application.
[0219] Obviously, those skilled in the art can make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these modifications and variations.
Claims
1. A traffic question-answering method based on a large language model, characterized in that: The method comprises: Obtain a question text, and divide the question text into a plurality of sub-question texts; for the plurality of sub-question texts, determine a target entity with the highest similarity corresponding to the sub-question text in a pre-constructed traffic safety knowledge graph; determine a target subgraph in the traffic safety knowledge graph that has a first-order relationship with the target entity; For the multiple sub-question texts, input the sub-question texts, entities and relationships in the corresponding target subgraphs, and traffic long text data into a large language model, and determine the sub-answer texts corresponding to the sub-question texts based on the large language model; The question text, the multiple sub-question texts and the corresponding sub-answer texts are input into the large language model, and a target answer text corresponding to the question text is determined based on the large language model.
2. The method according to claim 1, characterized in that The process of determining the sub-answer text corresponding to the sub-question text based on the large language model includes: Dividing the traffic long text data into individual text blocks according to the preset number of characters in the text blocks and the number of overlapping characters in adjacent text blocks; For the multiple sub-question texts, determining a target text block with the highest similarity corresponding to the sub-question texts; The sub-question text, entities and relations in the corresponding target subgraph, and the corresponding target text block are input into a large language model, and a sub-answer text corresponding to the sub-question text is determined based on the large language model.
3. The method according to claim 2, characterized in that The process of determining the sub-answer text corresponding to the sub-question text based on the large language model includes: For the multiple sub-question texts, determine the sub-answer text corresponding to the previous sub-question text of the sub-question text; input the sub-question text, the entities and relationships in the corresponding target subgraph, the corresponding target text block, and the sub-answer text corresponding to the previous sub-question text into a large language model, and determine the sub-answer text corresponding to the sub-question text based on the large language model.
4. The method according to claim 1, characterized in that The training process of the large language model includes: Perform data tokenization processing on each sample traffic safety question-answer pair data to obtain each tokenized question-answer pair data; For each of the tokenized question-answer pair data, the tokenized question-answer pair data is input into a large language model to be trained, and based on a generative pre-trained model and a low-rank adaptation network in the large language model, the semantic vectors of the tokenized question-answer pair data are respectively extracted; a predicted answer text is determined based on the semantic vector; a loss value is determined based on the predicted answer text and the answer text label in the tokenized question-answer pair data; and the large language model is trained according to the loss value.
5. The method according to claim 4, characterized in that Training the large language model according to the loss value includes: During the training process, the parameters of the generative pre-training model are fixed, and the model parameters of the low-rank adaptation network are updated according to the loss value.
6. The method according to claim 4, characterized in that The sample traffic safety question-and-answer data include at least one of road information retrieval question-and-answer data, safety hazard information question-and-answer data, road design specification question-and-answer data, road hazard measures question-and-answer data, and hazard disposal reasoning question-and-answer data.
7. The method according to claim 2, characterized in that The process of pre-building a traffic safety knowledge graph includes: For each text block, input the text block and entity relationship extraction prompt sentence into the large language model, and determine each entity of the text block and the relationship between entities based on the large language model; The entities and the relationships between the entities that integrate the standardized prompt sentences and each text block are input into the large language model, and the entities and the relationships between the entities corresponding to the long traffic text data are determined based on the large language model; the traffic safety knowledge graph is constructed based on the entities and the relationships between the entities corresponding to the long traffic text data.
8. A traffic question-answering device based on a large language model, characterized in that: The device comprises: The first determination module is used to obtain a question text and divide the question text into a plurality of sub-question texts; for the plurality of sub-question texts, determine a target entity with the highest similarity corresponding to the sub-question text in a pre-constructed traffic safety knowledge graph; and determine a target subgraph in the traffic safety knowledge graph that has a first-order relationship with the target entity; A second determination module is used for inputting the sub-question texts, entities and relationships in the corresponding target subgraphs, and traffic long text data into a large language model for the multiple sub-question texts, and determining the sub-answer texts corresponding to the sub-question texts based on the large language model; The third determination module is used to input the question text, the multiple sub-question texts and the corresponding sub-answer texts into the large language model, and determine the target answer text corresponding to the question text based on the large language model.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method according to any one of claims 1 to 7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Multi-type question and answer data chain generation method for scientific and technical literature question and answer system
CN120929568A
Knowledge graph multi-level logical reasoning method based on large language model
CN121094152A
Problem query method and device, problem query equipment, program product and medium
CN121210498A
Road intersection hidden danger diagnosis method based on adaptive map and multi-link reasoning
CN121724164A
A Road Intersection Hazard Diagnosis Method Based on Adaptive Graph and Multi-Link Inference
CN121724164B