Hash code generation model training method and hash code generation method

CN122654232APending Publication Date: 2026-08-28INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611153359.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-08-28

AI Technical Summary

Technical Problem

[0004]本申请提供了哈希编码生成模型训练方法及哈希编码生成方法,以至少解决相关技术中哈希函数使用简单测度衡量向量相似性的方式无法有效衡量文本向量的语义信息,导致无法有效区分相似向量,降低检索性能的问题

Benefits of technology

[0010]This application describes a process involving: acquiring a text dataset comprising multiple text data samples, each sample including a text data item and its corresponding category descriptor; sampling a batch of data from the text dataset, the batch including multiple categories of text data samples, with at least one sample from each category; inputting the target text data from the samples in the batch into an initial hash encoding generation model to obtain a feature projection vector corresponding to the target text data, the length of which is the same as the hash encoding length; determining the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value based on the feature projection vector; determining the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value; updating the model parameters of the initial hash encoding generation model based on the total loss value; and returning to the step of sampling a batch of data from the text dataset until the model converges, thus obtaining the target hash encoding generation model. By constraining the model's generation of feature projection vectors and hash codes based on contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss, the trained target hash code generation model can generate binary hash codes with strong semantic relevance, high discriminative power, and sufficient space utilization. Therefore, it can solve the technical problem in related technologies that cannot effectively measure the semantic information of text vectors, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance. This achieves the technical effect of effectively measuring the semantic information of text, accurately distinguishing similar vectors, and improving retrieval performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122654232A_ABST
    Figure CN122654232A_ABST
Patent Text Reader

Abstract

The application discloses a hash code generation model training method and a hash code generation method, relates to the technical field of artificial intelligence, and comprises the following steps: sampling a batch of data from a text data set; inputting target text data in a text data sample in the batch of data into an initial hash code generation model to obtain a feature projection vector corresponding to the target text data, so as to determine a contrast loss value, an optimal transport distance margin loss value and a uniform distribution regularization loss value, and then determine a total loss value; based on the total loss value, updating model parameters of the initial hash code generation model, returning to the step of sampling a batch of data from the text data set until the model converges, and obtaining a target hash code generation model. The technical problem that a hash function in the related art cannot effectively distinguish similar vectors is solved, and the technical effect of effectively distinguishing similar vectors is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method for training a hash encoding generation model and a method for generating hash codes. Background Technology

[0002] With the rapid development of artificial intelligence technology, data such as text, images, and videos are processed by models and transformed into fixed-length vectors stored in vector databases for rapid retrieval. Vector hashing technology is the core of vector databases for achieving fast vector similarity calculation. It uses a hash function to map input vectors into a hash code and store it in corresponding buckets. The hash function ensures that similar vectors should be stored in the same bucket as much as possible for easy retrieval. Related technologies use simple measures such as cosine similarity, Euclidean distance, or Hamming distance to measure vector similarity.

[0003] This simple measure has a speed advantage when processing vector data, but it cannot effectively measure the semantic information of text vectors, resulting in an inability to effectively distinguish similar vectors and reducing retrieval performance. Summary of the Invention

[0004] This application provides a method for training a hash encoding generation model and a method for generating hash encoding, in order to at least solve the problem in related technologies that the use of simple measures to measure vector similarity in hash functions cannot effectively measure the semantic information of text vectors, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance.

[0005] This application provides a method for training a hash-encoding generation model, including: Obtain a text data set, which includes multiple text data samples. Each text data sample includes a text data and its corresponding category descriptor. Sample a batch of text data from a text dataset. The batch of text data includes text data samples from multiple categories, with at least one text data sample from each category. Input the target text data from the text data samples in this batch of data into the initial hash encoding generation model to obtain the feature projection vector corresponding to the target text data. The length of the feature projection vector is the same as the hash encoding length. Based on the feature projection vector corresponding to the target text data, determine the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value; The total loss value is determined based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value. Based on the total loss value, the model parameters of the initial hash coding generation model are updated, and the step of sampling a batch of data from the text dataset is returned until the model converges, thus obtaining the target hash coding generation model.

[0006] This application also provides a hash code generation method, including: Obtain the text data to be encoded; Input the text data to be encoded into the target hash encoding generation model to obtain the target hash encoding corresponding to the text data to be encoded. The target hash code generation model is the target hash code generation model trained using any of the above hash code generation model training methods.

[0007] This application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of any of the above-described hash code generation model training methods or the steps of any of the above-described hash code generation methods.

[0008] This application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of any of the above-described hash encoding generation model training methods or the steps of any of the above-described hash encoding generation methods.

[0009] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described hash encoding generation model training methods or the steps of any of the above-described hash encoding generation methods.

[0010] This application describes a process involving: acquiring a text dataset comprising multiple text data samples, each sample including a text data item and its corresponding category descriptor; sampling a batch of data from the text dataset, the batch including multiple categories of text data samples, with at least one sample from each category; inputting the target text data from the samples in the batch into an initial hash encoding generation model to obtain a feature projection vector corresponding to the target text data, the length of which is the same as the hash encoding length; determining the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value based on the feature projection vector; determining the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value; updating the model parameters of the initial hash encoding generation model based on the total loss value; and returning to the step of sampling a batch of data from the text dataset until the model converges, thus obtaining the target hash encoding generation model. By constraining the model's generation of feature projection vectors and hash codes based on contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss, the trained target hash code generation model can generate binary hash codes with strong semantic relevance, high discriminative power, and sufficient space utilization. Therefore, it can solve the technical problem in related technologies that cannot effectively measure the semantic information of text vectors, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance. This achieves the technical effect of effectively measuring the semantic information of text, accurately distinguishing similar vectors, and improving retrieval performance. Attached Figure Description

[0011] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application; Figure 2 A flowchart illustrating a hash-encoding generation model training method provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of the feature projection network provided in the embodiments of this application; Figure 4 A flowchart illustrating another hash encoding generation model training method provided in this application embodiment; Figure 5 A flowchart illustrating another hash-encoding generation model training method provided in this application embodiment; Figure 6A flowchart illustrating a hash code generation method provided in this application embodiment; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0014] It should be noted that, in the description of this application, 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. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0015] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0016] With the rapid development of artificial intelligence (AI) technology, AI models are increasingly used to process user-input text, images, and videos. After processing this data, the models often represent it as fixed-length vectors and store them in vector databases for rapid retrieval and querying. As a fundamental function of vector databases, how to quickly and accurately retrieve similar vectors from massive amounts of vector data has become a key issue in the application, design, and development of vector databases. Currently, vector hashing technology is the core of vector databases for achieving fast vector similarity calculation. It maps input vectors to a hash code using a hash function, then allocates them to corresponding buckets for storage. The hash function ensures that similar vectors should be stored in the same bucket as much as possible for easy retrieval.

