A method, apparatus and storage medium for constructing a corpus
By processing text data using a pre-trained emotion classification model, the problems of high time and economic costs and low efficiency in the construction of traditional emotion corpora are solved, and efficient and accurate emotion corpus construction is achieved.
Patent Information
- Application Number
- CN202511192607.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-25
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2045-08-25
AI Technical Summary
Traditional methods of building emotion corpora suffer from high time and economic costs, low efficiency, and inaccurate labeling.
A pre-trained emotion classification model is used to process text data through a word embedding module, a graph structure analysis module, and an emotion classification module to build an emotion corpus, reducing manual intervention and improving the accuracy and efficiency of annotation.
It has enabled the efficient construction of an emotion corpus, reduced time and economic costs, improved the accuracy of annotation, and ensured the objective classification of emotion categories.
Smart Images

Figure CN121117216B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus and storage medium for constructing a corpus. Background Technology
[0002] Corpus construction and analysis are widely studied areas in natural language processing. With the rapid growth of large-scale text data such as social media and online comments, corpus construction has become increasingly important. Sentiment corpora, as a type of corpus, provide rich data support for fields such as education management, public opinion monitoring, and sentiment computing.
[0003] The construction of a traditional emotion corpus is a systematic project, encompassing the entire process from data collection to data annotation. The specific process includes: First, operators manually collect multiple text data points. Then, based on pre-established emotion classification standards, operators determine the emotion category corresponding to each text data point and annotate each text data point with emotion. Finally, operators construct the emotion corpus based on the annotated data points. However, the above-described traditional method of constructing an emotion corpus has certain drawbacks.
[0004] For example, in the traditional process of building an emotion corpus, text data needs to be collected and labeled manually. This manual processing constitutes the majority of the entire process, significantly increasing the economic cost of building the corpus. Furthermore, manual data collection and labeling greatly increase the time required for corpus construction, thus increasing the time cost and reducing efficiency. Additionally, because traditional methods rely on operators to determine the emotion category for each text data entry based on emotion classification standards, the subjective nature of this process can lead to inaccuracies in the classification.
[0005] The existing methods for constructing corpora have technical problems such as high time and economic costs, low efficiency, and inaccurate corpus annotation. Currently, no effective solution has been proposed. Summary of the Invention
[0006] The embodiments of this disclosure provide a corpus construction method, apparatus, and storage medium to at least solve the technical problems of high time and economic costs, low efficiency, and inaccurate corpus annotation in traditional corpus construction methods in the prior art.
[0007] According to one aspect of the embodiments of this disclosure, a corpus construction method is provided, comprising: collecting multiple text data and inputting each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module; when the word embedding module receives each text data, the word embedding module outputs a first feature vector corresponding to the smallest semantic unit in each text data; inputting multiple first feature vectors corresponding to each text data into the graph structure analysis module, constructing a first graph structure corresponding to each text data using the graph structure analysis module and based on the multiple first feature vectors corresponding to each text data, and analyzing the relationship between nodes in each first graph structure to generate multiple second graph structures; determining emotion category labels corresponding to each text data using the emotion classification module and based on the second graph structures corresponding to each text data; and labeling each text data based on the determined emotion category labels, and constructing a corpus based on the labeled text data.
[0008] According to another aspect of the present disclosure, a storage medium is also provided, the storage medium including a stored program, wherein, when the program is executed, a processor performs any of the methods described above.
[0009] According to another aspect of the present disclosure, a corpus construction implementation apparatus is also provided, comprising: a text data acquisition module, used to acquire multiple text data and input each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module; a word embedding module, used to output a first feature vector corresponding to the smallest semantic unit in each text data when the word embedding module receives each text data; a graph structure analysis module, used to input multiple first feature vectors corresponding to each text data into the graph structure analysis module, and use the graph structure analysis module and based on the multiple first feature vectors corresponding to each text data to construct a first graph structure corresponding to each text data, and analyze the relationship between each node in each first graph structure to generate multiple second graph structures; an emotion classification module, used to use the emotion classification module and based on the second graph structures corresponding to each text data to determine the emotion category label corresponding to each text data; and a corpus construction module, used to label each text data based on the determined emotion category labels, and construct a corpus based on the labeled text data.
[0010] According to another aspect of the present disclosure, a corpus construction implementation apparatus is also provided, including: a processor; and a memory connected to the processor, used to provide the processor with instructions to process the following steps: collecting multiple text data and inputting each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module; when the word embedding module receives each text data, the word embedding module outputs a first feature vector corresponding to the smallest semantic unit in each text data; inputting multiple first feature vectors corresponding to each text data into the graph structure analysis module, constructing a first graph structure corresponding to each text data using the graph structure analysis module and based on the multiple first feature vectors corresponding to each text data, and analyzing the relationship between nodes in each first graph structure to generate multiple second graph structures; determining emotion category labels corresponding to each text data using the emotion classification module and based on the second graph structures corresponding to each text data; and labeling each text data based on the determined emotion category labels, and constructing a corpus based on the labeled text data.
[0011] This application discloses a method for constructing a corpus. First, a processor collects multiple text data points and inputs each text data point into a pre-trained sentiment classification model. Then, with the word embedding module receiving each text data point, the processor uses the word embedding module to output a first feature vector corresponding to the smallest semantic unit in each text data point. Further, the processor inputs multiple first feature vectors corresponding to each text data point into a graph structure analysis module. Using the graph structure analysis module and based on the multiple first feature vectors corresponding to each text data point, a first graph structure corresponding to each text data point is constructed, and the relationships between nodes in each first graph structure are analyzed to generate multiple second graph structures. Then, the processor uses the sentiment classification module and based on the second graph structures corresponding to each text data point, to determine the sentiment category label corresponding to each text data point. Finally, based on the determined sentiment category labels, the processor standardizes each text data point and constructs a corpus based on the labeled text data points.
[0012] As described above, this application utilizes a pre-trained emotion classification model to label the emotions of multiple collected text data sets. In the process of classifying and matching emotion category labels for each text data set using the emotion classification model, there is no subjectivity; the corresponding emotion category labels are determined solely based on the objective content of the text data. This allows for accurate classification of the emotion category corresponding to each text data set.
[0013] Furthermore, unlike manually collecting multiple text data points and labeling each text data point, this application crawls multiple text data points using a processor and uses a pre-trained emotion classification model to label the emotions of multiple text data points. This improves the efficiency of data collection and labeling, thereby reducing the time cost required to build a corpus and increasing the efficiency of corpus construction.
[0014] This solves the technical problems of traditional corpus construction methods in existing technologies, such as high time and economic costs, low efficiency, and inaccurate corpus annotation. Attached Figure Description
[0015] The accompanying drawings, which are included to provide a further understanding of this disclosure and form part of this application, illustrate exemplary embodiments of this disclosure and are used to explain this disclosure, but do not constitute an undue limitation of this disclosure. In the drawings:
[0016] Figure 1 This is a hardware structure block diagram of a computing device for implementing the method described in Embodiment 1 of this disclosure;
[0017] Figure 2 This is a schematic diagram of the corpus construction implementation system according to Embodiment 1 of this application;
[0018] Figure 3 This is a flowchart illustrating the corpus construction method according to Embodiment 1 of this application;
[0019] Figure 4 This is a schematic diagram of the emotion classification model according to Embodiment 1 of this application;
[0020] Figure 5 This is a schematic diagram of the first graph structure corresponding to text data P1 according to Embodiment 1 of this application;
[0021] Figure 6 This is a schematic diagram of the corpus construction implementation apparatus according to Embodiment 2 of this application; and
[0022] Figure 7 This is a schematic diagram of the corpus construction implementation device according to Embodiment 3 of this application. Detailed Implementation
[0023] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this disclosure.
[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0025] Example 1
[0026] According to this embodiment, a method embodiment for corpus construction is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0027] The method embodiments provided in this example can be executed on mobile terminals, computer terminals, servers, or similar computing devices. Figure 1 A hardware block diagram of a computing device for implementing a corpus construction method is shown. For example... Figure 1 As shown, a computing device may include one or more processors (processors may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), memory for storing data, transmission devices for communication functions, and input / output interfaces. The memory, transmission devices, and input / output interfaces are connected to the processor via a bus. In addition, it may also include a display, keyboard, and cursor control device connected to the input / output interfaces. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, a computing device may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0028] It should be noted that the aforementioned one or more processors and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element in a computing device. As involved in the embodiments of this disclosure, the data processing circuits serve as processor control (e.g., selection of a variable resistor termination path connected to an interface).
[0029] The memory can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the corpus construction implementation method in this disclosure embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the corpus construction implementation method of the aforementioned application. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the computing device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0030] The transmission device is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the computing device's communications provider. In one example, the transmission device includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0031] The display can be, for example, a touchscreen liquid crystal display (LCD), which allows users to interact with the user interface of the computing device.
[0032] It should be noted here that, in some optional embodiments, the above... Figure 1 The computing device shown may include hardware elements (including circuitry), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware and software elements. It should be noted that... Figure 1 This is only one instance of a specific particular instance, and is intended to illustrate the types of components that may exist in the aforementioned computing devices.
[0033] Figure 2 This is a schematic diagram of the corpus construction implementation system described in this embodiment. (Refer to...) Figure 2 As shown, the system includes a terminal device 100 and a processor 200. The user sends a command to the processor 200 to construct a corpus (e.g., a command to construct an emotion corpus) through the terminal device 100. The processor 200 then responds to the command and uses web crawling technology to crawl multiple text data from various websites. The processor 200 also inputs each text data into a pre-trained emotion classification model and uses the model to determine the emotion category label corresponding to each text data. Furthermore, the processor 200 annotates each text data based on the determined emotion category label and constructs a corpus based on the annotated text data.
[0034] It should be noted that the terminal device 100 and processor 200 in the system can both use the hardware structure described above.
[0035] Under the aforementioned operating environment, according to the first aspect of this embodiment, a corpus construction implementation method is provided, which consists of... Figure 2 The processor 200 shown is implemented. Figure 3 A flowchart illustrating the method is shown below. (Refer to...) Figure 3 As shown, the method includes:
[0036] S302: Collect multiple text data and input each text data into a pre-trained emotion classification model, which includes a word embedding module, a graph structure analysis module, and an emotion classification module.
[0037] S304: When the word embedding module receives each piece of text data, the word embedding module outputs the first feature vector corresponding to the smallest semantic unit in each piece of text data.
[0038] S306: Input the multiple first feature vectors corresponding to each text data into the graph structure analysis module. Using the graph structure analysis module and based on the multiple first feature vectors corresponding to each text data, construct the first graph structure corresponding to each text data, and analyze the relationship between each node in each first graph structure to generate multiple second graph structures.
[0039] S308: Using the emotion classification module and based on the second graph structure corresponding to each piece of text data, determine the emotion category label corresponding to each piece of text data; and
[0040] S310: Based on the determined emotion category labels, annotate each piece of text data, and construct a corpus based on the annotated text data.
[0041] Specifically, firstly, the user sends a command to the processor 200 to build a corpus via the terminal device 100. Then, the processor 200 responds to the command by collecting multiple text data entries. The processor 200 can obtain these text data entries, for example, using web crawling techniques (such as the Scrapy framework) and third-party tools (such as Octoparse). Furthermore, if the data to be crawled by the processor 200 is microblog posts, it can also utilize the microblog API to crawl the text data. Table 1 shows the format of the text data.
[0042] Table 1
[0043] Field Name Field Description ID Website ID Bid Website Bid username User nickname who posted the post content The main content of the post topic The topic associated with the post Location of publication Posting location Release time Posting time Source of publication Client for posting Number of likes Number of likes on the post Number of comments Number of comments on the post Number of reposts Number of posts forwarded
[0044] The processor 200 then selects the publication time and content from the text data and stores them separately in an Excel spreadsheet. Further, a Python script is used to clean and preprocess the content. The data cleaning rules include: 1) deleting text between two ## symbols (i.e., topic tags) to remove unnecessary content; 2) replacing consecutive question marks with a single question mark to reduce redundancy; 3) using regular expressions to retain Chinese characters, letters, numbers, spaces, and common punctuation marks (such as commas, periods, question marks, exclamation marks, quotation marks, and dashes), replacing all other special symbols; 4) deleting text shorter than 15 characters or longer than 120 characters to ensure the retained text meets length requirements, avoiding the inclusion of unambiguous short text and excessively long text; 5) deduplication to ensure each cleaned text appears only once, retaining the first occurrence.
[0045] For example, if the collected text data is "Heavy rain in a certain province, the heavy rain in a certain city is terrible!??? Everyone please be careful!", then the text data after data cleaning will be "The heavy rain in a certain city is terrible! Everyone please be careful!".
[0046] The processor 200 then inputs the pre-processed text data into the pre-trained sentiment classification model (S302). Figure 4 A schematic diagram of an emotion classification model is shown. (Reference) Figure 4 As shown, the emotion classification model is mainly used to classify emotions in input text data, and the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module.
[0047] Upon receiving multiple text data input from the processor 200, the word embedding module performs TF-IDF feature extraction, PMI feature extraction, and RoBERTa embedding on each text data, thereby outputting a first feature vector (S304) corresponding to the smallest semantic unit (i.e., token) in each text data. TF-IDF feature extraction is primarily used to assess the importance of each word in each text data. PMI feature extraction is mainly used to calculate the point-to-point mutual information (i.e., the degree of association) between words in each text data. RoBERTa embedding is mainly used for word segmentation and word embedding, generating multiple first feature vectors. These details will be described in more detail later and will not be repeated here.
[0048] Furthermore, it is worth noting that in this embodiment, the method for calculating the point mutual information between words in each text data can also be PPMI feature extraction, and no specific restrictions are imposed here.
[0049] It is worth noting that, since each piece of text data contains multiple smallest semantic units, each piece of text data corresponds to multiple first feature vectors. For example, processor 200 collects multiple pieces of text data P1 to P2. m Then the text data P1 corresponds to multiple first feature vectors T 1,1 ~T 1,t The text data P2 corresponds to the first feature vector T. 2,1 ~T 2,t Text data P m The corresponding first eigenvector T m,1 ~T m,t Those skilled in the art should understand that the above description assumes that each piece of text data corresponds to t first feature vectors. In reality, the number of first feature vectors corresponding to each piece of text data can be different, which will not be elaborated here.
[0050] The processor 200 then inputs multiple first feature vectors corresponding to each piece of text data into the graph structure analysis module. Using the graph structure analysis module and based on these first feature vectors, it constructs a first graph structure corresponding to each piece of text data and analyzes the relationships between nodes in each first graph structure, thereby generating multiple second graph structures (S306). Specifically, the graph structure analysis includes a graph structure construction unit, a first graph attention network unit, and a second graph attention network unit. The graph structure construction unit is used to construct the first graph structure corresponding to each piece of text data. The first and second graph attention network units are mainly used to analyze the first graph structures corresponding to each piece of text data, extract and mine features and patterns in multiple first graph structures, thereby effectively capturing the complex relationships between nodes and edges, and generating second graph structures corresponding to each piece of text data. The above will be described in detail later, so it will not be repeated here.
[0051] Further, the processor 200 inputs the second graph structure corresponding to each piece of text data into the emotion classification module and determines the emotion category label corresponding to each piece of text data (S308). The emotion classification module includes a fully connected unit and an emotion classification unit. Specifically, first, the processor 200 inputs the second feature vector corresponding to each node in each second graph structure into the fully connected layer and generates emotion category vectors corresponding to each piece of text data. Then, the processor 200 uses the sigmoid function to map the emotion category vectors corresponding to each piece of text data to the interval [0,1] and outputs the emotion category probability sequence corresponding to each piece of text data. The emotion category probability sequence includes the probability values of each emotion type corresponding to the text data. Finally, the processor 200 inputs the emotion category probability sequence corresponding to each piece of text data into the emotion classification unit and determines the emotion category label corresponding to each piece of text data. The above will be described in detail later, so it will not be repeated here.
[0052] Finally, the processor 200 manually reviews the determined emotion category labels corresponding to each piece of text data, ensuring that the accuracy of the emotion category labels reaches 100%. During the review process, the emotion category labels are verified and corrected based on the basic content of the text data to ensure that the emotion category labels for each piece of text data are accurate. After the review is completed, the text data is labeled based on the confirmed emotion category labels. The confirmed emotion classification results are then merged with the publication time information in the text data to form a complete emotion corpus, which is stored in an Excel file to construct the corpus (S310). The fields in the Excel file include: Corpus ID, a unique identifier for each piece of text data; Text content: the original text content; Emotion labels: the reviewed emotion category labels; Emotion keywords: manually labeled emotion-related keywords; Publication time: the publication time of the text.
[0053] Alternatively, you can use Python's sqlite3 library to connect to an SQLite database and create a structured table to store the sentiment corpus data. The table fields should match those of the Excel file. Read data from the Excel file, extract the fields to be stored, normalize the data, ensure consistent field formats, and then insert the processed data into the SQLite database table. After data insertion, close the database connection to ensure data integrity and security.
[0054] As described in the background section, for example, in the traditional process of building an emotion corpus, text data needs to be collected and labeled manually. That is, manual processing accounts for the majority of the entire emotion corpus construction process, significantly increasing the economic cost. Furthermore, manual data collection and labeling greatly increase the time required to build the emotion corpus, thus increasing the time cost and reducing efficiency. Moreover, because traditional emotion corpus construction relies on operators determining the emotion category corresponding to each piece of text data based on emotion classification standards, the operator's subjectivity may lead to inaccurate classifications.
[0055] In view of this, this application provides a method for constructing a corpus. As described above, this application utilizes a pre-trained emotion classification model to label the collected text data with emotion categories. In the process of classifying and matching emotion category labels for each text data item using the emotion classification model, there is no subjectivity; the corresponding emotion category labels are determined solely based on the objective content of the text data. This allows for accurate classification of the emotion category corresponding to each text data item.
[0056] Furthermore, unlike manually collecting multiple text data points and labeling each text data point, this application crawls multiple text data points using a processor and uses a pre-trained emotion classification model to label the emotions of multiple text data points. This improves the efficiency of data collection and labeling, thereby reducing the time cost required to build a corpus and increasing the efficiency of corpus construction.
[0057] This solves the technical problems of traditional corpus construction methods in existing technologies, such as high time and economic costs, low efficiency, and inaccurate corpus annotation.
[0058] Optionally, the emotion classification module includes a fully connected unit and an emotion classification unit. The operation of determining the emotion category label corresponding to each text data item using the emotion classification module and based on the second graph structure corresponding to each text data item includes: generating emotion category vectors corresponding to each text data item using the fully connected layer and based on the second feature vectors corresponding to each node in each second graph structure; mapping the emotion category vectors corresponding to each text data item to the interval [0,1] using the sigmoid function and outputting the emotion category probability sequence corresponding to each text data item; and using the emotion classification unit and based on the emotion category sequence corresponding to each text data item to classify the emotion of each text data item and determine the emotion category label corresponding to each text data item.
[0059] Specifically, the emotion classification module includes a fully connected unit and an emotion classification unit. Furthermore, after the processor 200 generates a second graph structure corresponding to each piece of text data, it extracts the second feature vector corresponding to each node in each second graph structure, and inputs these multiple second feature vectors corresponding to each second graph structure into the fully connected layer for final mapping. The fully connected layer works by mapping node features in the second graph structure through dynamic attention, and its calculation is as follows:
[0060] y = w1h + b
[0061] Where y is the final output, representing the score of each text data in each sentiment category, w1 represents the weight matrix of the fully connected layer, which maps the input features to the dimension of the output category, and b represents the bias term.
[0062] The processor 200 then uses the sigmoid activation function to normalize the scores of each text data point across different sentiment categories, thereby obtaining a probability sequence of sentiment categories corresponding to each text data point. The specific formula is as follows:
[0063]
[0064] in, This represents the probability of each text data point in each sentiment category, and σ represents the sigmoid activation function. The specific formula is as follows:
[0065]
[0066] The sigmoid activation function maps the output value y to the interval [0, 1], models the probability of the existence of each emotion category, and reflects the prediction confidence of each emotion category in each piece of text data.
[0067] Therefore, the probability sequence of the emotion category corresponding to each piece of text data can be determined through the above method. For example, processor 200 collected multiple pieces of text data P1 to P2. m And includes emotion categories a1 to a2 h Then, when the processor 200 inputs the second feature vectors corresponding to each node in the second graph structure corresponding to each piece of text data into the fully connected layer, it can output the probability sequence of the sentiment category corresponding to the text data P1. The probability sequence of sentiment categories corresponding to text data P2 And so on, with text data P m Corresponding emotion category probability sequence
[0068] Finally, the processor 200 inputs the probability sequence of the emotion category corresponding to each piece of text data into the emotion classification unit. The emotion classification unit uses a multi-encoder to convert the emotion labels into binary vectors. Each dimension corresponds to an emotion category, and the emotion classification unit outputs the probability value for each emotion category, taking the emotion category corresponding to the highest probability value as the final emotion label for that piece of text data. For example, in the probability sequence of the emotion category corresponding to text data P1... In the middle, the probability value corresponding to the emotion category a1 If the value is the largest, then for text data P1, the emotion category a1 is the final emotion label for that text data.
[0069] Thus, the above operations achieve the technical effect of accurately classifying emotions based on each piece of text data and annotating each piece of text data to ensure the accuracy of the corpus subsequently constructed.
[0070] Optionally, the graph structure analysis module includes a graph structure construction unit, and multiple first feature vectors corresponding to each piece of text data are input into the graph structure analysis module. The operation of constructing a first graph structure corresponding to each piece of text data using the graph structure analysis module and based on the multiple first feature vectors corresponding to each piece of text data includes: determining nodes for constructing the first graph structure, where nodes represent the smallest semantic units in the text data, and the initial features of the nodes correspond to the first feature vectors; determining edges for constructing the first graph structure, where edges represent the association relationships between the smallest semantic units in the text data; and constructing the first graph structure corresponding to each piece of text data based on the nodes and edges.
[0071] Specifically, firstly, the graph structure building unit determines the nodes used to construct the first graph structure corresponding to each piece of text data. Here, each node in the first graph structure represents the smallest semantic unit (i.e., a token) in the text data. Furthermore, the initial feature of each node is a first feature vector corresponding to each smallest semantic unit in the text data.
[0072] Then, the graph structure building unit determines the edges used to construct the first graph structure corresponding to each piece of text data. The edges of the first graph structure represent the relationships between the smallest semantic units in the text data.
[0073] Furthermore, given the nodes and edges used to construct the first graph structure, the graph structure construction unit constructs the first graph structure corresponding to each piece of text data. For example, Figure 5 This is a schematic diagram of the first graph structure corresponding to text data P1 according to an embodiment of this application. (Reference) Figure 5 As shown, the text data P1 includes Y1 to Y2. t Where Y represents the token. The graph structure building unit will then combine Y1 to Y2. t As a node used to construct the first graph structure, and the initial feature of node Y1 is the first feature vector T. 1,1 The initial feature of node Y2 is the first feature vector T. 1,2 ..., node Y t The initial feature is the first feature vector T. 1,t Furthermore, the graph structure building units determine each smallest semantic unit Y1~Y t The relationships between them are used to determine the edges Z1 to Z2 used to construct the first graph structure. uFinally, the graph structure building units are based on nodes Y1 to Y2. t and edges Z1 to Z u Construct the first graph structure corresponding to the text data P1.
[0074] Optionally, the graph structure analysis module includes a first graph attention network unit and a second graph attention network unit. Multiple first feature vectors corresponding to each piece of text data are input into the graph structure analysis module. The graph structure analysis module, based on the multiple first feature vectors corresponding to each piece of text data, analyzes the relationships between nodes in each first graph structure to generate multiple second graph structures. This includes: inputting the first graph structures corresponding to each piece of text data into the first graph attention network unit, and dynamically weighting and aggregating the first feature vectors corresponding to the adjacent nodes of the target node in the first graph structure, thereby updating the first feature vectors to third feature vectors, where the target node indicates any node in the first graph structure; updating each first graph structure to a third graph structure based on the multiple third feature vectors corresponding to each first graph structure; and generating multiple second graph structures using the second graph attention network unit and based on the multiple third graph structures.
[0075] Specifically, after the graph structure construction unit constructs the first graph structure corresponding to each piece of text data, the processor 200 inputs the first graph structure corresponding to each piece of text data into the first graph attention network unit. The first graph attention network unit dynamically weights and aggregates the first feature vectors corresponding to the neighboring nodes of each node in the first graph structure. Specifically, for each node Y in the first graph structure... i First, its feature representation is generated through linear transformation:
[0076] H' i =w2H i
[0077] Among them, H' i Let w2 be the weighted feature representation of the i-th node, and H be the learned weight matrix. i This represents the feature representation (i.e., the first feature vector) of the i-th node.
[0078] The attention network unit in the first diagram calculates the attention coefficient α between each pair of adjacent nodes. i,j This is used to quantify the influence of node j on node i. The specific formula is as follows:
[0079]
[0080] Where, α i,j This represents the influence of node j on node i. H i H represents the feature representation of the i-th node.j This represents the feature representation of the j-th node.
[0081] After the attention network unit in the first graph obtains the attention coefficients of all neighboring nodes of node i, it is necessary to further normalize the attention weights using the softmax function. The specific formula is as follows:
[0082]
[0083] Where, N i Let i represent the set of neighboring nodes of node i. The new feature representation of each node can be obtained by aggregating the weighted features of its neighboring nodes, as shown in the following formula:
[0084]
[0085] in, Let σ represent the third feature vector obtained by weighted aggregation of neighboring node features, and σ be the activation function. Through the activation function, node i can update its feature representation to reflect the information and context of its neighboring nodes.
[0086] Furthermore, given that the first graph attention network unit determines multiple third feature vectors corresponding to each first graph structure, each first graph structure is updated to a third graph structure based on these multiple third feature vectors. For example, the nodes Y1 to Y2 in the first graph structure of text data P1... t The initial features and the first feature vector T 1,1 ~T 1,t Correspondingly, the attention network unit in the first graph determines the relationship with each node Y1 to Y2. t The corresponding third eigenvector T” 1,1 ~T” 1,t In this case, the structure of the first graph is updated, and the corresponding structure of the third graph is generated.
[0087] Finally, the second graph attention network unit is used to aggregate and map the third graph structure to generate the second graph structure corresponding to each piece of text data.
[0088] Thus, the above operations achieve the technical effect of dynamically weighting and aggregating the first graph structure corresponding to each piece of text data, thereby improving the feature representation ability of each node in the first graph structure.
[0089] Optionally, the operation of generating multiple second graph structures using the second graph attention network unit and based on multiple third graph structures includes: inputting the third graph structure corresponding to each piece of text data into the second graph attention network unit, and dynamically weighting and aggregating the third feature vectors corresponding to the neighboring nodes of the target node in the third graph structure, thereby updating the third feature vectors to second feature vectors; and generating multiple second graph structures corresponding to each third graph structure based on the multiple second feature vectors corresponding to each third graph structure.
[0090] Specifically, when the processor 200 generates multiple third graph structures using the first graph attention network unit and based on the first graph structure corresponding to each piece of text data, it further generates multiple second graph structures using the second graph attention network unit and based on the third graph structure corresponding to each piece of text data.
[0091] That is, the second graph attention network unit further aggregates and maps the third graph structure corresponding to each text data point, output by the first graph attention network unit, thereby improving the feature representation capability. In the second graph attention network unit, the third feature vectors corresponding to each node in the third graph structure of each text data point also undergo linear transformation, calculation of new attention coefficients, and feature aggregation. Thus, through the multi-head attention mechanism, k heads independently calculate attention weights and perform feature aggregation, ultimately connecting these features to obtain a more comprehensive representation.
[0092] Therefore, since the first graph structure corresponding to each piece of text data in this application has undergone two aggregations and mappings, the feature representation ability of each node in the second graph structure corresponding to each piece of text data can be greatly improved.
[0093] Optionally, when the word embedding module receives each piece of text data, the operation of outputting the first feature vector corresponding to the smallest semantic unit in each piece of text data by the word embedding module includes: calculating the importance of words in each piece of text data in the corresponding text data, and generating multiple fourth feature vectors corresponding to each piece of text data; calculating the point mutual information between each word in each piece of text data, and generating multiple fifth feature vectors corresponding to each piece of text data; performing word segmentation and word embedding on each piece of text data, and generating sixth feature vectors corresponding to the multiple smallest semantic units in each piece of text data respectively; and concatenating and fusing the multiple fourth feature vectors, multiple fifth feature vectors and multiple sixth feature vectors to generate multiple first feature vectors corresponding to each piece of text data.
[0094] Specifically, when the processor 200 collects multiple text data entries, each text data entry is input into the word embedding module, which then calculates the importance of each word in the collected text data within the total text data. The specific calculation formula is as follows:
[0095]
[0096] Where TF represents the frequency of a word in the text data, B1 represents the number of times a word appears in the text data, and B2 represents the total number of words in the text data.
[0097]
[0098] Wherein, IDF represents the rarity of a word in all the collected text data, C1 represents the total number of collected text data, and C2 represents the number of text data containing the word.
[0099] TF_IDF = TF*IDF
[0100] TF_IDF represents the importance of a word in all the collected text data.
[0101] Based on the above formula, feature vectors based on word frequency inverse document frequency (i.e., multiple fourth feature vectors corresponding to each text data) are generated.
[0102] The word embedding module then calculates the point-to-point mutual information between words in each text data set, using the following formula:
[0103]
[0104] Here, PMI(x,y) represents the feature vector (i.e., the fifth feature vector) that reflects the semantic relationship between any two words. x and y represent any two words in the text data.
[0105] Furthermore, the word embedding module segments each piece of text data and generates a token sequence corresponding to each piece of text data based on the smallest semantic unit. Each token in the token sequence is mapped to a unique ID and converted into a dense vector through the embedding layer.
[0106] The self-attention mechanism calculates the similarity between each token and other tokens in the token sequence, generating attention weights to dynamically adjust the representation of each token. A multi-layer transformer encoder extracts deep semantic features from the text data, with the final layer outputting a context-dependent vector for each token (i.e., the sixth feature vector corresponding to the smallest semantic unit), thus better capturing the semantic information of the text.
[0107] Finally, after the word embedding module determines the sixth feature vector corresponding to each smallest semantic unit in each text data, the multiple fourth feature vectors, multiple fifth feature vectors, and multiple sixth feature vectors corresponding to each text data are concatenated and fused to generate multiple first feature vectors corresponding to each text data.
[0108] For example, first, calculate the text data P1 to P2. m The words in the text correspond to text data P1 to P2. m The importance of each text (TF-IDF) is determined, and a correlation is generated between each text data P1 and P2. m The corresponding multiple fourth feature vectors TF1~TF m For example, calculating the word S in text data P1. 1,1 ~S 1,s Importance of TF in text data P1 1,1 ~TF 1,s And generate each word S 1,1 ~S 1,s The corresponding fourth feature vector TF1, TF1 = {TF 1,1 ,TF 1,2 ,...,TF 1,s}. Among them, TF 1,1 Indicator S 1,1 Importance of TF in text data P1 1,2 Indicator S 1,2 The importance of TF in text data P1, and so on, is given by TF. 1,s Indicator S 1,s Importance in text data P1.
[0109] Similarly, word S in text data P2 can be calculated. 2,1 ~S 2,s Importance of TF in text data P2 2,1 ~TF 2,s And generate each word S 2,1 ~S 2,s The corresponding fourth eigenvector is TF2, TF2 = {TF 2,1 ,TF 2,2 ,...,TF 2,s}. Among them, TF 2,1 Indicator S 2,1 Importance of TF in text data P2 2,2 Indicator S 2,2 The importance of TF in text data P2, and so on, is given by TF. 2,s Indicator S 2,s Importance in text data P2.
[0110] Based on the method described above, the relationship between each piece of text data P1 to P2 can be determined. m The corresponding multiple fourth feature vectors TF1~TF m .
[0111] Then, calculate the text data P1 to P2. m The mutual information between words in the text is used to generate the text data P1 to P2. m The corresponding multiple fifth feature vectors PM1 to PM m For example, calculating the sum of each word S in text data P1. 1,1 ~S 1,s Point-to-point information PM 1,1 ~PM 1,w And generate each word S 1,1 ~S 1,s The corresponding fifth feature vector is PM1, PM1 = {PM 1,1 PM 1,2 PM 1,w}. Among them, PM 1,1 Indicator S 1,1 With word S 1,2 Point-to-point information, PM 1,2 Indicator S 1,1 With word S 1,3 Point-to-point mutual information, ..., PM 1,s Indicator S 1,1 With word S 1,s Point-to-point mutual information, ..., PM 1,w Indicator S 1,s-1 With word S 1,s Inter-point information between them.
[0112] Similarly, we can calculate the value of each word S in the text data P2. 2,1 ~S 2,s Point-to-point information PM 2,1 ~PM 2,w And generate each word S 2,1 ~S 2,s The corresponding fifth eigenvector is PM2, PM2 = {PM 2,1 PM 2,2 PM 2,w}. Among them, PM 2,1 Indicator S 2,1 With word S 2,2 Point-to-point information, PM 2,2 Indicator S 2,1 With word S 2,3 Point-to-point mutual information, ..., PM 2,s Indicator S2,1 With word S 2,s Point-to-point mutual information, ..., PM 2,w Indicator S 2,s-1 With word S 2,s Inter-point information between them.
[0113] Based on the method described above, the relationship between each piece of text data P1 to P2 can be determined. m The corresponding multiple fifth feature vectors PM1 to PM m .
[0114] Furthermore, for each piece of text data P1 to P... m Perform word segmentation and word embedding, and generate corresponding text data P1 to P2. m The sixth feature vector Ro corresponds to the multiple smallest semantic units (i.e., tokens) 1 to t in the dataset. 1,1 ~Ro m,t For example, the smallest semantic unit 1 in text data P1 corresponds to the sixth feature vector Ro. 1,1 The smallest semantic unit 2 in text data P1 corresponds to the sixth feature vector Ro. 1,2 The smallest semantic unit t in the text data P1 corresponds to the sixth feature vector Ro. 1,t .
[0115] And so on.
[0116] Text data P m The smallest semantic unit 1 in the vector corresponds to the sixth feature vector Ro. m,1 Text data P m The smallest semantic unit 2 in the vector corresponds to the sixth feature vector Ro. m,2 Text data P m The smallest semantic unit t in the vector corresponds to the sixth feature vector Ro. m,t .
[0117] Then, the text data P1 to P2 were analyzed. m The corresponding multiple fourth feature vectors TF1~TF m , and each text data P1~P m The corresponding multiple fifth feature vectors PM1 to PM m And the text data P1 to P1 m The sixth feature vector Ro corresponds to the multiple smallest semantic units (i.e., tokens) 1 to t in the dataset. 1,1 ~Ro m,t The data is then spliced and merged to generate a sequence of text data P1 to P2. m The first feature vector T corresponding to the smallest semantic unit 1 to t in the model 1,1 ~Tm,t .
[0118] For example, the first feature vector T corresponding to the smallest semantic unit 1 in text data P1. 1,1 The first feature vector T corresponding to the smallest semantic unit 2 in text data P1 1,2 ..., the first feature vector T corresponding to the smallest semantic unit t in the text data P1. 1,t .
[0119] And so on.
[0120] With text data P m The first feature vector T corresponding to the smallest semantic unit 1 in the [text / data] m,1 , with text data P m The first feature vector T corresponding to the smallest semantic unit 2 in the middle m,2 ... and text data P m The first feature vector T corresponding to the smallest semantic unit t in the [text / data] m,t .
[0121] In addition, before using the sentiment classification model to build the corpus, the sentiment classification model needs to be trained in advance. The specific steps are as follows:
[0122] First, multiple text samples were collected, and data cleaning and preprocessing were performed on these samples. The format of the collected text samples is shown in Table 1 above, and will not be repeated here. The specific methods for data cleaning and preprocessing of the multiple text samples are the same as described above, and therefore will not be repeated here.
[0123] Then, the processor 200 removes stop words using a Python script and stores the removed files in an Excel spreadsheet for subsequent sentiment annotation and corpus storage.
[0124] Furthermore, the processor 200 uses the Label-Studio tool to perform emotion annotation on multiple preprocessed text samples. Emotion categories include anger, happiness, sadness, fear, liking, surprise, and disgust. After annotation, the processor 200 exports the data as a CSV file and performs column splitting in Excel, ultimately creating an Excel spreadsheet containing time, text, emotion words, and emotion tags. For example, a text sample like "The torrential rain in a certain place is terrible!" would be labeled with the emotion "fear". Notably, this application uses 1866 emotion-annotated text samples as the training dataset. These text samples are labeled with various emotion categories, and the training dataset is divided into a training set and a validation set (i.e., 80% training set, 20% validation set) for training and evaluating the performance of the emotion classification model.
[0125] Next, processor 200 constructs an emotion classification model. The emotion classification model includes a word embedding module, a graph structure analysis module (including a graph structure construction unit, a first graph attention network unit, and a second graph attention network unit), and an emotion classification module (including a fully connected unit, a softmax classifier, and an emotion classification unit).
[0126] Furthermore, the processor 200 trains the constructed sentiment classification model using multiple text samples from the training set. After training the sentiment classification model using these text samples, the performance of the model is then evaluated using a validation set.
[0127] This ensures that the classification and annotation effects of the trained emotion classification model meet the standards expected by the operators, thereby guaranteeing the accuracy of the constructed corpus.
[0128] Thus, according to the first aspect of this embodiment, the technical effects of reducing the time and economic costs of building a corpus, improving the efficiency of building a corpus, and improving the accuracy of corpus annotation are achieved.
[0129] In addition, refer to Figure 1 As shown, according to a second aspect of this embodiment, a storage medium is provided. The storage medium includes a stored program, wherein, when the program is executed, a processor performs any of the methods described above.
[0130] Thus, according to this embodiment, the technical effects of reducing the time and economic costs of building a corpus, improving the efficiency of building a corpus, and improving the accuracy of corpus annotation are achieved.
[0131] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0132] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0133] Example 2
[0134] Figure 6 A corpus construction implementation apparatus 600 according to this embodiment is shown, which corresponds to the method described according to Embodiment 1. Reference Figure 6 As shown, the device 600 includes: a text data acquisition module 610, used to acquire multiple text data and input each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module; a word embedding module 620, used to output a first feature vector corresponding to the smallest semantic unit in each text data when the word embedding module receives each text data; and a graph structure analysis module 630, used to input multiple first feature vectors corresponding to each text data into the graph structure analysis module. The system utilizes a graph structure analysis module and, based on multiple first feature vectors corresponding to each text data, constructs a first graph structure corresponding to each text data, and analyzes the relationships between nodes in each first graph structure to generate multiple second graph structures; an emotion classification module 640 is used to determine the emotion category label corresponding to each text data using the emotion classification module and based on the second graph structure corresponding to each text data; and a corpus construction module 650 is used to label each text data based on the determined emotion category labels, and construct a corpus based on the labeled text data.
[0135] Optionally, the emotion classification module includes a fully connected unit and an emotion classification unit, and the emotion classification module 640 further includes: an emotion category vector generation module, used to generate emotion category vectors corresponding to each text data using the fully connected layer and based on the second feature vectors corresponding to each node in each second graph structure; an emotion category probability value output module, used to map the emotion category vectors corresponding to each text data to the interval [0,1] using the sigmoid function, and output the emotion category probability sequences corresponding to each text data; and an emotion category label determination module, used to classify the emotion of each text data using the emotion classification unit and based on the emotion category sequences corresponding to each text data, and determine the emotion category labels corresponding to each text data.
[0136] Optionally, the graph structure analysis module includes a graph structure construction unit, and the graph structure analysis module 630 includes: a node determination module, used to determine nodes for constructing a first graph structure, wherein nodes represent the smallest semantic units in the text data, and the initial features of the nodes correspond to a first feature vector; an edge determination module, used to determine edges for constructing the first graph structure, wherein edges represent the association relationships between the smallest semantic units in the text data; and a graph structure construction module, used to construct a first graph structure corresponding to each piece of text data based on the nodes and edges.
[0137] Optionally, the graph structure analysis module includes a first graph attention network unit and a second graph attention network unit, and the graph structure analysis module 630 includes: a first weighted aggregation module, used to input the first graph structure corresponding to each text data into the first graph attention network unit, and dynamically weight and aggregate the first feature vectors corresponding to the adjacent nodes of the target node in the first graph structure, thereby updating the first feature vectors to third feature vectors, wherein the target node is used to indicate any node in the first graph structure; a graph structure update module, used to update each first graph structure to a third graph structure based on multiple third feature vectors corresponding to each first graph structure; and a graph structure generation module, used to generate multiple second graph structures using the second graph attention network unit and based on multiple third graph structures.
[0138] Optionally, the graph structure generation module includes: a second weighted aggregation module, used to input the third graph structure corresponding to each text data into the second graph attention network unit, and dynamically weight and aggregate the third feature vectors corresponding to the neighboring nodes of the target node in the third graph structure, thereby updating the third feature vectors to second feature vectors; and a graph structure generation submodule, used to generate multiple second graph structures corresponding to each third graph structure based on the multiple second feature vectors corresponding to each third graph structure.
[0139] Optionally, the word embedding module 620 includes: an importance calculation module, used to calculate the importance of words in each text data in the corresponding text data, and generate multiple fourth feature vectors corresponding to each text data; an association calculation module, used to calculate the point mutual information between each word in each text data, and generate multiple fifth feature vectors corresponding to each text data; a word embedding submodule, used to perform word segmentation and word embedding on each text data, and generate sixth feature vectors corresponding to multiple smallest semantic units in each text data; and a splicing and fusion module, used to splice and fuse multiple fourth feature vectors, multiple fifth feature vectors and multiple sixth feature vectors, and generate multiple first feature vectors corresponding to each text data.
[0140] Thus, according to this embodiment, the technical effects of reducing the time and economic costs of building a corpus, improving the efficiency of building a corpus, and improving the accuracy of corpus annotation are achieved.
[0141] Example 3
[0142] Figure 7 A corpus construction implementation apparatus 700 according to this embodiment is shown, which corresponds to the method described according to Embodiment 1. Reference Figure 7 As shown, the device 700 includes: a processor 710; and a memory 720 connected to the processor 710, used to provide the processor 710 with instructions to process the following steps: acquiring multiple text data, and inputting each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module; when the word embedding module receives each text data, it outputs a first feature vector corresponding to the smallest semantic unit in each text data; inputting multiple first feature vectors corresponding to each text data into the graph structure analysis module, constructing a first graph structure corresponding to each text data based on the multiple first feature vectors corresponding to each text data, and analyzing the relationship between nodes in each first graph structure to generate multiple second graph structures; determining the emotion category label corresponding to each text data based on the emotion classification module and the second graph structure corresponding to each text data; and labeling each text data based on the determined emotion category label, and constructing a corpus based on the labeled text data.
[0143] Optionally, the emotion classification module includes a fully connected unit and an emotion classification unit. The operation of determining the emotion category label corresponding to each text data item using the emotion classification module and based on the second graph structure corresponding to each text data item includes: generating emotion category vectors corresponding to each text data item using the fully connected layer and based on the second feature vectors corresponding to each node in each second graph structure; mapping the emotion category vectors corresponding to each text data item to the interval [0,1] using the sigmoid function and outputting the emotion category probability sequence corresponding to each text data item; and using the emotion classification unit and based on the emotion category sequence corresponding to each text data item to classify the emotion of each text data item and determine the emotion category label corresponding to each text data item.
[0144] Optionally, the graph structure analysis module includes a graph structure construction unit, and multiple first feature vectors corresponding to each piece of text data are input into the graph structure analysis module. The operation of constructing a first graph structure corresponding to each piece of text data using the graph structure analysis module and based on the multiple first feature vectors corresponding to each piece of text data includes: determining nodes for constructing the first graph structure, where nodes represent the smallest semantic units in the text data, and the initial features of the nodes correspond to the first feature vectors; determining edges for constructing the first graph structure, where edges represent the association relationships between the smallest semantic units in the text data; and constructing the first graph structure corresponding to each piece of text data based on the nodes and edges.
[0145] Optionally, the graph structure analysis module includes a first graph attention network unit and a second graph attention network unit. Multiple first feature vectors corresponding to each piece of text data are input into the graph structure analysis module. The graph structure analysis module, based on the multiple first feature vectors corresponding to each piece of text data, analyzes the relationships between nodes in each first graph structure to generate multiple second graph structures. This includes: inputting the first graph structures corresponding to each piece of text data into the first graph attention network unit, and dynamically weighting and aggregating the first feature vectors corresponding to the adjacent nodes of the target node in the first graph structure, thereby updating the first feature vectors to third feature vectors, where the target node indicates any node in the first graph structure; updating each first graph structure to a third graph structure based on the multiple third feature vectors corresponding to each first graph structure; and generating multiple second graph structures using the second graph attention network unit and based on the multiple third graph structures.
[0146] Optionally, the operation of generating multiple second graph structures using the second graph attention network unit and based on multiple third graph structures includes: inputting the third graph structure corresponding to each piece of text data into the second graph attention network unit, and dynamically weighting and aggregating the third feature vectors corresponding to the neighboring nodes of the target node in the third graph structure, thereby updating the third feature vectors to second feature vectors; and generating multiple second graph structures corresponding to each third graph structure based on the multiple second feature vectors corresponding to each third graph structure.
[0147] Optionally, when the word embedding module receives each piece of text data, the operation of outputting the first feature vector corresponding to the smallest semantic unit in each piece of text data by the word embedding module includes: calculating the importance of words in each piece of text data in the corresponding text data, and generating multiple fourth feature vectors corresponding to each piece of text data; calculating the point mutual information between each word in each piece of text data, and generating multiple fifth feature vectors corresponding to each piece of text data; performing word segmentation and word embedding on each piece of text data, and generating sixth feature vectors corresponding to the multiple smallest semantic units in each piece of text data respectively; and concatenating and fusing the multiple fourth feature vectors, multiple fifth feature vectors and multiple sixth feature vectors to generate multiple first feature vectors corresponding to each piece of text data.
[0148] Thus, according to this embodiment, the technical effects of reducing the time and economic costs of building a corpus, improving the efficiency of building a corpus, and improving the accuracy of corpus annotation are achieved.
[0149] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0150] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0151] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0152] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0153] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0154] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0155] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for constructing a corpus, characterized in that, include: Multiple text data points are collected, and each text data point is input into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module. When the word embedding module receives each piece of text data, it outputs a first feature vector corresponding to the smallest semantic unit in each piece of text data. Multiple first feature vectors corresponding to each text data are input into the graph structure analysis module. The graph structure analysis module is used to construct a first graph structure corresponding to each text data based on the multiple first feature vectors corresponding to each text data. The relationship between each node in each first graph structure is analyzed to generate multiple second graph structures. Using the emotion classification module and based on the second graph structure corresponding to each piece of text data, emotion category labels corresponding to each piece of text data are determined respectively; as well as Based on the determined emotion category labels, each piece of text data is labeled, and a corpus is constructed based on the labeled text data.
2. The method according to claim 1, characterized in that, The emotion classification module includes a fully connected layer and an emotion classification unit. The operation of determining the emotion category label corresponding to each piece of text data using the emotion classification module and based on the second graph structure corresponding to each piece of text data includes: Using a fully connected layer and based on the second feature vectors corresponding to each node in each of the second graph structures, emotion category vectors corresponding to each piece of text data are generated. The sigmoid function is used to map the sentiment category vector corresponding to each text data point to the interval [0,1], and the probability sequences of sentiment categories corresponding to each text data point are output; and Using the emotion classification unit and based on the emotion category sequence corresponding to each piece of text data, the emotions of each piece of text data are classified, and the emotion category label corresponding to each piece of text data is determined.
3. The method according to claim 2, characterized in that, The graph structure analysis module includes a graph structure construction unit, and inputs multiple first feature vectors corresponding to each piece of text data into the graph structure analysis module. The operation of constructing a first graph structure corresponding to each piece of text data using the graph structure analysis module and based on the multiple first feature vectors corresponding to each piece of text data includes: Determine the nodes used to construct the first graph structure, wherein the nodes represent the smallest semantic units in the text data, and the initial features of the nodes correspond to the first feature vector; Determine the edges used to construct the first graph structure, wherein the edges represent the relationships between the smallest semantic units in the text data; and Based on the nodes and edges, a first graph structure corresponding to each piece of text data is constructed.
4. The method according to claim 3, characterized in that, The graph structure analysis module includes a first graph attention network unit and a second graph attention network unit. Multiple first feature vectors corresponding to each piece of text data are input into the graph structure analysis module. The module analyzes the relationships between nodes in each first graph structure based on these first feature vectors, thereby generating multiple second graph structures. This process includes: The first graph structure corresponding to each text data is input into the first graph attention network unit, and the first feature vectors corresponding to the adjacent nodes of the target node in the first graph structure are dynamically weighted and aggregated, thereby updating the first feature vector to a third feature vector, wherein the target node is used to indicate any node in the first graph structure. Based on multiple third feature vectors corresponding to each of the first graph structures, each of the first graph structures is updated to a third graph structure; and The plurality of second graph structures are generated using the second graph attention network unit and based on the plurality of third graph structures.
5. The method according to claim 4, characterized in that, The operation of generating the plurality of second graph structures using the second graph attention network unit and based on the plurality of third graph structures includes: The third graph structure corresponding to each text data item is input into the second graph attention network unit, and the third feature vectors corresponding to the neighboring nodes of the target node in the third graph structure are dynamically weighted and aggregated, thereby updating the third feature vectors to the second feature vectors; and Based on multiple second feature vectors corresponding to each of the third graph structures, multiple second graph structures corresponding to each of the third graph structures are generated.
6. The method according to claim 1, characterized in that, When the word embedding module receives each piece of text data, the operation of outputting the first feature vector corresponding to the smallest semantic unit in each piece of text data using the word embedding module includes: Calculate the importance of each word in the text data in the corresponding text data, and generate multiple fourth feature vectors corresponding to each text data; Calculate the point mutual information between each word in each piece of text data, and generate multiple fifth feature vectors corresponding to each piece of text data; Each text data item is segmented and embedded, and a sixth feature vector corresponding to each of the smallest semantic units in each text data item is generated; and The plurality of fourth feature vectors, the plurality of fifth feature vectors, and the plurality of sixth feature vectors are concatenated and fused to generate a plurality of first feature vectors corresponding to each text data.
7. A storage medium, characterized in that, The storage medium includes a stored program, wherein, when the program is executed, a processor performs the method according to any one of claims 1 to 6.
8. A corpus construction implementation device, characterized in that, include: The text data acquisition module is used to collect multiple text data and input each text data into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module. A word embedding module is used to output a first feature vector corresponding to the smallest semantic unit in each of the text data when the word embedding module receives each piece of text data; The graph structure analysis module is used to input multiple first feature vectors corresponding to each text data into the graph structure analysis module, and use the graph structure analysis module to construct a first graph structure corresponding to each text data based on the multiple first feature vectors corresponding to each text data, and analyze the relationship between each node in each first graph structure to generate multiple second graph structures. An emotion classification module is used to determine the emotion category label corresponding to each piece of text data by utilizing the emotion classification module and based on the second graph structure corresponding to each piece of text data; as well as The corpus construction module is used to annotate each piece of text data based on the determined emotion category labels, and to construct a corpus based on the annotated text data.
9. The apparatus according to claim 8, characterized in that, The emotion classification module includes a fully connected layer and an emotion classification unit, and further includes: The emotion category vector generation module is used to generate emotion category vectors corresponding to each piece of text data by utilizing the fully connected layer and based on the second feature vectors corresponding to each node in each of the second graph structures. The emotion category probability output module is used to map the emotion category vector corresponding to each piece of text data to the interval [0,1] using the sigmoid function, and output the emotion category probability sequence corresponding to each piece of text data; and The emotion category label determination module is used to classify the emotions of each text data based on the emotion classification unit and the emotion category sequence corresponding to each text data, and determine the emotion category label corresponding to each text data.
10. A corpus construction implementation device, characterized in that, include: processor; as well as A memory, connected to the processor, for providing the processor with instructions to perform the following processing steps: Multiple text data points are collected, and each text data point is input into a pre-trained emotion classification model, wherein the emotion classification model includes a word embedding module, a graph structure analysis module, and an emotion classification module. When the word embedding module receives each piece of text data, it outputs a first feature vector corresponding to the smallest semantic unit in each piece of text data. Multiple first feature vectors corresponding to each text data are input into the graph structure analysis module. The graph structure analysis module is used to construct a first graph structure corresponding to each text data based on the multiple first feature vectors corresponding to each text data. The relationship between each node in each first graph structure is analyzed to generate multiple second graph structures. Using the emotion classification module and based on the second graph structure corresponding to each piece of text data, emotion category labels corresponding to each piece of text data are determined respectively; Based on the determined emotion category labels, each piece of text data is labeled, and a corpus is constructed based on the labeled text data.
Citation Information
Patent Citations
Financial news text emotional tendency analysis method based on graph convolutional network
CN112948541A
GraphSAGE graph model and RoBERTa fusion-based text classification system
CN116975287A