Traffic accident text classification method, storage medium and electronic equipment
By collecting and labeling traffic accident text, obtaining high-frequency keywords and inputting them into pre-trained models, combining cross-entropy loss function and average pooling operation, the problem of low classification accuracy in the existing traffic accident text classification method is solved, and the Higher classification accuracy and performance performance.
Patent Information
- Application Number
- CN202411260525.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2025-02-14
AI Technical Summary
Among the existing traffic accident text classification methods, the classification accuracy is low and the judgment is inaccurate, especially affected by language and cultural differences, noise and irrelevant information.
By collecting and part-of-speech annotation of traffic accident text, high-frequency keyword sets are obtained, and text data is converted into serialized data and keyword tag matrix, input pre-trained model to obtain text representation sets, combining cross entropy loss function and average pooling Operation, iteratively train the model to improve classification performance.
By extracting and utilizing high-frequency keywords and context information, the model's attention to local features is enhanced, and the accuracy and performance performance of traffic accident text classification are improved.
Smart Images

Figure BDA0005035431180000061 
Figure BDA0005035431180000071 
Figure BDA0005035431180000121
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of semantic matching, and in particular relates to a traffic accident text classification method, a storage medium and an electronic device. Background Art
[0002] With the acceleration of urbanization and the rapid growth of car ownership, traffic accidents have become a global problem. Traffic accidents not only cause huge losses to people's lives and property, but also pose a serious threat to social stability and security. Therefore, effective text classification and analysis of traffic accidents is of great significance for preventing accidents and improving road safety.
[0003] Traditional traffic accident text classification methods mainly rely on manual analysis and processing, which is not only inefficient but also easily affected by subjective factors, resulting in inaccurate classification results. With the rapid development of artificial intelligence and machine learning technologies, traffic accident text classification methods based on these advanced technologies have gradually emerged. These technologies can automatically extract useful information from a large amount of traffic accident text data and achieve automatic classification through training models. Compared with traditional methods, text classification methods based on artificial intelligence and machine learning have higher efficiency and accuracy and can better meet the needs of practical applications. However, there are still some challenges and problems in the current traffic accident text classification technology. For example, there may be language and cultural differences in traffic accident texts in different regions, which will affect the performance and accuracy of the classification model. In addition, traffic accident texts often contain a lot of noise and irrelevant information, which also increases the difficulty of classification. Summary of the invention
[0004] In view of the above problems, the purpose of the present invention is to provide a traffic accident text classification method, storage medium and electronic device to solve the problems of low classification accuracy and inaccurate judgment in existing traffic accident text classification.
[0005] To achieve the above object, the technical solution adopted by the present invention includes:
[0006] A traffic accident text classification method comprises the following steps:
[0007] S1, collect multiple traffic accident texts and perform part-of-speech tagging on them to obtain all keywords, then perform word frequency statistics on all keywords, take the top 30% of keywords as high-frequency keywords, and obtain a high-frequency keyword set;
[0008] S2, obtain labels corresponding to the multiple traffic accident texts in S1, and add a standard traffic accident text to each traffic accident text to obtain a traffic accident text dataset, which is a collection of multiple traffic accident text data, each traffic accident text data includes a standard traffic accident text, a traffic accident text and its corresponding label;
[0009] Compare the traffic accident text in each traffic accident text data with the high-frequency keyword set to obtain the high-frequency keyword set of each text, and obtain a traffic accident keyword data set, the traffic accident keyword data set is a collection of multiple traffic accident keyword data, and each traffic accident keyword data includes a standard traffic accident text, a traffic accident text, a high-frequency keyword set of the text, and a label corresponding to the traffic accident text;
[0010] The standard traffic accident text and traffic accident text in each traffic accident text data are serialized to obtain a text sequence S X Set, and then the text sequence S x The set is compared with the high-frequency keyword set and the position of the high-frequency keywords is marked to obtain the keyword labeling matrix set; at the same time, the text sequence S x The set is compared with the high-frequency keyword set and the positions of the non-high-frequency keywords are marked to obtain a contextual marking matrix set;
[0011] S3, build a pre-training model, and convert the text sequence S obtained in S2 x The set, the keyword label matrix set and the context label matrix set are input into the pre-training model to obtain the traffic accident text representation set, which includes a global representation set, a global keyword representation set, a local keyword representation set, a global context representation set and a local context representation set;
[0012] The global representation set is the text sequence S x The set is obtained after the model representation, and the global keyword representation set is the text sequence S x The local keyword representation set is obtained by multiplying the set with the keyword tag matrix set and then passing through the model representation. The local keyword representation set is the text sequence S x The set is obtained by multiplying the keyword tag matrix set after being represented by the model. The global context representation set is the text sequence S x The local context representation set is obtained by multiplying the set with the context tag matrix set and then passing through the model representation. The local context representation set is the text sequence S x The set is obtained by multiplying the context label matrix set after being represented by the model;
[0013] S4, the global representation set obtained in S3 is calculated by the cross entropy loss function to obtain a first loss value; the global keyword representation set, the local keyword representation set, the global context representation set and the local context representation set obtained in S3 are respectively averaged and pooled, and then concatenated, and then the second loss value is calculated by the cross entropy loss function;
[0014] S5, adding the first loss value and the second loss value obtained in S4 to obtain a loss function, and using the loss function to iterate the pre-trained models in S3 and S4 to the optimum, to obtain multiple traffic accident text classification results.
[0015] A computer-readable storage medium stores executable instructions for causing a processor to execute the executable instructions to implement the traffic accident text classification method of the present invention.
[0016] An electronic device comprises: a memory for storing executable instructions; and a processor for implementing the traffic accident text classification method of the present invention when executing the executable instructions stored in the memory.
[0017] Compared with the prior art, the advantages of the present invention are:
[0018] A traffic accident text classification method, storage medium and electronic device of the present invention ensure data label balance, convert text classification tasks into text matching tasks, and use statistical methods to obtain data set keywords, use them as local features, and compare and interact local features with global features to enhance the model's attention to local features, thereby improving the model's performance. DETAILED DESCRIPTION
[0019] For the sake of clarity and conciseness, not all features of actual embodiments are described in the specification. However, it should be understood that many implementation-specific decisions may be made in the process of developing any such implementation in order to achieve the developer's specific goals, and these decisions may vary from one embodiment to another. In this document, embodiments may be combined with each other, features may be replaced or borrowed between different embodiments, and one or more features may be omitted in one embodiment, where feasible.
[0020] Example 1
[0021] This embodiment discloses a traffic accident text classification method, comprising the following steps:
[0022] S1, collect multiple traffic accident texts and perform part-of-speech tagging on them to obtain all keywords, then perform word frequency statistics on all keywords, take the top 30% of keywords as high-frequency keywords, and obtain a high-frequency keyword set;
[0023] In this embodiment, part-of-speech tagging selects noun categories with actual meanings in the tag categories as keywords, specifically "common nouns", "place nouns", "work names", "other proper nouns", "time" and "place names". (Note: if English appears in the word segmentation, it will be uniformly converted to lowercase, that is, it is case-insensitive. For example, Traffic Light and traffic light are considered to be the same phrase after conversion.) The above keywords are saved separately as all keywords.
[0024] Then we count the frequency of all keywords (the number of times the keywords appear), sort the keyword set from high to low according to the frequency, and select the top 30% of the words as the high-frequency keyword set. This is because the frequency of the last 70% of the keywords is only in the single digit, and these words are considered rare words and contribute less to the overall traffic accident corpus. Finally, we get the high-frequency keyword set, as shown in Table 1:
[0025] Table 1 High frequency keyword set
[0026] Keywords Word frequency die 4039 ACCIDENT 3812 Injuried 2746 car 2460 Traffic Accidents 1813 Together 1685 vehicle 1228 on the spot 1204 Collision 1156 Road Section 1029
[0027] S2, obtaining labels corresponding to the multiple traffic accident texts in S1, and adding a standard traffic accident text to each traffic accident text to obtain a traffic accident text dataset, wherein the traffic accident text dataset is a collection of multiple traffic accident text data, and each traffic accident text data includes a standard traffic accident text, a traffic accident text, and a label corresponding to the traffic accident text;
[0028] Among them, the standard traffic accident text contains the significant features of the traffic accident text, such as accident time, accident vehicle, witness situation, casualties, rescue situation, etc. The traffic accident text dataset is shown in Table 2;
[0029] Table 2 Traffic accident text data
[0030]
[0031]
[0032] Compare the traffic accident text in each traffic accident text data with the high-frequency keyword set to obtain the high-frequency keyword set of each text, and obtain a traffic accident keyword data set, wherein the traffic accident keyword data set is a collection of multiple traffic accident keyword data, and each traffic accident keyword data includes a standard traffic accident text, a traffic accident text, a high-frequency keyword set of the text, and a label corresponding to the traffic accident text;
[0033] The standard traffic accident text and traffic accident text in each traffic accident text data are serialized to obtain a text sequence S xSet, and then the text sequence S x The set is compared with the high-frequency keyword set and the position of the high-frequency keywords is marked to obtain the keyword labeling matrix set; at the same time, the text sequence S x The set is compared with the high-frequency keyword set and the positions of the non-high-frequency keywords are marked to obtain a contextual marking matrix set;
[0034] S3, build a pre-training model, and convert the text sequence S obtained in S2 x A set, a keyword label matrix set, and a context label matrix set are input into a pre-training model to obtain a traffic accident text representation set, wherein the traffic accident text representation set includes a global representation set, a global keyword representation set, a local keyword representation set, a global context representation set, and a local context representation set;
[0035] For the pre-training model, see Devlin J, Chang MW, Lee K, et al. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding[J]. 2018. DOI: 10.48550 / arXiv.1810.04805.
[0036] The global representation set is a text sequence S x The set is obtained after being represented by the model, and the global keyword representation set is a text sequence S x The local keyword representation set is obtained by multiplying the set with the keyword tag matrix set and then represented by the model. The local keyword representation set is the text sequence S x The set is obtained by multiplying the keyword tag matrix set after being represented by the model. The global context representation set is the text sequence S x The local context representation set is obtained by multiplying the set with the context tag matrix set and then passing through the model representation. The local context representation set is the text sequence S x The set is obtained by multiplying the context label matrix set after being represented by the model;
[0037] Take the sentence "The traffic accident caused 9 deaths and 2 injuries" as an example. It contains the high-frequency keywords "traffic accident", "death" and "injury". After the word segmentation, the sentence becomes "The traffic accident caused 9 deaths and 2 injuries", with a total of 10 phrases.
[0038] The keyword tag matrix is M kw ={0, 1, 0, 0, 0, 1, 0, 0, 1}, that is, the keyword position is 1, and the other context positions are 0;
[0039] The context label matrix is M ctx={1, 0, 1, 1, 1, 0, 1, 1, 0}, that is, the context position is 1, and the other keyword positions are 0;
[0040] The global representation set includes multiple global representations, where the input of one global representation is a text sequence Sx = {w1, w2, w3, w4, w5, w6, w7, w8, w9, w 10}, the output is the global representation h last_hidden_state ={v1, v2, v3, v4, v5, v6, v7, v8, v9, v 10}, where w i represents the i-th phrase after the original text is segmented, v i Represents the vector of the corresponding phrase after being represented by the pre-trained model;
[0041] The global keyword representation set includes multiple global keyword representations, one of which is a global keyword representation h part_kw The input is S x *M kw ={0,W2,0,0,0,0,W7,0,0,W 10}, the output is a global keyword representing h part_kw =PLM(S x *M kw )={v1, v2, v3, v4, v5, v6, v7, v8, v9, v 10}, where v′1≠v1, because the v1 vector integrates the semantic interaction relationship between all words in the whole sentence and the word, while v′1 only represents the semantic interaction relationship between the key words in the whole sentence and the word;
[0042] The local keyword representation set includes multiple local keyword representations, one of which is a local keyword representation h global_kw The input is S x ={w1,w2,w3,w4,w5,w6,w7,w8,w9,w 10}, the output is the local keyword representation: h global_kw =PLM(S x )*M kw =h last_hidden_state *M kw ={0,v2,0,0,0,0,v7,0,0,V 10}
[0043] The global context representation set includes multiple global context representations, one of which is h part_ctx The input is S x *M ctx ={W1, 0, W3, W4, W5, W6, 0, W8, W9, 0}, the output is the global context representation hpart_ctx =PLM(S x *M ctx )={v″1, v″2, v″3, v″4, v″5, v″6, v″7, v″8, v″9, v″ 10}, where v″1≠v1, because the v1 vector integrates the semantic interaction relationship of all words in the whole sentence to the word, while v″1 only represents the semantic interaction relationship of the context words in the whole sentence to the word;
[0044] The local context representation set includes multiple local context representations, one of which is h global_ctx Input is S x ={w1,w2,w3,w4,w5,w6,w7,w8,w9,w 10}, the output is the local context representation:
[0045] h global_ctx =PLM(S x )*M ctx =h last_hidden_state *M ctx
[0046] ={V1, 0, V3, V4, V5, V6, 0, V8, V9, 0}
[0047] S4, the global representation set obtained in S3 is calculated by the cross entropy loss function to obtain a first loss value; the global keyword representation set, the local keyword representation set, the global context representation set and the local context representation set obtained in S3 are respectively averaged and pooled, and then concatenated, and then the second loss value is calculated by the cross entropy loss function;
[0048] S5, adding the first loss value and the second loss value obtained in S4 to obtain a loss function, and using the loss function to iterate the pre-trained models of S3 and S4 to the optimum, to obtain multiple traffic accident text classification results, i.e., whether there is a traffic accident or not.
[0049] Example 2
[0050] This embodiment discloses an electronic device, including: a memory for storing executable instructions; a processor for executing the executable instructions stored in the memory to implement the traffic accident text classification method disclosed in Example 1.
[0051] Example 3
[0052] This embodiment discloses a computer-readable storage medium storing executable instructions for causing a processor to execute the executable instructions to implement the traffic accident text classification method disclosed in Embodiment 1.
[0053] The storage medium can be a computer-readable storage medium, for example, a ferroelectric random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disk, or a compact disk read-only memory (CD-ROM); it can also be various devices including one or any combination of the above memories.
[0054] In one embodiment, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0055] As an example, executable instructions may, but need not necessarily, correspond to a file in a file system, may be stored as part of a file storing other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions). As an example, executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed at multiple locations and interconnected by a communication network.
[0056] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0057] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0058] Example 4
[0059] This example is the experimental verification part of Example 1:
[0060] In order to determine the effectiveness of the dataset constructed by this method, a semantic matching method without feature engineering and not limited to special domain data is used to benchmark the dataset, with accuracy, precision, recall and macro-F1 as indicators, and accuracy as the main criterion. The specific method is as follows:
[0061] BERT classification model: The single sentence text in the dataset is fed into the BERT classification model, on which a linear classification layer is added to perform label prediction on the output representation vector.
[0062] The results are shown in Table 3. From the experimental results, we can see that the proposed method has achieved leading results in all indicators. Among them, the accuracy and F1 value are two summation indicators, and the proposed method far exceeds the baseline model. In the third row, the keyword information is removed for ablation experiments. The experiment shows that the introduction of keyword information effectively improves the model's ability to classify text. At the same time, by comparing the third row with the first row, it can be seen that the introduction of standard traffic accident text as a comparison also effectively improves the model's ability to capture text, thereby improving classification performance.
[0063] Table 3 Experimental results of experimental benchmarks
[0064]
[0065] The above are only various implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A traffic accident text classification method, characterized in that: The following steps are involved: S1, collect multiple traffic accident texts and perform part-of-speech tagging on them to obtain all keywords, then perform word frequency statistics on all keywords, take the top 30% of keywords as high-frequency keywords, and obtain a high-frequency keyword set; S2, obtaining labels corresponding to the multiple traffic accident texts in S1, and adding a standard traffic accident text to each traffic accident text to obtain a traffic accident text dataset, wherein the traffic accident text dataset is a collection of multiple traffic accident text data, each traffic accident text data includes a standard traffic accident text, a traffic accident text and its corresponding label; Compare the traffic accident text in each traffic accident text data with the high-frequency keyword set to obtain the high-frequency keyword set of each text, and obtain a traffic accident keyword data set, wherein the traffic accident keyword data set is a collection of multiple traffic accident keyword data, and each traffic accident keyword data includes a standard traffic accident text, a traffic accident text, a high-frequency keyword set of the text, and a label corresponding to the traffic accident text; The standard traffic accident text and traffic accident text in each traffic accident text data are serialized to obtain a text sequence S x Set, and then the text sequence S x The set is compared with the high-frequency keyword set and the position of the high-frequency keywords is marked to obtain the keyword labeling matrix set; at the same time, the text sequence S x The set is compared with the high-frequency keyword set and the positions of the non-high-frequency keywords are marked to obtain a contextual marking matrix set; S3, build a pre-training model, and convert the text sequence S obtained in S2 x A set, a keyword label matrix set, and a context label matrix set are input into a pre-training model to obtain a traffic accident text representation set, wherein the traffic accident text representation set includes a global representation set, a global keyword representation set, a local keyword representation set, a global context representation set, and a local context representation set; The global representation set is a text sequence S x The set is obtained after being represented by the model, and the global keyword representation set is a text sequence S x The local keyword representation set is obtained by multiplying the set with the keyword tag matrix set and then represented by the model. The local keyword representation set is the text sequence S x The set is obtained by multiplying the keyword tag matrix set after being represented by the model. The global context representation set is the text sequence S x The local context representation set is obtained by multiplying the set with the context tag matrix set and then passing through the model representation. The local context representation set is the text sequence S x The set is obtained by multiplying the context label matrix set after being represented by the model; S4, the global representation set obtained in S3 is calculated by the cross entropy loss function to obtain a first loss value; the global keyword representation set, the local keyword representation set, the global context representation set and the local context representation set obtained in S3 are respectively averaged and pooled, and then concatenated, and then the second loss value is calculated by the cross entropy loss function; S5, adding the first loss value and the second loss value obtained in S4 to obtain a loss function, and using the loss function to iterate the pre-trained models in S3 and S4 to the optimum, to obtain multiple traffic accident text classification results.
2. A computer-readable storage medium, characterized in that: Executable instructions are stored, which are used to cause the processor to execute the executable instructions to implement the traffic accident text classification method of claim 1.
3. An electronic device, characterized in that: include: A memory for storing executable instructions; The processor is used to implement the traffic accident text classification method of claim 1 when executing the executable instructions stored in the memory.