[0017] The fundamental idea behind vector hashing is the complete opposite of that of cryptographic hash functions, which ensure data integrity. Traditional hashing requires that any tiny change in the input should lead to a drastic change in the output hash value, while vector hashing aims for "similar inputs to produce similar or identical hash values ​​with a higher probability." This characteristic allows it to transform the nearest neighbor search problem in high-dimensional space into an exact matching problem in low-dimensional space, thereby achieving an exponential improvement in retrieval efficiency.

[0018] Locality-Sensitive Hashing (LSH) is a typical example of vector hashing. Its working principle is based on a carefully designed probabilistic framework: for a specific distance metric (such as Euclidean distance or cosine similarity), there exists a family of hash functions that guarantees that two vectors that are close in space are more likely to be mapped to the same "hash bucket" than vectors that are far apart. Specifically, this technique maps high-dimensional vectors to discrete hash signatures or hash values ​​by designing random projections or random partitioning functions. For example, for cosine similarity, the random hyperplane method is commonly used, generating a bit by calculating the positional relationship (same side or opposite side) of the vector with the random hyperplane; multiple such bits constitute a hash signature. For Euclidean distance, random projection based on a p-stable distribution is often used, combined with uniform offset and quantization (rounding) operations to distribute the projected continuous values ​​into specific integer buckets.

[0019] To balance retrieval precision and efficiency, Locality Sensitive Hashing (LSH) typically employs a two-stage amplification structure. First, there's the AND operation, which requires two vectors to produce the same result under multiple independent hash functions before being considered a candidate pair. This significantly enhances the stringency of the selection process, effectively reducing the false positive rate of dissimilar vectors being mistakenly identified as candidates. Second, there's the OR operation, which establishes multiple independent hash tables. If a vector is identified as a candidate in any of these tables, it proceeds to the next round of selection. This greatly increases the probability of finding all true nearest neighbors, ensuring the system's recall rate.

[0020] In practical applications, the system pre-builds locality-sensitive hash indexes for vectors in all databases, distributing them across corresponding buckets in multiple hash tables. When a new query vector arrives, the system first calculates its hash signature, then quickly locates the buckets it might belong to in each hash table, and extracts all vectors from these buckets as candidate sets.

[0021] Deep learning-based hashing algorithms are a type of vector hashing technique, a data-driven hashing method. They utilize neural networks (such as deep belief networks, autoencoders, and convolutional neural networks) as learners of the hash function. By optimizing an objective function related to a specific similarity metric (such as cosine similarity, Hamming distance, or Jaccard coefficient), they learn a non-linear mapping from raw data (such as images or text) to low-dimensional binary hash codes. The ultimate training goal is to ensure that similar data points in Hamming space have similar hash codes, while dissimilar data points have significantly different hash codes. A typical deep learning-based hashing algorithm requires the following components: 1. A neural network model to map input data to equal-length vectors before hash encoding; 2. A hash encoding function that maps the aforementioned vectors to integer hash codes according to certain rules; 3. A model objective function that constrains model training by calculating the similarity or distance between vectors using predefined model assumptions and metrics; 4. Model training, which optimizes the model using backpropagation and gradient descent algorithms.

[0022] Locality-Sensitive Hashing (LSH) and its variants are data-agnostic hashing methods. They rely on random projection to approximate Euclidean distance or cosine similarity, but fail to learn the inherent semantic structure of the data. For high-dimensional sparse semantic data such as text, the hash codes generated by LSH have weak semantic relevance, leading to a severe "semantic gap"—samples with similar distances in the feature space may have drastically different semantics, resulting in a natural upper limit to retrieval accuracy.

[0023] Deep learning-based hashing algorithms learn hash functions related to data through neural networks, partially bridging the semantic gap. However, their commonly used loss functions (such as pairwise similarity loss and triplet loss) are mostly based on Euclidean distance or cosine similarity to constrain sample relationships. These measures are often suboptimal and superficial in complex semantic spaces (such as the implied intentions and emotions in multi-turn dialogues), failing to accurately characterize the deep probability distribution differences between samples, resulting in insufficient ability of the model to distinguish difficult samples (semantically ambiguous, boundary cases).

[0024] As can be seen, hash functions in related technologies use simple measures such as cosine similarity, Euclidean distance, or Hamming distance to measure vector similarity.

[0025] This simple measure has a speed advantage when processing vector data, but it cannot effectively measure the semantic information of text vectors, resulting in an inability to effectively distinguish similar vectors and reducing retrieval performance.

[0026] Meanwhile, real-world data generally exhibits a long-tail distribution: a few head categories occupy a large number of samples, while most tail categories have scarce samples. Hash functions in related technologies are easily dominated by head categories during training, leading to insufficient learning of the feature representations of tail category samples, resulting in feature collapse. This, in turn, causes uneven distribution of hash code space, ultimately causing a sharp decline in retrieval performance. Furthermore, traditional hashing techniques employ a two-stage paradigm of "feature learning first, quantization later," where the quantization process and feature learning stage are disconnected and fail to achieve synergistic optimization. This results in significant loss of quantization information when mapping continuous feature vectors to discrete hash codes, further limiting the improvement of retrieval accuracy.

[0027] To address the aforementioned technical problems, this application provides a hash encoding generation model training method and a hash encoding generation method. The hash encoding generation model training method includes: acquiring a text data set, which includes multiple text data samples, each text data sample including a single text data and its corresponding category descriptor; sampling a batch of data from the text data set, the batch including multiple categories of text data samples, with at least one text data sample in each category; inputting the target text data from the text data samples in the batch into an initial hash encoding generation model to obtain a feature projection vector corresponding to the target text data, the length of which is the same as the hash encoding length; determining a contrast loss value, an optimal transmission distance edge loss value, and a uniform distribution regularization loss value based on the feature projection vector corresponding to the target text data; determining a total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value; updating the model parameters of the initial hash encoding generation model based on the total loss value, and returning to the step of sampling a batch of data from the text data set until the model converges, thus obtaining the target hash encoding generation model. The method provided by the above scheme constrains the process of generating feature projection vectors and hash codes by using contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss. This enables the trained target hash code generation model to generate binary hash codes with strong semantic relevance, high discriminative power, and sufficient space utilization. Therefore, it can solve the technical problem in related technologies that cannot effectively measure the semantic information of text vectors, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance. The method achieves the technical effect of effectively measuring the semantic information of text, accurately distinguishing similar vectors, and improving retrieval performance.

