Model training methods, devices, electronic equipment, and computer-readable storage media
By constructing triplet samples and adjusting neural network parameters, a personality coding model was trained, solving the problem of difficulty in identifying fuzzy personalities in existing technologies and achieving higher accuracy in personality detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2025-01-03
- Publication Date
- 2026-06-30
Smart Images

Figure CN122311136A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, specifically to a model training method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] With the development of deep learning technology, users have increasingly higher demands for social platform interest matching and group segmentation, psychological state assessment, and advertising content recommendation. They hope that personality detection models can perform more accurately for personality detection tasks, which has prompted more and more researchers to focus on personality trait learning.
[0003] Current personality detection models are trained on neural networks using limited classification datasets. However, these models discretize personality traits during the detection process, making it difficult to effectively identify and encode ambiguous personality types, thus affecting the accuracy of the personality test. Summary of the Invention
[0004] This application provides a model training method, apparatus, electronic device, and computer-readable storage medium, which can train a personality coding model that effectively identifies and encodes fuzzy personalities, thereby improving the accuracy of personality detection. The specific solution is as follows:
[0005] In a first aspect, embodiments of this application provide a model training method, the method comprising:
[0006] Determine a set of text samples, which includes text samples of various personality categories;
[0007] Three text samples are selected from the text sample set, and one of the selected text samples is determined as the anchor sample. The remaining two text samples in the selected text samples are determined as candidate samples to obtain the initial triplet.
[0008] The positive and negative samples are determined from the two candidate samples to obtain the target triplet;
[0009] The target triple is input into the neural network to be trained, and the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample are determined by the neural network.
[0010] The parameters of the neural network are adjusted based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample to train the neural network and obtain the trained personality coding model.
[0011] Secondly, embodiments of this application provide a model training processing apparatus, the apparatus comprising:
[0012] A determining unit is used to determine a set of text samples, wherein the set of text samples includes text samples of multiple personality categories;
[0013] The selection unit is used to select three text samples from the text sample set, determine one of the selected text samples as the anchor sample, and determine the remaining two text samples in the selected text samples as candidate samples to obtain an initial triplet.
[0014] The determining unit is further configured to determine positive and negative samples among the two candidate samples to obtain the target triplet;
[0015] The determining unit is further configured to input the target triplet into a neural network to be trained, and determine the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample through the neural network;
[0016] An adjustment unit is used to adjust the parameters of the neural network based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample, so as to train the neural network and obtain a trained personality coding model.
[0017] Thirdly, this application also provides an electronic device, including:
[0018] Processor; and
[0019] A memory for storing a data processing program, which, when the electronic device is powered on and runs through the processor, executes the method described in the first aspect.
[0020] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a data processing program that is executed by a processor to perform the method described in the first aspect.
[0021] Compared with the prior art, this application has the following advantages:
[0022] The model training method provided in this application includes the following steps: determining a text sample set, which includes text samples of various personality categories; selecting three text samples from the text sample set, and determining one of the selected text samples as an anchor sample, and determining the remaining two text samples from the selected text samples as candidate samples, to obtain an initial triplet; determining a positive sample and a negative sample from the two candidate samples to obtain a target triplet; inputting the target triplet into a neural network to be trained, and determining the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample through the neural network; adjusting the parameters of the neural network according to the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample to train the neural network, thereby obtaining a trained personality coding model. It can be seen that in this application, firstly, three text samples are selected from text samples of various personality categories to construct a triplet, and the positive and negative samples in the triplet are determined. The triplet including the anchor sample, the positive sample, and the negative sample is used as the training samples for the model, increasing the quantity and richness of the training samples. Secondly, by training the neural network based on the distances between positive samples and anchor samples and between negative samples and anchor samples in the triplet, the neural network can learn the relative personality characteristics between samples in the triplet. This allows the trained model to determine the relative differences between personalities, thereby effectively identifying and encoding fuzzy personalities. Therefore, the model training method provided in this application can train a personality coding model that effectively identifies and encodes fuzzy personalities, thereby improving the accuracy of personality detection. Attached Figure Description
[0023] Figure 1 A schematic flowchart illustrating the model training method provided in this application embodiment;
[0024] Figure 2 Provided for the embodiments of this application Figure 1 A schematic diagram of an implementation process of S105 in China;
[0025] Figure 3 Provided for the embodiments of this application Figure 2 A schematic diagram of an implementation process of S201 in China;
[0026] Figure 4 This is a schematic structural block diagram of the model training device provided in the embodiments of this application;
[0027] Figure 5 This is a schematic block diagram of an electronic device 500 for implementing a model training method, provided in an embodiment of this application. Detailed Implementation
[0028] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.
[0029] It should be noted that the terms "first," "second," "third," etc., in the claims, specification, and drawings of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. Such data are interchangeable where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that shown or described herein. Furthermore, the terms "comprising," "having," and their variations are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that includes 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 these processes, methods, products, or apparatuses.
[0030] It should be understood that in the embodiments of this application, "at least one" means one or more, and "more than one" means two or more. "And / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. The character " / " generally indicates that the related objects before and after it are in an "or" relationship. "Contains A, B and / or C" means containing any one, two, or three of A, B, and C.
[0031] It should be understood that in the embodiments of this application, "B corresponding to A", "B corresponding to A", "A corresponds to B" or "B corresponds to A" means that B is associated with A, and B can be determined based on A. Determining B based on A does not mean that B is determined solely based on A; B can also be determined based on A and / or other information.
[0032] With the development of deep learning technologies such as ChatGPT, users have increasingly higher demands for social platform interest matching and group segmentation, psychological state assessment, and advertising content recommendation, hoping that models can perform more accurately. This has prompted more and more researchers to focus on personality learning. Traditional personality detection tasks discretize personality, assuming that "the boundaries between different personalities are clear." However, in reality, a person's personality is ambiguous, and limited textual information exacerbates this ambiguity. In addition, model performance is limited by the quality and quantity of training data, but currently there is no dataset specifically for fuzzy personalities, which poses a challenge to research on fine-grained personality coding.
[0033] In the early development of personality testing, Francis and Booth introduced Language Query and Word Count (LIWC), pioneering the use of psycholinguistic features for personality analysis through text. With the advent of neural networks, techniques such as CNN and LSTM enhanced personality prediction on social media, and the introduction of BERT further advanced the field. Recent research has explored multi-task and multimodal personality testing methods. Sang et al. used movie scripts to predict the MBTI type of fictional characters, demonstrating the potential of integrating different data. Li et al. employed multi-task learning to simultaneously detect emotion and personality traits, demonstrating the efficiency of shared representations. However, current personality testing datasets are all classification datasets, failing to label fine-grained differences in personality traits.
[0034] In the field of text encoding, contrastive learning is a primary technique used by the NLP community. Contrastive learning can be divided into supervised and unsupervised contrastive learning. The former distinguishes samples using data labels, while the latter typically uses data augmentation techniques to construct positive and negative examples. The most typical method is SimCSE. For supervised data, it adopts the natural structure of the SNLI dataset, treating samples of the same category as positive examples and those of opposite categories as negative examples. For unsupervised data, a dropout strategy is used to construct positive examples. Specifically, a sample is processed twice by the encoder to obtain a positive example pair, while negative examples are other sentences in the same batch.
[0035] While current personality testing technologies have shown good results in personality recognition, they neglect fine-grained differences in personality, making it difficult to effectively identify and encode ambiguous personality traits. Furthermore, current contrastive learning strategies are designed for general data and remain challenging in capturing fine-grained personality characteristics.
[0036] For reasons related to the background technology, in order to enable the model to better learn fine-grained personality information and improve the accuracy of personality detection, the first embodiment of this application provides a model training method.
[0037] The technical solution of this application will be described in detail below through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0038] Figure 1 This is a schematic flowchart illustrating the model training method provided in an embodiment of this application. Figure 1 As shown, the method may include S101 to S105. S101 to S105 will be described in detail below.
[0039] S101. Determine the set of text samples.
[0040] For example, the text sample set includes text samples of various personality categories. Each personality category may correspond to one or more text samples. The text samples may include a person's voice or text in a dialogue, or a comment posted by a person on a social media platform. The category explanation words corresponding to the personality categories can be input into the language model, and the language model can output the text sample set corresponding to the personality categories.
[0041] For example, if the category explanation word "lively and cheerful" corresponding to personality category E is input into the language model, the language model can output a set of text samples corresponding to personality category E, such as (1) "Every day is a new adventure, and I always greet the sunrise with anticipation!" (2) "Encounter difficulties? It's okay, this is a good opportunity to train us! Let's cheer each other on!" (3) "Haha, the little joys in life are everywhere, and I discovered many interesting things today."
[0042] The personality categories described in this disclosure may include one or more of the following: single personality categories and composite personality categories. The distinctions between different single personality categories are relatively clear, such as "extroverted," "introverted," "rational," "emotional," "cautious," and "impulsive." Composite personality categories can represent more complex personalities and can be composed of multiple single personality categories, such as "generally extroverted but with some introverted traits," "generally rational but with some emotional traits," "extroverted and rational," and "extroverted and emotional." Compared to the similarity between different composite personality categories, the similarity between different single personality categories can be smaller, and the differences can be greater.
[0043] In optional embodiments, the personality categories described in this disclosure can be obtained by personality classification methods such as the Myers-Briggs Type Indicator (MBTI), the Big Five personality theory, and the Enneagram.
[0044] S102. Select three text samples from the text sample set, and determine one of the selected text samples as the anchor sample, and determine the remaining two text samples in the selected text samples as candidate samples to obtain the initial triplet.
[0045] For example, if MBTI classification is used to obtain personality categories, the personality categories of the three samples in the initial triplet must be of the same order. For instance, the personality categories of the three samples in initial triplet A can all be first-order personality categories, or they can all be second-order personality categories. When using MBTI to construct a labeling system to obtain multiple personality categories, first-order and second-order personality categories can be identified. Second-order personality categories provide a finer granular description of personality characteristics than first-order categories. In first-order personality categories, different personality categories describe personality characteristics with a single dimension, and the boundaries between the personality characteristics described by different categories are relatively clear. In second-order personality categories, each personality category can describe two dimensions of personality characteristics, making the boundaries between different dimensions of personality characteristics more blurred, thus obtaining a dataset for fuzzy personalities. For example, assuming first-order personality categories are E, I, N, and S, and second-order personality categories are EN, IN, ES, and IS, then the personality traits described by EN include some of the personality traits described by E and some of the personality traits described by N, and the personality traits described by IN include some of the personality traits described by I and some of the personality traits described by N. Each personality category can include eight subcategories, and each subcategory can include three Chinese terms to explain that personality category. For example, Table 1 shows examples of first-order personality categories, and Table 2 shows examples of second-order personality categories.
[0046] Table 1 First-order personality categories
[0047] Personality Categories Category Explanation Words E Socially-minded, optimistic, cheerful, and straightforward. I Social phobia, introverted passivity, introverted negativity N Abstract thinking, full of inspiration, and highly creative S Realism, empiricism, and down-to-earth approach T Rational, far-sighted, and ruthless F Sensitive, loving, and compassionate P Flexible thinking, carefree attitude, quick thinking J Follow the rules, be meticulous and serious
[0048] Table 2 Second-order personality categories
[0049] Personality Categories Category Explanation Words EN Full of energy, unrestrained, and rebellious IN Insecure and sensitive, calm and composed, cold on the outside but warm on the inside. NS Passionate and flamboyant, naturally charming, down-to-earth IS Deeply devoted, arrogant, and eccentric. TP A refined scoundrel, lazy and wicked, unconventional and rebellious FP Drama queen, reckless, little lamb TJ Meticulous, control freak, domineering and ruthless FJ Gentle and considerate, possessive and obsessive, well-educated and reasonable
[0050] Based on the above embodiments, for example, three text samples can be selected from a text sample set using a preset code. The three selected text samples are Sample 1, Sample 2, and Sample 3. The personality categories corresponding to Sample 1, Sample 2, and Sample 3 can be E, E, E, or E, E, I, or E, I, S, or EN, IN, NS, etc. When the personality category corresponding to Sample 1, Sample 2, and Sample 3 is E, E, E, then Sample 1, Sample 2, and Sample 3 belong to the same personality category. When the personality category corresponding to Sample 1, Sample 2, and Sample 3 is E, E, I, or E, I, S, then Sample 1, Sample 2, and Sample 3 belong to different personality categories. However, the personality categories corresponding to Sample 1, Sample 2, and Sample 3 cannot be E, E, EN, or E, IN, EN, etc. One of the selected text samples is determined as the anchor sample, and the remaining two text samples are determined as candidate samples, resulting in an initial triplet.
[0051] S103. Determine the positive and negative samples from the two candidate samples to obtain the target triplet.
[0052] The above-mentioned "determining positive and negative samples from two candidate samples to obtain a target triplet" may include: obtaining annotation information for two candidate samples in the initial triplet, determining positive and negative samples from the two candidate samples based on the annotation information, and obtaining a target triplet.
[0053] For example, the annotation information of the two candidate samples in the initial triplet can be obtained through manual annotation, and then the aforementioned annotation information can be acquired. Specifically, the annotator can analyze the two candidate samples in the initial triplet from three perspectives: "viewpoint," "attitude," and "tone," and annotate the two candidate samples to obtain the annotation information of the two candidate samples in the initial triplet. Alternatively, the two candidate samples in the initial triplet can be annotated using a preset annotation model, and then the annotation results of the preset annotation model can be corrected through manual annotation to obtain the annotation information of the two candidate samples in the initial triplet. The annotation information of the two candidate samples in the initial triplet obtained through the above methods can then be acquired to provide data support for subsequent data processing.
[0054] For example, the initial triplet includes sample 1, sample 2, and sample 3. When sample 1 is selected as the anchor sample, samples 2 and 3 are candidate samples. Annotators can analyze samples 2 and 3 from three perspectives: "viewpoint," "attitude," and "tone," and then annotate them accordingly. For instance, a label can be added to sample 2 indicating it is a positive sample, and a label can be added to sample 3 indicating it is a negative sample, thus obtaining the annotation information for samples 2 and 3. Alternatively, samples 2 and 3 can be annotated using a pre-defined annotation model, and then the annotation results can be corrected through manual annotation. For example, if the pre-defined model labels sample 2 as a positive sample and sample 3 as a negative sample, and the annotator analyzes the data and labels sample 2 as a negative sample and sample 3 as a positive sample, then the annotation results of the pre-defined model have been corrected, resulting in the annotation information for samples 2 and 3.
[0055] For example, in the target triplet, the definitions of positive and negative samples are relative; that is, the definitions of positive and negative samples are relative to the anchor sample. Positive and negative samples are not distinguished based on absolute personality categories, but also on their relative similarity to the anchor sample. This relativity allows the personality triplet to flexibly represent the similarity and differences between samples. A positive sample is more similar to the anchor sample than a negative sample, but this does not mean that the positive sample and the anchor sample are necessarily in the same category, nor does it mean that the negative sample and the anchor sample are necessarily in different categories. This non-absolute nature indicates that the target triplet not only focuses on the personality category label of the samples, but also on the similarity between the samples. Existing methods might simply classify samples into categories that are the same as or different from the anchor sample. However, in the target triplet above, positive and negative samples are defined by their similarity to the anchor sample. For example, two samples with very similar but not identical personality categories may appear as the anchor sample and positive sample respectively in a triplet, thus being distinguished.
[0056] For example, assuming the anchor sample's personality category is "extroverted and outgoing," the positive sample's personality category might be "slightly introverted but still possessing outgoing traits," while the negative sample's personality category might be "relatively introverted and emotionally repressed." As another example, assuming the anchor sample's personality category is "cautious," the positive sample's personality category might be "relatively cautious but occasionally impulsive," while the negative sample's personality category might be "very impulsive." Similarly, assuming the anchor sample's personality category is "very lively and extroverted," the positive sample's personality category might be "relatively lively and extroverted but with some introverted traits," while the negative sample's personality category might be "relatively introverted but with some lively and extroverted traits." The definition of positive and negative samples does not solely depend on whether the sample and the anchor sample belong to the same or different categories. It also defines positive and negative samples based on their relative similarity to the anchor sample. Even if the positive and anchor samples differ in some aspects, or the negative and anchor samples are similar in some details, they can still be defined as positive and negative samples based on their similarity to the anchor sample. This allows the target triple to distinguish personality information more meticulously and capture more subtle personality differences.
[0057] Based on the above embodiments, for example, the initial triplet includes anchor sample A, candidate sample B, and candidate sample C. The personality category corresponding to anchor sample A is EN, the personality category corresponding to candidate sample B is E, and the personality category corresponding to candidate sample C is I. Based on the annotation information of candidate sample B and candidate sample C, candidate sample B is determined to be a positive sample and candidate sample C is a negative sample. It can be seen that the personality categories corresponding to the positive sample and the anchor sample are different.
[0058] Optionally, the above-mentioned "determining positive and negative samples from two candidate samples based on annotation information to obtain the target triplet" can also be achieved in the following way: If the consistency of annotations of two candidate samples in the initial triplet by multiple annotators in the annotation information is higher than a preset threshold, then the initial triplet is taken as the target triplet. For example, the preset threshold can be 90%. When 9 out of 10 annotators have the same annotation results for the candidate samples in the initial triplet after analysis, then the initial triplet can be determined as the target triplet.
[0059] S104. Input the target triplet into the neural network to be trained, and use the neural network to determine the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample.
[0060] For example, after obtaining the target triplet, the target triplet can be input into the neural network to be trained. The neural network to be trained determines the encoding vector of the anchor sample, the encoding vector of the positive sample, and the encoding vector of the negative sample. Then, the distance between the encoding vector of the positive sample and the encoding vector of the anchor sample, and the distance between the encoding vector of the negative sample and the encoding vector of the anchor sample can be determined, thus obtaining the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample. The distances between the above encoding vectors are all Euclidean distances.
[0061] Optionally, the above-mentioned "inputting the target triples into the neural network to be trained, and determining the distance between positive samples and anchor samples and the distance between negative samples and anchor samples through the neural network to be trained" can also be achieved in the following way: taking the historical dialogue text of the preset object as input and the personality category label of the preset object as output, training the neural network to be trained to obtain an initial classification model; deleting the classification head of the initial classification model to obtain an initial encoding model; inputting the target triples into the initial encoding model, and determining the distance between positive samples and anchor samples and the distance between negative samples and anchor samples through the initial encoding model, wherein the historical dialogue text of the preset object has relatively consistent personality characteristics, that is, all the historical dialogue text of the preset object corresponds to the unique personality category label of the preset object.
[0062] S105. Adjust the parameters of the neural network based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample to train the neural network and obtain the trained personality coding model.
[0063] For example, Table 3 compares the performance of the aforementioned personality coding model with that of a large language model (LLM) on multiple triplet datasets. As can be seen from Table 3, the personality coding model trained using the model training method proposed in this application can improve the accuracy of personality detection.
[0064] Model Dataset1 Dataset2 Dataset3 Claude3 76.24% 65.34% 65.12% ChatGPT 62.98% 56.91% 56.27% GPT-4o 77.42% 67.57% 67.72% Our 81.44% 84.01% 75.53%
[0065] Figure 2 Provided for the embodiments of this application Figure 1 A schematic diagram of one implementation process of S105. For example... Figure 3 As shown, Figure 1 S105 can include S201-S202.
[0066] S201. Determine the first difference between the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample.
[0067] S202. Based on the first difference, adjust the parameters of the neural network to train the neural network and obtain the personality coding model.
[0068] For example, the first difference between the distance between a positive sample and an anchor sample and the distance between a negative sample and an anchor sample can be determined by a first loss function. Taking the Triplet Loss function as the first loss function as an example, the function value of the first loss function can be determined by the following formula (1), and the function value of the first loss function can represent the aforementioned first difference.
[0069] Triplet Loss=max{D(f(a),f(p))-D(f(a),f(n))+margin,0} Formula (1)
[0070] Where a, p, and n represent the anchor sample, positive sample, and negative sample in the target triplet, respectively. f(a) represents the encoding vector of the anchor sample, f(p) represents the encoding vector of the positive sample, and f(n) represents the encoding vector of the negative sample. D(·) is a distance function that can be used to calculate the Euclidean distance between two encoding vectors. D(f(a), f(p)) represents the distance between the encoding vector of the anchor sample and the encoding vector of the positive sample, and D(f(a), f(p)) represents the distance between the encoding vector of the anchor sample and the encoding vector of the negative sample. margin is a first preset parameter. In an optional example, the value of margin can be selected as 0.6. 0 represents a preset threshold.
[0071] For example, after determining the first difference, an optimization algorithm, such as gradient descent or its variants, can be used to iteratively adjust the parameters of the neural network to be trained in the direction of decreasing the first difference, thereby training the neural network and obtaining a personality coding model. The Triplet Loss function measures the difference in distance between positive and negative samples and anchor samples. Based on the model f, the Triplet Loss function obtains the encoded vectors of the samples and then calculates the Euclidean distance between the two encoded vectors using the distance function D(·). When adjusting the model parameters, it can ensure that the distance between the anchor sample and the positive sample is always less than the distance between the anchor sample and the negative sample, that is, adjusting the parameters in the direction that makes the distance between the anchor sample and the positive sample less than the distance between the anchor sample and the negative sample, i.e., adjusting the parameters in the direction that makes the output of the Triplet Loss function zero.
[0072] Figure 3 Provided for the embodiments of this application Figure 2 A schematic diagram of one implementation process of S201. (Example) Figure 3 As shown, Figure 2 S201 can include S301-S303.
[0073] S301. Determine the second difference between the distance between the positive sample and the anchor sample and the preset positive sample label.
[0074] For example, a second difference between the distance between the positive sample and the anchor sample and the preset positive sample label can be determined by a second loss function, which can be the binary classification cross-entropy loss function. Taking the BCE Loss function as the second loss function as an example, the second difference between the distance between the positive sample and the anchor sample and the preset positive sample label can be determined by the following formulas (2) and (3), where the BCE Loss function is used to measure the difference between the model's true output for a sample and the label corresponding to that sample.
[0075] BCE Loss=w1*[y*log(d p )+(1-y)*log(1-d p )] Formula (2)
[0076] w1=γ1-d p Formula (3)
[0077] Where w1 represents the first weight, y represents the preset parameter, and in an optional example, the value of y can be 0, d p γ represents the distance between the encoding vector of the anchor sample and the encoding vector of the positive sample, and γ1 represents the preset hyperparameter. In an optional example, the value of γ1 can be 0.5.
[0078] For example, the sample features can be normalized before calculating the distance between the positive sample and the anchor sample to obtain d. p The value range of d is [0, 2]. The training objective is to make the distance between positive samples and anchor samples as close as possible. p The value range of is [0, 2], so the training objective is that the distance between the positive sample and the anchor sample is close to 0, therefore d p The corresponding preset positive sample label is 0. The BCE Loss function can make the distance between the positive sample and the anchor sample close to 0, so as to learn the positive sample information.
[0079] S302. Determine the third difference between the distance between the negative sample and the anchor sample and the preset negative sample label.
[0080] For example, a third difference between the distance between the negative sample and the anchor sample and the preset negative sample label can be determined by a second loss function. Taking the BCE Loss function as the second loss function as an example, the third difference between the distance between the negative sample and the anchor sample and the preset negative sample label can be determined by the following formulas (4) and (5).
[0081] BCEloss=w2*[y*log(2-d n )+(1-y)*log(1-(2-d n ))] Formula (4)
[0082] w2=(d n -γ2)*(2-d n ) Formula (5)
[0083] Where w2 represents the second weight, y represents the preset parameter, and in an optional example, the value of y can be 0, d n γ represents the distance between the encoding vector of the anchor sample and the encoding vector of the negative sample, and γ2 represents the preset hyperparameter. In an optional example, the value of γ2 can be selected as 1.0.
[0084] For example, the sample features can be normalized before calculating the distance between the negative sample and the anchor sample to obtain d. n The value range of d is [0, 2]. The training objective is to maximize the distance between negative samples and anchor samples. n The value range of is [0, 2], so the training target is that the distance between the negative sample and the anchor sample is close to 2. Therefore, (2-d n The default negative sample label is 0. The BCE Loss function can make the distance between the negative sample and the anchor sample close to 2, so as to learn the negative sample information.
[0085] For example, to avoid noise interfering with model training, reliable data can be given higher weights, prompting the model to focus more on credible samples. Specifically, for positive samples, the closer they are to the anchor sample, the more credible the sample, and the closer the anchor sample's characteristics are to the positive sample; for negative samples, the farther they are from the anchor sample, the more credible the sample, and the less consistent the anchor sample's characteristics are with the negative sample. Therefore, for positive samples, the weight is w1 = γ1 - d. p γ1 is a preset hyperparameter, which can be set to 0.5, and the distance d p The smaller the value, the larger the weight. For negative samples, the weight is w2 = (d n -γ2)*(2-d n ), γ2 is a preset hyperparameter, which can be set to 1.0, and the distance d n The larger the value, the greater the weight.
[0086] S303. Based on the first difference, the second difference, and the third difference, adjust the parameters of the neural network to train the neural network and obtain a personality coding model.
[0087] Exemplary, the embodiments of this application do not specifically limit the order in which the first difference, second difference, and third difference are determined. For example, the order of determining the three differences can be: first difference, second difference, third difference; second difference, first difference, third difference; or third difference, second difference, first difference, etc. After determining the first difference through the first loss function and the second and third differences through the second loss function, the first difference, second difference, and third difference can be added sequentially to obtain the sum of the first difference, second difference, and third difference. Then, based on the sum of the first difference, second difference, and third difference, the gradient descent algorithm is used to iteratively adjust the parameters of the neural network to be trained in the direction of decreasing the sum of the first difference, second difference, and third difference, so as to train the neural network to be trained until a personality coding model that meets the training stopping condition is obtained. The training stopping condition may include the sum of the first difference, second difference, and third difference not decreasing for N consecutive times.
[0088] Based on the above embodiments, for example, the gradient refers to the derivative of the loss function with respect to each parameter, indicating the direction in which the loss increases most rapidly. To reduce the loss, the parameters need to be updated in the opposite direction of the gradient. In the above embodiments, the second loss function can be determined relative to d. p and d n The derivative of d, and then towards making d p The direction closer to the 0 label, i.e., the direction in which the distance between the positive sample and the anchor sample is closer to the 0 label, and making d n Adjust the parameters in the direction closer to 2, i.e., the direction in which the distance between the negative sample and the anchor sample is closer to 2.
[0089] In some embodiments, the method further includes: obtaining a personality encoding vector corresponding to the target text sample; and determining the personality category corresponding to the target text sample based on the distance between the personality encoding vector and the encoding vectors of multiple preset personality category labels.
[0090] For example, obtaining the personality encoding vector corresponding to a target text sample can be achieved as follows: input the target text sample into the personality encoding model, and output the personality encoding vector corresponding to the target text sample through the personality encoding model. That is, after training the personality encoding model, the personality features of the input target text sample can be encoded through the personality encoding model to obtain the personality encoding vector of the target text sample. Then, the distance between the personality encoding vector of the target text sample and the encoding vectors of multiple preset personality category labels is determined, and the encoding vector of the preset personality category label with the smallest distance to the personality encoding vector of the target text sample is obtained. The personality category label corresponding to the encoding vector of this preset personality category label is determined as the personality category corresponding to the target text sample.
[0091] For example, taking the prediction of the personality category of Sun Wukong, a character in "Journey to the West," we first obtain multiple lines of dialogue from Sun Wukong, such as: "I, Old Sun, am off!" "Don't talk about scriptures and doctrines, I, Old Sun, only know the word 'reason'," "I, Old Sun, made a great disturbance in the Heavenly Palace five hundred years ago, and the Jade Emperor couldn't do anything to me, so what can you do to me?" "If anyone dares to bully my friends, they won't get away with it." We then convert these lines of dialogue into text form, and then input each line of dialogue as a target text sample into a personality coding model. The personality coding model outputs a personality coding vector corresponding to each line of dialogue, and then aggregates the personality coding vectors corresponding to each line of dialogue to obtain an aggregated vector. The preset personality category labels can include label 1, label 2, label 3, and label 4. The encoding vectors for each label can be determined. Then, the distances between the encoding vectors of labels 1, 2, 3, and 4 are calculated. Finally, the personality category corresponding to the label with the smallest distance to the aggregation vector is taken as Sun Wukong's personality category. For example, if the distance between the encoding vector of label 2 and the aggregation vector is the smallest, the personality category corresponding to label 2 is category EN. The explanatory words for category EN are "full of energy," "unrestrained," and "rebellious." Based on the personality coding results for Sun Wukong, the personality coding model predicts that Sun Wukong's personality category is EN.
[0092] The above is a specific implementation of a model training method. In practice, other feasible methods can also be used to train the model, and the embodiments in this application are not limited to this.
[0093] Corresponding to the model training method provided in the first embodiment of this application, the second embodiment of this application also provides a model training apparatus, such as... Figure 5 As shown, the model training device 400 includes:
[0094] The determining unit 401 is used to determine the text sample set, which includes text samples of various personality categories.
[0095] The selection unit 402 is used to select three text samples from the text sample set, determine one of the selected text samples as the anchor sample, and determine the remaining two text samples in the selected text samples as candidate samples to obtain the initial triplet.
[0096] The determining unit 401 is also used to determine the positive and negative samples among the two candidate samples to obtain the target triplet.
[0097] The determining unit 401 is also used to input the target triplet into the neural network to be trained, and to determine the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample through the neural network.
[0098] The adjustment unit 403 is used to adjust the parameters of the neural network based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample, so as to train the neural network and obtain the trained personality coding model.
[0099] like Figure 4 As shown, the above-mentioned model training device also includes: an acquisition unit 404.
[0100] The acquisition unit 404 is used to acquire the annotation information of the two candidate samples in the initial triplet; the determination unit 401 is specifically used to determine the positive sample and the negative sample in the two candidate samples according to the annotation information, so as to obtain the target triplet.
[0101] Optionally, the adjustment unit 403 is specifically used to determine a first difference between the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample; based on the first difference, the parameters of the neural network are adjusted to train the neural network and obtain a personality coding model.
[0102] Optionally, the adjustment unit 403 is specifically used to determine the first difference through the first loss function.
[0103] Optionally, the adjustment unit 403 is specifically used to determine the second difference between the distance between the positive sample and the anchor sample and the preset positive sample label; determine the third difference between the distance between the negative sample and the anchor sample and the preset negative sample label; and adjust the parameters of the neural network according to the first difference, the second difference, and the third difference to train the neural network and obtain a personality coding model.
[0104] Optionally, the adjustment unit 403 is specifically used to determine the second difference through the second loss function; and to determine the third difference through the second loss function.
[0105] Optionally, the acquisition unit 404 is further configured to acquire the personality encoding vector corresponding to the target text sample; the determination unit 401 is further configured to determine the personality category corresponding to the target text sample based on the distance between the personality encoding vector and the encoding vectors of multiple preset personality category labels.
[0106] Optionally, the acquisition unit 404 is specifically used to input the target text sample into the personality coding model, and output the personality coding vector corresponding to the target text sample through the personality coding model.
[0107] Corresponding to the model training method provided in the first embodiment of this application, the third embodiment of this application also provides an electronic device for the model training method.
[0108] like Figure 5 The diagram shown is a structural block diagram of an example of an electronic device for a model training method provided in an embodiment of this application.
[0109] In this embodiment, an optional hardware structure of the electronic device 500 may be as follows: Figure 5 As shown, it includes: at least one processor 501, at least one memory 502 and at least one communication bus 505; the memory 502 contains a program 503 and data 504.
[0110] Bus 505 can be a communication device for transmitting data between components within electronic device 500, such as an internal bus (e.g., CPU-memory bus, where the processor is the central processing unit, or CPU for short) or an external bus (e.g., a universal serial bus port or a peripheral component interconnection fast port).
[0111] Additionally, the electronic device also includes at least one network interface 506 and at least one peripheral interface 507. The network interface 506 provides wired or wireless communication with an external network 508 (e.g., the Internet, intranet, local area network, mobile communication network, etc.). In some embodiments, the network interface 506 may include any number of network interface controllers (NICs), radio frequency (RF) modules, repeaters, transceivers, modems, routers, gateways, any combination of wired network adapters, wireless network adapters, Bluetooth adapters, infrared adapters, near field communication (NFC) adapters, cellular network chips, etc.
[0112] Peripheral interface 507 is used to connect to peripherals, such as peripheral 1 in the figure. Figure 5 509 in the middle), peripheral 2 ( Figure 5 510 in the middle) and peripheral 3 ( Figure 5 (511 in the original text). Peripherals are peripheral devices, which may include, but are not limited to, cursor control devices (such as mice, touchpads, or touchscreens), keyboards, displays (such as cathode ray tube displays, liquid crystal displays), monitors or light-emitting diode displays, video input devices (such as cameras or input interfaces coupled to video files), etc.
[0113] The processor 501 may be a CPU, an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0114] Memory 502 may include high-speed RAM (Random Access Memory) memory, and may also include non-volatile memory, such as at least one disk storage device.
[0115] Specifically, processor 501 calls the program and data stored in memory 502 to execute the following steps:
[0116] Determine the text sample set, which includes text samples from multiple personality categories;
[0117] Three text samples are selected from the text sample set, and one of the selected text samples is determined as the anchor sample. The remaining two text samples in the selected text samples are determined as candidate samples to obtain the initial triplet.
[0118] The positive and negative samples are determined from the two candidate samples to obtain the target triplet;
[0119] The target triple is input into the neural network to be trained, and the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample are determined by the neural network.
[0120] The parameters of the neural network are adjusted based on the distances between positive samples and anchor samples, and between negative samples and anchor samples, to train the neural network and obtain the trained personality coding model.
[0121] Corresponding to the model training method provided in the first embodiment of this application, the fourth embodiment of this application provides a computer-readable storage medium storing a program for a model training method, which is executed by a processor to perform the following steps:
[0122] Determine the text sample set, which includes text samples from multiple personality categories;
[0123] Three text samples are selected from the text sample set, and one of the selected text samples is determined as the anchor sample. The remaining two text samples in the selected text samples are determined as candidate samples to obtain the initial triplet.
[0124] The positive and negative samples are determined from the two candidate samples to obtain the target triplet;
[0125] The target triple is input into the neural network to be trained, and the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample are determined by the neural network.
[0126] The parameters of the neural network are adjusted based on the distances between positive samples and anchor samples, and between negative samples and anchor samples, to train the neural network and obtain the trained personality coding model.
[0127] It should be noted that for a detailed description of the apparatus, electronic device and computer-readable storage medium provided in the second, third and fourth embodiments of this application, please refer to the relevant description of the first embodiment of this application, which will not be repeated here.
[0128] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.
[0129] In a typical configuration, a node device in a blockchain includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0130] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0131] 1. Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage media, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carrier waves.
[0132] 2. Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0133] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.
Claims
1. A model training method, characterized in that, The method includes: Determine a set of text samples, which includes text samples of various personality categories; Three text samples are selected from the text sample set, and one of the selected text samples is determined as the anchor sample. The remaining two text samples in the selected text samples are determined as candidate samples to obtain the initial triplet. The positive and negative samples are determined from the two candidate samples to obtain the target triplet; The target triple is input into the neural network to be trained, and the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample are determined by the neural network. The parameters of the neural network are adjusted based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample to train the neural network and obtain the trained personality coding model.
2. The method of claim 1, wherein, The step of determining positive and negative samples from the two candidate samples to obtain the target triplet includes: Obtain the annotation information for the two candidate samples in the initial triplet; Based on the annotation information, positive and negative samples are determined from the two candidate samples to obtain the target triplet.
3. The method of claim 1, wherein, The step of adjusting the parameters of the neural network based on the distances between the positive samples and the anchor samples and the distances between the negative samples and the anchor samples to train the neural network and obtain a trained personality coding model includes: Determine the first difference between the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample; Based on the first difference, the parameters of the neural network are adjusted to train the neural network and obtain the personality coding model.
4. The method of claim 3, wherein, Determining the first difference between the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample includes: The first difference is determined by the first loss function.
5. The method of claim 3, wherein, The step of adjusting the parameters of the neural network based on the first difference to train the neural network and obtain the personality coding model includes: Determine the second difference between the distance between the positive sample and the anchor sample and the preset positive sample label; Determine the third difference between the distance between the negative sample and the anchor sample and the preset negative sample label; Based on the first difference, the second difference, and the third difference, the parameters of the neural network are adjusted to train the neural network and obtain the personality coding model.
6. The method of claim 5, wherein, Determining the second difference between the distance between the positive sample and the anchor sample and the preset positive sample label includes: The second difference is determined by the second loss function; The determination of the third difference between the distance between the negative sample and the anchor sample and the preset negative sample label includes: The third difference is determined by the second loss function.
7. The method of claim 1, wherein, The method further includes: Obtain the personality encoding vector corresponding to the target text sample; The personality category corresponding to the target text sample is determined based on the distance between the personality encoding vector and the encoding vectors of multiple preset personality category labels.
8. The method of claim 7, wherein, The process of obtaining the personality encoding vector corresponding to the target text sample includes: The target text sample is input into the personality coding model, and the personality coding model outputs the personality coding vector corresponding to the target text sample.
9. The method of claim 1, wherein, The determined text sample set includes: Input the category explanation words corresponding to the personality category into the language model, and output the text sample set corresponding to the personality category through the language model.
10. A model training apparatus, comprising: The device includes: A determining unit is used to determine a set of text samples, wherein the set of text samples includes text samples of multiple personality categories; The selection unit is used to select three text samples from the text sample set, determine one of the selected text samples as the anchor sample, and determine the remaining two text samples in the selected text samples as candidate samples to obtain an initial triplet. The determining unit is further configured to determine positive and negative samples among the two candidate samples to obtain the target triplet; The determining unit is further configured to input the target triplet into a neural network to be trained, and determine the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample through the neural network; An adjustment unit is used to adjust the parameters of the neural network based on the distance between the positive sample and the anchor sample and the distance between the negative sample and the anchor sample, so as to train the neural network and obtain a trained personality coding model.
11. An electronic device, comprising: include: processor; as well as A memory for storing a data processing program, which, when the electronic device is powered on and runs through the processor, executes the method as described in any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, The system contains a data processing program that is executed by a processor to perform the method as described in any one of claims 1-9.