A server and negative sample sampling method
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-01
- Publication Date
- 2026-08-14
AI Technical Summary
目前负样本采样通常选用静态负采样,例如从样本数据集中按照均匀分布采样得到负样本,但是静态负采样得到的负样本质量较低,影响模型训练的效率
[0017]本公开实施例提供的技术方案与现有技术相比具有如下优点:
Smart Images

Figure CN115659179B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of machine learning technology, and in particular to a server and a negative sample sampling method. Background Technology
[0002] With the development of machine learning, models have become larger and deeper. To accelerate model convergence, how to select training samples, especially negative samples, has become a key issue in the model training process. Currently, static negative sampling is commonly used, such as sampling negative samples from the sample dataset according to a uniform distribution. However, the negative samples obtained by static negative sampling are of low quality, which affects the efficiency of model training. Summary of the Invention
[0003] To address, or at least partially address, the aforementioned technical problems, this disclosure provides a server and a negative sample sampling method that can improve the quality of negative samples and enhance the efficiency of model training.
[0004] To achieve the above objectives, the technical solutions provided by the embodiments of this disclosure are as follows:
[0005] In a first aspect, this disclosure provides a server comprising:
[0006] The controller is configured to: acquire an initial sample set, which includes multiple sample data pairs;
[0007] Take any pair of sample data in the initial sample set as a positive sample and the rest of the sample data pairs as negative samples; input the positive sample and the first negative sample data pair in the negative sample into the initial model respectively to obtain the first similarity score corresponding to the positive sample and the second similarity score corresponding to the first negative sample data pair output by the initial model.
[0008] The first training difficulty of the first negative sample data pair is calculated based on the first similarity score and the second similarity score. The first training difficulty is used to characterize the difficulty of the first negative sample data pair compared to the positive samples. The training difficulty of each negative sample data pair in the negative samples is obtained by traversing the initial sample set.
[0009] Based on the training difficulty of each negative sample data pair in the negative samples, a non-uniform probability distribution is determined, and negative sampling is performed according to the non-uniform probability distribution to obtain the target negative sample set.
[0010] Secondly, this disclosure provides a negative sample sampling method, including:
[0011] Obtain the initial sample set, which includes multiple sample data pairs;
[0012] Take any pair of sample data in the initial sample set as a positive sample and the rest of the sample data pairs as negative samples; input the positive sample and the first negative sample data pair in the negative sample into the initial model respectively to obtain the first similarity score corresponding to the positive sample and the second similarity score corresponding to the first negative sample data pair output by the initial model.
[0013] The first training difficulty of the first negative sample data pair is calculated based on the first similarity score and the second similarity score. The first training difficulty is used to characterize the difficulty of the first negative sample data pair compared to the positive samples. The training difficulty of each negative sample data pair in the negative samples is obtained by traversing the initial sample set.
[0014] Based on the training difficulty of each negative sample data pair in the negative samples, a non-uniform probability distribution is determined, and negative sampling is performed according to the non-uniform probability distribution to obtain the target negative sample set.
[0015] Thirdly, this disclosure provides a computer-readable storage medium, including: storing a computer program on the computer-readable storage medium, wherein when the computer program is executed by a processor, it implements the negative sample sampling method as shown in the second aspect.
[0016] Fourthly, this disclosure provides a computer program product comprising a computer program that, when run on a computer, causes the computer to implement the negative sample sampling method as described in the second aspect.
[0017] The technical solution provided in this disclosure has the following advantages compared with the prior art:
[0018] This disclosure provides a server and a negative sample sampling method, wherein the controller of the server is configured to: firstly acquire an initial sample set for model training; select any sample data pair in the initial sample set as a positive sample; select all sample data pairs other than the positive sample as negative samples; input the positive sample and the first negative sample data pair in the negative sample into the initial model to obtain a first similarity score corresponding to the positive sample output by the initial model, and a second similarity score corresponding to the first negative sample data pair in the negative sample; then calculate a first training difficulty of the first negative sample data pair based on the first similarity score and the second similarity score, wherein the first training difficulty characterizes the degree of difficulty of the first negative sample data pair compared to the positive sample; traverse the initial sample set to obtain the training difficulty of each negative sample data pair in the negative sample; further, determine a non-uniform probability distribution for negative sampling based on the training difficulty of each data pair in the negative sample, and then perform negative sampling based on the non-uniform probability distribution to obtain a target negative sample set. This method calculates a non-uniform probability distribution for negative sample sampling based on the initial sample set and the initial model, thereby updating the negative samples used for model training. This improves the quality of negative samples and allows for negative sample sampling to follow model changes, which helps to accelerate model convergence and improve model quality. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0020] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 These are schematic diagrams of scenarios provided in some embodiments of the present disclosure;
[0022] Figure 2 This is a block diagram showing the configuration of the control device in an embodiment of this disclosure;
[0023] Figure 3 This is a hardware configuration block diagram of the server in an embodiment of this disclosure;
[0024] Figure 4 This is a schematic diagram of the structure of a server provided in an embodiment of this disclosure;
[0025] Figure 5 A schematic diagram of the software configuration of the server provided in an embodiment of this disclosure;
[0026] Figure 6A flowchart illustrating a negative sample sampling method provided in this embodiment of the disclosure;
[0027] Figure 7 This is a schematic diagram illustrating the process of obtaining an initial sample dataset according to an embodiment of this disclosure;
[0028] Figure 8 A schematic diagram illustrating the output of the first similarity score of the initial model provided in this embodiment of the disclosure;
[0029] Figure 9 A schematic diagram illustrating the output of a first similarity score and a second similarity score for the initial model provided in this embodiment of the disclosure;
[0030] Figure 10 This is a schematic diagram of positive and negative samples provided in the embodiments of this disclosure. Detailed Implementation
[0031] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.
[0032] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.
[0033] The process of constructing negative examples that correspond to positive examples based on a certain strategy is called negative sampling. When training a model, each positive sample needs to be compared with a negative sample in order to learn sufficient and comprehensive information, thereby accurately distinguishing positive samples and improving the generalization ability of the samples. Therefore, high-quality sampling of negative samples can ensure the training effect of the model.
[0034] Currently, the most commonly used negative sampling method is static negative sampling, which samples from the dataset based on sample weights. Examples include uniform negative sampling and popularity-biased negative sampling (PNS). Uniform negative sampling randomly selects negative samples from the dataset; popularity-biased negative sampling selects negative samples based on sample frequency or degree, with higher-popularity samples having a greater probability of being considered negative. However, static negative sampling often results in low-quality negative samples, and the weights of each sample do not change during model training, making it impossible to select more challenging samples during model training to aid model convergence.
[0035] In addition, there are logarithmic negative sampling or graph-based negative sampling methods, but these two negative sampling methods are computationally complex and affect the speed of model training.
[0036] To address some or all of the aforementioned technical problems, embodiments of this disclosure provide a server and a negative sampling method. The controller of the server is configured to: first, acquire an initial sample set for model training; select any sample data pair in the initial sample set as a positive sample; select all sample data pairs excluding the positive sample as negative samples; input the positive sample and the first negative sample data pair from the negative samples into the initial model; obtain a first similarity score corresponding to the positive sample output by the initial model and a second similarity score corresponding to the first negative sample data pair from the negative samples; then calculate a first training difficulty for the first negative sample data pair based on the first and second similarity scores, whereby the first training difficulty characterizes the ease or difficulty of the first negative sample data pair compared to the positive sample; traverse the initial sample set to obtain the training difficulty of each negative sample data pair in the negative samples; further, determine a non-uniform probability distribution for negative sampling based on the training difficulty of each data pair in the negative samples, and then sample from the sample dataset according to this non-uniform probability distribution to obtain a target negative sample set. This method calculates a non-uniform probability distribution for negative sample sampling based on the initial sample set and initial model to update the negative samples used for model training. This improves the quality of negative samples and allows for negative sample sampling to follow model changes, thereby accelerating model convergence, improving model quality, and enhancing the effectiveness of model training.
[0037] Figure 1 These are schematic diagrams illustrating scenarios from some embodiments provided in this disclosure. For example... Figure 1As shown in the figure, the device includes a control unit 100, a display device 200, a smart device 300, and a server 400. Users can operate the display device 200 through the smart device 300 or the control unit 100 to search for audio and video resources on the display device 200.
[0038] refer to Figure 1 The scenario illustrated uses a user controlling a display device 200 via a control device 100 as an example. The user inputs a query statement into the display device 200 through the control device 100. The display device 200 generates a query request based on the query statement and sends it to the server 400. The server 400 responds to the query request by inputting the query statement into an information retrieval model to obtain interactive information output by the model, and then feeds this interactive information back to the display device 200. This interactive information includes, but is not limited to, audio and video resources corresponding to the query statement and recommended resources associated with the query statement.
[0039] The information retrieval model is a pre-trained, converged model. The negative sample mining and sampling steps during the training process of this information retrieval model are as follows:
[0040] Server 400 first acquires an initial sample set for model training. It selects any data pair from the initial sample set as a positive sample and all other data pairs except the positive sample as negative samples, thus obtaining initial negative samples through sampling. The initial negative samples are then used for model training, while negative sample sampling continues to update the negative samples. Specifically, the positive samples and the first negative sample data pair from the negative samples are input into the initial model to obtain the first similarity score corresponding to the positive samples output by the initial model, and the second similarity score corresponding to the first negative sample data pair from the negative samples. Then, based on the first and second similarity scores, the first training difficulty of the first negative sample data pair is calculated. This first training difficulty characterizes the ease or difficulty of the first negative sample data pair compared to the positive samples. It should be noted that selecting a certain number of negative samples with higher training difficulty is beneficial for model training.
[0041] Similar to the process of calculating the first training difficulty of the first negative sample data pair, the training difficulty of each negative sample data pair in the negative samples is obtained by traversing the initial sample set; further, a non-uniform probability distribution for negative sampling is determined based on the training difficulty of each data pair in the negative samples, and then sampling is performed in the sample dataset according to the non-uniform probability distribution to obtain the target negative sample set.
[0042] Server 400 obtains target negative samples through the above steps. The above negative sampling process accompanies the model training process and can obtain different non-uniform probability distributions for negative sampling according to the changes in model parameters. This enables efficient and convenient sampling of high-quality negative samples, which helps to accelerate model convergence and improve model training performance.
[0043] In some embodiments, the control device 100 may be a remote control, and communication between the remote control and the display device may include infrared protocol communication, Bluetooth protocol communication, wireless or other wired methods to control the display device 200. Users can input user commands through buttons on the remote control, voice input, control panel input, etc., to control the display device 200. In some embodiments, mobile terminals, tablet computers, computers, laptops, and other smart devices may also be used to control the display device 200.
[0044] In some embodiments, the smart device 300 can install software applications with the display device 200 to connect and communicate via network communication protocols, achieving one-to-one control operations and data communication. Audio and video content displayed on the smart device 300 can also be transmitted to the display device 200 to achieve synchronous display. The display device 200 also communicates with the server 400 via various communication methods. The display device 200 can communicate via a local area network (LAN), wireless local area network (WLAN), and other networks. The server 400 can provide various content and interactive features to the display device 200. The display device 200 can be a liquid crystal display (LCD), an organic light-emitting diode (OLED) display, or a projection display device. In addition to providing broadcast television reception functionality, the display device 200 can also be equipped with a smart network television function that provides computer support.
[0045] Figure 2 This is a block diagram showing the configuration of the control device in an embodiment of this disclosure. Figure 2 As shown, the control device 100 includes a controller 110, a communication interface 130, a user input / output interface 140, a memory, and a power supply. The control device 100 can receive user input commands and convert them into commands that the display device 200 can recognize and respond to, acting as an intermediary for interaction between the user and the display device 200. The communication interface 130 is used for external communication and includes at least one of a Wi-Fi chip, a Bluetooth module, NFC, or a replacement module. The user input / output interface 140 includes at least one of a microphone, a touchpad, a sensor, buttons, or a replacement module.
[0046] Figure 3This is a hardware configuration block diagram of the server in an embodiment of this disclosure. For example... Figure 3 As shown, server 400 includes: communicator 210, detector 220, external device interface 230, memory 240, controller 250, power supply, etc.
[0047] The controller 250 includes a central processing unit (CPU), a video processor, an audio processor, a graphics processing unit (GPU), random access memory (RAM), read-only memory (ROM), a first to an nth interface for input / output, and a communication bus. The detector 220 is used to acquire signals from the external environment or to interact with external systems.
[0048] In some embodiments, the controller 250 controls the operation of the server 400 and responds to user operations through various software control programs stored in memory. The controller 250 controls the overall operation of the server 400.
[0049] The communicator 210 is used to communicate with other devices according to various communication protocol types. For example, the communicator may include at least one of the following: a Wireless Fidelity (Wi-Fi) module, a Bluetooth module, a wired Ethernet module, other network communication protocol chips or near-field communication protocol chips, and an infrared receiver. The server 400 can establish the transmission and reception of control signals and data signals with other devices through the communicator 210.
[0050] The external device interface 230 may include, but is not limited to, one or more of the following: High Definition Multimedia Interface (HDMI), analog or high-definition component input interface (component), Composite Video Broadcast Signal (CVBS), Universal Serial Bus (USB), RGB port, etc. It may also be a composite input / output interface formed by multiple of the above interfaces.
[0051] This disclosure provides a server 400, which includes:
[0052] Controller 250 is configured to: acquire an initial sample set, which includes multiple sample data pairs;
[0053] Take any pair of sample data in the initial sample set as a positive sample and the rest of the sample data pairs as negative samples; input the positive sample and the first negative sample data pair in the negative sample into the initial model respectively to obtain the first similarity score corresponding to the positive sample and the second similarity score corresponding to the first negative sample data pair output by the initial model.
[0054] The first training difficulty of the first negative sample data pair is calculated based on the first similarity score and the second similarity score. The first training difficulty is used to characterize the difficulty of the first negative sample data pair compared to the positive samples. The training difficulty of each negative sample data pair in the negative samples is obtained by traversing the initial sample set.
[0055] Based on the training difficulty of each negative sample data pair in the negative samples, a non-uniform probability distribution is determined, and negative sampling is performed according to the non-uniform probability distribution to obtain the target negative sample set.
[0056] The aforementioned server first performs negative sampling according to a uniform distribution as initial negative samples for model training. During model training, the training difficulty of each negative sample data pair in the initial negative samples is determined based on the similarity score output by the model. A higher training difficulty indicates a greater probability that the corresponding negative sample data pair is a difficult sample. It should be noted that appropriately selecting difficult samples for training during the model training process can help accelerate model convergence. After obtaining the training difficulty of each negative sample data pair, a non-uniform probability distribution is calculated to obtain the probability that each negative sample data pair will be sampled as a negative sample. This is then used to update the negative samples used for model training, resulting in the target negative sample set. This improves the quality of the negative samples and is beneficial to improving the model's training performance.
[0057] In some embodiments, the controller 250 determines a non-uniform probability distribution based on the training difficulty of each negative sample data pair in the negative samples, specifically configured to: determine the cumulative weight mean and the cumulative weight second moment based on the training difficulty of each negative sample data pair in the negative samples; calculate the cumulative variance based on the cumulative weight mean and the cumulative weight second moment; and calculate the non-uniform probability distribution based on the cumulative weight mean and the cumulative variance.
[0058] In some embodiments, after the controller 250 obtains the target negative sample by negative sampling of the sample dataset according to a non-uniform probability distribution, it is further configured to:
[0059] The initial model is trained based on positive samples and target negative samples, and the loss function value is calculated.
[0060] If the loss function value is greater than a preset threshold, update the parameters of the initial model so that the updated initial model can be trained in the next round.
[0061] When the loss function value is less than or equal to a preset threshold, a convergent target model is obtained through training.
[0062] In some embodiments, the controller 250 calculates a first training difficulty for the first negative sample data pair based on a first similarity score and a second similarity score, specifically configured as follows:
[0063] Calculate the difference between the first similarity score and the second similarity score;
[0064] The first training difficulty of the first negative sample data pair is determined based on the difference, and the first training difficulty is positively correlated with the difference.
[0065] In some embodiments, the controller 250 acquires an initial sample set, specifically configured as follows:
[0066] Obtain the sample dataset;
[0067] The sample dataset is sampled according to a uniform distribution to obtain the initial sample set.
[0068] In some embodiments, the controller 250 obtains the target negative sample by performing negative sampling according to a non-uniform probability distribution, specifically configured as follows:
[0069] The difficult sample set is obtained by negative sampling of the sample dataset based on the non-uniform probability distribution;
[0070] The easy sample set is obtained by negative sampling of the sample dataset based on a uniform distribution;
[0071] Difficult sample data pairs are obtained by sampling from the difficult sample set according to the first preset ratio, and easy sample data pairs are obtained by sampling from the easy sample set according to the second preset ratio. The difficult sample data pairs and easy sample data pairs are combined to obtain the target negative sample set.
[0072] In some embodiments, the controller 250 is configured to treat any pair of sample data in the initial sample set as a positive sample and the remaining sample data pairs as negative samples, specifically as follows:
[0073] Divide the initial sample set into N initial subsets;
[0074] Any sample data pair in any initial subsample set of N initial subsample sets is taken as a positive sample, and all sample data pairs in any initial subsample set except for any sample data pair, as well as the remaining initial subsample sets outside of any initial subsample set, are taken as negative samples.
[0075] In some embodiments, the positive sample includes a first query sample and a first interaction sample corresponding to the first query sample; the first negative sample data pair includes a second query sample and a second interaction sample corresponding to the second query sample.
[0076] The controller 250 inputs positive samples and the first negative sample data pair from the negative samples into the initial model, respectively, to obtain the first similarity score corresponding to the positive samples and the second similarity score corresponding to the first negative sample data pair output by the initial model. Specifically, it is configured as follows:
[0077] Positive samples are input into the initial model. The initial model obtains the first interaction estimate based on the first query sample and calculates the first interaction estimate and the first similarity score of the first interaction sample.
[0078] The first negative sample data pair is input into the initial model. The initial model obtains the second interaction estimate based on the second query sample and calculates the second interaction estimate and the second similarity score of the second interaction sample.
[0079] Figure 4 This is a schematic diagram of the structure of a server provided in an embodiment of this disclosure. See also... Figure 4 Server 400 can be a cluster or multiple clusters, and can include one or more types of servers, or it can be a cloud server. The server 400 provided in this embodiment can provide various content and interactive features to the display device 200.
[0080] The server 400 provided in this embodiment includes a central processing unit (CPU) 401, a system memory 404 including random access memory (RAM) 402 and read-only memory (ROM) 403, and a system bus 405 connecting the system memory 404 and the CPU 401. The server 400 also includes a basic input / output (I / O) system 406 that facilitates information transfer between various devices within the computer, and a mass storage device 407 for storing the operating system 413, application programs 414, and other program modules 415.
[0081] The basic input / output system 406 includes a display 408 for displaying information and an input device 409 for user input, such as a mouse or keyboard. Both the display 408 and the input device 409 are connected to the central processing unit 401 via an input / output controller 410 connected to the system bus 405. The basic input / output system 406 may also include the input / output controller 410 for receiving and processing input from multiple other devices such as a keyboard, mouse, or stylus. Similarly, the input / output controller 410 also provides output to a display screen, printer, or other types of output devices.
[0082] Mass storage device 407 is connected to central processing unit 401 via a mass storage controller (not shown) connected to system bus 405. Mass storage device 407 and its associated computer-readable media provide non-volatile storage for server 400. That is, mass storage device 407 may include computer-readable media (not shown) such as hard disk or compact disc read-only memory (CD-ROM) drive.
[0083] System memory 404 and mass storage device 407 can be collectively referred to as memory.
[0084] According to various embodiments of this disclosure, server 400 can also be connected to a remote computer on a network, such as the Internet. That is, server 400 can be connected to network 412 via network interface unit 411 connected to system bus 405, or it can use network interface unit 411 to connect to other types of networks or remote computer systems (not shown).
[0085] like Figure 5 As shown, Figure 5 This is a schematic diagram of the software configuration of the server provided in an embodiment of this disclosure, as shown below. Figure 5 As shown, the system is divided into four layers, from top to bottom: the Applications layer (referred to as the "Application Layer"), the Application Framework layer (referred to as the "Framework Layer"), the Android runtime and system library layer (referred to as the "System Runtime Library Layer"), and the kernel layer.
[0086] In some embodiments, at least one application runs in the application layer. These applications may be Windows programs, system settings programs, or clock programs that come with the operating system; they may also be applications developed by third-party developers. In specific implementations, the application packages in the application layer are not limited to the examples above.
[0087] The framework layer provides application programming interfaces (APIs) and a programming framework for applications. The application framework layer includes predefined functions. It acts as a central processing unit, determining the actions taken by applications within the application layer. Through the API, applications can access system resources and obtain system services during execution.
[0088] In this embodiment, the application framework layer includes managers, content providers, etc., wherein the managers include at least one of the following modules: an Activity Manager for interacting with all activities running in the system; a Location Manager for providing system services or applications with access to system location services; a Package Manager for retrieving various information related to application packages currently installed on the device; and a Notification Manager for controlling the display and clearing of notification messages. The Activity Manager manages the lifecycle of each application and common navigation and back functions, such as controlling application exit, opening, and back.
[0089] In some embodiments, the system runtime library layer provides support for the upper layer, namely the framework layer. When the framework layer is used, the Android operating system runs the C / C++ libraries contained in the system runtime library layer to implement the functions that the framework layer needs to perform.
[0090] In some embodiments, the kernel layer is a layer between hardware and software. For example... Figure 5 As shown, the kernel layer includes at least one of the following drivers: Bluetooth driver, WIFI driver, USB driver, HDMI driver, and power driver.
[0091] To illustrate this solution in more detail, the following will use examples to illustrate it. Figure 6 To explain, it is understandable that Figure 6 The steps involved may include more or fewer steps in actual implementation, and the order of these steps may also be different, depending on whether the negative sample sampling method provided in the embodiments of this disclosure can be implemented.
[0092] like Figure 6 As shown, Figure 6 This is a flowchart illustrating a negative sample sampling method provided in an embodiment of the present disclosure. The method includes the following steps S601 to S604:
[0093] S601. Obtain the initial sample set.
[0094] The initial sample set includes multiple sample data pairs, each of which includes a query sample and an interaction sample corresponding to the query sample.
[0095] In some embodiments, the server first collects a sample dataset D = {(c,k)} using currently mature technologies, where c represents a query sample and k represents the interaction sample corresponding to query sample c; then, it samples the sample dataset D according to a uniform distribution to obtain... Each sample data pair constitutes the initial sample set. Initial sample set Place it in the sampling pool.
[0096] For example, Figure 7 This is a schematic diagram illustrating the acquisition of the initial sample dataset according to an embodiment of this disclosure, as shown below. Figure 7 As shown, first, a sample dataset D is obtained, and then |C| sample data pairs are sampled from the sample dataset according to a uniform distribution. The uniform distribution indicates that each sample data pair in the sample dataset D has the same probability of being sampled. The obtained |C| sample data pairs are used as the initial sample set C and put into the sampling pool.
[0097] S602. Take any sample data pair in the initial sample set as a positive sample and the remaining sample data pairs as negative samples. Input the positive sample and the first negative sample data pair in the negative sample into the initial model respectively to obtain the first similarity score corresponding to the positive sample and the second similarity score corresponding to the first negative sample data pair output by the initial model.
[0098] The initial model can be an information retrieval model including a dual encoder, or a recommendation system model including a dual-tower model. The above is only an illustrative example, and this disclosure does not limit the type of initial model. It should be noted that the initial model mentioned in the embodiments of this disclosure is an untrained and non-converged model. It is any model corresponding to any round of training during the process of changing the model parameters. That is, the initial model is any model in the process of changing the preset model parameters to the final converged model parameters, and does not specifically refer to the model in the first round or the first training.
[0099] The initial model takes sample data pairs as input and outputs similarity scores between interacting samples and predicted interacting values within those pairs. This can be represented by S... θ (c,k) represents the model parameters, such as the number of layers in the neural network.
[0100] In some embodiments, any pair of sample data (c) in the initial sample set C is used. i i) is taken as a positive sample, and the remaining sample data pairs are taken as negative samples; and any negative sample data pair among the negative samples is taken as the first negative sample data pair (c) j Furthermore, positive samples (c) i i) Input the initial model, which is based on the first query sample c in the sample data pair.i The first interaction estimate is obtained, and then the first similarity score S between the two is calculated based on the first interaction estimate and the first interaction sample i in the sample data pair. θ (c i ,i); and, the first negative sample data pair (c j j) Input the initial model, which is based on the second query sample c in the first negative sample data pair. j The second interaction estimate is obtained, and then the second similarity score S between the two is calculated based on the second interaction estimate and the second interaction estimate j in the first negative sample data pair. θ (c j ,j).
[0101] For example, refer to Figure 8 As shown, Figure 8 This diagram illustrates the output of the first similarity score by the initial model provided in this embodiment. Positive samples are input into the initial model. A positive sample is any sample data pair in the initial sample set C. The sample data pair includes a first query sample and a first interaction sample. The first query sample and the first interaction sample are processed by the neural network in the initial model to obtain a first interaction estimate. Then, the initial model compares the first interaction estimate with the first interaction sample and calculates the first similarity score between the two.
[0102] The process of taking any negative sample data pair from the negative samples as the first negative sample data pair and inputting it into the initial model, and then outputting the second similarity score from the initial model, is the same as or similar to the above, and will not be repeated here.
[0103] like Figure 9 As shown, Figure 9 This diagram illustrates the output of a first similarity score and a second similarity score by the initial model provided in this embodiment. Any one sample data pair is selected from the initial sample set C as a positive sample, and the remaining sample data pairs are treated as negative samples. The positive sample is then input into the initial model to obtain the first similarity score output by the initial model. Similarly, any one negative sample data pair (the first sample data pair) is input into the initial model to obtain the second similarity score output by the initial model. In this embodiment, inputting the positive sample and the first negative sample data into the initial model is part of the initial model training process. This allows for the calculation of the loss function value, adjustment of the initial model's parameters, and the sampling of new negative samples based on the updated initial model. The process of calculating the loss function value and adjusting the initial model's parameters will be described in subsequent steps and will not be elaborated upon here.
[0104] In some embodiments, reference is made to Figure 10 As shown, Figure 10This is a schematic diagram of positive and negative samples provided in an embodiment of this disclosure. The initial sample set C is divided into N initial subsets. For any initial subset R within the N initial subsets, any sample data pair (c...) in the initial subset R... i i) is taken as a positive sample, and the sample data pairs (c) in the initial subset R are excluded. i The sample data pairs other than those in (i) and the remaining sample data pairs in the initial subset are considered as negative samples. Using the InBatch Sampling algorithm, all sample data pairs other than positive samples in the same batch of the initial sample set are considered as negative samples. Dividing the initial sample set into smaller initial subsets for batch negative sample sampling helps to accelerate the negative sample sampling efficiency.
[0105] S603. Calculate the first training difficulty of the first negative sample data pair based on the first similarity score and the second similarity score; traverse the initial sample set to obtain the training difficulty of each negative sample data pair in the negative samples.
[0106] The first training difficulty characterizes the relative difficulty of the first negative sample data pair compared to the positive samples. A higher first training difficulty indicates a greater probability that the first negative sample data pair is a difficult sample. It should be noted that during the model training process using sample data, training samples that the model cannot correctly identify can generate larger backpropagation errors. Since this error is the decisive basis for updating the model parameters, these samples play a crucial role in the model parameter update process and are called difficult samples.
[0107] In some embodiments, the difference between a second similarity score and a first similarity score is calculated, and then a first training difficulty of the first negative sample data pair is determined based on the difference, the first training difficulty being positively correlated with the difference.
[0108] Optionally, the first training difficulty of the first negative sample data pair can be calculated according to the following formula (1):
[0109] w(j|c j ,j)=σ(S θ (c j ,j)-S θ (c i ,i)) (1)
[0110] Among them, w(j|c j ,j) represents the first training difficulty. σ is the activation function (Sigmoid) of the neural network, which maps the difference between the first and second similarity scores to the range (0,1).
[0111] Similar to the method for calculating the first training difficulty, this disclosure iterates through the initial sample set to obtain the training difficulty of each negative sample data pair in the negative samples.
[0112] S604. Determine the non-uniform probability distribution based on the training difficulty of each negative sample data pair in the negative samples, and perform negative sampling based on the non-uniform probability distribution to obtain the target negative sample set.
[0113] In some embodiments, the cumulative weight mean is determined based on the training difficulty of each sample data pair in the negative samples. Optionally, in this embodiment of the disclosure, the cumulative weight mean v is determined according to the following formula (2). j :
[0114] v j =(1-α)v j +α·w(j|c j ,j) (2)
[0115] Where α is the hyperparameter of the moving average, α∈[0,1].
[0116] Based on the training difficulty of each sample data pair in the negative samples, the cumulative weight second moment is determined. Optionally, in this embodiment, the cumulative weight second moment m is determined according to the following formula (3). j :
[0117] m j =(1-α)m j +α·w 2 (j|c j ,j) (3)
[0118] Furthermore, the cumulative variance is calculated based on the cumulative weight mean and the cumulative weight second moment. Optionally, in this embodiment of the disclosure, the cumulative variance d is determined according to the following formula (4). j :
[0119]
[0120] Furthermore, a non-uniform probability distribution for negative sample sampling is calculated based on the cumulative weight mean and cumulative variance. Optionally, in this embodiment of the disclosure, the non-uniform probability distribution is calculated according to the following formula (5):
[0121]
[0122] This gives the probability that each data pair in the sample dataset will be selected as a negative sample.
[0123] After determining the above non-uniform probability distribution, the sample dataset D is sampled according to the non-uniform probability distribution to obtain the target negative sample set.
[0124] In some embodiments, the sample dataset is negatively sampled according to the above-mentioned non-uniform probability distribution to obtain a hard sample set, and the sample dataset is negatively sampled according to a uniform distribution to obtain an easy sample set. Further, hard sample data pairs are collected from the hard sample set according to a first preset ratio, and easy sample data pairs are collected from the easy sample set according to a second preset ratio. The hard sample data pairs and easy sample data pairs are combined to obtain the target negative sample set.
[0125] For example, the first preset ratio is set to 30%, and the second preset ratio is 70%. A difficult sample set is obtained by sampling from the sample dataset D according to a non-uniform probability distribution, and an easy sample set is obtained by sampling from the sample dataset D according to a uniform probability distribution. Then, according to the first preset ratio of 30%, difficult sample data pairs are obtained by sampling with replacement from the difficult sample set, and according to the second preset ratio of 70%, easy sample data pairs are obtained by sampling with replacement from the easy sample set. These are combined as the target negative sample set, updating the initial negative samples in the sampling pool and improving the quality of the negative samples.
[0126] In some embodiments, after obtaining the target negative sample set based on a non-uniform probability distribution, the initial model is trained based on the positive samples and the target negative sample set. It should be noted that the positive samples were previously collected according to a uniform distribution. This disclosure mainly focuses on negative sample sampling without altering the initial positive samples to avoid disrupting the original distribution of the positive samples and affecting the training effect. During training using the positive samples and the target negative sample set, a loss function value is calculated. The loss function can be an improved normalized exponential (softmax) cross-entropy function, which is not limited in this disclosure. It is determined whether the loss function value is less than or equal to a preset threshold. If the loss function value is less than the preset threshold, a converged target model is obtained. Training using the target negative sample set sampled according to a non-uniform probability distribution improves the efficiency and effectiveness of model training due to the high quality of the target negative sample dataset. If the loss function value is greater than the preset threshold, it indicates that the model has not converged, and gradient backpropagation is required to update the model parameters and proceed to the next round of model training until the model converges or reaches the preset maximum number of training rounds.
[0127] In summary, this disclosure provides a negative sample sampling method, wherein the controller of the server is configured to first acquire an initial sample set for model training, select any sample data pair in the initial sample set as a positive sample, and take all sample data pairs other than the positive sample as negative samples. The controller then inputs the first negative sample data pair from the positive and negative samples into the initial model to obtain a first similarity score corresponding to the positive sample output by the initial model and a second similarity score corresponding to the first negative sample data pair in the negative samples. Based on the first and second similarity scores, a first training difficulty of the first negative sample data pair is calculated, whereby the first training difficulty characterizes the degree of difficulty of the first negative sample data pair compared to the positive sample. The method then iterates through the initial sample set to obtain the training difficulty of each negative sample data pair in the negative samples. Further, based on the training difficulty of each data pair in the negative samples, a non-uniform probability distribution for negative sampling is determined, and a target negative sample set is obtained by sampling from the sample dataset according to this non-uniform probability distribution. This method calculates a non-uniform probability distribution for negative sample sampling based on the initial sample set and initial model to update the negative samples used for model training. This improves the quality of negative samples and allows for negative sample sampling to follow model changes, thereby accelerating model convergence, improving model quality, and enhancing the effectiveness of model training.
[0128] This disclosure provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the negative sample sampling method described above and achieves the same technical effect. To avoid repetition, further details are omitted here.
[0129] The computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0130] This disclosure provides a computer program product that includes a computer program that, when run on a computer, causes the computer to implement the aforementioned negative sample sampling method.
[0131] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, systems, or computer program products. Therefore, this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this disclosure can take the form of a computer program product embodied on one or more computer-usable storage media containing computer-usable program code.
[0132] It should be understood, in the several embodiments provided in this disclosure, that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0133] In this disclosure, the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0134] In this disclosure, memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0135] In this disclosure, computer-readable media includes both permanent and non-permanent, removable and non-removable storage media. Storage media can store information using any method or technology; the information can be computer-readable instructions, data structures, program modules, 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, disk storage or other magnetic storage devices, 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 transient media, such as modulated data signals and carrier waves.
[0136] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0137] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the discussion in some embodiments above is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the embodiments and various different variations of the embodiments suitable for specific application considerations.
Claims
1. A server, characterized in that, include: The controller is configured to: acquire an initial sample set, the initial sample set including multiple sample data pairs, each sample data pair containing a query sample and its corresponding interaction sample; Any sample data pair in the initial sample set is taken as a positive sample, and the remaining sample data pairs are taken as negative samples. The positive sample and the first negative sample data pair in the negative sample are respectively input into the initial model. The neural network of the initial model calculates a first similarity score corresponding to the positive sample and a second similarity score corresponding to the first negative sample data pair. The first similarity score is the matching degree between the interaction prediction value generated by the initial model based on the query sample in the positive sample and the interaction sample in the positive sample; the second similarity score is the matching degree between the interaction prediction value generated by the initial model based on the query sample in the first negative sample data pair and the interaction sample in the first negative sample data pair. Based on the difference between the first similarity score and the second similarity score, a first training difficulty of the first negative sample data pair is calculated. The first training difficulty is used to characterize the difficulty of the first negative sample data pair compared to the positive sample, and the first training difficulty is positively correlated with the difference. The training difficulty of each negative sample data pair in the negative sample is obtained by traversing the initial sample set. Based on the training difficulty of each negative sample data pair in the negative samples, a non-uniform probability distribution is determined, and the sample dataset is negatively sampled according to the non-uniform probability distribution to obtain a target negative sample set. The target negative sample set is used to train the initial model in conjunction with the positive samples. The initial model is an information retrieval model, which obtains interactive information output by the information retrieval model based on the input query statement, and feeds the interactive information back to the display device. The interactive information includes audio and video resources corresponding to the query statement and recommended resources associated with the query statement.
2. The server according to claim 1, characterized in that, The controller, based on the training difficulty of each negative sample data pair in the negative samples, determines a non-uniform probability distribution, specifically configured as follows: Based on the training difficulty of each negative sample data pair in the negative samples, the cumulative weight mean and the cumulative weight second moment are determined; Calculate the cumulative variance based on the cumulative weight mean and the cumulative weight second moment; The non-uniform probability distribution is calculated based on the cumulative weight mean and the cumulative variance.
3. The server according to claim 1, characterized in that, After obtaining the target negative sample by negative sampling according to the non-uniform probability distribution, the controller is further configured to: The initial model is trained based on the positive samples and the target negative samples, and the loss function value is calculated; If the loss function value is greater than a preset threshold, the parameters of the initial model are updated so that the updated initial model can be trained in the next round. When the loss function value is less than or equal to the preset threshold, a converged target model is trained.
4. The server according to claim 1, characterized in that, The controller acquires the initial sample set, specifically configured as follows: Obtain the sample dataset; The initial sample set is obtained by sampling the sample dataset according to a uniform distribution.
5. The server according to claim 4, characterized in that, The controller, which obtains the target negative sample by negative sampling according to the non-uniform probability distribution, is specifically configured as follows: The difficult sample set is obtained by negative sampling of the sample dataset according to the non-uniform probability distribution. The sample dataset is negatively sampled according to the uniform distribution to obtain an easy sample set; Difficult sample data pairs are obtained by sampling from the difficult sample set according to a first preset ratio, and easy sample data pairs are obtained by sampling from the easy sample set according to a second preset ratio. The difficult sample data pairs and the easy sample data pairs are combined to obtain the target negative sample set.
6. The server according to claim 1, characterized in that, The controller is configured to treat any pair of sample data in the initial sample set as a positive sample and the remaining pairs of sample data as negative samples, specifically as follows: The initial sample set is divided into N initial sub-sample sets; Any sample data pair from any initial subsample set in the N initial subsample sets is taken as a positive sample, and all sample data pairs in any initial subsample set except for the aforementioned sample data pair, as well as the remaining initial subsample sets outside of the aforementioned initial subsample set, are taken as negative samples.
7. The server according to claim 6, characterized in that, The positive samples include a first query sample and a first interaction sample corresponding to the first query sample; the first negative sample data pair includes a second query sample and a second interaction sample corresponding to the second query sample. The controller inputs the positive samples and the first negative sample data pair from the negative samples into the initial model to obtain the first similarity score corresponding to the positive samples and the second similarity score corresponding to the first negative sample data pair output by the initial model. Specifically, it is configured as follows: The positive sample is input into the initial model, and the initial model obtains a first interaction estimate based on the first query sample, and calculates the first interaction estimate and the first similarity score of the first interaction sample; The first negative sample data pair is input into the initial model, which obtains a second interaction estimate based on the second query sample, and calculates the second interaction estimate and the second similarity score of the second interaction sample.
8. A negative sample sampling method, characterized in that, include: Obtain an initial sample set, which includes multiple sample data pairs, each sample data pair containing a query sample and its corresponding interaction sample; Any sample data pair in the initial sample set is taken as a positive sample, and the remaining sample data pairs are taken as negative samples. The positive sample and the first negative sample data pair in the negative sample are respectively input into the initial model. The neural network of the initial model calculates a first similarity score corresponding to the positive sample and a second similarity score corresponding to the first negative sample data pair. The first similarity score is the matching degree between the interaction prediction value generated by the initial model based on the query sample in the positive sample and the interaction sample in the positive sample; the second similarity score is the matching degree between the interaction prediction value generated by the initial model based on the query sample in the first negative sample data pair and the interaction sample in the first negative sample data pair. Based on the difference between the first similarity score and the second similarity score, a first training difficulty of the first negative sample data pair is calculated. The first training difficulty is used to characterize the difficulty of the first negative sample data pair compared to the positive sample, and the first training difficulty is positively correlated with the difference. The training difficulty of each negative sample data pair in the negative sample is obtained by traversing the initial sample set. Based on the training difficulty of each negative sample data pair in the negative samples, a non-uniform probability distribution is determined, and the sample dataset is negatively sampled according to the non-uniform probability distribution to obtain a target negative sample set. The target negative sample set is used to train the initial model in conjunction with the positive samples. The initial model is an information retrieval model, which obtains interactive information output by the information retrieval model based on the input query statement, and feeds the interactive information back to the display device. The interactive information includes audio and video resources corresponding to the query statement and recommended resources associated with the query statement.
9. The method according to claim 8, characterized in that, The step of determining the non-uniform probability distribution based on the training difficulty of each negative sample data pair in the negative samples includes: Based on the training difficulty of each negative sample data pair in the negative samples, the cumulative weight mean and the cumulative weight second moment are determined; Calculate the cumulative variance based on the cumulative weight mean and the cumulative weight second moment; The non-uniform probability distribution is calculated based on the cumulative weight mean and the cumulative variance.
Citation Information
Patent Citations
Target recognition model training method and device, equipment and storage medium
CN111523596A
Method for training cross-modal retrieval model, electronic device and storage medium
US20220284246A1