[0028] The specific application environment architecture or specific hardware architecture on which the hash encoding generation model training method depends is described here.

[0029] The hash encoding generation model training method provided in this application embodiment is used to train a target hash encoding generation model. For example... Figure 1 The diagram shows the structure of the computing device upon which this application is based. The computing device can be a server. The computing device includes a solid-state drive (SSD), memory, and a graphics processing unit (GPU). The SSD stores a text data set, which includes multiple text data samples. Each text data sample includes a single text data item and its corresponding category descriptor. The GPU runs an initial hash encoding generation model. During training of the initial hash encoding generation model, the text data set from the SSD is loaded into memory via Direct Memory Access (DMA). The memory samples a batch of data from the text data set according to a preset rule and sends the sampled batch of data to the GPU. The preset rule is that a sampled batch of data includes text data samples from multiple categories, with at least one text data sample from each category. The graphics processor inputs the target text data from the text data samples in the batch of data into the initial hash coding generation model to obtain the feature projection vector corresponding to the target text data. The length of the feature projection vector is the same as the hash coding length. Based on the feature projection vector corresponding to the target text data, the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value are determined. Based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value, the total loss value is determined. Based on the total loss value, the model parameters of the initial hash coding generation model are updated, and batch data is continued to be retrieved from memory until the model converges, thus obtaining the target hash coding generation model.

[0030] The model parameters of the target hash encoding generation model are saved to a solid-state drive (SSD). When the target hash encoding generation model is needed to encode the text data to be encoded, the model parameters from the SSD are loaded into memory, the model class is initialized, and then the model instance is transferred to the GPU to run the target hash encoding generation model on the GPU. The model receives the text data to be encoded from the user, inputs the text data to be encoded into the target hash encoding generation model, and obtains the target hash code corresponding to the text data to be encoded.

[0031] Embodiments of this application provide a hash encoding generation model training method, applied to the aforementioned computing device. Figure 2 The flowchart of the hash encoding generation model training method provided in the embodiments of this application is as follows: Figure 2 As shown, the training method for this hash encoding generation model includes the following steps: Step S201: Obtain a text data set, which includes multiple text data samples. Each text data sample includes a text data and its corresponding category descriptor.

[0032] Text Data Set ,in, For the i-th text data sample, For the first A text data, This is the category descriptor corresponding to the i-th text data, used to represent the category of the i-th text data.

[0033] The text data samples in the text dataset can be from the financial sector, the healthcare sector, or the e-commerce sector. In the case of financial text data samples, the categories could include market reports, research report summaries, financial announcements, financial news, regulatory documents, etc. In the case of healthcare text data samples, the categories could include electronic medical records, online consultation dialogues, medical literature, drug instructions, etc. In the case of e-commerce text data samples, the categories could include product titles, user reviews, customer service dialogues, etc.

[0034] Step S202: Sample a batch of data from the text data set. The batch of data includes text data samples of multiple categories, with at least one text data sample in each category.

[0035] It is understandable that the category of the text data sample is consistent with the category of the text data it includes.

[0036] Specifically, a batch of data is randomly sampled from the text dataset. The target number of categories are sampled evenly from the categories included in the text dataset, meaning each category has an equal probability of being sampled. For each sampled category, at least one text data sample is randomly sampled from the corresponding text data samples. The text data samples corresponding to each sampled category are determined as the batch of data. This combination of balanced category sampling and random instance sampling ensures that each batch of data contains a sufficient number of tail category samples, preventing the training process from being dominated by the head categories, preventing the feature representation collapse of tail category samples, and ensuring a uniform distribution of the hash code space across different categories.

[0037] Step S203: Input the target text data from the text data samples in the batch of data into the initial hash encoding generation model to obtain the feature projection vector corresponding to the target text data. The length of the feature projection vector is the same as the hash encoding length.

[0038] The initial hash encoding generation model comprises a semantic extraction network, a feature projection network, and a hash encoding network. The semantic extraction network encodes the target text data into semantic feature vectors, i.e., it encodes the input text into dense semantic feature vectors, which are then input into the feature projection network. The feature projection network projects the semantic feature vectors into feature projection vectors of the same length as the hash encoding vectors; that is, it projects the semantic feature vectors to feature projection vectors of the predefined hash encoding length, and then inputs these feature projection vectors into the hash encoding network. The hash encoding network performs hash encoding on the feature projection vectors, generating the hash encoding, i.e., the binary hash encoding, corresponding to the target text data.

[0039] Semantic extraction networks, or text encoding models, can be pre-trained embedding models, such as BERT and RoBERTa, which employ bidirectional attention mechanisms. These models naturally have good adaptability to tasks like natural language understanding and feature extraction because they generate text vectors using bidirectional attention. The state vector corresponding to the classification label [CLS] position in the output of the last layer of the semantic extraction network is used as the semantic feature vector of the input text. ,in, Let represent an h-dimensional real space, where h is the dimension of the semantic feature vector.

[0040] Figure 3 This is a schematic diagram of the structure of the feature projection network provided in the embodiments of this application, such as... Figure 3As shown, the feature projection network is a two-layer perceptron network, including a first fully connected layer (Linear(h, 2h)), a one-dimensional batch normalization layer (BatchNorm1d), a non-linear activation function (ReLU), a second fully connected layer (Linear(2h, m)), and a hyperbolic tangent activation function (Tanh). The first fully connected layer, with an input dimension of h and an output dimension of 2h, first increases the dimensionality of the original semantic feature vector, expanding its expressive power and providing more information for subsequent non-linear transformations. The one-dimensional batch normalization layer normalizes the output of the first fully connected layer, making the feature distribution of each batch of data more stable. This accelerates model convergence and avoids training instability caused by drastic changes in the input distribution of subsequent layers. The non-linear activation function sets elements less than 0 in the input to 0 and retains elements greater than 0. Introducing non-linear transformations allows the network to learn more complex semantic feature mapping relationships, preventing the model from degenerating into a simple linear model. The second fully connected layer has an input dimension of 2h and an output dimension of m, where m is the hash code length of the target vector database. Its function is to compress the features, which have undergone upsizing and nonlinear transformation, to a dimension consistent with the hash code length, thus completing the core task of feature projection. The hyperbolic tangent activation function has an output range between (-1, 1), constraining the final projection result to the (-1, 1) interval. This allows for a more stable distinction between positive and negative boundaries when generating 0 / 1 hash codes using the sign function, reducing the loss of quantization information.

[0041] This can be understood as the feature projection network output vector being... ,in, This represents the value of the k-th dimension in the feature projection vector.

