Unsupervised domain adaptation method and device for sentiment classification, and medium
Patent Information
- Application Number
- CN202410816066.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2044-06-24
AI Technical Summary
[0005]现有技术存在两个问题,第一个问题是领域适配器训练的过程中,虽然对齐了源领域和目标领域的领域表示信息,但是对齐的领域表示信息是直接在通用的预训练模型上面直接进行微调的,没有利用到源领域的任务信息,所以对于域适应能力是有影响的
[0050]1、首先训练任务适配器,然后堆叠在任务适配器上进行训练以获得更好的域对齐表示,最后融合堆叠领域适配器和任务适配器进行训练后在目标领域进行域适应。双适配器融合方法通过适配器融合模块解决了动态区分领域不变信息和任务表示信息重要程度的问题,而堆叠领域适配器堆叠在任务适配器上进行训练,学习的域不变信息是基于任务信息的,比基于预训练模型的通用信息在目标领域域适应的时候更加有用。
Smart Images

Figure CN118820845B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of emotion classification technology, and more specifically, to an unsupervised, domain-adaptive emotion classification method, apparatus, and medium. Background Technology
[0002] The Unsupervised Domain Adaptation method using adapters (UDAPTER) proposes two improved methods to enhance domain adaptation capabilities: Two-Step Domain and Task Adapters (TSDTA) and Joint Domain Task Adapters (JDTA). TSDTA first adds a domain adapter to learn domain alignment information, then stacks a task adapter on top of this domain adapter to use the domain alignment information to learn the task representation of the source domain, which is then used for domain adaptation. JDTA, on the other hand, adds only one adapter to simultaneously learn both domain alignment knowledge and the source domain task representation.
[0003] Two-stage adapter training is a process for domain adaptation, particularly suitable for situations where there is a significant difference between a source domain with abundant labeled data and a target domain that may lack labeled data and for which the model is expected to generalize. This process consists of two main steps: training the Domain Adapter and training the Task Adapter. The authors first train the Domain Adapter using unsupervised data from both the source and target domains. The Domain Adapter aims to learn how to transform the data representation from the source domain into a representation that is more generalizable to the target domain. After training, the weights of the Domain Adapter are saved. This step ensures that the learned domain-invariant features are preserved for subsequent steps. Next, the Task Adapter is stacked on top of the Domain Adapter. The Task Adapter focuses on supervised data from the source domain, learning how to perform a specific task based on the features provided by the Domain Adapter. While training the Task Adapter, the Domain Adapter is frozen (i.e., its weights are not updated), ensuring that the domain-invariant features learned by the Domain Adapter are not destroyed during task learning. In practical applications (inference), the Domain Adapter and Task Adapter are stacked. This ensures that the input data is first processed by the domain adapter to learn domain-invariant features, and then these features are fed into the task adapter to make the final prediction.
[0004] The Connected Domain Task Adapter (TLTA) is an ensemble domain adaptation method that aims to simultaneously learn task-relevant representations and reduce distributional discrepancies between the source and target domains through a single adapter. During training, the TTLTA employs a joint loss function consisting of two parts: task loss and domain divergence loss. The task loss focuses on supervised samples from the source domain to improve task performance, while the domain divergence loss attempts to reduce distributional discrepancies between the source and target domains. The TTLTA's key objective is to map the representations of supervised samples (i.e., correctly labeled samples) from the source domain and unsupervised samples (unlabeled samples) from the target domain into a common feature space, thus reducing distributional discrepancies between the two domains while preserving task-useful information.
[0005] Existing technologies have two problems. First, while the domain representation information of the source and target domains is aligned during the domain adapter training process, this alignment is done by directly fine-tuning a general pre-trained model without utilizing task information from the source domain. This impacts domain adaptability. Second, the connection method for linking the domain task adapter is too simplistic, merely a linear summation. It cannot effectively and dynamically distinguish the importance of domain-invariant information and task representation information, leading to room for improvement in the accuracy of sentiment classification. Summary of the Invention
[0006] This invention addresses the aforementioned problems in the prior art. Therefore, there is a need for an unsupervised, domain-adaptive sentiment classification method, apparatus, and medium to more effectively utilize task representation information from the source domain to enhance domain adaptability.
[0007] According to a first aspect of the present invention, an unsupervised domain-adaptive sentiment classification method is provided, the method comprising:
[0008] Obtain domain adaptation pairs, which include a source domain and a target domain. The source domain is supervised sentiment data with data instances and labels, and the target domain is unsupervised sentiment data with only instances and no labels.
[0009] The first parameters are obtained by training the task adapter using instances and labels from the source domain;
[0010] A domain adapter is stacked on the task adapter configured with the first parameter, and the domain adapter is trained using instances of the source and target domains to obtain the second parameter.
[0011] The learning results of the task adapter and the domain adapter are fused by the fusion module. With the first and second parameters unchanged, the fusion module is trained using the source domain to obtain the third parameter.
[0012] The fusion module configured with the third parameter fuses the task adapter configured with the first parameter and the domain adapter configured with the second parameter to obtain a prediction model, and the prediction model is used to realize sentiment classification prediction.
[0013] Furthermore, the goal of the task adapter is to learn a representation for a specific task, and the calculation process is as follows:
[0014] TA l =W up ·(W down ·h l )+r l (1)
[0016] Among them, TA l For the representation of a specific task, h l For hidden layer output, r l For the output of the feedforward layer, W down ∈R h×d W is the lower projection matrix, which projects the hidden layer representation to a lower dimension. up ∈R d×h Let R be the upprojection matrix, which projects the activated low-dimensional features back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, and d << h.
[0017] Furthermore, during the training of the task adapter, the parameters of the task adapter are updated only during training on the emotion classification task, and are updated using the following formula:
[0018]
[0019] Where, Φ n D represents the update parameters of the task adapter. n Let L represent the source domain data, where there are n source domains. Θ0 represents the pre-trained model parameters frozen during training. n This represents minimizing the loss function.
[0020] Furthermore, the new hidden layer representation in the domain adapter is calculated using the following formula:
[0021] TA l =W up ·(W down ·h l )+r l (3)
[0023] SDA l =W up1 ·(W down1 ·TA l )+TA l (4)
[0025] Among them, TA l h is the output of the task adapter, representing a specific task. l For the hidden output of the task adapter, r l W is the output of the feedforward layer of the task adapter. down ∈R h×d W is the lower projection matrix of the task adapter, which projects the hidden representation of the task adapter to a lower dimension. up ∈R d×h Let R be the upprojection matrix of the task adapter, which projects the low-dimensional features in the activated task adapter back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, d << h, and W up1 W is the upper projection matrix of the domain adapter. down1 SDA is the lower projection matrix of the domain adapter. l This is the output of the domain adapter.
[0026] Furthermore, the cumulative distance metric between the source and target domain hidden layer outputs of each domain adapter layer in the last layer of the pre-trained model is expressed as:
[0027]
[0028] Where div{·} represents the distance metric function. This indicates the source domain's output in the domain adapter at layer l. This indicates the output of the domain adapter at layer l for the target domain.
[0029] Furthermore, the fusion module includes a Key, Value, and Query matrix for each layer l, denoted as K. l V l and Q l ,
[0030] The output of each adapter is used as input to the Key matrix and Value matrix. The adapters include at least one service adapter and at least one domain adapter. The outputs of the adapters are calculated using formulas (5) and (6):
[0031]
[0032] in, This represents the output of the domain adapter. This represents the up projection matrix of the domain adapter. The upper projection matrix of the domain adapter, x l,t This represents the hidden layer output after summation and normalization in the transformer, r lThis represents the hidden layer output before normalization in the transformer. This indicates the output of the task adapter. This represents the upper projection matrix of the task adapter. This represents the lower projection matrix of the task adapter;
[0033] At each layer l and at each time step t, the Query matrix is the output h of the pre-trained model. l As input, the Key matrix takes the output of its respective adapter as input, and the dot product of the Query matrix and all Key matrices is passed to a softmax function, calculated as shown in formulas (8) and (9):
[0034]
[0035] in, This represents the intermediate result of vector operations in the domain adapter after being processed by the softmax function. This represents the transpose of the hidden layer output of the transformer in the pre-trained model. This represents the output after projection onto the domain adapter. This represents the intermediate result of vector operations in the task adapter after being processed by the softmax function. This represents the output after projection onto the task adapter;
[0036] The Value matrix takes the adapter's output as input and performs matrix operations using formulas (10) and (11):
[0037]
[0038] in, This represents the intermediate result after matrix operations are performed on the Query matrix of the domain adapter and adapter fusion module. This represents the output of the domain adapter. This represents the intermediate result after matrix operations are performed on the Query matrix of the task adapter and the adapter fusion module. This indicates the output of the task adapter;
[0039] The intermediate results of the two adapters are concatenated using formula (12) to obtain the output:
[0040]
[0041] Among them, o l,t This indicates the output of the transformer layer after adding the adapter and adapter fusion module.
[0042] According to a second aspect of the present invention, an unsupervised domain-adaptive sentiment classification apparatus is provided, the apparatus comprising:
[0043] The data acquisition module is configured to acquire domain adaptation pairs, which include a source domain and a target domain. The source domain is supervised sentiment data with data instances and labels, and the target domain is unsupervised sentiment data with only instances and no labels.
[0044] The first training module is configured to train the task adapter using instances and labels from the source domain to obtain the first parameters;
[0045] The second training module is configured to stack a domain adapter on a task adapter configured with the first parameter, and train the domain adapter using instances of the source and target domains to obtain the second parameter.
[0046] The third training module is configured to fuse the learning results of the task adapter and the domain adapter through the fusion module. With the first and second parameters unchanged, the fusion module is trained using the source domain to obtain the third parameters.
[0047] The classification prediction module is configured to fuse the task adapter configured with the first parameter and the domain adapter configured with the second parameter into a prediction model, which is then used to achieve sentiment classification prediction.
[0048] According to a third aspect of the present invention, a readable storage medium is provided, the readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the method described above.
[0049] The present invention has at least the following beneficial effects:
[0050] 1. First, the task adapter is trained, then training is performed on top of the task adapter to obtain a better domain-aligned representation. Finally, the stacked domain adapter and task adapter are fused and trained before domain adaptation in the target domain. The dual-adaptor fusion method solves the problem of dynamically distinguishing the importance of domain-invariant information and task representation information through the adapter fusion module. Furthermore, the domain-invariant information learned by stacking the domain adapter on top of the task adapter is task-informed, which is more useful in target domain adaptation than the general information based on the pre-trained model.
[0051] 2. This invention utilizes task representation information learned from task adapters and domain-invariant information learned from (stacked) domain adapters. Extraction is performed using pluggable adapters, followed by fusion of the two adapters via an adapter fusion module. Supervised training is conducted in the source domain through this module, resulting in better unsupervised domain adaptation in the target domain. Experimental results demonstrate that this invention improves the domain adaptation capability of multi-domain sentiment classification datasets. Attached Figure Description
[0052] Figure 1 A flowchart of an unsupervised domain-adaptive sentiment classification method according to an embodiment of the present invention is shown.
[0053] Figure 2 A structural diagram of a task adapter according to an embodiment of the present invention is shown.
[0054] Figure 3 A schematic diagram illustrating the training process and structure of a stacked domain adapter according to an embodiment of the present invention is shown.
[0055] Figure 4 A structural diagram of a fusion module according to an embodiment of the present invention is shown.
[0056] Figure 5 A structural diagram of an unsupervised domain-adaptive sentiment classification device according to an embodiment of the present invention is shown. Detailed Implementation
[0057] To enable those skilled in the art to better understand the technical solutions of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. The embodiments of the present invention will be further described in detail below with reference to the accompanying drawings and specific examples, but this is not intended to limit the present invention. If there is no necessary sequential relationship between the various steps described herein, the order in which they are described as examples should not be considered a limitation. Those skilled in the art should understand that the order can be adjusted, as long as it does not disrupt the logical consistency between them and render the entire process impossible.
[0058] This invention provides an unsupervised domain-adaptive sentiment classification method. The method aims to more effectively utilize task representation information from the source domain to enhance domain adaptation capabilities. First, a task adapter is trained, then multiple adapters are stacked on top of the task adapter for further training to obtain a better domain-aligned representation. Finally, the stacked domain adapter and task adapter are fused and trained before being used for domain adaptation in the target domain. The dual-adaptor fusion method addresses the problem of dynamically distinguishing the importance of domain-invariant information and task representation information through an adapter fusion module. Furthermore, the domain-invariant information learned by stacking the domain adapter on top of the task adapter is task-informed and more useful in target domain adaptation than general information based on pre-trained models.
[0059] In this embodiment, given a source-target domain adaptation pair, the source domain is supervised data with data instances and labels, and the target domain is unsupervised data with only instances but no labels. First, a task adapter is trained using the instances and labels from the source domain. Then, a domain adapter is trained using the instances from both the source and target domains. The domain adapter can be stacked on top of the task adapter to learn domain alignment information. Finally, the task adapter and (stacked) domain adapter from the first two steps are fused and trained on the source domain to obtain a dual-adaptor fusion module. It should be noted that the data described in this embodiment is sentiment data used for sentiment classification. The type of sentiment data can be text data, voice data, image data, video data, etc., and this embodiment does not specifically limit the types.
[0060] Specifically, such as Figure 1 The diagram shows the flowchart of this unsupervised, domain-adaptive sentiment classification method, which includes the following steps:
[0061] Step 1: Training the Task Adapter: The goal of this step is to learn the task representation knowledge of the source domain. The task adapter focuses on capturing the features of a specific task, such as the representation of classification or natural language understanding tasks in the source domain. Specifically, an adapter is added to each layer of the Transformer structure in the pre-trained model, and other pre-trained parameters are frozen, training only the parameters of the task adapter module.
[0062] Step 2, Training (Stacking) Domain Adapters: The goal of this step is to align the domain features of the source and target domains. Furthermore, building upon the task representation knowledge learned by the task adapter, stacked domain adapters can learn further to capture features that remain invariant across different domains (e.g., different data distributions), contributing to better domain alignment. Only the parameters of the domain adapter modules are trained in this process. The difference between stacked and regular domain adapters is that stacked domain adapters are trained on top of task adapters, so the learned domain-invariant information is based on specific task representation information. This leads to improved performance in subsequent domain adaptation scenarios compared to those based on general task representation information. However, the drawback is increased coupling, requiring the domain adapter to be trained first, whereas regular domain adapters and task adapters can be trained in parallel.
[0063] Step 3: Fusing (Stacking) the Domain Adapter and Task Adapter: This step involves fusing the learning outcomes of the task adapter and the domain adapter, enabling the model to learn both domain alignment and task representation knowledge simultaneously during training on the source domain. This step freezes the task adapter and (stacked) domain adapter from Steps 1 and 2, and only trains the parameters of the fused module.
[0064] Overall, this dual-adaptor fusion method, through hierarchical training, enables the model to better adapt to different domains while preserving task-related information. In this way, the model not only learns specific task-specific processing methods but also generalizes better to new, unseen datasets or domains. The dual-adaptor fusion method addresses the problem of existing methods where domain-invariant information and task representation information are merely linearly added, failing to effectively enhance domain adaptability.
[0065] In this embodiment, the goal of the task adapter is to learn task-specific representations. The structure of the task adapter is to reduce the dimensionality of the hidden layer features using a lower projection matrix, and then project the features back to their original size using an upper projection matrix, such as... Figure 2 As shown.
[0066] The calculation process of the task adapter is shown in formula (1).
[0067] TA l =W up ·(W down ·h l )+r l (1)
[0069] Among them, TA l For the representation of a specific task, h l For hidden layer output, r l For the output of the feedforward layer, W down ∈R h×dW is the lower projection matrix, which projects the hidden layer representation to a lower dimension. up ∈R d×h Let R be the upprojection matrix, which projects the activated low-dimensional features back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, and d << h.
[0070] The input to the task adapter is labeled samples from the source domain. The parameters of the task adapter are only updated when training on the final task, such as sentiment classification. The Transformer layer in the pre-trained model is frozen during training. The classifier parameters are added to the last layer of the pre-trained model. The task is in the form of Equation (2).
[0071]
[0072] Among them, D n Let Θ0 represent the source domain data, where there are n source domains. Let Θ0 represent the pre-trained model parameters frozen during training. Our goal is to minimize the loss function L. n This allows the adapter parameters Φ to be learned across n source domains, enabling the learning of task representation information and its modular storage for subsequent use by the method.
[0073] In this embodiment, a domain adapter needs to be trained to learn the domain-invariant representation. There are two types of domain adapters: a regular domain adapter and a stacked domain adapter. Taking the stacked domain adapter as an example, it is learned by stacking it on top of the task adapter that has already been trained in the previous step. The purpose is that after the task adapter has learned the task representation information, training the domain adapter allows it to better learn the domain-invariant representation information of the source and target domains. This ensures that the domain-invariant information is strongly correlated with the task, which can benefit future target domain tasks. During the training of the domain adapter, the parameters of the task adapter and the pre-trained model are frozen; only the domain adapter is trained. Figure 3 As shown.
[0074] The initial input to the domain adapter is instances of the source and target domains. The task and domain adapter are stacked in each Transformer layer, and the following transformations are performed to compute the new hidden layer representation as shown in Equations (3) and (4).
[0075] TA l =W up ·(W down ·h l )+r l (3)
[0077] SDA l =W up1 ·(Wdown1 ·TA l )+TA l (4)
[0079] Among them, TA l h is the output of the task adapter, representing a specific task. l For the hidden output of the task adapter, r l W is the output of the feedforward layer of the task adapter. down ∈R h×d W is the lower projection matrix of the task adapter, which projects the hidden representation of the task adapter to a lower dimension. up ∈R d×h Let R be the upprojection matrix of the task adapter, which projects the low-dimensional features in the activated task adapter back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, d << h, and W up1 W is the upper projection matrix of the domain adapter. down1 SDA is the lower projection matrix of the domain adapter. l This is the output of the domain adapter.
[0080] It is important to note that W down W up r l Similar to the meaning of the task adapter, the difference is that the input of the domain adapter is no longer the hidden output of the Transformer, but the output TA of the task adapter. l In the last layer of the pre-trained model, instead of a classifier, the cumulative distance between the source domain hidden layer output and the target domain hidden layer output of each domain adapter is measured, as shown in Equation (5).
[0081]
[0082] Where div{·} represents the distance metric function, including multi-core maximum mean difference, center distance difference, and correlation alignment distance, etc. This patent uses the multi-core maximum mean difference function and has also conducted experimental comparisons with other metric functions. This indicates the source domain's output in the stacked domain adapter at layer l. This indicates the output of the stacked domain adapter in layer l of the target domain.
[0083] In this embodiment, after training the (stacked) domain adapter and task adapter, the task adapter formed in the first step and the (stacked) domain adapter formed in the second step are fused using AdapterFusion. That is, AdapterFusion is selected as the fusion module. The initial design purpose of AdapterFusion is to solve the problems of knowledge sharing, catastrophic forgetting, and task balancing in multi-task learning through a flexible and efficient framework, thereby improving the model's performance and generalization ability across multiple tasks. This patent utilizes the AdapterFusion module to intelligently fuse the domain adapter and knowledge adapter, allowing the fusion module to learn the importance of domain alignment and task representation, thus better utilizing domain alignment knowledge combined with task representation information for domain adaptation in the target domain. The specific model structure is as follows: Figure 4 As shown.
[0084] AdapterFusion introduces a new set of weight matrices that learn to dynamically combine the weights of the domain adapter and the task adapter based on the target task. AdapterFusion consists of the Key, Value, and Query matrices for each layer l, denoted as K. l V l and Q l The output z of each adapter l,t The inputs used as Key and Value are calculated using the formulas (6) and (7) for the output of the adapter.
[0085]
[0086] in, This represents the output of the domain adapter. This represents the up projection matrix of the domain adapter. The upper projection matrix of the domain adapter, x l,t This represents the hidden layer output after summation and normalization in the transformer, r l This represents the hidden layer output before normalization in the transformer. This indicates the output of the task adapter. This represents the upper projection matrix of the task adapter. This represents the lower projection matrix of the task adapter;
[0087] At each layer l and each time step t of the Transformer, the Query is the output h of the pre-trained Transformer model. l As input, each Key takes the output of its respective adapter as input. The dot product of Query and all Keys is passed to a softmax function, calculated as shown in equations (8) and (9).
[0088]
[0089] in, This represents the intermediate result of vector operations in the domain adapter after being processed by the softmax function. This represents the transpose of the hidden layer output of the transformer in the pre-trained model. This represents the output after projection onto the domain adapter. This represents the intermediate result of vector operations in the task adapter after being processed by the softmax function. This represents the output after projection onto the task adapter;
[0090] Value takes the adapter's output as input and performs matrix operations, as shown in formulas (10) and (11).
[0091]
[0092] in, This represents the intermediate result after matrix operations are performed on the Query matrix of the domain adapter and adapter fusion module. This represents the output of the domain adapter. This represents the intermediate result after matrix operations are performed on the Query matrix of the task adapter and the adapter fusion module. This indicates the output of the task adapter;
[0093] Then, the intermediate results of the two adapters are spliced together to obtain the output, as shown in formula (12).
[0094]
[0095] Among them, o l,t This indicates the output of the transformer layer after adding the adapter and adapter fusion module.
[0096] The method described in this embodiment is a dual-adaptor fusion method based on (stacked) domain adapters and task adapters. This model mainly fuses task adapters and domain adapters. On the one hand, it uses task representation information learned from the task adapter; on the other hand, it uses domain-invariant information learned from the (stacked) domain adapter. Extraction is performed through pluggable adapters, and then the dual adapters are fused using an adapter fusion module. Supervised training is conducted in the source domain through the adapter fusion module, thereby achieving better unsupervised domain adaptation in the target domain. Experimental results show that the dual-adaptor fusion method based on (stacked) domain adapters and task adapters can improve the domain adaptation ability of multi-domain sentiment classification datasets.
[0097] To verify the effectiveness of the DAF method (hereinafter referred to as the DAF method), this embodiment performs domain adaptation on five domains on a sentiment classification dataset, training and testing on a total of 20 domain adaptation pairs. The results are compared with multiple methods such as DANN, DSN, TSDTA, and JDTA, with the main comparison metric being the average F1 score of the 20 domain adaptation pairs.
[0098] It should be noted that the dual-adaptor fusion method (DAF) has two types: dual-adaptor fusion based on domain adapters and task adapters (DAF-DT) and dual-adaptor fusion based on stacked domain adapters and task adapters (DAF-SDT).
[0099] DANN, DSN, TSDTA, and JDTA refer to Domain Adversarial Networks (DAN) and Domain Adversarial Neural Networks (DANN), Domain Separation Networks (DSN), and Two-Step Domain and Task Adapters (TSDTA) and Joint Domain Task Adapters (JDTA), respectively.
[0100] As shown in Tables 1 and 2, DAF outperforms both DAN and UDAPTER methods in the absence of sufficient data. From the perspective of average values, Table 1 shows that DAF-DT outperforms DAN methods by 0.35 and UDAPTER methods by 0.11. DAF-SDT outperforms DAN methods by 0.44 and UDAPTER methods by 0.20. From Table 2, from the perspective of the number of domain adaptation pairs, DAF's F1 score surpasses DAN methods for 13 / 20 domain adaptation pairs, is not lower than DAN methods for 16 / 20 domain adaptation pairs, surpasses UDAPTER methods for 13 / 20 domain adaptation pairs, and is not lower than UDAPTER methods for 17 / 20 domain adaptation pairs. These data strongly demonstrate that DAF improves domain adaptation capabilities on small datasets with limited data.
[0101] Table 1 Comparison of experimental results of DAF method on AMAZON dataset
[0102]
[0103] Table 2 Number of Domain Fit Pairs Improved by DAF on the AMAZON Dataset
[0104]
[0105] This invention also provides an unsupervised, domain-adaptive sentiment classification device, such as... Figure 5 As shown, the device 500 includes:
[0106] The data acquisition module 501 is configured to acquire domain adaptation pairs, the domain adaptation pairs including a source domain and a target domain, the source domain being supervised sentiment data with data instances and labels, and the target domain being unsupervised sentiment data with only instances and no labels;
[0107] The first training module 502 is configured to train the task adapter using instances and labels from the source domain to obtain the first parameters;
[0108] The second training module 503 is configured to stack a domain adapter on a task adapter configured with the first parameter, and train the domain adapter using instances of the source and target domains to obtain the second parameter.
[0109] The third training module 504 is configured to fuse the learning results of the task adapter and the domain adapter through the fusion module, and to train the fusion module using the source domain while keeping the first and second parameters unchanged, so as to obtain the third parameter.
[0110] The classification prediction module 505 is configured to fuse the task adapter configured with the first parameter and the domain adapter configured with the second parameter into a prediction model, and to use the prediction model to realize sentiment classification prediction.
[0111] In some embodiments, the goal of the task adapter is to learn a representation of a specific task, and the calculation process is as follows:
[0112] TA l =W up ·(W down ·h l )+r l (1)
[0114] Among them, TA l For the representation of a specific task, h l For hidden layer output, r l For the output of the feedforward layer, W down ∈R h×d W is the lower projection matrix, which projects the hidden layer representation to a lower dimension. up ∈R d×h Let R be the upprojection matrix, which projects the activated low-dimensional features back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, and d << h.
[0115] In some embodiments, the first training module is further configured to update the parameters of the task adapter only when training on the sentiment classification task, using the following formula:
[0116]
[0117] Where, Φ n D represents the update parameters of the task adapter. n Let L represent the source domain data, where there are n source domains. Θ0 represents the pre-trained model parameters frozen during training. n This represents minimizing the loss function.
[0118] In some embodiments, the second training module is further configured to compute a new hidden layer representation in the domain adapter using the following formula:
[0119] TA l =W up ·(W down ·h l )+r l (3)
[0121] SDA l =Wup1 ·(W down1 ·TA l )+TA l (4)
[0123] Among them, TA l h is the output of the task adapter, representing a specific task. l For the hidden output of the task adapter, r l W is the output of the feedforward layer of the task adapter. down ∈R h×d W is the lower projection matrix of the task adapter, which projects the hidden representation of the task adapter to a lower dimension. up ∈R d×h Let R be the upprojection matrix of the task adapter, which projects the low-dimensional features in the activated task adapter back to a higher dimension, where R represents the set of real numbers, d and h represent dimensions, d << h, and W up1 W is the upper projection matrix of the domain adapter. down1 SDA is the lower projection matrix of the domain adapter. l This is the output of the domain adapter.
[0124] In some embodiments, the second training module is further configured to measure the accumulated distance between the source domain hidden layer output and the target domain hidden layer output of each layer of the domain adapter in the last layer of the pre-trained model, expressed as:
[0125]
[0126] Where div{·} represents the distance metric function. This indicates the source domain's output in the domain adapter at layer l. This indicates the output of the domain adapter at layer l for the target domain.
[0127] In some embodiments, the fusion module includes a Key, Value, and Query matrix for each layer l, denoted as K. l V l and Q l The third training module is further configured as follows:
[0128] The output of each adapter is used as input to the Key matrix and Value matrix. The adapters include at least one service adapter and at least one domain adapter. The outputs of the adapters are calculated using formulas (5) and (6):
[0129]
[0130] in, This represents the output of the domain adapter. This represents the up projection matrix of the domain adapter. The upper projection matrix of the domain adapter, x l,t This represents the hidden layer output after summation and normalization in the transformer, r l This represents the hidden layer output before normalization in the transformer. This indicates the output of the task adapter. This represents the upper projection matrix of the task adapter. This represents the lower projection matrix of the task adapter;
[0131] At each layer l and at each time step t, the Query matrix is the output h of the pre-trained model. l As input, the Key matrix takes the output of its respective adapter as input, and the dot product of the Query matrix and all Key matrices is passed to a softmax function, calculated as shown in formulas (8) and (9):
[0132]
[0133] in, This represents the intermediate result of vector operations in the domain adapter after being processed by the softmax function. This represents the transpose of the hidden layer output of the transformer in the pre-trained model. This represents the output after projection onto the domain adapter. This represents the intermediate result of vector operations in the task adapter after being processed by the softmax function. This represents the output after projection onto the task adapter;
[0134] The Value matrix takes the adapter's output as input and performs matrix operations using formulas (10) and (11):
[0135]
[0136]
[0137] in, This represents the intermediate result after matrix operations are performed on the Query matrix of the domain adapter and adapter fusion module. This represents the output of the domain adapter. This represents the intermediate result after matrix operations are performed on the Query matrix of the task adapter and the adapter fusion module. This indicates the output of the task adapter;
[0138] The intermediate results of the two adapters are concatenated using formula (12) to obtain the output:
[0139]
[0140] Among them, o l,t This indicates the output of the transformer layer after adding the adapter and adapter fusion module.
[0141] It should be noted that the various device structures described in this embodiment and the previously described methods belong to the same technical concept and achieve the same technical effect through the same principle, which will not be repeated here.
[0142] This invention also provides a readable storage medium storing one or more programs that can be executed by one or more processors to implement the methods described in any of the above embodiments.
[0143] Furthermore, although exemplary embodiments have been described herein, their scope includes any and all embodiments based on the invention that have equivalent elements, modifications, omissions, combinations (e.g., schemes involving intersections of various embodiments), adaptations, or alterations. Elements in the claims will be interpreted broadly based on the language used in the claims and are not limited to the examples described in this specification or during the implementation of this application, and such examples will be interpreted as non-exclusive. Therefore, this specification and examples are intended to be considered illustrative only, and the true scope and spirit are indicated by the following claims and the full scope of their equivalents.
[0144] The above description is intended to be illustrative and not restrictive. For example, the above examples (or one or more of them) can be used in combination with each other. Other embodiments can be used by those skilled in the art when reading the above description. Furthermore, in the above detailed description, various features may be grouped together to simplify the invention. This should not be construed as an intention that a feature of an unclaimed invention is necessary for any claim. Rather, the subject matter of the invention may be less than all the features of a particular embodiment of the invention. Thus, the following claims are incorporated herein by reference as examples or embodiments, wherein each claim is an independent, separate embodiment, and these embodiments are contemplated to be combined with each other in various combinations or arrangements. The scope of the invention should be determined by reference to the appended claims and the full scope of their equivalents.
Claims
1. An unsupervised, domain-adaptive sentiment classification method, characterized in that, The method includes: Obtain domain adaptation pairs, which include a source domain and a target domain. The source domain is supervised sentiment data with data instances and labels, and the target domain is unsupervised sentiment data with only instances and no labels. The sentiment data can be text data, speech data, image data, or video data. The first parameters are obtained by training the task adapter using instances and labels from the source domain; A domain adapter is stacked on the task adapter configured with the first parameter, and the domain adapter is trained using instances of the source and target domains to obtain the second parameter. The learning results of the task adapter and the domain adapter are fused by the fusion module. With the first and second parameters unchanged, the fusion module is trained using the source domain to obtain the third parameter. The fusion module configured with the third parameter fuses the task adapter configured with the first parameter and the domain adapter configured with the second parameter to obtain a prediction model, and the prediction model is used to realize sentiment classification prediction. The goal of the task adapter is to learn a representation for a specific task, and the calculation process is as follows: (1) in, For the representation of a specific task, For hidden layer output, For the output of the feedforward layer, The lower projection matrix projects the hidden layer representation to a lower dimension. The upprojection matrix projects the activated low-dimensional features back to a higher dimension, where... R Represents the set of real numbers. d , h Representing dimension, ; When training the task adapter, its parameters are updated only during training on the sentiment classification task, using the following formula: (2) in, This indicates the update parameters for the task adapter. Represents source domain data, with n One source domain, This represents the pre-trained model parameters that are frozen during the training process. This represents minimizing the loss function; The new hidden layer representation in the domain adapter is calculated using the following formula: (4) in, This is the down projection matrix of the domain adapter. This is the down projection matrix of the domain adapter. For the output of the domain adapter; The cumulative distance metric between the source and target domain hidden layer outputs of each domain adapter layer in the last layer of the pre-trained model is expressed as: (5) in This represents the distance measurement function. Indicates the source domain in The domain adapter output of the layer, Indicates the target domain in The layer's domain adapter output; The fusion module includes each layer The Key, Value, and Query matrices are represented as follows: , and , The output of each adapter is used as input to the Key matrix and Value matrix. The adapters include at least one task adapter and at least one domain adapter. The outputs of the adapters are calculated using formulas (6) and (7): (6) (7) in, This represents the output of the domain adapter. This represents the up projection matrix of the domain adapter. This represents the up projection matrix of the domain adapter. This represents the hidden layer output after summation and normalization in the transformer. This represents the hidden layer output before normalization in the transformer. This indicates the output of the task adapter. This represents the upper projection matrix of the task adapter. This represents the lower projection matrix of the task adapter; In each layer and each time step The query matrix is the output of the pre-trained model. As input, the Key matrix takes the output of its respective adapter as input, and the dot product of the Query matrix and all Key matrices is passed to a softmax function, calculated as shown in formulas (8) and (9): (8) (9) in, This represents the intermediate result of vector operations in the domain adapter after being processed by the softmax function. This represents the transpose of the hidden layer output of the transformer in the pre-trained model. This represents the output after projection onto the domain adapter. This represents the intermediate result of vector operations in the task adapter after being processed by the softmax function. This represents the output after projection onto the task adapter; The Value matrix takes the adapter's output as input and performs matrix operations using formulas (10) and (11): (10) (11) in, This represents the intermediate result after matrix operations are performed on the Query matrix of the domain adapter and adapter fusion module. This represents the output of the domain adapter. This represents the intermediate result after matrix operations are performed on the Query matrix of the task adapter and the adapter fusion module. This indicates the output of the task adapter; The intermediate results of the two adapters are concatenated using formula (12) to obtain the output: (12) in, This indicates the output of the transformer layer after adding the adapter and adapter fusion module.
2. An unsupervised, domain-adaptive sentiment classification device for implementing the method as described in claim 1, characterized in that, The device includes: The data acquisition module is configured to acquire domain adaptation pairs, which include a source domain and a target domain. The source domain is supervised sentiment data with data instances and labels, and the target domain is unsupervised sentiment data with only instances and no labels. The first training module is configured to train the task adapter using instances and labels from the source domain to obtain the first parameters; The second training module is configured to stack a domain adapter on a task adapter configured with the first parameter, and train the domain adapter using instances of the source and target domains to obtain the second parameter. The third training module is configured to fuse the learning results of the task adapter and the domain adapter through the fusion module. With the first and second parameters unchanged, the fusion module is trained using the source domain to obtain the third parameters. The classification prediction module is configured to fuse the task adapter configured with the first parameter and the domain adapter configured with the second parameter into a prediction model, which is then used to achieve sentiment classification prediction.
3. A non-transitory computer-readable storage medium storing instructions that, when executed by a processor, perform the method according to claim 1.
Citation Information
Patent Citations
Cross-domain text sentiment classification method based on multi-source domain adaptive joint learning
CN110032646A
Small sample relation extraction method and system, electronic equipment and storage medium
CN116205217A