An accident classification method based on an LSTM-TextCNN algorithm combined with a word cloud display, a storage medium and an apparatus
By combining the LSTM-TextCNN algorithm with word cloud visualization, the problems of insufficient accuracy and lack of intuitive analysis in text classification are solved. This enables the visualization of accident classification and intuitive display of keywords, thereby improving the accuracy of classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAIYIN INSTITUTE OF TECHNOLOGY
- Filing Date
- 2022-12-29
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies cannot effectively utilize the semantic information of text context in text classification, resulting in insufficient classification accuracy, and lack intuitive chart analysis tools to observe influencing factors.
By employing the LSTM-TextCNN algorithm combined with word cloud visualization, and through data mining, preprocessing, classification training, and word cloud visualization, an intuitive display of accident classification keywords is achieved.
It enables visualization of accident classification, allowing for intuitive observation of text keywords and direct identification of factors influencing accident classification, thereby improving the accuracy and intuitiveness of the classification.
Smart Images

Figure CN116204633B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of natural language processing and text classification, and in particular to an accident classification method, storage medium, and apparatus based on the LSTM-TextCNN algorithm combined with word cloud display. Background Technology
[0002] Long Short-Term Memory (LSTM) networks, proposed by Hochreiter and Schmidhuber in 1997, are a special type of recurrent neural network used in machine learning. They can remember inputs and predict outputs for any given time period and solve the vanishing and exploding gradient problems common in recurrent neural networks, making them widely used in natural language processing.
[0003] The paper "Convolutional Neural Networks for Sentence Classification" proposes the TextCNN model, which uses one-dimensional convolution to obtain n-gram feature representations in sentences. TextCNN has a strong ability to extract shallow features from text and performs well in short text domains such as search and dialogue, focusing on intent classification. It is widely used and fast, and is generally the first choice. However, for long text domains, TextCNN mainly relies on filter windows to extract features, which limits its ability to model long distances and is not sensitive to word order.
[0004] The existing technology, "A News Text Classification Method and Medium Based on LSTM-TextCNN Algorithm" (Publication No. CN114491032A), while capable of effective text classification, lacks a method for intuitive observation. Therefore, when it's necessary to observe factors influencing classification, there's no effective and intuitive graphical analysis to support each classification. The existing technology, "A Text Classification Method Based on Attention Mechanism" (Publication No. CN115017314A), fails to utilize semantic information from the text context, resulting in insufficient accuracy in text classification. The existing technology, "A Method for Extracting Key Hidden Danger Factors in Power-Related Personal Injury Accidents Based on Text Mining" (Publication No. CN114064879A), focuses on extracting key accident factors, only utilizing word clouds and lacking research on text classification. Summary of the Invention
[0005] Purpose of the invention: The purpose of this invention is to provide an accident classification method, storage medium, and device based on the LSTM-TextCNN algorithm combined with word cloud display, which can generate a word cloud map of accident classification keywords, allowing for a very intuitive observation of the text keywords of each accident classification and direct acquisition of factors affecting accident classification.
[0006] Technical Solution: The present invention provides an accident classification method, storage medium, and device based on the LSTM-TextCNN algorithm combined with word cloud display. The method includes the following steps:
[0007] (1) Data mining: By sending page requests to the network server through the network address of the accident information, the extensible markup language text of the accident information is obtained; the path language of the extensible markup language is used for matching and searching to obtain text data and form a CSV file; wherein, the text data includes accident name crawling, accident classification data, accident link data, accident introduction data, accident cause data, and accident handling data;
[0008] (2) Table structure determination: Determine the relationship between incidents, category tags, and crawled data; the table structure includes the following fields: id field, type INT, storing record sequence number; name field, type CHAR, storing incident name data; label field, type INT, storing incident category tag; link field, type VARCHAR, storing incident link data; introduction field, type TEXT, storing incident introduction data; reason field, type TEXT, storing incident cause data; treatment field, type TEXT, storing incident treatment data.
[0009] (3) Data preprocessing, including: data cleaning, sentence segmentation, stop word removal, and data entry;
[0010] (4) Classify and train the accident information data stored in the database;
[0011] (5) Use word cloud method to display the keyword of accident classification information;
[0012] (6) Backend design: Obtain comprehensive accident information by establishing multiple services.
[0013] Furthermore, step (3) includes the following steps:
[0014] (31) Data cleaning: Remove duplicate words, spaces, or text information that is irrelevant to the accident information;
[0015] (32) Sentence segmentation: Using articles as the unit, the accident information after data cleaning is segmented into sentences according to punctuation marks;
[0016] (33) Stop word removal: Using manual verification, irrelevant words are combined with general stop words to create a corresponding stop word list;
[0017] (34) Data import: Import the processed data into the database, that is, import the crawled CSV file data into the MySQL database;
[0018] Furthermore, step (4) includes the following steps:
[0019] (41) Set the parameters required for the word2vec model, including: word vector dimension, number of parallel threads, maximum distance between the current word and the target word, and number of training rounds;
[0020] (42) The accident information processed in step (3) is divided into training set data and test set data in an 8:2 ratio. The training set data and test set data are used as inputs to the word2vec model to obtain the corresponding word vector feature matrices. The corresponding feature matrices are then designated as the training set and the test set. The dimension of the vector feature matrix is:
[0021] (43) Construct the LSTM-TextCNN model and set up the training process;
[0022] (44) Input the training set into the TextCNN model and the LSTM model respectively, and train for 20-30 rounds;
[0023] (45) Set the output of the TextCNN model as feature vector one and the output of the LSTM model as feature vector two.
[0024] (46) Use the Concatenta() function to merge feature vector 1 and feature vector 2 into feature vector 3; use the Softmax method to perform classification prediction on feature vector 3;
[0025] (47) Finally, the test set is input into the trained model for prediction, and the final classification model will be obtained.
[0026] Furthermore, step (43) includes the following steps:
[0027] (431) Construct a TextCNN network to filter vector features;
[0028] (432) Construct an LSTM network and use the LSTM network for feature extraction.
[0029] Furthermore, step (5) includes the following steps:
[0030] (51) Merge the preprocessed accident information text data under each tag category; each category has a text file;
[0031] (52) Read each text file and set the corresponding word cloud parameters: the background color is white, the maximum number of words in the word cloud is 1000, and the maximum font size of the word cloud is 100.
[0032] (53) Use the WordCloud method to output the word cloud, save the word cloud for display, and form an intuitive keyword display of accident information.
[0033] Furthermore, step (6) specifically involves obtaining accident information through the user center's accident query service, accident evaluation service, and favorites list management service.
[0034] Furthermore, a storage medium storing a computer program, wherein the computer program is configured to execute the above-described method at runtime.
[0035] Furthermore, an apparatus includes a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the above-described method.
[0036] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: By combining deep learning algorithms with word cloud technology, a word cloud diagram of accident classification keywords can be generated, and the text keywords of each accident classification can be observed very intuitively. By observing the word cloud diagram, the factors affecting accident classification can be directly obtained, and a general understanding of a certain type of accident can be obtained; to a certain extent, the visualization of accident classification technology has been realized. Attached Figure Description
[0037] Figure 1 This is a schematic diagram of the structure of the present invention; Detailed Implementation
[0038] The technical solution of the present invention will be further described below with reference to the accompanying drawings.
[0039] like Figure 1 As shown, this embodiment of the invention provides an accident classification method, storage medium, and device based on the LSTM-TextCNN algorithm combined with word cloud display. The method includes the following steps:
[0040] (1) Data mining: By sending page requests to the network server through the network address of the accident information, the extensible markup language text of the accident information is obtained; the path language of the extensible markup language is used for matching and searching to obtain text data and form a CSV file; wherein, the text data includes accident name crawling, accident classification data, accident link data, accident introduction data, accident cause data, and accident handling data;
[0041] (2) Table structure determination: Determine the relationship between accidents, category tags, and crawled data; the table structure includes the following fields: id field, type INT, storing record sequence number; name field, type CHAR, storing accident name data; label field, type INT, storing accident category tag; link field, type VARCHAR, storing accident link data; introduction field, type TEXT, storing accident introduction data; reason field, type TEXT, storing accident cause data; treatment field, type TEXT, storing accident treatment measures;
[0042] (3) Data preprocessing, including: data cleaning, sentence segmentation, stop word removal, and data import, including the following steps:
[0043] (31) Data cleaning: Remove duplicate words, spaces, or text information that is irrelevant to the accident information;
[0044] (32) Sentence segmentation: Using articles as the unit, the accident information after data cleaning is segmented into sentences according to punctuation marks;
[0045] (33) Stop word removal: Using manual verification, irrelevant words are combined with general stop words to create a corresponding stop word list;
[0046] (34) Data import: Import the processed data into the database, that is, import the crawled CSV file data into the MySQL database;
[0047] (4) Classify and train the accident information data stored in the database, including the following steps:
[0048] (41) Set the parameters required for the word2vec model, including: word vector dimension, number of parallel threads, maximum distance between the current word and the target word, and number of training rounds;
[0049] (42) The accident information processed in step (3) is divided into training set data and test set data in a ratio of 8:2. The training set data and test set data are used as inputs to the word2vec model to obtain the corresponding word vector feature matrix. The corresponding feature matrix is divided into training set and test set.
[0050] (43) Construct the LSTM-TextCNN model and set up the training process, including the following steps:
[0051] (431) Construct a TextCNN network to filter vector features;
[0052] (432) Construct an LSTM network and use the LSTM network for feature extraction.
[0053] (44) Input the training set into the TextCNN model and the LSTM model respectively, train for 20 rounds, and then train;
[0054] (45) Set the output of the TextCNN model as feature vector one and the output of the LSTM model as feature vector two.
[0055] (46) Use the Concatenta() function to merge feature vector 1 and feature vector 2 into feature vector 3; use the Softmax method to perform classification prediction on feature vector 3;
[0056] (47) Finally, the test set is input into the trained model for prediction, and the final classification model will be obtained.
[0057] (5) Using the word cloud method, a word cloud of accident classification information keywords is displayed, including the following steps:
[0058] Includes the following steps:
[0059] (51) Merge the preprocessed accident information text data under each tag category; each category has a text file;
[0060] (52) Read each text file and set the corresponding word cloud parameters: background color is white, maximum number of words in the word cloud is 1000, and maximum font size in the word cloud is 100.
[0061] (53) Use the WordCloud method to output the word cloud, save the word cloud for display, and form an intuitive keyword display of accident information.
[0062] (6) Backend Design: Comprehensive incident information is obtained by establishing multiple services, specifically: incident information is obtained through the user center for incident query service, incident evaluation service, and favorites list management service.
[0063] The specific parameter settings for this embodiment of the invention are as follows: word2vec model word vector dimension: 300; word2vec model parallel thread count: 8; maximum distance between the current word and the target word in the word2vec model: 10; word2vec model training epochs: 10; TextCNN convolutional kernel height: 2, 100, 3, 100, 4, 100; number of labels: 9. Word cloud background color: white; maximum number of words in the word cloud: 1000; maximum font size in the word cloud: 100.
[0064] An embodiment of the present invention provides a storage medium storing a computer program, wherein the computer program is configured to execute the method described above when running.
[0065] This invention also provides an apparatus including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the above-described method.
Claims
1. An accident classification method based on the LSTM-TextCNN algorithm combined with word cloud display, characterized in that, Includes the following steps: (1) Data mining: Send page requests to the network server through the network address of the accident information to obtain the extensible markup language text of the accident information; use the path language of the extensible markup language to match and search to obtain text data and form a CSV file; wherein, the text data includes accident name crawling, accident classification data, accident link data, accident introduction data, accident cause data, and accident handling data; (2) Determining the table structure: Determine the relationship between accidents, category tags, and crawled data; the table structure includes the following fields: id field, type INT, storing record number; name field, type CHAR, storing accident name data; label field, type INT, storing accident category tag; link field, type VARCHAR, storing accident link data; introduction field, type TEXT, storing accident introduction data; reason field, type TEXT, storing accident cause data; treatment field, type TEXT, storing accident treatment measures; (3) Data preprocessing, including: data cleaning, sentence segmentation, stop word removal, and data entry; (4) Classify and train the accident information data stored in the database; including the following steps: (41) Set the parameters required for the word2vec model, including: word vector dimension, number of parallel threads, maximum distance between the current word and the target word, and number of training rounds; (42) The accident information processed in step (3) is divided into training set data and test set data in a ratio of 8:
2. The training set data and test set data are used as inputs to the word2vec model to obtain the corresponding word vector feature matrix. The corresponding feature matrix is divided into training set and test set. The dimension of the vector feature matrix is 1*300. (43) Construct the LSTM-TextCNN model and set up the training process; (44) Input the training set into the TextCNN model and the LSTM model respectively, and train for 20-30 rounds; (45) Set the output of the TextCNN model as feature vector one and the output of the LSTM model as feature vector two. (46) Use the Concatenta() function to merge feature vector 1 and feature vector 2 into feature vector 3; use the Softmax method to perform classification prediction on feature vector 3; (47) Finally, the test set is input into the trained model for prediction, and the final classification model will be obtained; (5) Using the word cloud method, display the word cloud of accident classification information keywords; including the following steps: (51) Merge the preprocessed accident information text data under each tag category; each category has a text file; (52) Read each text file and set the corresponding word cloud parameters: the background color is white, the maximum number of words in the word cloud is 1000, and the maximum font size of the word cloud is 100. (53) Use the WordCloud method to output the word cloud, save the word cloud for display, and form an intuitive keyword display of accident information; (6) Backend design: Obtain comprehensive accident information by establishing multiple services.
2. The accident classification method based on LSTM-TextCNN algorithm combined with word cloud display according to claim 1, characterized in that, Step (3) includes the following steps: (31) Data cleaning: Remove duplicate words, spaces, or text information that is irrelevant to the accident information; (32) Sentence segmentation: Using articles as units, the accident information after data cleaning is segmented into sentences according to punctuation marks; (33) Stop word removal: Using manual verification, irrelevant words are combined with general stop words to create a corresponding stop word list; (34) Data import: Import the processed data into the database, that is, import the crawled CSV file data into the MySQL database.
3. The accident classification method based on LSTM-TextCNN algorithm combined with word cloud display according to claim 1, characterized in that, Step (43) includes the following steps: (431) Construct a TextCNN network to filter vector features; (432) Construct an LSTM network and use the LSTM network for feature extraction.
4. The accident classification method based on LSTM-TextCNN algorithm combined with word cloud display according to claim 1, characterized in that, The specific steps (6) are as follows: obtain accident information through the user center's accident query service, accident evaluation service, and favorites list management service.
5. A storage medium storing a computer program, wherein, The computer program is configured to execute the method as described in any one of claims 1-3 at runtime.
6. An apparatus comprising a memory and a processor, wherein, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1-3.