[0042] The hash coding network generates the hash code corresponding to the target text data based on the following formula:

[0043] in, This is the hash code corresponding to the target text data in the i-th text data sample of this batch of data. The `Sign` function is used to apply the sign function to the values ​​of multiple dimensions of the feature projection vector corresponding to the target text data in the i-th text data sample of this batch of data, resulting in binary values. Here, `B` indicates that the hash encoding is binary. It should be noted that for any dimension value, if the value is greater than 0, the corresponding hash code bit after applying `Sign` is the first value; if the value is not greater than 0, the corresponding hash code bit after applying `Sign` is the second value. The first and second values ​​can be 1 and 0, or +1 and -1, respectively; there are no specific restrictions. Since the values ​​of each dimension of the feature projection vector are constrained by the hyperbolic tangent activation function within the interval (-1, 1) and are symmetrically distributed about zero, the quantization error is minimized when the sign function performs binarization with zero as the quantization boundary. This achieves a synergistic connection between feature learning and quantization encoding, reducing the loss of quantization information when mapping continuous features to discrete hash codes.

[0044] Step S204: Based on the feature projection vector corresponding to the target text data, determine the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value.

[0045] The contrast loss term ensures that feature projection vectors corresponding to target text data of the same category have similarity measures, while feature projection vectors corresponding to target text data of different categories have different similarity measures. The contrast loss term is used to generate the contrast loss value. This term pulls positive sample pairs closer and pushes negative sample pairs further away in the high-dimensional hyperspherical space, learning semantic features with discriminative power.

[0046] Minimizing the optimal transmission distance edge loss term results in a more compact and consistent distribution of feature projection vectors for target text data of the same category in the feature space. Unlike the contrast loss term, the optimal transmission distance edge loss term operates at the category distribution level, making it more robust to noisy samples and long-tailed categories. It shapes the overall geometry of the feature space, preventing overlap between different category distribution regions. The optimal transmission distance edge loss term is used to generate the optimal transmission distance edge loss value.

[0047] The uniform distribution regularization loss term is used to generate the uniform distribution regularization loss value. This term forces that each bit of the hash code has a probability of activation close to 50% across the entire batch of data. This is key to generating high-quality hash codes, namely, maximizing the information content of each bit of the hash code and avoiding some bits from being always invalid, thereby improving the space utilization of the hash code.

[0048] Step S205: Determine the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value.

[0049] Step S206: Based on the total loss value, update the model parameters of the initial hash coding generation model, return to the step of sampling a batch of data from the text data set, until the model converges and the target hash coding generation model is obtained.

[0050] Understandably, based on the total loss value, the model parameters of the initial hash-encoded model are updated using either the gradient descent algorithm or the Adaptive Moment Estimation (Adam) method.

[0051] The hash coding generation model training method provided in this application constrains the process of generating feature projection vectors and hash codes based on contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss. This enables the trained target hash coding generation model to generate binary hash codes with strong semantic relevance, high discriminative power, and sufficient space utilization. Therefore, it can solve the technical problem in related technologies where the semantic information of text vectors cannot be effectively measured, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance. This method achieves the technical effect of effectively measuring the semantic information of text, accurately distinguishing similar vectors, and improving retrieval performance.

[0052] Training batches are constructed using a combination of class-balanced sampling and instance random sampling to ensure that each batch contains a sufficient number of tail class samples.

[0053] Embodiments of this application provide a hash encoding generation model training method, applied to the aforementioned computing device. Figure 4 The flowchart of the hash encoding generation model training method provided in the embodiments of this application is as follows: Figure 4 As shown, the training method for this hash encoding generation model includes the following steps: Step S401: Obtain a text data set. The text data set includes multiple text data samples. Each text data sample includes a text data item and its corresponding category descriptor. For details, please refer to [link to relevant documentation]. Figure 2 Step S201 of the illustrated embodiment will not be described again here.

[0054] Step S402: Sample a batch of data from the text dataset. The batch of data includes text data samples from multiple categories, with at least one sample from each category. See details below. Figure 2 Step S202 of the illustrated embodiment will not be described again here.

[0055] Step S403: Input the target text data from the text data samples in this batch of data into the initial hash encoding generation model to obtain the feature projection vector corresponding to the target text data. The length of the feature projection vector is the same as the hash encoding length. For details, please refer to [link to relevant documentation]. Figure 2Step S203 of the illustrated embodiment will not be described again here.

[0056] Step S404: Based on the feature projection vector corresponding to the target text data, determine the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value.

[0057] Specifically, step S404 includes: Step S4041: Determine the contrast loss value based on the sample size of the text data samples included in the batch of data and the feature projection vector corresponding to the target text data.

[0058] Step S4042: Based on the total number of categories of text data samples included in the batch of data and the feature projection vector corresponding to the target text data, determine the optimal transmission distance edge loss value.

[0059] Step S4043: Based on the feature projection vector corresponding to the target text data, determine the activation value of each dimension in the feature projection vector.

[0060] Step S4044: Determine the uniform distribution regularization loss value based on the activation value of each dimension in the feature projection vector and the sample size of the text data samples included in the batch of data.

[0061] Step S405: Determine the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value. For details, please refer to [link to details]. Figure 2 Step S205 of the illustrated embodiment will not be described again here.

[0062] Step S406: Based on the total loss value, update the model parameters of the initial hash encoding generation model, and return to the step of sampling a batch of data from the text dataset until the model converges, obtaining the target hash encoding generation model. For details, please refer to [link to details]. Figure 2 Step S206 of the illustrated embodiment will not be described again here.

[0063] The hash coding generation model training method provided in this application calculates the contrast loss value by combining the "batch sample size" and the "feature projection vector," which can accurately quantify the semantic similarity difference between the same category (positive samples) and different categories (negative samples). This avoids the influence of single sample bias and ensures that "vectors of the same category are brought closer and vectors of different categories are pushed further apart" through batch-level statistics, allowing the generated hash codes to accurately reflect the deep semantic relationships of the text. The optimal transmission distance edge loss value is calculated based on the "total number of categories in the batch" and the "feature projection vector," which can force "compact distribution of samples of the same category and separation of samples of different categories" at the category distribution level. Even if the tail category has a small sample size, its features can be prevented from being "swallowed" by the head category through the "distribution constraint associated with the total number of categories." Because the loss calculation is based on the overall category distribution rather than a single sample, it can reduce the interference of noise on the loss, ensure a uniform spatial distribution of hash codes for different categories, and improve retrieval stability. By calculating the uniform distribution regularization loss value using "activation values ​​of each dimension of the feature projection vector + batch sample size", the activation probability of each bit in the hash code can be forced to be close to 50%, avoiding some bits from being always invalid (such as all 0s or all 1s), and significantly improving the space utilization of the hash code. This ensures that each bit of the hash code contains the maximum amount of information, reduces redundant encoding, and allows vector database retrieval to quickly match similar text with fewer hash bits, balancing retrieval accuracy and efficiency.

