Text retrieval method, device, electronic device and storage medium
By training the recall model, utilizing the graph neural network mechanism in the graph model, and combining the loss functions of the semantic model and the graph model, the problem of low recall rate in existing text retrieval methods is solved, and more efficient text retrieval effects are achieved.
Patent Information
- Application Number
- CN202311189354.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-14
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-09-14
AI Technical Summary
Among existing text retrieval methods, the inverted index based on word matching cannot understand semantics and has a low recall rate. Although the deep learning-based model can understand semantics, the recall rate is still low.
By training the recall model and utilizing the graph neural network mechanism in the graph model, the first sample text and the second sample text can interact more during the training phase. By combining the loss functions of the semantic model and the graph model, the recall rate of text retrieval can be improved.
It effectively alleviates the problem of insufficient interaction of simple semantic models, improves the recall rate of recall models, enhances information interaction capabilities, reduces the storage requirements of graph models, and improves computing efficiency.
Smart Images

Figure CN117235207B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a text retrieval method, device, electronic device, and storage medium. Background Art
[0002] Relevant search systems typically deal with data volumes in the hundreds of millions or even larger. Related technologies employ offline inverted indexing based on word matching. This method can efficiently retrieve a batch of relevant texts based on keywords, rapidly reducing the size of the data. However, this method fails to understand semantic meaning based solely on word matching; if a keyword is present in a text, it is retrieved; otherwise, it is not. Methods such as synonym rewriting can mitigate the shortcomings of inverted indexes, but they do not fundamentally resolve the problem.
[0003] Another related technique uses a deep learning-based model for text retrieval, mapping the input text and target text into a common embedding space. Low-dimensional real vectors are used to represent the target text and the text dataset, respectively, and a distance function is used to determine their similarity. This method calculates the embedding vectors corresponding to the text dataset offline and creates an index. Online retrieval requires only calculating the embedding vector of the target text for rapid recall. However, this method still results in a low recall rate. Summary of the Invention
[0004] The present disclosure provides a text retrieval method, apparatus, electronic device, and storage medium to at least address the problem of low retrieval recall rate in related technologies. The technical solutions of the present disclosure are as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, a text retrieval method is provided, comprising:
[0006] Get the first text to be retrieved;
[0007] Inputting the first text into a recall model and outputting a feature vector corresponding to the first text; wherein the recall model is obtained by training an initial semantic model and an initial graph model based on the sample first text and the sample second text; wherein the sample first text and the sample second text are annotated with an association relationship;
[0008] A target feature vector whose similarity with the feature vector satisfies a preset condition is determined from the feature vector data set, and a retrieval result is determined to be a second text corresponding to the target feature vector.
[0009] In a possible implementation, training the initial semantic model and the initial graph model based on the sample first text and the sample second text includes:
[0010] Acquire a sample set; wherein the sample set includes a first sample text and a second sample text;
[0011] Inputting the first sample text into an initial semantic model and outputting a first semantic feature, and inputting the second sample text into the initial semantic model and outputting a second semantic feature;
[0012] generating a feature map according to the first semantic feature and the second semantic feature;
[0013] Inputting the first semantic feature and the feature map into an initial graph model, and outputting a first graph embedding feature; and inputting the second semantic feature and the feature map into the initial graph model, and outputting a second graph embedding feature;
[0014] A loss function is constructed based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship, and the initial semantic model and the initial graph model are iteratively adjusted based on the loss function to obtain a recall model.
[0015] In one possible implementation, the recall model includes a semantic model, constructing a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship, and iteratively adjusting the initial semantic model and the initial graph model based on the loss function to obtain the recall model, including:
[0016] Determining a first loss function based on the first semantic feature, the second semantic feature, and the association relationship;
[0017] determining a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship;
[0018] Performing a weighted summation on the first loss function and the second loss function to obtain a joint loss function;
[0019] Based on the joint loss function, the initial semantic model and the initial graphical model are iteratively adjusted to obtain a semantic model and a graphical model.
[0020] In a possible implementation, the first sample text and the second sample text are respectively input into an initial semantic model, and the first semantic feature and the second semantic feature are output, including:
[0021] Extracting a preset number of sample first texts and sample second texts in batches from the sample set;
[0022] Inputting the first sample text and the second sample text of each batch into the initial semantic model respectively, and outputting the first semantic feature and the second semantic feature corresponding to the batch;
[0023] Generating a feature map according to the first semantic feature and the second semantic feature includes:
[0024] A sub-feature map is generated according to the first semantic feature and the second semantic feature corresponding to the batch.
[0025] In a possible implementation, generating a feature map according to the first semantic feature and the second semantic feature includes:
[0026] Obtaining a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature;
[0027] A feature graph is constructed using the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity, and the third similarity as edges.
[0028] In a possible implementation, inputting the first semantic feature and the feature graph into an initial graph model and outputting a first graph embedding feature includes:
[0029] Extracting the first semantic feature and a neighborhood semantic feature within a preset range from the feature graph using the initial graph model to obtain a first graph embedding feature;
[0030] The step of inputting the second semantic feature and the feature graph into the initial graph model and outputting a second graph embedding feature includes:
[0031] The initial graph model is used to perform feature extraction on the second semantic feature and neighborhood semantic features within a preset range in the feature graph to obtain a second graph embedding feature.
[0032] In one possible implementation, extracting the target first semantic feature and the neighborhood semantic features within a preset range using the initial graph model to obtain a first graph embedding feature includes:
[0033] Using the initial graph model, feature extraction is performed on the target first semantic feature and neighborhood semantic features within a preset range to obtain a plurality of intermediate first graph embedding features;
[0034] A weighted sum is performed on the plurality of intermediate first graph embedding features to obtain a first graph embedding feature.
[0035] According to a second aspect of an embodiment of the present disclosure, a text search device is provided, comprising:
[0036] A first acquisition module, configured to acquire a first text to be retrieved;
[0037] a first generation module, configured to input the first text into a recall model and output a feature vector corresponding to the first text; wherein the recall model is obtained by training an initial semantic model and an initial graph model based on a sample first text and a sample second text; wherein an association relationship is annotated between the sample first text and the sample second text;
[0038] The recall module is used to determine a target feature vector from the feature vector data set whose similarity with the feature vector meets a preset condition, and determine that the retrieval result is a second text corresponding to the target feature vector.
[0039] In a possible implementation, the apparatus further includes:
[0040] A second acquisition module is configured to acquire a sample set, wherein the sample set includes a first sample text and a second sample text;
[0041] a first input module, configured to first input the first sample text into an initial semantic model and output a first semantic feature, and input the second sample text into the initial semantic model and output a second semantic feature;
[0042] a second generating module, configured to generate a feature map according to the first semantic feature and the second semantic feature;
[0043] a second input module, configured to input the first semantic feature and the feature map into an initial graph model and output a first graph embedding feature, and to input the second semantic feature and the feature map into the initial graph model and output a second graph embedding feature;
[0044] An adjustment module is used to construct a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature and the association relationship, and iteratively adjust the initial semantic model and the initial graph model based on the loss function to obtain a recall model.
[0045] In a possible implementation, the recall model includes a semantic model and an adjustment module, including:
[0046] A first determining submodule, configured to determine a first loss function based on the first semantic feature, the second semantic feature, and the association relationship;
[0047] A second determining submodule, configured to determine a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship;
[0048] a calculation submodule, configured to perform a weighted summation of the first loss function and the second loss function to obtain a joint loss function;
[0049] The adjustment submodule is used to iteratively adjust the initial semantic model and the initial graphical model based on the joint loss function to obtain a semantic model and a graphical model.
[0050] In a possible implementation, the first input module includes:
[0051] a sampling submodule, configured to extract a preset number of sample first texts and sample second texts from the sample set in batches;
[0052] An input submodule, configured to input the first sample text and the second sample text of each batch into the initial semantic model, and output the first semantic feature and the second semantic feature corresponding to the batch;
[0053] The second generation module includes:
[0054] The first generating submodule is configured to generate a sub-feature map according to the first semantic feature and the second semantic feature corresponding to the batch.
[0055] In a possible implementation, the second generating module includes:
[0056] a first acquisition submodule, configured to acquire a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature;
[0057] The second generating submodule is configured to construct a feature graph using the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity, and the third similarity as edges.
[0058] In a possible implementation, the second input module includes:
[0059] A first extraction submodule is configured to extract the first semantic feature and a neighborhood semantic feature within a preset range from the feature graph using the initial graph model to obtain a first graph embedding feature;
[0060] The second extraction submodule is used to extract the second semantic feature and the neighborhood semantic features within a preset range in the feature graph by using the initial graph model to obtain a second graph embedding feature.
[0061] In a possible implementation, the first extraction submodule includes:
[0062] an extraction unit, configured to extract the target first semantic feature and the neighborhood semantic features within a preset range using the initial graph model to obtain a plurality of intermediate first graph embedding features;
[0063] A computing unit is configured to perform weighted summation on the plurality of intermediate first graph embedding features to obtain a first graph embedding feature.
[0064] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement a text retrieval method as described in any one of the embodiments of the present disclosure.
[0065] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the text retrieval method as described in any one of the embodiments of the present disclosure.
[0066] According to a fourth aspect of an embodiment of the present disclosure, a computer program product is provided, which includes instructions. When the instructions are executed by a processor of an electronic device, the electronic device can execute the text retrieval method described in any one of the embodiments of the present disclosure.
[0067] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: In the above-mentioned text retrieval method, the initial semantic model and the initial graph model are trained by annotating the associated sample first text and sample second text to obtain a recall model. Compared with the traditional method of using only the initial semantic model to train the recall model, the embodiments of the present disclosure utilize the message passing mechanism of the graph neural network in the graph model to enable more interaction between the sample first text and the sample second text during the training phase, effectively alleviating the problem of insufficient interaction when a simple semantic model is used as a recall model, and improving the recall rate of the recall model.
[0068] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute an improper limitation of the present disclosure.
[0070] Figure 1 The figure is a flowchart of a text retrieval method according to an exemplary embodiment.
[0071] Figure 2The figure is a flowchart of a text retrieval method according to another exemplary embodiment.
[0072] Figure 3 The figure is an effect diagram of a loss function according to an exemplary embodiment.
[0073] Figure 4 It is a structural diagram of a recall model training method according to an exemplary embodiment.
[0074] Figure 5 The figure is a structural diagram of a text retrieval method according to an exemplary embodiment.
[0075] Figure 6 It is a structural diagram of a feature map construction method according to an exemplary embodiment.
[0076] Figure 7 is a structural diagram of a feature map construction method according to another exemplary embodiment.
[0077] Figure 8 The figure is a flowchart of a recall model training method according to an exemplary embodiment.
[0078] Figure 9 is a structural diagram of a recall model training method according to another exemplary embodiment.
[0079] Figure 10 The figure is a block diagram of a text search device according to an exemplary embodiment.
[0080] Figure 11 It is a block diagram of an electronic device according to an exemplary embodiment.
[0081] Figure 12 is a block diagram of an electronic device according to another exemplary embodiment. DETAILED DESCRIPTION
[0082] In order to enable ordinary people in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0083] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure as detailed in the appended claims.
[0084] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0085] In order to facilitate those skilled in the art to understand the technical solution provided by the embodiments of the present disclosure, the technical environment in which the technical solution is implemented is described below.
[0086] In modern search systems, rather than returning the final results directly based on the user's search criteria, they filter candidate results layer by layer to reduce the amount of data to be processed. This process is typically divided into three distinct phases: preprocessing, recall, and ranking. The recall phase aims to perform the initial round of filtering of search objects, quickly selecting tens of thousands of relevant objects from billions of data points. With the advancement of deep learning technology and computing power, a growing number of deep learning-based models have emerged in the recall field, using deep neural networks to learn the correlation between a first document (e.g., the text entered into the search box) and a second document (a text stored in the dataset). In the recall field, deep learning-based models are primarily divided into two categories: dual-tower models and single-tower models. Dual-tower models typically map the first and second documents into a common embedding space, representing them using low-dimensional real vectors, and then using a distance function to determine their similarity. Single-tower models, on the other hand, directly input the first and second documents into a deep model, perform extensive feature crosstalk in the early stages, and then directly output a similarity score. In terms of recall accuracy, the single-tower model allows for full interaction between the first and second texts, resulting in higher accuracy. In the dual-tower model, however, the interaction between the first and second texts is only completed during the final similarity calculation, resulting in weaker interaction and lower accuracy. However, in terms of performance, the dual-tower model can calculate the feature vector of the second text offline and create an index. During online searches, only the feature vector of the first text needs to be calculated, enabling rapid recall. However, since the single-tower model requires the entire data of the first and second texts before inputting them into the model, offline preparation is impossible, resulting in low efficiency. This makes it suitable only for sorting data with smaller data volumes and high precision requirements.
[0087] Based on actual technical requirements similar to those described above, an embodiment of the present disclosure provides a text retrieval method.
[0088] Figure 1 is a flowchart of a text retrieval method according to an exemplary embodiment. Figure 1 As shown, the method is used in a terminal or a server and includes the following steps.
[0089] Step S101: Obtain the first text to be searched.
[0090] Specifically, the first text may include text entered in the search box, such as "How to make hot and sour potato shreds." The first text may also include text converted from other multimedia text, such as a voice, an image, or a video. The voice may be recognized as text using a voice recognition algorithm, or the image or video may be recognized as descriptive text using image recognition or video recognition methods.
[0091] Step S103: input the first text into a recall model and output a feature vector corresponding to the first text; wherein the recall model is obtained by training an initial semantic model and an initial graph model based on the sample first text and the sample second text; wherein an association relationship is marked between the sample first text and the sample second text.
[0092] Specifically, the recall model is used to extract feature information from text and obtain a feature vector corresponding to the text. The text may include a first text or a second text. The second text includes text from the dataset to be retrieved, and may include article text or descriptive text of other multimedia resources. The descriptive text may take the form of a title, description, tag, or identifying text. To improve retrieval performance, features may be pre-extracted from the second text and stored in a feature vector dataset.
[0093] In the embodiment of the present disclosure, the recall model includes training the initial semantic model and the initial graph model, referring to Figure 2 As shown, the sample first text represents the input text to be retrieved, and the sample second text represents the text stored in the data set. There is an association relationship between the sample first text and the sample second text. For example, the user inputs the first text and multiple second texts are displayed. The second text selected by the user from the second text can be used as a positive sample, and the second text not selected by the user can be used as a negative sample. Therefore, an association relationship can be marked between the sample first text and the second text as a positive sample, and other second samples without an association relationship can be used as negative samples. Figure 2 As shown, the first text of the sample is input into the neural network (initial semantic model), and the first semantic feature is output; the second text of the sample is input into the neural network, and the second semantic feature is output. In an exemplary embodiment, the initial semantic model is used to extract the semantic information of the first text of the sample, and may include a long short-term memory model LSTM or a pre-trained model BERT model, etc. A feature graph is constructed based on multiple first semantic features and multiple second semantic features. The feature graph and the first semantic feature are input into the graph neural network (initial graph model), and the first graph embedding feature is output; the feature graph and the second semantic feature are input into the graph neural network, and the second graph embedding feature is output. Among them, the initial graph model is used to extract semantic features and feature information within a preset range of the neighborhood. Therefore, the obtained first graph embedding feature can contain features of its surrounding neighborhood information compared to the first semantic feature.
[0094] In one exemplary embodiment, independent loss functions can be constructed for the initial semantic model and the initial graph model, and independent training can be performed to obtain the semantic model and the graph model. Accordingly, the recall model includes a semantic model and a graph model. Specifically, the first text is input into the recall model, and a feature vector corresponding to the first text is output. This includes: inputting the first text into the semantic model to obtain a first semantic feature, and then inputting the first semantic feature into the graph model to obtain a first graph embedding feature. Inputting the first semantic feature into the graph model to obtain the first graph embedding feature can specifically include: inputting the first semantic feature and a preset feature graph into the graph model, and outputting the first graph embedding feature. In one example, the graph model determines the target first semantic feature that is most similar to the first semantic feature from the feature graph based on similarity, and then extracts feature information of the target first semantic feature and its surrounding neighboring nodes to obtain the first graph embedding feature. In another example, a K-nearest neighbor classification algorithm can be used to determine the first semantic feature and its K nearest neighbor nodes, match the first semantic feature and the K nearest neighbor nodes to the feature graph, and extract feature information of the first semantic feature and the K nearest neighbor nodes to obtain the first graph embedding feature. It should be noted that the process of obtaining the second image embedding feature through the second text is similar to the process of obtaining the first image embedding feature through the first text, and will not be described in detail here.
[0095] In another exemplary embodiment, a joint loss function can be constructed for the initial semantic model and the initial graph model, wherein the joint loss function can include a weighted sum of a first loss function of the initial semantic model and a second loss function of the initial graph model. In the process of joint training, the initial graph model is a "non-intrusive" structure, which is only used for optimizing the initial semantic model in the training phase. In the subsequent application phase, the optimized graph model can be removed, and only the optimized semantic model is retained. Accordingly, the recall model includes a semantic model. That is, the first text is input into the semantic model, and a feature vector corresponding to the first text is output, wherein the feature vector contains semantic information and feature information of the neighborhood.
[0096] Step S105 , determining a target feature vector from the feature vector data set whose similarity to the feature vector satisfies a preset condition, and determining the retrieval result as a second text corresponding to the target feature vector.
[0097] Specifically, the preset conditions may include a preset number of target feature vectors with the highest similarity, or may include target feature vectors with similarity greater than a preset threshold, and may be set specifically based on the application scenario. The feature vectors in the feature vector dataset may be pre-generated as follows: a second text is input into the recall model, a feature vector corresponding to the second text is input, and the feature vectors corresponding to the plurality of second texts are combined into a feature vector dataset.
[0098] In the above-mentioned text retrieval method, the initial semantic model and the initial graph model are trained by annotating the associated sample first text and sample second text to obtain a recall model. Compared with the traditional method of using only the initial semantic model to train the recall model, the embodiment of the present disclosure utilizes the message passing mechanism of the graph neural network in the graph model to enable more interaction between the sample first text and the sample second text during the training phase, effectively alleviating the problem of insufficient interaction when the semantic model alone is used as the recall model, and improving the recall rate of the recall model.
[0099] In a possible implementation, training the initial semantic model and the initial graph model based on the sample first text and the sample second text includes:
[0100] Acquire a sample set; wherein the sample set includes a first sample text and a second sample text;
[0101] Inputting the first sample text into an initial semantic model and outputting a first semantic feature, and inputting the second sample text into the initial semantic model and outputting a second semantic feature;
[0102] generating a feature map according to the first semantic feature and the second semantic feature;
[0103] Inputting the first semantic feature and the feature map into an initial graph model, and outputting a first graph embedding feature; and inputting the second semantic feature and the feature map into the initial graph model, and outputting a second graph embedding feature;
[0104] A loss function is constructed based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship, and the initial semantic model and the initial graph model are iteratively adjusted based on the loss function to obtain a recall model.
[0105] Specifically, a feature map is generated based on the first semantic feature and the second semantic feature, which may include multiple mapping methods, such as a fully connected map, a kNN map based on prior semantic similarity, an interaction map based on click relationships, random mapping, etc.
[0106] In an embodiment of the present disclosure, a loss function is constructed based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship. In an exemplary embodiment, the following may be included: constructing a first loss function based on the first semantic feature, the second semantic feature, and the association relationship. Constructing a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship. Adjusting the parameters of the initial semantic model based on the first loss function until convergence to obtain a semantic model, and adjusting the parameters of the initial graph model based on the second loss function until convergence to obtain a graph model. The recall model obtained according to the embodiment of the present disclosure includes two parts: a semantic model and a graph model. In the inference stage (the application stage of the recall model), the second text can be pre-input into the semantic model of the recall model to obtain a second semantic feature. The second semantic feature and the pre-constructed feature graph are input into the graph model to obtain a second graph embedding feature. All second graph embedding features are used as a feature vector dataset. The feature graph can be obtained by mapping the historical first semantic feature, the historical second semantic feature, and the second semantic feature. Among them, the historical first semantic feature may include the one obtained by the historical first text after passing through the semantic model, the historical second semantic feature may include the one obtained by the historical second text after passing through the semantic model, and the second semantic feature may include the one obtained by passing through the semantic model of the second text in the current data set.
[0107] In an embodiment of the present disclosure, a loss function is constructed based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship. In another exemplary embodiment, it may include: determining a first loss function based on the first semantic feature, the second semantic feature, and the association relationship; determining a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship; and performing a weighted summation of the first loss function and the second loss function to obtain a joint loss function. In an exemplary embodiment, the first loss function L D The following formula (1) may be included:
[0108] L D =∑max(0,m+sim(q,d - )-sim(q,d + )) (1)
[0109] Among them, sim(q,d) is the similarity between the first text q and the second text d, d - Denotes negative samples that have no association with the first text, d + represents the positive sample associated with the first text, m represents a preset value, and cosine similarity can be used, that is:
[0110]
[0111] Among them, h q ∈R dim Represents the semantic features of the first text, h d ∈R dim Represents the semantic features of the second text.
[0112] The method of constructing the first loss function in the above formula (1) brings the semantically similar first text and the second text closer together in the embedding space, and pushes the semantically inconsistent first text and the second text further apart.
[0113] In an exemplary embodiment, the second loss function L G The following formula (3) may be included:
[0114]
[0115] Among them, m represents the preset value, z q represents the first graph embedding feature corresponding to the first text, Represents the second graph embedding feature corresponding to the negative sample in the second text, The second graph embedding feature corresponding to the positive sample in the second text.
[0116] In an exemplary embodiment, the joint loss function L may include the following formula (4):
[0117] L=βL D +(1-β)L G (4)
[0118] Among them, β∈[0,1] is a hyperparameter that controls the ratio of the two loss functions. When β is 1, it means that only the first loss function of the semantic model is considered; when β is 0, it means that only the second loss function of the graphical model is considered.
[0119] In the above embodiment, reference Figure 3As shown, the training goal of the semantic model is a point-wise learning method. It brings the positive samples in the sample second text closer to the sample first text in the embedding space (the vector space of semantic features), and pushes the negative samples in the sample second text away from the sample first text in the embedding space. The training goal of the graph model is a cluster-wise learning method. Since the graph embedding features of each sample first text and sample second text can aggregate neighbor node information, each graph embedding feature aggregates neighbor node information. Therefore, when the same metric learning goal is used for training, the information of its neighbor nodes can also have a certain impact. Therefore, the embodiment of the present disclosure no longer narrows or pushes the distance between the sample first text and the sample second text as a single point, but narrows or pushes the distance of a cluster of nodes centered on the sample first text and the sample second text, thereby improving the recall rate of the retrieval and finding more similar second texts.
[0120] For further reference, Figure 4 and Figure 5 During the training phase, a joint loss function is used to train the initial semantic model and the initial graph model. During the training process, the parameters of the initial semantic model and the initial graph model are jointly adjusted, allowing the trained semantic model to be used solely as the recall model during the inference phase. This recall model can obtain neighborhood node information for the first or second text, enhancing the information interaction capabilities of the original recall model. While improving the recall rate, compared to independently training the initial semantic model and the initial graph model, the storage of the graph model during the inference phase can be reduced, making the recall model more lightweight and the computational efficiency of graph embedding features higher.
[0121] In a possible implementation, the first sample text and the second sample text are respectively input into an initial semantic model, and the first semantic feature and the second semantic feature are output, including:
[0122] Extracting a preset number of sample first texts and sample second texts in batches from the sample set;
[0123] Inputting the first sample text and the second sample text of each batch into the initial semantic model respectively, and outputting the first semantic feature and the second semantic feature corresponding to the batch;
[0124] Generating a feature map according to the first semantic feature and the second semantic feature includes:
[0125] A sub-feature map is generated according to the first semantic feature and the second semantic feature corresponding to the batch.
[0126] Specifically, refer to Figure 6As shown, in constructing a feature graph, an implementation method includes: obtaining all sample first texts and sample second texts from a sample set, and obtaining first semantic features and second semantic features through an initial semantic model, and constructing a global large graph based on all first semantic features and second semantic features. The global large graph sampling subgraphs or sample neighbor nodes are trained as training samples of the initial graph model. The method of constructing a global large graph is more complicated when the sample set contains more sample first texts and sample second texts. In the embodiment of the present disclosure, reference Figure 7 As shown, a preset number of sample first texts and sample second texts are extracted (sampled) in batches from a sample set, where the preset number can include the total number of sample first texts and sample second texts or a certain number of sample first texts and a certain number of sample second texts. For the first semantic features and second semantic features of the same batch, a small sub-feature graph is constructed, and the sub-feature graph, the first semantic features, and the second semantic features are used to train the initial graph model.
[0127] Table 1 Experimental results of graph-assisted training model
[0128]
[0129] Table 1 shows the experimental results of the graph-assisted training model. KSBERT is the original recall model, DSSMGNN-lite uses the graph-assisted training module to directly train KSBERT (without using a phased training approach), and DSSMGNN uses the graph-assisted training module to train KSBERT in a phased training approach. It can be seen that DSSMGNN has a certain degree of improvement in recall rates at all levels (such as R@10, R@50, and R@100 in Table 1) compared to the original recall model. It is worth noting that DSSMGNN only uses the graph-assisted training module proposed in this paper to assist in the training of KSBERT during the training phase, and only uses the embedding vectors extracted from the optimized KSBERT model during verification.
[0130] In the above-mentioned embodiments, the use of a global large-scale map approach to construct feature maps can retain as much relevant information as possible and provide stronger representation capabilities. However, map construction and training are relatively complex, and mapping the entire sample set data significantly impacts the model structure and training methods. The disclosed embodiments attempt a "non-invasive" auxiliary training mode, employing a batch mapping approach that seamlessly adapts to traditional recall model training methods and is more suitable as a mapping strategy for auxiliary training.
[0131] In a possible implementation, generating a feature map according to the first semantic feature and the second semantic feature includes:
[0132] Obtaining a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature;
[0133] A feature graph is constructed using the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity, and the third similarity as edges.
[0134] Specifically, construct feature maps Where V={v1,v2,...,v n} represents the set of nodes in the feature graph, which consists of the first semantic feature and the second semantic feature, E = {e1, e2, ..., e m} is the set of all edges in the graph, including the first similarity between the first semantic feature and the first semantic feature, the second similarity between the second semantic feature and the second semantic feature, and the third similarity between the first semantic feature and the second semantic feature.
[0135] Table 2. Differences between various mapping methods and the optimal group kNN-10
[0136]
[0137] Table 2 shows the differences between different graph construction methods. "self-loop" only adds self-loop edges, and nodes do not aggregate neighboring features. "kNN-k" builds a k-nearest neighbor graph based on the features output by the initial semantic model. Each node is connected to the k nodes with the highest cosine similarity between its semantic features. No distinction is made between the first and second sample texts; the first and second sample texts can be connected to each other. All nodes form a cluster structure based on prior semantic similarity, and the features of neighboring nodes are aggregated. "random-k" randomly selects k nodes for connection. In this case, all nodes are essentially connected to nodes with different semantics. "complete" represents a complete graph, with all nodes connected to each other. "click" establishes connections based on click relationships, connecting the first sample text to the positive examples in its second sample text. "change-query" establishes connections based on query-change relationships. A query-change relationship refers to a user switching search keywords within a short period of time. This is generally believed to indicate that the user is dissatisfied with the search results for a particular query-change behavior and attempts to switch search keywords to obtain better results. We consider the two query-change behaviors to be semantically similar, and establish edges based on this relationship.
[0138] After various experiments, we found that constructing a feature graph with the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity, and the third similarity as edges has better recall effect and can achieve a higher recall rate.
[0139] In a possible implementation, inputting the first semantic feature and the feature graph into an initial graph model and outputting a first graph embedding feature includes:
[0140] Extracting the first semantic feature and a neighborhood semantic feature within a preset range from the feature graph using the initial graph model to obtain a first graph embedding feature;
[0141] The step of inputting the second semantic feature and the feature graph into the initial graph model and outputting a second graph embedding feature includes:
[0142] The initial graph model is used to perform feature extraction on the second semantic feature and neighborhood semantic features within a preset range in the feature graph to obtain a second graph embedding feature.
[0143] Specifically, the initial graph model may include a GCN network, a GraphSAGE network, a GAT network, etc. The preset range may include a one-layer neighborhood, a two-layer neighborhood, or a multi-layer neighborhood. Message passing may be performed in the initial graph model. A target first semantic feature that matches the first semantic feature and a target second semantic feature that matches the second semantic feature are determined from the feature graph.
[0144] In an exemplary embodiment, the initial graph model has L layers. In this case, each node (first semantic feature or second semantic feature) can obtain the influence of L-order neighbors. For a node in the lth layer, the node's own features and the features of all its neighbors are used to calculate the next layer of features. Then:
[0145]
[0146] in, Represents the features of the l-th layer node v, whose dimension is d (l) . represents the features of the neighboring nodes of node v at layer l. AGGREGATE represents a function that aggregates neighboring features. It takes the features of the node itself and its neighboring nodes as input and outputs the next layer of features that aggregates the neighboring node features. With each layer of neighbor aggregation, the first and second semantic features gain the influence of one more layer of neighboring nodes. The first semantic feature is used as the input feature of the initial graph model. is the output feature of the initial graph model, that is, the graph embedding feature that aggregates the features of neighboring nodes.
[0147] The embodiment of the present disclosure utilizes the initial graph model to conveniently extract the first semantic feature and the neighborhood semantic feature within a preset range; the second semantic feature and the neighborhood semantic feature within the preset range are subjected to feature extraction to obtain the second graph embedding feature.
[0148] In one possible implementation, extracting the target first semantic feature and the neighborhood semantic features within a preset range using the initial graph model to obtain a first graph embedding feature includes:
[0149] Using the initial graph model, feature extraction is performed on the target first semantic feature and neighborhood semantic features within a preset range to obtain a plurality of intermediate first graph embedding features;
[0150] A weighted sum is performed on the plurality of intermediate first graph embedding features to obtain a first graph embedding feature.
[0151] Specifically, an attention mechanism can be used to perform weighted summation on the intermediate first graph embedding features. In an exemplary embodiment, assuming that the central node is v, the weight coefficients of its neighboring nodes u to v are defined as:
[0152] e uv =a(Wh u ,Wh v ) (6)
[0153] in, is the weight parameter of the feature transformation of the node in this layer, is a function that calculates the correlation between two nodes. and is the embedding vector of nodes u and v. a can use the same single-layer fully connected layer as GAT, then the weight coefficient between the two nodes can be expressed as:
[0154] e uv =LeakyReLU(a T [Wh u ‖Wh v ]) (7)
[0155] in, is the weight parameter of the fully connected layer, and the activation function used is LeakyReLU.
[0156] Calculate the weight coefficients for all neighbor nodes of the central node v and use SoftMax to normalize them. The final complete normalized weight coefficient α uv The calculation formula is as follows:
[0157]
[0158] According to the idea of weighted summation of attention mechanism, we get node v i The new embedding vector is:
[0159] h′ v =σ(∑ u∈N(v) α uv Wh u ) (9)
[0160] Finally, to further improve the representation capability of the attention layer and enable the attention mechanism to focus on multiple related features between the central node and its neighboring nodes, a multi-head attention mechanism is applied:
[0161]
[0162] in, Represents a splicing operation, is the weight coefficient calculated by the k-th group attention mechanism, W (k) is the corresponding parameter. The splicing operation can also replace the average operation. Combining the above formula, we can aggregate the neighbor operations of GNN
[0163] The disclosed embodiment performs weighted summation on the plurality of intermediate first graph embedding features to obtain the first graph embedding feature, which can better aggregate the information of neighboring nodes, eliminate the noise introduced by aggregating the information of neighboring nodes, and improve the recall rate of the recall model.
[0164] Figure 8 FIG. 1 is a flowchart of a recall model training method according to an exemplary embodiment. Figure 8 As shown, the training methods of the recall model include:
[0165] Step S801: Acquire a sample set; wherein the sample set includes a first sample text and a second sample text.
[0166] Step S803: input the sample first text into the initial semantic model to obtain a first semantic feature as output, and input the sample second text into the initial semantic model to obtain a second semantic feature as output.
[0167] Step S805: Generate a feature map based on the first semantic feature and the second semantic feature.
[0168] Step S807: input the first semantic feature and the feature map into the initial graph model, and output a first graph embedding feature; and input the second semantic feature and the feature map into the initial graph model, and output a second graph embedding feature.
[0169] Step S809: determining a first loss function based on the first semantic feature, the second semantic feature, and the association relationship;
[0170] Step S811: determining a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship;
[0171] Step S813: performing weighted summation on the first loss function and the second loss function to obtain a joint loss function;
[0172] Step S815 : Iteratively adjust the initial semantic model and the initial graphical model based on the joint loss function to obtain a semantic model and a graphical model.
[0173] Regarding the device in the above embodiment, the specific manner of each step has been described in detail in the embodiment of the method, and will not be elaborated here.
[0174] Figure 9 is a structural diagram of a recall model training method according to an exemplary embodiment. Figure 9 As shown, the upper part can be used as the original recall model that needs to be optimized, and the lower part can be used as a graph-assisted training module, which is composed of a graph attention network. Specifically, a sample set is obtained; wherein the sample set includes a first sample text and a second sample text; the first sample text is input into the initial semantic model to output a first semantic feature, and the second sample text is input into the initial semantic model to output a second semantic feature; a feature graph is generated based on the first semantic feature and the second semantic feature; the first semantic feature and the feature graph are input into the initial graph model to output a first graph embedding feature, and the second semantic feature and the feature graph are input into the initial graph model to output a second graph embedding feature; a first loss function is determined based on the first semantic feature, the second semantic feature, and the association relationship; a second loss function is determined based on the first graph embedding feature, the second graph embedding feature, and the association relationship; the first loss function and the second loss function are weighted summed to obtain a joint loss function; based on the joint loss function, the initial semantic model and the initial graph model are iteratively adjusted to obtain a semantic model and a graph model.
[0175] In terms of experimental methods, the embodiments of the present disclosure use a preset data set for training and are verified on a preset offline verification set. The preset data set is a data set generated based on the click information of Kuaishou users, and a second text clicked by the user under a first text is regarded as a second text related to the first text. It contains a total of 26,592,742 first texts and 487,691,532 different second texts. The preset offline verification set contains 444 first texts and 119,804,848 different second texts. Each first text can be annotated with a series of the most relevant second texts in a manually screened manner for experimental verification.
[0176] The disclosed embodiments mainly focus on the recall rate indicator on the offline validation set, compare the difference between using the graph-assisted training module to assist the original recall model training and the baseline model, and compare the effects of different graph neural networks, different mapping methods, and different model parameters on the model effect.
[0177] The goal of the disclosed embodiment is to maximize the recall rate, that is, to ensure that the relevant second text can be recalled and not discarded. The baseline model is the original dual-tower recall model, which is a BERT pre-trained model that has been improved for search recall scenarios. It can be performed on the basis of the pre-trained original dual-tower recall model, and the pre-trained original dual-tower recall model can be tuned using a graph-assisted training module. It is worth noting that the graph-assisted training module can be used to assist in the training of the original dual-tower recall model in the training phase, and the output of the optimized dual-tower model can be directly used for verification in the verification phase.
[0178] The embodiment of the present disclosure implements the graph-assisted training module based on PyTorch Geometric (PyG, a graph neural network framework based on PyTorch). In all experiments, a 64-dimensional embedding vector consistent with the pre-trained model (the optimized BERT model can be used) is used. In terms of batch mapping, the embodiment of the present disclosure adopts uniform random sampling by default, and the batch-size is fixed to 36. In terms of composition, the embodiment of the present disclosure adopts the kNN mapping method based on BERT prior semantic similarity by default, and selects the 10 nodes with the highest cosine similarity in the mini-batch for each node to establish a unidirectional edge. In terms of the selection of the initial graph model, a GAT network containing 8 attention heads is used, and meanpooling is used to aggregate information from different attention heads. Since the graph-assisted training module consists of the aforementioned dual-tower backbone network and the GNN network, the dual-tower backbone network is pre-trained, while the GNN is trained from scratch. Therefore, different learning rates are used for the dual-tower backbone network and the GNN. Specifically, a smaller constant learning rate of 5e-6 is used for the dual-tower backbone network pre-training model, while the cosine annealing strategy is used to set the learning rate for the GNN model, with the initial learning rate set to 3e-5. β is a relatively important hyperparameter in this model, which determines the proportion of the two losses. In the disclosed embodiment, the default value of β during training can be set to 0.9, which means that the BERT loss accounts for 90% and the GNN loss accounts for 10%. Considering that the dual-tower backbone network is ultimately used for verification, its original loss function should account for a larger proportion. The GNN loss only plays an auxiliary role during training, introducing the influence of the first and second text neighbor nodes in a backpropagation manner. The default training method is joint training, that is, first fix the dual-tower backbone network pre-training model, train the subsequent GNN model separately, and then perform end-to-end training with the previous dual-tower backbone network after the GNN model converges.
[0179] Compared with traditional methods, the biggest highlight of the disclosed embodiment is the proposal of a "non-invasive" dual-tower recall model assisted training method. It can be easily applied to the traditional dual-tower recall model. Without changing the original training set and loss function of the model, the message passing mechanism of the graph attention network in the graph-assisted training module is used to improve the interaction ability between the first text and the second text, thereby optimizing the recall ability of the dual-tower recall model. After the training is completed, the graph-assisted training module can be discarded and the optimized dual-tower recall model can be used directly without destroying the original dual-tower recall model structure.
[0180] Batch mapping solves the challenges of traditional industrial applications, such as large datasets, difficulty in mapping the entire dataset, and slow training. It is well-suited to the training methods of the original dual-tower recall model, facilitating the introduction of graph neural networks based on it.
[0181] The phased training strategy enables each part of the model to fully utilize its respective advantages, avoiding the degradation of the dual-tower recall model to be optimized due to the uninitialized graph-assisted training module, and ensuring the model optimization effect.
[0182] It should be understood that although the various steps in the flowchart are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the figure may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0183] It can be understood that the same / similar parts between the various embodiments of the above method in this specification can be referred to each other, and each embodiment focuses on the differences from other embodiments. For related parts, please refer to the description of other method embodiments.
[0184] Based on the same inventive concept, the present disclosure also provides a text retrieval method apparatus for implementing the aforementioned text retrieval method. The solution provided by this apparatus is similar to the solution described in the aforementioned method. Therefore, the specific limitations in the text retrieval method apparatus embodiment provided below can be found in the above-mentioned limitations on the text retrieval method and will not be further elaborated here.
[0185] The device may include a system (including a distributed system), software (application), module, component, server, client, etc. that uses the method described in the embodiments of this specification and is combined with the necessary implementation hardware. Based on the same innovative concept, the device in one or more embodiments provided by the embodiments of the present disclosure is as described in the following embodiments. Since the implementation scheme and method for solving the problem of the device are similar, the implementation of the specific device in the embodiments of this specification can refer to the implementation of the aforementioned method, and the repetitions will not be repeated. As used below, the term "unit" or "module" can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.
[0186] Figure 10 FIG. 1 is a block diagram of a text retrieval method according to an exemplary embodiment. Figure 10 , the apparatus 1000 comprises:
[0187] A first acquisition module 1001 is used to acquire a first text to be searched;
[0188] A first generation module 1003 is configured to input the first text into a recall model and output a feature vector corresponding to the first text; wherein the recall model is obtained by training an initial semantic model and an initial graph model based on a sample first text and a sample second text; wherein an association relationship is annotated between the sample first text and the sample second text;
[0189] The recall module 1005 is configured to determine a target feature vector from the feature vector data set whose similarity to the feature vector satisfies a preset condition, and determine that the retrieval result is a second text corresponding to the target feature vector.
[0190] In a possible implementation, the apparatus further includes:
[0191] A second acquisition module is configured to acquire a sample set, wherein the sample set includes a first sample text and a second sample text;
[0192] a first input module, configured to first input the first sample text into an initial semantic model and output a first semantic feature, and input the second sample text into the initial semantic model and output a second semantic feature;
[0193] a second generating module, configured to generate a feature map according to the first semantic feature and the second semantic feature;
[0194] a second input module, configured to input the first semantic feature and the feature map into an initial graph model and output a first graph embedding feature, and to input the second semantic feature and the feature map into the initial graph model and output a second graph embedding feature;
[0195] An adjustment module is used to construct a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature and the association relationship, and iteratively adjust the initial semantic model and the initial graph model based on the loss function to obtain a recall model.
[0196] In a possible implementation, the recall model includes a semantic model and an adjustment module, including:
[0197] A first determining submodule, configured to determine a first loss function based on the first semantic feature, the second semantic feature, and the association relationship;
[0198] A second determining submodule, configured to determine a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship;
[0199] a calculation submodule, configured to perform a weighted summation of the first loss function and the second loss function to obtain a joint loss function;
[0200] The adjustment submodule is used to iteratively adjust the initial semantic model and the initial graphical model based on the joint loss function to obtain a semantic model and a graphical model.
[0201] In a possible implementation, the first input module includes:
[0202] a sampling submodule, configured to extract a preset number of sample first texts and sample second texts from the sample set in batches;
[0203] An input submodule, configured to input the first sample text and the second sample text of each batch into the initial semantic model, and output the first semantic feature and the second semantic feature corresponding to the batch;
[0204] The second generation module includes:
[0205] The first generating submodule is configured to generate a sub-feature map according to the first semantic feature and the second semantic feature corresponding to the batch.
[0206] In a possible implementation, the second generating module includes:
[0207] a first acquisition submodule, configured to acquire a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature;
[0208] The second generating submodule is configured to construct a feature graph using the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity, and the third similarity as edges.
[0209] In a possible implementation, the second input module includes:
[0210] A first extraction submodule is configured to extract the first semantic feature and a neighborhood semantic feature within a preset range from the feature graph using the initial graph model to obtain a first graph embedding feature;
[0211] The second extraction submodule is used to extract the second semantic feature and the neighborhood semantic features within a preset range in the feature graph by using the initial graph model to obtain a second graph embedding feature.
[0212] In a possible implementation, the first extraction submodule includes:
[0213] an extraction unit, configured to extract the target first semantic feature and the neighborhood semantic features within a preset range using the initial graph model to obtain a plurality of intermediate first graph embedding features;
[0214] A computing unit is configured to perform weighted summation on the plurality of intermediate first graph embedding features to obtain a first graph embedding feature.
[0215] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0216] Figure 11 1 is a block diagram of an electronic device 1100 for a text retrieval method according to an exemplary embodiment. For example, the electronic device 1100 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0217] Reference Figure 11 , the electronic device 1100 may include one or more of the following components: a processing component 1102 , a memory 1104 , a power component 1106 , a multimedia component 1108 , an audio component 1110 , an input / output (I / O) interface 1112 , a sensor component 1114 , and a communication component 1116 .
[0218] The processing component 1102 generally controls the overall operation of the electronic device 1100, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 1102 may include one or more processors 1120 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 1102 may include one or more modules to facilitate interaction between the processing component 1102 and other components. For example, the processing component 1102 may include a multimedia module to facilitate interaction between the multimedia component 1108 and the processing component 1102.
[0219] The memory 1104 is configured to store various types of data to support operations on the electronic device 1100. Examples of such data include instructions for any application or method operating on the electronic device 1100, contact data, phone book data, messages, pictures, videos, etc. The memory 1104 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, optical disk, or graphene memory.
[0220] The power supply component 1106 provides power to the various components of the electronic device 1100. The power supply component 1106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 1100.
[0221] The multimedia component 1108 includes a screen that provides an output interface between the electronic device 1100 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1108 includes a front camera and / or a rear camera. When the electronic device 1100 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0222] The audio component 1110 is configured to output and / or input audio signals. For example, the audio component 1110 includes a microphone (MIC), which is configured to receive external audio signals when the electronic device 1100 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 1104 or transmitted via the communication component 1116. In some embodiments, the audio component 1110 also includes a speaker for outputting audio signals.
[0223] I / O interface 1112 provides an interface between processing component 1102 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0224] The sensor assembly 1114 includes one or more sensors for providing various aspects of the status assessment of the electronic device 1100. For example, the sensor assembly 1114 can detect the open / closed state of the electronic device 1100, the relative positioning of components, such as the display and keypad of the electronic device 1100. The sensor assembly 1114 can also detect changes in the position of the electronic device 1100 or its components, the presence or absence of user contact with the electronic device 1100, the orientation or acceleration / deceleration of the device 1100, and changes in the temperature of the electronic device 1100. The sensor assembly 1114 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1114 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1114 can also include an accelerometer, a gyroscope, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0225] The communication component 1116 is configured to facilitate wired or wireless communication between the electronic device 1100 and other devices. The electronic device 1100 can access a wireless network based on a communication standard, such as WiFi, an operator network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 1116 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1116 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0226] In an exemplary embodiment, the electronic device 1100 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-described methods.
[0227] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 1104 including instructions, and the instructions can be executed by the processor 1120 of the electronic device 1100 to perform the above method. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0228] In an exemplary embodiment, a computer program product is further provided. The computer program product includes instructions, and the instructions can be executed by the processor 1120 of the electronic device 1100 to implement the above method.
[0229] Figure 12 1 is a block diagram of an electronic device 1200 for a text retrieval method according to an exemplary embodiment. For example, the electronic device 1200 may be a server. Figure 12 The electronic device 1200 includes a processing component 1220, which further includes one or more processors, and a memory resource represented by a memory 1222 for storing instructions executable by the processing component 1220, such as an application. The application stored in the memory 1222 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1220 is configured to execute the instructions to perform the above method.
[0230] The electronic device 1200 may further include a power supply component 1224 configured to perform power management of the electronic device 1200, a wired or wireless network interface 1226 configured to connect the electronic device 1200 to a network, and an input / output (I / O) interface 1228. The electronic device 1200 may operate based on an operating system stored in the memory 1222, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, or the like.
[0231] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 1222 including instructions, and the instructions can be executed by a processor of the electronic device 1200 to perform the above method. The storage medium can be a computer-readable storage medium, for example, a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0232] In an exemplary embodiment, a computer program product is further provided. The computer program product includes instructions, and the instructions can be executed by a processor of the electronic device 1200 to implement the above method.
[0233] It should be noted that the above-mentioned devices, electronic devices, computer-readable storage media, computer program products, etc. can also include other implementation methods according to the description of the method embodiments. The specific implementation methods can refer to the description of the relevant method embodiments and will not be described one by one here.
[0234] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the claims.
[0235] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A text retrieval method, characterized in that: include: Get the first text to be retrieved; The first text is input into the recall model, and the feature vector corresponding to the first text is output; wherein the recall model is obtained by training the initial semantic model and the initial graph model based on the sample first text and the sample second text; wherein the sample first text and the sample second text are annotated with an association relationship; wherein, based on the sample first text and the sample second text, the initial semantic model and the initial graph model are trained, including: obtaining a sample set; wherein the sample set includes the sample first text and the sample second text; inputting the sample first text into the initial semantic model, outputting a first semantic feature, and inputting the sample second text into the initial semantic model, outputting a second semantic feature; generating a feature map based on the first semantic feature and the second semantic feature; inputting the first semantic feature and the feature map into the initial graph model, outputting a first graph embedding feature, and finally generating a feature map based on the first semantic feature and the second semantic feature. and inputting the second semantic feature and the feature graph into the initial graph model, outputting the second graph embedding feature; constructing a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature and the association relationship, and iteratively adjusting the initial semantic model and the initial graph model based on the loss function to obtain a recall model; wherein, generating a feature graph based on the first semantic feature and the second semantic feature includes: obtaining a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature; constructing a feature graph with the first semantic feature and the second semantic feature as nodes, and the first similarity, the second similarity and the third similarity as edges; A target feature vector whose similarity with the feature vector satisfies a preset condition is determined from the feature vector data set, and a retrieval result is determined to be a second text corresponding to the target feature vector.
2. The method according to claim 1, characterized in that The recall model includes a semantic model, constructing a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature, and the association relationship, and iteratively adjusting the initial semantic model and the initial graph model based on the loss function to obtain the recall model, including: Determining a first loss function based on the first semantic feature, the second semantic feature, and the association relationship; determining a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship; Performing a weighted summation on the first loss function and the second loss function to obtain a joint loss function; Based on the joint loss function, the initial semantic model and the initial graphical model are iteratively adjusted to obtain a semantic model and a graphical model.
3. The method according to claim 2, characterized in that Inputting the sample first text and the sample second text into the initial semantic model respectively, and outputting a first semantic feature and a second semantic feature, including: Extracting a preset number of sample first texts and sample second texts in batches from the sample set; Inputting the first sample text and the second sample text of each batch into the initial semantic model respectively, and outputting the first semantic feature and the second semantic feature corresponding to the batch; Generating a feature map according to the first semantic feature and the second semantic feature includes: A sub-feature map is generated according to the first semantic feature and the second semantic feature corresponding to the batch.
4. The method according to claim 1, wherein The step of inputting the first semantic feature and the feature graph into an initial graph model and outputting a first graph embedding feature includes: Extracting the first semantic feature and a neighborhood semantic feature within a preset range from the feature graph using the initial graph model to obtain a first graph embedding feature; The step of inputting the second semantic feature and the feature graph into the initial graph model and outputting a second graph embedding feature includes: The initial graph model is used to perform feature extraction on the second semantic feature and neighborhood semantic features within a preset range in the feature graph to obtain a second graph embedding feature.
5. The method according to claim 4, characterized in that Using the initial graph model to extract features from the first semantic feature and neighborhood semantic features within a preset range to obtain a first graph embedding feature, including: Using the initial graph model, feature extraction is performed on the first semantic feature and neighborhood semantic features within a preset range to obtain a plurality of intermediate first graph embedding features; A weighted sum is performed on the plurality of intermediate first graph embedding features to obtain a first graph embedding feature.
6. A text retrieval device, characterized in that: include: A first acquisition module, configured to acquire a first text to be retrieved; a first generation module, configured to input the first text into a recall model and output a feature vector corresponding to the first text; wherein the recall model is obtained by training an initial semantic model and an initial graph model based on a sample first text and a sample second text; wherein an association relationship is annotated between the sample first text and the sample second text; A recall module is used to determine a target feature vector from the feature vector data set whose similarity with the feature vector meets a preset condition, and determine that the retrieval result is a second text corresponding to the target feature vector; A second acquisition module is configured to acquire a sample set, wherein the sample set includes a first sample text and a second sample text; a first input module, configured to first input the first sample text into an initial semantic model and output a first semantic feature, and input the second sample text into the initial semantic model and output a second semantic feature; a second generation module for generating a feature graph based on the first semantic feature and the second semantic feature; the second generation module comprising: a first acquisition submodule for acquiring a first similarity between every two first semantic features in a plurality of first semantic features, a second similarity between every two second semantic features in a plurality of second semantic features, and a third similarity between the first semantic feature and the second semantic feature; and a second generation submodule for constructing a feature graph using the first semantic feature and the second semantic feature as nodes and the first similarity, the second similarity, and the third similarity as edges, respectively. a second input module, configured to input the first semantic feature and the feature map into an initial graph model and output a first graph embedding feature, and to input the second semantic feature and the feature map into the initial graph model and output a second graph embedding feature; An adjustment module is used to construct a loss function based on the first semantic feature, the second semantic feature, the first graph embedding feature, the second graph embedding feature and the association relationship, and iteratively adjust the initial semantic model and the initial graph model based on the loss function to obtain a recall model.
7. The device according to claim 6, characterized in that The adjustment module includes: A first determining submodule, configured to determine a first loss function based on the first semantic feature, the second semantic feature, and the association relationship; A second determining submodule, configured to determine a second loss function based on the first graph embedding feature, the second graph embedding feature, and the association relationship; a calculation submodule, configured to perform a weighted summation of the first loss function and the second loss function to obtain a joint loss function; The adjustment submodule is used to iteratively adjust the initial semantic model and the initial graphical model based on the joint loss function to obtain a semantic model and a graphical model.
8. The device according to claim 6, characterized in that The first input module includes: a sampling submodule, configured to extract a preset number of sample first texts and sample second texts from the sample set in batches; An input submodule, configured to input the first sample text and the second sample text of each batch into the initial semantic model, and output the first semantic feature and the second semantic feature corresponding to the batch; The second generation module includes: The first generating submodule is configured to generate a sub-feature map according to the first semantic feature and the second semantic feature corresponding to the batch.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the text retrieval method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the text retrieval method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Training and retrieval method and device of recall model and electronic equipment
CN116010681A
Pivoting from a graph of semantic similarity of documents to a derivative graph of relationships between entities mentioned in the documents
US9710544B1