[0064] In some optional implementations, step S4041 above includes: Step a1: Determine the contrast loss value based on the first formula, which is:

[0065] in, This represents the contrast loss value. This refers to the sample size of the text data included in this batch of data. This is the feature projection vector corresponding to the target text data in the i-th text data sample of this batch of data; The set of positive samples. For positive sample feature projection vectors, The negative sample feature projection vector. The set of negative samples. For temperature hyperparameters, This is a similarity measurement function.

[0066] Positive samples are text data samples in this batch of data that belong to the same category as the i-th text data sample, excluding the i-th text data sample. The category of the positive sample is the same as the category of the text data within it. Negative samples are text data samples in this batch of data that belong to a different category than the i-th text data sample. The feature projection vector of a positive sample is the feature projection vector corresponding to the target text data in the positive sample, and the feature projection vector of a negative sample is the feature projection vector corresponding to the target text data in the negative sample.

[0067] It should be noted that the similarity metric function in this embodiment is the cosine similarity function. The temperature hyperparameter is a temperature coefficient used to scale the smoothness of the similarity distribution in the calculation of the contrast loss value. It is determined by technicians based on experiments and generally takes a value in the range of (0, 1). The smaller the temperature hyperparameter, the stronger the amplification effect of the exponential operation on similarity differences, and the higher the discrimination of the contrast loss value for difficult negative samples; the larger the temperature hyperparameter, the less sensitive the loss is to differences in similarity between samples.

[0068] Understandably, this involves calculating the cosine similarity between the feature projection vector of the target text data in the i-th text data sample of this batch and the feature projection vector of each positive sample. It also involves calculating the cosine similarity between the feature projection vector of the target text data in the i-th text data sample of this batch and the feature projection vector of each negative sample.

[0069] The hash encoding generation model training method provided in this application embodiment can accurately quantify the semantic similarity difference between the same category (positive samples) and different categories (negative samples) - avoiding the influence of single sample bias, and ensuring "same category vectors are brought closer and different category vectors are pushed further apart" through batch-level statistics, so that the generated hash encoding can accurately reflect the deep semantic relationship of the text.

[0070] In some optional implementations, step S4042 above includes: Step b1: Based on the feature projection vectors corresponding to the target text data, determine the slice Wasserstein distance between the feature projection vectors corresponding to the same category of target text data and the slice Wasserstein distance between the feature projection vectors corresponding to different categories of target text data.

[0071] Sliced ​​Wasserstein Distance (SWD) is a metric for measuring the overall difference between two probability distributions. It is a simplified computational version of the Wasserstein Distance, and an efficient, differentiable approximation that can be computed in parallel using GPUs or NPUs. Essentially, the Wasserstein Distance represents the minimum 'cost' required to transform one distribution into another (e.g., the minimum effort required to push a pile of sand into another pile), and it more robustly measures distribution differences (insensitive to noise and outliers).

[0072] However, calculating the Wasserstein distance in high-dimensional space is complex. SWD simplifies this by "dimensionality reduction slicing": randomly projecting the high-dimensional distribution onto multiple one-dimensional directions, calculating the Wasserstein distance for each one-dimensional projection, and then taking the average value—this preserves the robustness of the Wasserstein distance while reducing computational complexity.

[0073] It should be noted that the specific solution method for SWD is implemented using a common numerical approximation iterative algorithm, which will not be elaborated here.

[0074] Step b2: Based on the total number of categories of text data samples included in the batch of data, the slice Wasserstein distance between the feature projection vectors corresponding to the same category of target text data, and the slice Wasserstein distance between the feature projection vectors corresponding to different categories of target text data, determine the optimal transmission distance edge loss value.

[0075] In some alternative implementations, step b2 above includes: Step b21: Based on the second formula, determine the optimal transmission distance edge loss value. The second formula is:

[0076] in, The optimal transmission distance edge loss value, This represents the total number of categories in the text data samples included in this batch of data; The slice Wasserstein distance between the feature projection vectors of the two disjoint subsets after randomly dividing the target text data of category c into two disjoint subsets; This is the current threshold for the distribution distance between different categories; Let be the slice Wasserstein distance between the feature projection vector of target text data of category c and the feature projection vector of target text data of category k; the set of categories of the text data samples included in this batch of data is . . The feature distribution of the feature projection vector corresponding to the target text data of category c. The feature distribution of the feature projection vector corresponding to the target text data of category k. The feature distribution of the feature projection vectors corresponding to the target text data in one subset of the two disjoint subsets mentioned above; Let be the feature distribution of the feature projection vectors corresponding to the target text data in the other subset of the two disjoint subsets mentioned above. It can be understood that the feature projection vectors corresponding to the two disjoint subsets are the feature projection vectors corresponding to the target text data in the two disjoint subsets.

[0077] The term is an edge loss, which is applied when the slice Wasserstein distance between the feature projection vectors corresponding to two different categories of target text data is less than a preset threshold. When this happens, a penalty is imposed, which explicitly drives the feature distributions of the feature projection vectors corresponding to different categories of target text data to move away from each other and maintain a safe interval of at least one margin.

[0078] The margin parameter in OTM can be set according to the experiment, or it can be set to be learnable, or it can grow linearly from a small value with the number of training rounds, so that the distribution separation task is made easier and more difficult.

[0079] The current distribution distance threshold between different categories can be determined based on the initial distribution distance threshold between different categories, the target distribution distance threshold between different categories, the current training round number, and the maximum training round number.

[0080] Specifically, based on the third formula, the distribution distance threshold between different categories is determined. The third formula is:

[0081] in, This is the current distribution distance threshold between different categories. This serves as the initial threshold for the distribution distance between different categories. The threshold for the distribution distance between different categories of the target. This is the current training round number. This represents the maximum number of training rounds.

[0082] The initial distribution distance threshold between different categories, the target distribution distance threshold between different categories, and the maximum number of training rounds are set in advance by technicians.

[0083] By setting It grows linearly with the number of training epochs until the target is reached. This avoids excessive edge constraints in the early stages of training, which could lead to unstable optimization.

[0084] The hash coding generation model training method provided in this application proposes an optimal transmission distance edge loss term oriented towards category distribution. In the original feature space, a distribution estimate based on batch samples is constructed for each category, and a loss function containing two terms is designed: the first term minimizes the SWD between sample distributions within the same category to promote intra-class aggregation; the second term forces the SWD between different categories to be greater than a preset distribution distance threshold between different categories to promote inter-class separation. This loss directly optimizes the feature space geometry at the distribution level.

[0085] The hash coding generation model training method provided in this application introduces the optimal transmission distance calculation to calculate the distance between the projection vectors of different categories of data features, but does not introduce the highly complex optimal transmission distance calculation process into the model's data flow. Instead, it only uses the loss function calculated by the optimal transmission metric in the model optimization aspect, thereby improving the convenience of model deployment and use and lowering the threshold for algorithm application.

[0086] In some optional implementations, step S4044 above includes: Step c1: Based on the fourth formula, determine the uniform distribution regularization loss value. The fourth formula is:

[0087] in, To uniformly distribute the regularized loss value, This refers to the sample size of the text data included in this batch of data. Let be the activation value of the i-th dimension in the feature projection vector corresponding to the t-th target text data, and m be the hash encoding length.

[0088] The hash code generation model training method provided in this application proposes a uniform distribution regularization loss term. By optimizing this loss, it is required that each bit of the hash code has a probability of activation close to 50% in the entire batch of data, thereby maximizing the information entropy of the hash code and increasing the information content per bit.

[0089] In some optional implementations, step S405 above includes: Step d1: If the current training round number has not reached the preset training round number threshold, then determine the total loss value based on the contrast loss value.

[0090] The preset training round threshold is determined by technicians based on experience, and is generally 20% of the total training rounds.

[0091] A training round involves training using multiple batches of data, the total number of text data samples in each batch being the same as the number of text data samples included in the text data set.

[0092] Understandably, in the initial stage of model training, only the contrast loss value is used as the total loss value, allowing the model to learn basic semantic discrimination capabilities first.

[0093] Step d2: If the current training round number reaches the preset training round number threshold, then determine the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value.

[0094] If the current training rounds reach the preset training rounds threshold, then the optimal transmission distance edge loss value and the uniform distribution regularization loss value are introduced. Based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value, the total loss value is determined.

[0095] The hash coding generation model training method provided in this application has a two-stage progressive training process: the first stage uses contrast loss value to warm up the model; the second stage gradually introduces the optimal transmission distance edge loss value and the uniform distribution regularization loss value, the weights of which increase linearly with the training rounds to achieve stable optimization.

[0096] In some alternative implementations, step d2 above includes: Step d21: Based on the fifth formula, determine the total loss value. The fifth formula is:

[0097] in, This represents the total loss value. This represents the contrast loss value. The optimal transmission distance edge loss value; The loss value is a uniformly distributed regularized value; The current weight of the edge loss value for the optimal transmission distance; The current weights are for the uniformly distributed regularized loss values.

[0098] Specifically, the current weight of the optimal transmission distance edge loss value is determined based on the initial weight of the optimal transmission distance edge loss value, the target weight of the optimal transmission distance edge loss value, the current training round number, and the maximum training round number; the current weight of the uniform distribution regularized loss value is determined based on the initial weight of the uniform distribution regularized loss value, the target weight of the uniform distribution regularized loss value, the current training round number, and the maximum training round number.

[0099] Specifically, based on the sixth formula, the current weights of the optimal transmission distance edge loss values ​​are determined. The sixth formula is:

[0100] in, The initial weights for the optimal transmission distance edge loss value. The target weights are the edge loss values ​​for the optimal transmission distance. This is the current training round number. For the maximum number of training rounds, This is the preset threshold for the number of training rounds.

[0101] The initial weight of the optimal transmission distance edge loss value can be 0.1, and the target weight of the optimal transmission distance edge loss value can be 0.5.

[0102] Based on the seventh formula, the current weights of the uniform distribution regularization loss value are determined. The seventh formula is:

[0103] in, The initial weights are used to uniformly distribute the regularized loss values. The target weights are used to uniformly distribute the regularization loss values.

[0104] The initial weight of the uniform distribution regularization loss value can be 0.01, and the target weight of the uniform distribution regularization loss value can be 0.05.

[0105] By setting the weights of the optimal transmission distance edge loss value and the uniform distribution regularization loss value to increase linearly with the number of training rounds, the model focuses on learning semantic discrimination ability during the warm-up phase, and smoothly introduces distribution-level constraints and code point uniformity constraints during the joint training phase, ensuring a smooth and stable optimization process.

[0106] The hash coding generation model training method provided in this application proposes a joint optimization framework that incorporates constraints such as contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss. The total loss function value of this framework consists of a weighted sum of three parts: the contrast loss value at the sample level, the optimal transmission distance edge loss value at the distribution level, and the uniform distribution regularization loss value of the hash code bits. This framework performs multi-task learning through a shared Transformer backbone network and ultimately outputs high-quality binary hash codes.

[0107] In some optional implementations, step S406 above further includes: Step e1: Based on the total loss value, update the model parameters of the initial hash coding generation model, return to the step of sampling a batch of data from the text data set, until the decrease in the total loss value of a consecutive preset number of batches of data is less than a preset decrease threshold, and obtain the target hash coding generation model.

[0108] The preset quantity and preset decrease threshold are set by technical personnel based on their experience.

[0109] The hash encoding generation model training method provided in this application avoids undertraining or overfitting by quantifying the model convergence conditions, ensuring the stability and generalization ability of the target hash encoding generation model. It also ensures sufficient model parameter updates, enabling hash encoding to accurately capture text semantics and improve retrieval accuracy.

[0110] Embodiments of this application provide a hash encoding generation model training method, applied to the aforementioned computing device. Figure 5 The flowchart of the hash encoding generation model training method provided in the embodiments of this application is as follows: Figure 5 As shown, the training method for this hash encoding generation model includes the following steps: Obtain the training dataset, where each training data point is accompanied by a corresponding category label.

[0111] A batch of data is randomly sampled from the training dataset. The batch of data includes training data for multiple classes, with at least one training data point for each class.

[0112] The training data from this batch of data is input into the semantic extraction network of the initial hash encoding generation model to obtain the semantic feature vector corresponding to the training data.

[0113] The semantic feature vector is input into the feature projection network of the initial hash encoding generation model to obtain a feature projection vector with the same length as the hash encoding.

[0114] The feature projection vector is input into the hash encoding network of the initial hash encoding generation model to obtain the binary hash encoding corresponding to the training data.

[0115] Based on the category labels and feature projection vectors corresponding to the training data in this batch of data, calculate the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value. Based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value, determine the total loss value. Update the model parameters of the initial hash coding generation model through gradient descent or the Adam method, and return to execute the step of randomly sampling a batch of data from the training dataset until the model converges, thus obtaining the target hash coding generation model.

[0116] The hash encoding generation model training method provided in this application uses an autoencoder large language model to map text into semantic vectors, then projects the semantic vectors onto feature vectors. Constraints are then applied to the model's generation of feature vectors and hash codes based on contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss. This aims to achieve feature topology reconstruction of the correspondence between semantic feature vectors and categories simultaneously in both a high-dimensional hypersphere and the optimal transmission metric space. By constraining the similarity features of text data on a unit hypersphere and the feature distribution features on the optimal transmission metric, the model is guided to generate hash codes with high information density and hash encoding utilization.

[0117] An embodiment of this application provides a hash code generation method, applied to the aforementioned computing device. Figure 6 A flowchart of the hash encoding generation method provided in the embodiments of this application is shown below. Figure 6 As shown, the hash encoding generation method includes the following steps: Step S601: Obtain the text data to be encoded.

[0118] Step S602: Input the text data to be encoded into the target hash encoding generation model to obtain the target hash encoding corresponding to the text data to be encoded.

[0119] The target hash code generation model is the target hash code generation model trained using any of the above hash code generation model training methods.

[0120] The hash encoding generation method provided in this application constrains the process of generating feature projection vectors and hash codes by using contrast loss, optimal transmission distance edge loss, and uniform distribution regularization loss. This enables the trained target hash encoding generation model to generate binary hash codes with strong semantic relevance, high discriminative power, and sufficient space utilization. Therefore, it can solve the technical problem in related technologies where the semantic information of text vectors cannot be effectively measured, resulting in the inability to effectively distinguish similar vectors and reduce retrieval performance. The method achieves the technical effect of effectively measuring the semantic information of text, accurately distinguishing similar vectors, and improving retrieval performance.

[0121] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0122] Embodiments of this application also provide an electronic device, such as... Figure 7As shown, it includes a processor 701 and a memory 702, in which a computer program is stored. The processor 701 is configured to run the computer program to perform the steps in any of the above-described embodiments of the hash coding generation model training method or the steps in any of the above-described embodiments of the hash coding generation method.

[0123] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the hash coding generation model training method or the steps in any of the above-described embodiments of the hash coding generation method when it is run.

[0124] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0125] The embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described embodiments of the hash coding generation model training method or the steps in any of the above-described embodiments of the hash coding generation method.

[0126] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described embodiments of the hash encoding generation model training method or the steps in any of the above-described embodiments of the hash encoding generation method.

[0127] Any of the components, modules, units, parts, methods, and operations described herein can be implemented using software, firmware, hardware (e.g., fixed logic circuitry), manual processing, or any combination thereof. Alternatively or additionally, any functionality described herein can be executed at least in part by one or more hardware logic components, such as, but not limited to, a central processing unit (CPU), a field-programmable gate array (FPGA), an application-specific integrated circuit (ASIC), an application-specific standard product (ASSP), a system-on-a-chip (SoC), a complex programmable logic device (CPLD), a microprocessor (MCU), etc. The terms "system," "computing device," or "apparatus" as used herein encompass various means, devices, and machines for processing data, including, for example, one or more programmable processors, computers, SoCs, or combinations thereof. The apparatus may also include code that creates an execution environment for the computer program in question, such as code constituting processor firmware, a protocol stack, a database management system, an operating system, a cross-platform runtime environment, a virtual machine, or one or more combinations thereof. The aforementioned computer program (also known as a program, software, software application, app, script, or code) can be written in any form of programming language, including compiled or interpreted languages, declarative or procedural languages, and can be deployed in any form, including as a standalone program or as a module, component, subroutine, object, or other unit suitable for a computing environment.

[0128] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0129] The above provides a detailed description of the hash encoding generation model training method and hash encoding generation method provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only intended to help understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A method for training a hash-encoding generation model, characterized in that, The method includes: Obtain a text data set, which includes multiple text data samples, and each text data sample includes a text data and a category descriptor corresponding to the text data. A batch of data is sampled from the text data set, the batch of data including text data samples of multiple categories, and the number of text data samples of each category is not less than one; Input the target text data from the text data sample in the batch of data into the initial hash encoding generation model to obtain the feature projection vector corresponding to the target text data. The length of the feature projection vector is the same as the hash encoding length. Based on the feature projection vector corresponding to the target text data, determine the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value. The total loss value is determined based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value. Based on the total loss value, the model parameters of the initial hash encoding generation model are updated, and the step of sampling a batch of data from the text data set is returned until the model converges to obtain the target hash encoding generation model.

2. The method according to claim 1, characterized in that, The step of determining the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value based on the feature projection vector corresponding to the target text data includes: The contrast loss value is determined based on the sample size of the text data samples included in the batch of data and the feature projection vector corresponding to the target text data; Based on the total number of categories of text data samples included in the batch of data and the feature projection vector corresponding to the target text data, the optimal transmission distance edge loss value is determined; Based on the feature projection vector corresponding to the target text data, determine the activation value of each dimension in the feature projection vector; The uniform distribution regularization loss value is determined based on the activation value of each dimension in the feature projection vector and the sample size of the text data samples included in the batch of data.

3. The method according to claim 2, characterized in that, The step of determining the contrast loss value based on the sample size of the text data samples included in the batch of data and the feature projection vector corresponding to the target text data includes: Based on the first formula, the contrast loss value is determined. The first formula is: in, This represents the contrast loss value. This refers to the sample size of the text data included in this batch of data. This is the feature projection vector corresponding to the target text data in the i-th text data sample of this batch of data; The set of positive samples. For positive sample feature projection vectors, The negative sample feature projection vector. The set of negative samples. For temperature hyperparameters, This is a similarity measurement function; The positive sample is a text data sample in the batch of data that has the same category as the i-th text data sample, except for the i-th text data sample. The category of the text data sample is the same as the category of the text data in it. The negative sample is a text data sample in this batch of data that has a different category from the i-th text data sample; The positive sample feature projection vector is the feature projection vector corresponding to the target text data in the positive sample, and the negative sample feature projection vector is the feature projection vector corresponding to the target text data in the negative sample.

4. The method according to claim 3, characterized in that, The similarity metric function is the cosine similarity function.

5. The method according to claim 2, characterized in that, The determination of the optimal transmission distance edge loss value based on the total number of categories of text data samples included in the batch of data and the feature projection vector corresponding to the target text data includes: Based on the feature projection vectors corresponding to the target text data, determine the slice Wasserstein distance between the feature projection vectors corresponding to the same category of target text data and the slice Wasserstein distance between the feature projection vectors corresponding to different categories of target text data. Based on the total number of categories of text data samples included in the batch of data, the slice Wasserstein distance between feature projection vectors corresponding to target text data of the same category, and the slice Wasserstein distance between feature projection vectors corresponding to target text data of different categories, the optimal transmission distance edge loss value is determined.

6. The method according to claim 5, characterized in that, The determination of the optimal transmission distance edge loss value based on the total number of text data samples included in the batch of data, the slice Wasserstein distance between feature projection vectors corresponding to target text data of the same category, and the slice Wasserstein distance between feature projection vectors corresponding to target text data of different categories includes: Based on the second formula, the optimal transmission distance edge loss value is determined. The second formula is: in, The optimal transmission distance edge loss value, This represents the total number of categories of text data samples included in this batch of data; The slice Wasserstein distance between the feature projection vectors of the two disjoint subsets after randomly dividing the target text data of category c into two disjoint subsets; This is the current threshold for the distribution distance between different categories; Let be the slice Wasserstein distance between the feature projection vector of target text data of category c and the feature projection vector of target text data of category k; the set of categories of the text data samples included in this batch of data is . .

7. The method according to claim 6, characterized in that, The method further includes: The current distribution distance threshold between different categories is determined based on the initial distribution distance threshold between different categories, the target distribution distance threshold between different categories, the current training round number, and the maximum training round number.

8. The method according to claim 7, characterized in that, The determination of the current distribution distance threshold between different categories based on the initial distribution distance threshold between different categories, the target distribution distance threshold between different categories, the current training epoch, and the maximum training epoch includes: Based on the third formula, the distribution distance threshold between the different categories is determined, and the third formula is: in, This is the current distribution distance threshold between different categories. This serves as the initial threshold for the distribution distance between different categories. The threshold for the distribution distance between different categories of the target. This is the current training round number. This represents the maximum number of training rounds.

9. The method according to claim 2, characterized in that, The determination of the uniform distribution regularization loss value based on the activation value of each dimension in the feature projection vector and the sample size of the text data samples included in the batch of data includes: Based on the fourth formula, the uniform distribution regularization loss value is determined, and the fourth formula is: in, The uniform distribution regularization loss value is... This refers to the sample size of the text data included in this batch of data. Let be the activation value of the i-th dimension in the feature projection vector corresponding to the t-th target text data, and m be the hash encoding length.

10. The method according to claim 1, characterized in that, The determination of the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value includes: If the current training round number has not reached the preset training round number threshold, then the total loss value is determined based on the contrast loss value; If the current training round number reaches the preset training round number threshold, the total loss value is determined based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value.

11. The method according to claim 10, characterized in that, The determination of the total loss value based on the contrast loss value, the optimal transmission distance edge loss value, and the uniform distribution regularization loss value includes: The total loss value is determined based on the fifth formula, which is: in, The total loss value; This refers to the contrast loss value; This represents the edge loss value for the optimal transmission distance; This is the uniform distribution regularization loss value; The current weight of the edge loss value of the optimal transmission distance; The current weight of the uniformly distributed regularized loss value.

12. The method according to claim 11, characterized in that, The method further includes: The current weight of the optimal transmission distance edge loss value is determined based on the initial weight of the optimal transmission distance edge loss value, the target weight of the optimal transmission distance edge loss value, the current training round number, and the maximum training round number. The current weight of the uniformly distributed regularized loss value is determined based on the initial weight of the uniformly distributed regularized loss value, the target weight of the uniformly distributed regularized loss value, the current training round number, and the maximum training round number.

13. The method according to claim 12, characterized in that, The determination of the current weight of the optimal transmission distance edge loss value based on the initial weight of the optimal transmission distance edge loss value, the target weight of the optimal transmission distance edge loss value, the current training epoch number, and the maximum training epoch number includes: Based on the sixth formula, the current weight of the optimal transmission distance edge loss value is determined. The sixth formula is: in, The initial weights for the optimal transmission distance edge loss value are... The target weights are the edge loss values ​​of the optimal transmission distance. This is the current training round number. For the maximum number of training rounds, The preset training rounds threshold; The process of determining the current weight of the uniformly distributed regularized loss value based on the initial weight of the uniformly distributed regularized loss value, the target weight of the uniformly distributed regularized loss value, the current training epoch number, and the maximum training epoch number includes: Based on the seventh formula, the current weight of the uniform distribution regularization loss value is determined. The seventh formula is: in, The initial weights for the uniformly distributed regularized loss values ​​are... The target weight is the uniformly distributed regularized loss value.

14. The method according to claim 1, characterized in that, The initial hash encoding generation model includes a semantic extraction network, a feature projection network, and a hash encoding network; The semantic extraction network is used to encode the target text data into a semantic feature vector; The feature projection network is used to project the semantic feature vector into a feature projection vector with the same length as the hash code; The hash encoding network is used to hash the feature projection vector to generate the hash code corresponding to the target text data.

15. The method according to claim 14, characterized in that, The hash coding network is specifically used for: Based on the eighth formula, a hash code corresponding to the target text data is generated, wherein the eighth formula is: in, This is the hash code corresponding to the target text data in the i-th text data sample of this batch of data. The binary value is formed by applying the sign function Sign to the values ​​of multiple dimensions of the feature projection vector corresponding to the target text data in the i-th text data sample of the batch of data.

16. The method according to claim 1, characterized in that, The step of updating the model parameters of the initial hash encoding generation model based on the total loss value, and then returning to the step of sampling a batch of data from the text data set until the model converges to obtain the target hash encoding generation model includes: Based on the total loss value, the model parameters of the initial hash encoding generation model are updated, and the step of sampling a batch of data from the text data set is returned until the decrease in the total loss value of a consecutive preset number of batches of data is less than a preset decrease threshold, thereby obtaining the target hash encoding generation model.

17. A hash code generation method, characterized in that, include: Obtain the text data to be encoded; The text data to be encoded is input into the target hash encoding generation model to obtain the target hash encoding corresponding to the text data to be encoded. The target hash code generation model is a target hash code generation model trained using the hash code generation model training method according to any one of claims 1 to 16.

18. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the hash encoding generation model training method as described in any one of claims 1 to 16 or the steps of the hash encoding generation method as described in claim 17 when executing the computer program.

19. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, it implements the steps of the hash encoding generation model training method as described in any one of claims 1 to 16 or the steps of the hash encoding generation method as described in claim 17.

20. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the hash encoding generation model training method as described in any one of claims 1 to 16 or the steps of the hash encoding generation method as described in claim 17.