Semantic coding method and device, electronic equipment and storage medium

By determining the semantic granularity level in a generative task and obtaining sub-vectors of multiple semantic granularities for quantization encoding, the problem of insufficient generalization and accuracy of semantic vector encoding in the prior art is solved, and accurate representation and enhanced generalization of unseen data are achieved.

CN121234945APending Publication Date: 2025-12-30BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511417178.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-29
Publication Date
2025-12-30

AI Technical Summary

Technical Problem

In existing technologies, semantic vector encoding methods based on residual quantization in generative tasks have weak adaptability to unseen data, poor generalization ability, and cannot accurately represent semantic information.

Method used

By determining the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector, and each sub-vector is quantized to obtain the corresponding code table. Finally, the semantic vector is encoded based on the sub-vectors with different semantic granularities to generate multiple semantic codes.

Benefits of technology

It improves the generalization and accuracy of semantic encoding, enabling generative models to process unseen data more accurately and enhancing their ability to handle out-of-vocabulary words.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121234945A_ABST
    Figure CN121234945A_ABST
Patent Text Reader

Abstract

The invention provides a semantic coding method and device, electronic equipment and a storage medium, and relates to the technical field of computers. The method comprises the following steps: firstly, determining a to-be-processed semantic vector and a semantic granularity level, then obtaining a plurality of sub-vectors with different semantic granularities from the semantic vector based on the semantic granularity level, and then quantifying the sub-vector with each semantic granularity to obtain a code table corresponding to the sub-vector with the semantic granularity; and finally, coding the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities to obtain a plurality of semantic codes of the semantic vector, thereby improving generalization and accuracy of semantic coding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a semantic encoding method, apparatus, electronic device, and storage medium. Background Technology

[0002] Currently, in generative tasks, techniques such as residual quantization are commonly used to compress and quantize the semantic vector of the content, obtaining multiple discrete codewords (cluster centers). These codewords are then arranged into sequences to represent the semantic information of the content, thereby increasing the semantic information density. However, due to the discontinuous nature of discrete cluster spaces, sequences generated using this method have weak adaptability to unseen data, i.e., poor generalization and interpolation accuracy, failing to accurately represent semantic information. Summary of the Invention

[0003] This disclosure provides a semantic encoding method, apparatus, electronic device, and storage medium.

[0004] According to one aspect of this disclosure, a semantic encoding method is provided, comprising: Determine the semantic vector to be processed and the semantic granularity level; Based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector; The subvector of each semantic granularity is quantized to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords; Based on the code tables corresponding to the sub-vectors with different semantic granularities, the semantic vector is encoded to obtain multiple semantic codes for the semantic vector.

[0005] According to another aspect of this disclosure, a semantic encoding apparatus is provided, comprising: The determination module is used to determine the semantic vector to be processed and the semantic granularity level. The acquisition module is used to acquire multiple sub-vectors with different semantic granularities from the semantic vector based on the semantic granularity level; The quantization module is used to quantize the sub-vector of each semantic granularity to obtain the code table corresponding to the sub-vector of the semantic granularity, wherein the code table contains multiple codewords. The encoding module is used to encode the semantic vector based on the code tables corresponding to the sub-vectors of different semantic granularities, thereby obtaining multiple semantic codes for the semantic vector.

[0006] According to another aspect of this disclosure, an electronic device is provided, comprising: At least one processor; And, a memory that is communicatively connected to at least one processor; The memory stores instructions that can be executed by at least one processor, which enables the at least one processor to perform the methods of the above embodiments.

[0007] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to perform the method according to the above embodiments.

[0008] According to another aspect of this disclosure, a computer program product is proposed, comprising a computer program that, when executed by a processor, implements the methods as described in the embodiments of this disclosure above.

[0009] This disclosure provides a semantic encoding method, apparatus, electronic device, and storage medium. First, the semantic vector to be processed and its semantic granularity level are determined. Then, based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Next, each sub-vector of semantic granularity is quantized to obtain a code table corresponding to that semantic granularity. Finally, the semantic vector is encoded based on the code tables corresponding to the sub-vectors of different semantic granularities, resulting in multiple semantic codes for the semantic vector. Thus, by obtaining sub-vectors with multiple semantic granularities from the semantic vector, quantizing each sub-vector of semantic granularity to obtain a code table corresponding to that semantic granularity, and encoding based on the code tables of sub-vectors of different semantic granularities, multiple semantic codes for the semantic vector are obtained. This ensures that the obtained semantic codes contain semantic information from coarse to fine semantic granularity of the semantic vector, improving the generalization and accuracy of the semantic encoding. Attached Figure Description

[0010] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0011] Figure 1 A flowchart illustrating a semantic encoding method provided in an embodiment of this disclosure; Figure 2 A flowchart illustrating a semantic encoding method provided in an embodiment of this disclosure; Figure 3 This is a schematic diagram illustrating the process of obtaining multiple sub-vectors with different semantic granularities in the semantic encoding method proposed in this disclosure; Figure 4 A flowchart illustrating a semantic encoding method provided in an embodiment of this disclosure; Figure 5 This is a schematic diagram illustrating the process of obtaining the code table for each semantic granularity of the sub-vector in the semantic coding method proposed in this disclosure; Figure 6A flowchart illustrating a semantic encoding method provided in an embodiment of this disclosure; Figure 7 This is a schematic diagram illustrating the semantic coding method disclosed herein, which uses a two-dimensional grid table for encoding. Figure 8 A flowchart illustrating a semantic encoding method provided in an embodiment of this disclosure; Figure 9 This is a schematic diagram of the structure of a semantic coding device provided in an embodiment of the present disclosure; Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure.

[0012] The accompanying drawings have illustrated specific embodiments of this disclosure, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concepts of this disclosure to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0013] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0014] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, data stored, data displayed, etc.) and signals involved in this disclosure are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0015] It should be noted that the acquisition, transmission, storage, use, and processing of data in this disclosed technical solution all comply with the relevant provisions of national laws and regulations.

[0016] The semantic encoding method of the present disclosure will now be described in detail with reference to the accompanying drawings.

[0017] Figure 1 This is a flowchart illustrating a semantic encoding method provided in an embodiment of the present disclosure.

[0018] like Figure 1 As shown, the method includes: Step 101: Determine the semantic vector to be processed and the semantic granularity level.

[0019] It should be noted that the semantic encoding method proposed in this disclosure can be applied to generative task scenarios. For example, it can be applied to generative retrieval or generative recommendation scenarios, and this disclosure does not limit it.

[0020] The semantic vector to be processed can be a semantic vector that needs to be semantically encoded.

[0021] It should be noted that semantic vectors can be semantic vectors corresponding to OOV content or rare content in generative task scenarios.

[0022] Here, OOV stands for Out-of-Vocabulary (OOV). In other words, generative models encounter words (or symbols) that have never appeared in the training corpus when processing text, leading to inaccurate processing or weak generalization. The semantic encoding method proposed in this disclosure captures semantic information by encoding these words, thereby providing conditions for improving the generalization of generative models. For example, in e-commerce generative recommendation scenarios, OOV can represent newly added products, etc., and this disclosure does not limit this.

[0023] The semantic granularity level can be pre-defined as needed and can include multiple progressive semantic granularities. For example, the semantic granularity level can include three levels: coarse semantic granularity, medium semantic granularity, and fine semantic granularity. From coarse to fine granularity, the semantic scope continuously shrinks while the details continuously increase. That is to say, coarse semantic granularity can correspond to broad and general semantic information, while fine semantic granularity can correspond to specific and detailed semantic information, and medium semantic granularity corresponds to semantic information in between.

[0024] Step 102: Based on the semantic granularity level, obtain multiple sub-vectors with different semantic granularities from the semantic vector.

[0025] In this disclosure, after determining the semantic vector to be processed and the semantic granularity level, in order to improve the generalization of semantic encoding and enable the generative model to accurately and reliably process the OOV problem, before semantically encoding the semantic vector, multiple sub-vectors with different semantic granularities can be obtained from the semantic vector based on the semantic granularity level.

[0026] It's important to note that different semantic granularities correspond to different semantic ranges. As the semantic granularity increases from coarse to fine, the details that need to be represented also increase, requiring sufficient vector dimension to avoid semantic confusion. Therefore, the vector dimension of sub-vectors at different semantic granularities also differs. For example, sub-vectors at coarse semantic granularity may have a smaller vector dimension, while sub-vectors at fine semantic granularity may have a larger vector dimension, and sub-vectors at medium semantic granularity may have a vector dimension in between.

[0027] Step 103: Quantize the subvector of each semantic granularity to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords.

[0028] The code table contains multiple codewords, which are multiple discrete cluster centers corresponding to sub-vectors.

[0029] It should be noted that the specific quantization method for the sub-vectors can be preset as needed. For example, residual quantization can be performed on the sub-vectors, and this disclosure does not limit this.

[0030] Among them, residual quantization can represent a vector as a combination of multiple codewords. It can gradually approximate the original semantic vector through multiple quantizations, thereby reducing information loss and improving quantization accuracy.

[0031] Step 104: Encode the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities to obtain multiple semantic codes for the semantic vector.

[0032] The obtained semantic codes can represent the semantic information of the semantic vector at different semantic granularities. They can be obtained from a sequence of codewords in the code table.

[0033] In this disclosure, semantic vectors are encoded using code tables corresponding to sub-vectors with different semantic granularities, resulting in multiple semantic codes for the semantic vectors. This avoids the problem of weak generalization of semantic codes under single semantic granularity. Furthermore, the semantic codes under multi-semantic granularity encoding contain semantic information from coarse to fine granularity of the semantic vectors, and can accurately and reliably perform interpolation on the semantic codes. This enables the semantic codes to accurately represent semantic information when facing OOV problems, thereby improving the generalization and accuracy of semantic codes.

[0034] In this embodiment, the semantic vector to be processed and its semantic granularity level are first determined. Then, based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Each sub-vector at a specific semantic granularity is then quantized to obtain a code table corresponding to that granularity. Finally, the semantic vector is encoded based on the code tables corresponding to the sub-vectors at different semantic granularities, resulting in multiple semantic codes for the semantic vector. Thus, by obtaining sub-vectors with multiple semantic granularities from the semantic vector, quantizing each sub-vector at a specific semantic granularity to obtain a code table corresponding to that granularity, and encoding based on the code tables of sub-vectors at different semantic granularities, multiple semantic codes for the semantic vector are obtained. This ensures that the obtained semantic codes contain semantic information from coarse to fine semantic granularity, improving the generalization and accuracy of the semantic coding.

[0035] Figure 2This is a flowchart illustrating a semantic encoding method provided in an embodiment of the present disclosure.

[0036] like Figure 2 As shown, the method includes: Step 201: Determine the semantic vector to be processed and the semantic granularity level.

[0037] The specific implementation of step 201 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0038] Step 202: Compress the semantic vector to obtain the compressed vector.

[0039] In this disclosure, after determining the semantic vector to be processed, the vector dimension of the semantic vector can be compressed first to obtain a compressed low-dimensional vector.

[0040] It should be noted that the dimension of the compressed vector can be set as needed. For example, when the semantic vector is a 2048-dimensional vector, it can be compressed into a 512-dimensional vector, etc. This disclosure does not limit this.

[0041] Step 203: Based on the semantic granularity level and the dimension of the compressed vector, determine the sub-vector dimension corresponding to different semantic granularities.

[0042] In this disclosure, in order to accurately represent the semantic information of semantic vectors at different semantic granularities, the sub-vector dimensions corresponding to different semantic granularities can be determined based on the semantic granularity level and the dimension of the compressed vector. That is, based on the order of semantic granularity from coarse to fine, the amount of semantic information to be represented increases, and the determined sub-vector dimensions for the corresponding semantic granularities also increase progressively.

[0043] It should be noted that when determining the sub-vector dimensions corresponding to different semantic granularities based on the semantic granularity level and the dimension of the compressed vector, the specific dimension division can be determined according to the actual situation. For example, if the semantic granularity level is coarse-grained, medium-grained, and fine-grained, and the dimension of the compressed vector is 512, then the sub-vector dimension corresponding to coarse-grained can be 128, the sub-vector dimension corresponding to medium-grained can be 256, and the sub-vector dimension corresponding to fine-grained can be 512, etc. This disclosure does not impose any limitations on this.

[0044] Step 204: Based on the sub-vector dimension corresponding to each semantic granularity, obtain multiple sub-vectors with different semantic granularities from the compressed vector.

[0045] In this disclosure, after determining the sub-vector dimensions corresponding to different semantic granularities, multiple sub-vectors with different semantic granularities can be obtained from the compressed vector based on the sub-vector dimensions corresponding to each semantic granularity, thereby achieving progressive generalization of semantic vectors and providing a foundation for improving the generalization and accuracy of semantic encoding.

[0046] It should be noted that when obtaining multiple sub-vectors of different semantic granularities from the compressed vector based on the sub-vector dimension corresponding to each semantic granularity, the first dimension of each sub-vector can start from the first dimension of the compressed vector. For example, when the sub-vector dimension corresponding to the coarse semantic granularity is 128, obtaining the sub-vector of that semantic granularity from the compressed vector can start from the first dimension of the compressed vector, defining the first 128 dimensions as the sub-vector. When the sub-vector dimension corresponding to the medium semantic granularity is 256, obtaining the sub-vector of that semantic granularity from the compressed vector can start from the first dimension of the compressed vector, defining the first 256 dimensions as the sub-vector. When the sub-vector dimension corresponding to the fine semantic granularity is 512, obtaining the sub-vector of that semantic granularity from the compressed vector can start from the first dimension of the compressed vector, defining the first 512 dimensions as the sub-vector, and so on.

[0047] Optionally, when obtaining multiple sub-vectors with different semantic granularities from the compressed vector based on the sub-vector dimension corresponding to each semantic granularity, it is also possible to retain the content of a corresponding number of dimensions starting from the first dimension of the compressed vector based on the sub-vector dimension corresponding to each semantic granularity, and fill the content of the remaining dimensions with 0, thereby obtaining sub-vectors with different semantic granularities. This disclosure does not limit this.

[0048] The following is combined Figure 3 The process of obtaining multiple sub-vectors with different semantic granularities in the semantic encoding method proposed in this disclosure is illustrated with an example. Figure 3 This diagram illustrates the process of obtaining multiple sub-vectors with different semantic granularities in the semantic encoding method proposed in this disclosure. Figure 3 This is just an example; no restrictions are imposed here.

[0049] Figure 3 In this example, we will use the semantic granularity level, which includes coarse-grained, medium-grained, and fine-grained granularity, and the compressed vector with a dimension of 512 as an example to illustrate the concept.

[0050] like Figure 3 As shown, the semantic vector to be processed is first input into the encoder, which performs encoding and compression to obtain a 512-dimensional compressed vector. Then, based on the three semantic granularities and the 512-dimensional vector, the sub-vector dimensions for different semantic granularities are determined. Figure 3As shown, the coarse-grained sub-vector has a dimension of 128, the medium-grained sub-vector has a dimension of 256, and the fine-grained sub-vector has a dimension of 512. Finally, based on the determined sub-vector dimension for each semantic granularity, multiple sub-vectors with different semantic granularities are obtained from the compressed vector, namely, 128-dimensional vectors, 256-dimensional vectors, and 512-dimensional vectors. Figure 3 The vectors E1, E2, and E3 are shown in the figure.

[0051] It should be noted that, Figure 3 The specific structure of the encoder shown, as well as the specific encoding and compression process for the vector, can be set as needed, and this disclosure does not limit it.

[0052] Step 205: Quantize the subvector of each semantic granularity to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords.

[0053] Step 206: Encode the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities to obtain multiple semantic codes for the semantic vector.

[0054] The specific implementation of steps 205 to 206 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0055] In this embodiment, the semantic vector to be processed and the semantic granularity level are first determined. Then, the semantic vector is compressed to obtain a compressed vector. Based on the semantic granularity level and the dimension of the compressed vector, the sub-vector dimensions corresponding to different semantic granularities are determined. Then, based on the sub-vector dimensions corresponding to each semantic granularity, multiple sub-vectors of different semantic granularities are obtained from the compressed vector. Each sub-vector of semantic granularity is quantized to obtain the code table corresponding to the sub-vector of that semantic granularity. Finally, based on the code tables corresponding to the sub-vectors of different semantic granularities, the semantic vector is encoded to obtain multiple semantic codes of the semantic vector. Therefore, after determining the semantic vector to be processed and the semantic granularity level, the semantic vector is compressed, and the dimensions of sub-vectors of different semantic granularities are determined based on the semantic granularity level and the dimension of the compressed vector. This allows for the extraction of sub-vectors of multiple semantic granularities from the compressed vector, thereby obtaining a generalized representation of the semantic vector from coarse semantic granularity to fine semantic granularity. Then, each semantic granularity sub-vector is quantized to obtain the corresponding code table for encoding, thus obtaining the semantic encoding of the semantic vector and improving the generalization and accuracy of the semantic encoding.

[0056] Figure 4 This is a flowchart illustrating a semantic encoding method provided in an embodiment of the present disclosure.

[0057] like Figure 4As shown, the method includes: Step 401: Determine the semantic vector to be processed and the semantic granularity level.

[0058] Step 402: Based on the semantic granularity level, obtain multiple sub-vectors with different semantic granularities from the semantic vector.

[0059] The specific implementation of steps 401 to 402 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0060] Step 403: For each semantic granularity, obtain multiple candidate codewords corresponding to each quantization granularity layer under that semantic granularity.

[0061] It should be noted that the quantization granularity layer is the same for each semantic granularity. The number of quantization granularity layers under a semantic granularity can be preset as needed. For example, the quantization granularity layer under a semantic granularity may include three layers: coarse quantization granularity, medium quantization granularity, and fine quantization granularity. This disclosure does not limit this.

[0062] It should be noted that the multiple candidate codewords corresponding to each quantization granularity layer can all be pre-determined through training. For example, the multiple candidate codewords corresponding to each quantization granularity layer can be obtained by training the quantization model using sample data. That is, when determining the multiple candidate codewords for each quantization granularity layer, sample data can be obtained first, and the semantic vector corresponding to the sample data can be determined as sub-vectors at multiple different semantic granularities. The sub-vectors at each semantic granularity are then input into the quantization model to obtain multiple initial codewords for each quantization granularity layer. Reconstruction is then performed based on the multiple initial codewords at different quantization granularities for each semantic granularity layer. The quantization loss value is calculated based on the reconstructed sub-vectors and the corresponding original sub-vectors. Then, the reconstructed sub-vectors at multiple different semantic granularities are input into the decoder in the quantization model for vector reconstruction. The reconstruction loss value is calculated based on the reconstructed vectors and the original semantic vectors. Finally, the parameters of the quantization model are adjusted based on the quantization loss value and the reconstruction loss value, including adjusting the initial codewords for each quantization granularity layer, until multiple candidate codewords for each quantization granularity layer are obtained. This disclosure does not limit this process. It should be noted that the number of candidate codewords corresponding to different quantization granularity layers can be determined according to specific needs, and this disclosure does not limit this.

[0063] Step 404: Based on the multiple candidate codewords corresponding to the first quantization granularity layer, quantize the subvector to obtain the first codeword corresponding to the first quantization granularity layer.

[0064] The first quantization granularity layer can be the coarse quantization granularity layer that begins when quantizing a vector.

[0065] The first codeword is the codeword in the first quantization granularity layer that is closest to the sub-vector, i.e., the codeword with the highest similarity.

[0066] It should be noted that when quantizing the sub-vectors to obtain the first codeword corresponding to the first quantization granularity layer, the first codeword can be obtained through a distance metric. For example, the first codeword can be determined by calculating Euclidean distance, Manhattan distance, or cosine similarity, etc. This disclosure does not limit the scope of the method.

[0067] Step 405: Determine the first residual based on the sub-vector and the first codeword.

[0068] The first residual is the semantic information in the sub-vector that was not captured by the first codeword, that is, the remaining semantic information in the sub-vector to be quantized.

[0069] In this disclosure, after quantizing the sub-vector based on multiple candidate codewords corresponding to the first quantization granularity layer to obtain the first codeword corresponding to the first quantization granularity layer, since the first quantization granularity layer is a coarse quantization granularity layer, the first codeword may not be able to capture all the semantic information of the sub-vector. Therefore, it is necessary to quantize the remaining semantic information in the sub-vector that was not captured by the first codeword again. At this time, the first residual can be determined first based on the sub-vector and the first codeword.

[0070] Step 406: Based on the multiple candidate codewords corresponding to the second quantization granularity layer, quantize the first residual to obtain the second codeword corresponding to the second quantization granularity layer.

[0071] The second quantization granularity layer can be the next quantization granularity layer adjacent to the first quantization granularity layer. Its corresponding quantization granularity is finer than that of the first quantization granularity layer.

[0072] The second codeword is the codeword in the second quantization granularity layer that is closest to the first residual, i.e., the codeword with the highest similarity.

[0073] It should be noted that the specific implementation of quantizing the first residual based on multiple candidate codewords corresponding to the second quantization granularity layer to obtain the second codeword corresponding to the second quantization granularity layer is similar to the specific implementation of quantizing the subvector based on multiple candidate codewords corresponding to the first quantization granularity layer to obtain the first codeword corresponding to the first quantization granularity layer in step 404, and will not be repeated here.

[0074] Step 407: Determine the second residual based on the first residual and the second codeword.

[0075] The second residual is the semantic information in the first residual that was not captured by the second codeword, that is, the remaining semantic information to be quantized in the first residual.

[0076] Step 408: Based on the multiple candidate codewords corresponding to the third quantization granularity layer, quantize the second residual until the code table corresponding to the sub-vector is obtained.

[0077] The third quantization granularity layer is the next quantization granularity layer adjacent to the second quantization granularity layer, and its corresponding quantization granularity is finer than that of the second quantization granularity layer.

[0078] The code table corresponding to the sub-vector includes the codewords corresponding to each quantization granularity layer, such as the first codeword and the second codeword.

[0079] In this disclosure, the second residual is quantized based on multiple candidate codewords corresponding to the third quantization granularity layer until all semantic information of the sub-vector is quantized, thereby obtaining the code table corresponding to the sub-vector. This achieves multi-level quantization of sub-vectors with different semantic granularities, obtaining a code table containing codewords from coarse quantization granularity to fine quantization granularity, while capturing the semantic information of both coarse and fine quantization granularities, thus improving quantization accuracy.

[0080] The following is combined Figure 5 The process of obtaining the code table of sub-vectors for each semantic granularity in the semantic coding method proposed in this disclosure is illustrated with an example. Figure 5 This is a schematic diagram illustrating the process of obtaining the code table of sub-vectors for each semantic granularity using the semantic coding method proposed in this disclosure.

[0081] Figure 5 In this model, the structure used for vector quantization is a residual quantization model, which includes an encoder, a residual quantization module, and a decoder. The encoder is used for encoding and compressing the vector, the residual quantization module is used for quantizing the vector, and the decoder is used for vector reconstruction. Figure 5 The specific structure shown for quantizing vectors is merely an example and is not intended to be limiting.

[0082] Figure 5 In this example, the semantic granularity level has three levels, and the residual quantization module includes three quantization granularity levels: c11-c12-c13, c21-c22-c23, and c31-c32-c33. These are examples of code tables corresponding to sub-vectors with semantic granularity ranging from coarse to fine.

[0083] It should be noted that c11, c12, c13, c21, etc., can be used to represent codewords, and can be the corresponding codeword identifier. For example, they can be the index of the codeword among multiple candidate codewords, or the codeword itself, etc., and this disclosure does not limit them.

[0084] like Figure 5As shown, after encoding and compressing the semantic vector using an encoder to obtain a 512-dimensional compressed vector, and obtaining multiple sub-vectors with different semantic granularities based on the semantic granularity level and the dimension of the compressed vector, for each semantic granularity, the sub-vector of that semantic granularity is input into the residual quantization module to obtain the corresponding code table.

[0085] When using the residual quantization module to quantize subvectors with different semantic granularities, the specific quantization process can be referred to steps 403 to 408, which will not be repeated here.

[0086] In other words, by using the residual quantization module and referring to the specific implementation of steps 403 to 408, sub-vectors with different semantic granularities are quantized, and the resulting code table can be as follows: Figure 5 As shown: In code tables c11-c12-c13, c11 is the first codeword corresponding to the first quantization granularity layer under coarse semantic granularity, c12 is the second codeword corresponding to the second quantization granularity layer under coarse semantic granularity, and c13 is the codeword corresponding to the third quantization granularity layer under coarse semantic granularity. In code tables c21-c22-c23, c21 is the first codeword corresponding to the first quantization granularity layer under medium semantic granularity, c22 is the second codeword corresponding to the second quantization granularity layer under medium semantic granularity, and c23 is the codeword corresponding to the third quantization granularity layer under medium semantic granularity. In code tables c31-c32-c33, c31 is the first codeword corresponding to the first quantization granularity layer under fine semantic granularity, c32 is the second codeword corresponding to the second quantization granularity layer under fine semantic granularity, and c33 is the codeword corresponding to the third quantization granularity layer under fine semantic granularity.

[0087] It should be noted that when using Figure 5 To improve the accuracy and reliability of quantization, the residual quantization module shown can perform quantization reconstruction based on the code tables corresponding to sub-vectors with different semantic granularities after obtaining the code tables. The quantization loss is then calculated based on the reconstructed sub-vectors and the original sub-vectors. The reconstructed sub-vectors with different semantic granularities are then input into the decoder for vector reconstruction to obtain the reconstructed semantic vectors. The reconstruction loss is then calculated based on the reconstructed semantic vectors and the original semantic vectors. Finally, the parameters of the encoder, decoder, and residual quantization module are corrected based on the quantization loss and the reconstruction loss. This disclosure does not limit the scope of the invention.

[0088] Step 409: Encode the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities to obtain multiple semantic codes for the semantic vector.

[0089] The specific implementation of step 409 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0090] In this embodiment, the semantic vector to be processed and its semantic granularity level are first determined. Based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Then, for each semantic granularity, multiple candidate codewords corresponding to each quantization granularity layer under that semantic granularity are obtained. Based on the multiple candidate codewords corresponding to the first quantization granularity layer, the sub-vector is quantized to obtain the first codeword corresponding to the first quantization granularity layer. Then, based on the sub-vector and the first codeword, the first residual is determined. Based on the multiple candidate codewords corresponding to the second quantization granularity layer, the first residual is quantized to obtain the second codeword corresponding to the second quantization granularity layer. Next, based on the first residual and the second codeword, the second residual is determined. Based on the multiple candidate codewords corresponding to the third quantization granularity layer, the second residual is quantized until the code table corresponding to the sub-vector is obtained. Finally, based on the code tables corresponding to the sub-vectors with different semantic granularities, the semantic vector is encoded to obtain multiple semantic codes of the semantic vector. Therefore, after obtaining multiple sub-vectors with different semantic granularities from the semantic vector to be processed, each sub-vector with different semantic granularities is quantized based on multiple candidate codewords corresponding to different quantization granularity layers. The codeword corresponding to each quantization granularity layer is determined, and the code table of the sub-vector with that semantic granularity is obtained. Thus, by multi-level quantization of vectors with different semantic granularities, the semantic information of the vector can be accurately captured. Then, based on the code tables corresponding to the sub-vectors with different semantic granularities, the semantic encoding of the semantic vector is obtained. This realizes semantic encoding with multiple semantic granularities and multiple quantization granularities. The obtained semantic encoding can accurately represent the corresponding semantic information when facing new or rare data, thus improving the generalization and accuracy of semantic encoding.

[0091] Figure 6 This is a flowchart illustrating a semantic encoding method provided in an embodiment of the present disclosure.

[0092] like Figure 6 As shown, the method includes: Step 601: Determine the semantic vector to be processed and the semantic granularity level.

[0093] Step 602: Based on the semantic granularity level, obtain multiple sub-vectors with different semantic granularities from the semantic vector.

[0094] Step 603: Quantize the subvector of each semantic granularity to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords.

[0095] The specific implementation of steps 601 to 603 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0096] Step 604: Based on the code table corresponding to the sub-vector of each semantic granularity, construct a two-dimensional grid table containing all codewords.

[0097] In this two-dimensional grid table, each column corresponds to a different semantic granularity, each row corresponds to a different quantization granularity, and the granularities of adjacent columns or rows are progressive. Each element in the two-dimensional grid table corresponds to a codeword under different semantic and quantization granularities.

[0098] In this disclosure, after obtaining code tables corresponding to multiple sub-vectors with different semantic granularities, in order to improve the generalization and accuracy of semantic encoding, a two-dimensional grid table containing all codewords can be constructed based on the code tables corresponding to the sub-vectors of each semantic granularity.

[0099] Step 605: Based on the two-dimensional grid table, generate multiple codeword sequences corresponding to the semantic vector.

[0100] In this codeword sequence, multiple codewords correspond to different quantization granularities and are ordered from coarse to fine quantization granularity. That is, each codeword sequence contains codewords for each quantization granularity layer, which is not limited in this disclosure.

[0101] Optionally, when generating multiple codeword sequences corresponding to semantic vectors based on a two-dimensional grid structure, since the first codeword in each column is the codeword corresponding to the first quantization granularity layer and serves as the basis for subsequent generalization, the codeword sequence corresponding to the semantic vector can also include a sequence composed of the first codeword in each column, and sorted in order from coarse to fine according to the semantic granularity corresponding to each column.

[0102] Step 606: Encode the multiple codeword sequences separately to obtain multiple semantic codes of the semantic vector.

[0103] It should be noted that the specific method of encoding the codeword sequence can be determined according to specific needs. For example, multiple codewords in the codeword sequence can be concatenated in order of quantization granularity from coarse to fine, or weighted fusion can be used, etc. This disclosure does not limit this.

[0104] In this disclosure, after obtaining multiple codeword sequences corresponding to a semantic vector, multiple codewords in each codeword sequence can be encoded to obtain multiple semantic codes for the semantic vector.

[0105] Optionally, after constructing a two-dimensional grid table containing all codewords based on the code table corresponding to each semantic granularity sub-vector, and in the case where the codeword sequence consists of the first codeword in each column, the first codeword in each column can be encoded in order from coarse to fine semantic granularity to obtain the semantic encoding of the first semantic vector.

[0106] It should be noted that when the first codeword in each column is the same, it will lead to the collapse of the encoding of subvectors based on multiple different semantic granularities. In this case, a unique semantic encoding of the semantic vector can be obtained.

[0107] The following is combined Figure 7 The process of encoding based on a two-dimensional grid table in the semantic encoding method proposed in this disclosure is illustrated with an example. Figure 7 This is a schematic diagram illustrating the semantic encoding method disclosed herein, which uses a two-dimensional grid table for encoding.

[0108] Figure 7 In this example, we will use three semantic granularities and three quantization granularities as examples. The arrows indicate the path direction, i.e., the order in which the codewords make up the codeword sequence are ordered.

[0109] like Figure 7 In the two-dimensional grid table shown, each column corresponds to a different semantic granularity, and each row corresponds to a different quantization granularity. Based on this two-dimensional grid table, a codeword is randomly selected from each row to form a codeword sequence, such as c11-c12-c13, c11-c12-c23, c11-c12-c33, c11-c22-c12...c21-c12-c13... and so on. That is, with three levels of semantic granularity and three levels of quantization granularity, 27 codeword sequences can be obtained. Furthermore, the first codeword in each column can also form a codeword sequence, i.e., c11-c21-c31. Therefore, in this case, 28 codeword sequences can be obtained. Encoding these 28 codeword sequences respectively yields 28 semantic codes for the semantic vector.

[0110] More generally, assuming the semantic granularity is n layers and the quantization granularity is m layers, then we can obtain nm+1 codeword sequences. Encoding these nm+1 codeword sequences respectively can yield nm+1 semantic codes for the semantic vector.

[0111] It should be noted that when the first codeword of each column is the same, i.e., c11=c21=c31, it will lead to code collapse. In this case, a unique codeword sequence c11-c21-c31 can be obtained. Encoding this codeword sequence can obtain a unique semantic code for the semantic vector.

[0112] In this embodiment, the semantic vector to be processed and its semantic granularity level are first determined. Based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Then, each sub-vector of semantic granularity is quantized to obtain the code table corresponding to that semantic granularity. Next, based on the code table corresponding to each semantic granularity sub-vector, a two-dimensional grid table containing all codewords is constructed. Based on the two-dimensional grid table, multiple codeword sequences corresponding to the semantic vector are generated. Finally, the multiple codeword sequences are encoded separately to obtain multiple semantic codes for the semantic vector. Thus, after obtaining the code tables corresponding to multiple sub-vectors with different semantic granularities, a two-dimensional grid table is constructed based on the code table of each semantic granularity sub-vector, and multiple codeword sequences are generated based on the grid table. Then, the multiple codeword sequences are encoded separately to obtain multiple semantic codes for the semantic vector. This improves the semantic coding efficiency by obtaining the codeword sequences through the grid table.

[0113] Figure 8 This is a flowchart illustrating a semantic encoding method provided in an embodiment of the present disclosure.

[0114] like Figure 8 As shown, the method includes: Step 801: Determine the semantic vector to be processed and the semantic granularity level.

[0115] Step 802: Based on the semantic granularity level, obtain multiple sub-vectors with different semantic granularities from the semantic vector.

[0116] Step 803: Quantize the subvector of each semantic granularity to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords.

[0117] Step 804: Encode the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities to obtain multiple semantic codes for the semantic vector.

[0118] The specific implementation of steps 801 to 804 can be found in the detailed descriptions of other embodiments in this disclosure, and will not be repeated here.

[0119] Step 805: Based on the text corresponding to the semantic vector and multiple semantic codes, generate multiple fine-tuning data pairs, wherein each fine-tuning data pair includes text and a semantic code.

[0120] The text corresponding to the semantic vector can be a textual description of the content represented by the semantic vector. For example, when the content represented by the semantic vector is a product, the text corresponding to the semantic vector can be a textual description of the product, which may include product parameters and other information, etc. This disclosure does not limit this.

[0121] Among them, fine-tuning data pairs are data pairs that can be used to fine-tune generative models.

[0122] The specific type and structure of the generative model can be a pre-trained generative model, which can be a generative retrieval model or a generative recommendation model. This disclosure does not limit this.

[0123] Step 806: Fine-tune the generative model based on multiple fine-tuning data pairs.

[0124] In this disclosure, after generating multiple fine-tuning data pairs based on the text corresponding to the semantic vectors and multiple semantic codes, the generative model is fine-tuned based on the multiple fine-tuning data pairs, thereby improving the adaptability of the generative model when facing unseen data and improving the generalization and accuracy of the generative model.

[0125] In this embodiment, the semantic vector to be processed and its semantic granularity level are first determined. Based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Then, each sub-vector of semantic granularity is quantized to obtain the code table corresponding to that semantic granularity. Based on the code tables corresponding to the sub-vectors of different semantic granularities, the semantic vector is encoded to obtain multiple semantic codes for the semantic vector. Then, based on the text corresponding to the semantic vector and the multiple semantic codes, multiple fine-tuning data pairs are generated. Finally, the generative model is fine-tuned based on the multiple fine-tuning data pairs. Thus, after encoding the semantic vector at multiple semantic granularities and multiple quantization levels to obtain its corresponding multiple semantic codes, multiple fine-tuning data pairs are generated based on the text corresponding to the semantic vector and the multiple semantic codes. The generative model is then fine-tuned using these multiple fine-tuning data pairs, thereby improving the generalization and accuracy of the generative model.

[0126] To implement the above embodiments, this disclosure also proposes a semantic encoding device.

[0127] Figure 9 This is a schematic diagram of the structure of a semantic encoding device provided in an embodiment of the present disclosure.

[0128] like Figure 9 As shown, the semantic encoding device 900 may include: The determination module 901 is used to determine the semantic vector to be processed and the semantic granularity level; The acquisition module 902 is used to acquire multiple sub-vectors with different semantic granularities from the semantic vector based on the semantic granularity level; The quantization module 903 is used to quantize the subvector of each semantic granularity to obtain the code table corresponding to the subvector of that semantic granularity, wherein the code table contains multiple codewords. The encoding module 904 is used to encode the semantic vector based on the code tables corresponding to the sub-vectors with different semantic granularities, so as to obtain multiple semantic codes of the semantic vector.

[0129] Optionally, the aforementioned acquisition module 902 is specifically used for: The semantic vector is compressed to obtain the compressed vector; Based on the semantic granularity level and the dimension of the compressed vector, the sub-vector dimension corresponding to different semantic granularities is determined; Based on the sub-vector dimension corresponding to each semantic granularity, multiple sub-vectors with different semantic granularities are obtained from the compressed vector.

[0130] Optionally, the quantization module 903 described above is also used for: For each semantic granularity, obtain multiple candidate codewords corresponding to each quantization granularity layer under that semantic granularity; Based on multiple candidate codewords corresponding to the first quantization granularity layer, the subvector is quantized to obtain the first codeword corresponding to the first quantization granularity layer; Based on the sub-vector and the first codeword, determine the first residual; Based on multiple candidate codewords corresponding to the second quantization granularity layer, the first residual is quantized to obtain the second codeword corresponding to the second quantization granularity layer. Based on the first residual and the second codeword, determine the second residual; Based on multiple candidate codewords corresponding to the third quantization granularity layer, the second residual is quantized until the code table corresponding to the sub-vector is obtained.

[0131] Optionally, the encoding module 904 described above is also used for: Based on the code table corresponding to the sub-vector of each semantic granularity, a two-dimensional grid table containing all codewords is constructed. Each column of the two-dimensional grid table corresponds to a different semantic granularity, each row corresponds to a different quantization granularity, and the granularity of adjacent columns or rows is progressive. Each element in the two-dimensional grid table corresponds to a codeword under different semantic granularity and quantization granularity. Based on a two-dimensional grid table, multiple codeword sequences corresponding to semantic vectors are generated. In each codeword sequence, the multiple codewords correspond to different quantization granularities and are sorted in order from coarse to fine quantization granularity. Encode multiple codeword sequences separately to obtain multiple semantic codes for the semantic vector.

[0132] Optionally, the encoding module 904 described above is also used for: Encode the first codeword in each column according to the semantic granularity from coarse to fine, to obtain the semantic encoding of the first semantic vector.

[0133] Optionally, the encoding module 904 described above is also used for: Based on the text corresponding to the semantic vector and multiple semantic codes, multiple fine-tuning data pairs are generated, wherein each fine-tuning data pair includes text and a semantic code; The generative model is fine-tuned based on multiple fine-tuning data pairs.

[0134] The functions and specific implementation principles of the modules described in this embodiment can be found in the above method embodiments, and will not be repeated here.

[0135] In this disclosure, the semantic vector to be processed and its semantic granularity level are first determined. Then, based on the semantic granularity level, multiple sub-vectors with different semantic granularities are obtained from the semantic vector. Each sub-vector at a specific semantic granularity is then quantized to obtain a code table corresponding to that granularity. Finally, the semantic vector is encoded based on the code tables corresponding to the sub-vectors at different semantic granularities, resulting in multiple semantic codes for the semantic vector. Thus, by obtaining sub-vectors with multiple semantic granularities from the semantic vector, quantizing each sub-vector at a specific semantic granularity to obtain a code table, and encoding based on the code tables of sub-vectors at different semantic granularities, multiple semantic codes for the semantic vector are obtained. This ensures that the obtained semantic codes encompass semantic information from coarse to fine semantic granularity, improving the generalization and accuracy of the semantic coding.

[0136] Figure 10 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown.

[0137] Figure 10 The electronic device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.

[0138] like Figure 10As shown, electronic device 12 is represented in the form of a general-purpose computing device. Components of electronic device 12 may include, but are not limited to: one or more processors or processing units 16, memory 28, and a bus 18 connecting different system components (including memory 28 and processing unit 16). Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.

[0139] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0140] Memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and / or cache 32. Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 10 Not shown; usually referred to as a "hard drive".

[0141] although Figure 10As not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disc drive for reading and writing to a removable non-volatile optical disc (e.g., a compact disc read-only memory (CD-ROM), a digital video disc read-only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.

[0142] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of this disclosure.

[0143] Electronic device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable human interaction with electronic device 12, and / or with any device that enables electronic device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, electronic device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with other modules of electronic device 12 via bus 18. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0144] The processing unit 16 executes various functional applications and parameter information determination by running programs stored in the memory 28, such as implementing the semantic encoding method mentioned in the foregoing embodiments.

[0145] To implement the above embodiments, this disclosure also proposes a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the semantic encoding method proposed in the foregoing embodiments of this disclosure.

[0146] To implement the above embodiments, this disclosure also proposes a computer program product that, when executed by an instruction processor, performs the semantic encoding method as proposed in the foregoing embodiments of this disclosure.

[0147] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.

[0148] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

[0149] It should be noted that in the description of this disclosure, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this disclosure, unless otherwise stated, "a plurality of" means two or more.

[0150] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of preferred embodiments of this disclosure includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this disclosure pertain.

[0151] It should be understood that various parts of this disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0152] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0153] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0154] The storage media mentioned above can be read-only memory, disk, or optical disk, etc.

[0155] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0156] Although embodiments of the present disclosure have been shown and described above, it is to be understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present disclosure.

Claims

1. A method of semantic coding, characterized by, The method comprises the following steps: determining a semantic vector to be processed and a semantic granularity level; based on the semantic granularity level, obtaining sub-vectors of different semantic granularities from the semantic vector; quantizing each sub-vector of the semantic granularity to obtain a code table corresponding to the sub-vector of the semantic granularity, wherein the code table contains multiple code words; based on the code tables corresponding to the sub-vectors of different semantic granularities, encoding the semantic vector to obtain multiple semantic encodings of the semantic vector.

2. The method of claim 1, wherein, The method comprises the following steps: compressing the semantic vector to obtain a compressed vector; based on the semantic granularity level and the dimension of the compressed vector, determining the dimension of the sub-vector corresponding to different semantic granularities; based on the dimension of the sub-vector corresponding to each semantic granularity, obtaining sub-vectors of different semantic granularities from the compressed vector.

3. The method of claim 2, wherein, The method comprises the following steps: for each semantic granularity, obtaining multiple candidate code words corresponding to each quantization granularity level under the semantic granularity; based on the multiple candidate code words corresponding to the first quantization granularity level, quantizing the sub-vector to obtain the first code word corresponding to the first quantization granularity level; based on the sub-vector and the first code word, determining a first residual; based on the multiple candidate code words corresponding to the second quantization granularity level, quantizing the first residual to obtain the second code word corresponding to the second quantization granularity level; based on the first residual and the second code word, determining a second residual; based on the multiple candidate code words corresponding to the third quantization granularity level, quantizing the second residual until the code table corresponding to the sub-vector is obtained.

4. The method of claim 3, wherein, The method comprises the following steps: based on the code table corresponding to the sub-vector of each semantic granularity, constructing a two-dimensional grid table containing all code words, wherein each column of the two-dimensional grid table corresponds to a different semantic granularity, each row corresponds to a different quantization granularity, and the granularities corresponding to adjacent columns or rows are in a progressive relationship, and each element in the two-dimensional grid table corresponds to a code word under different semantic granularities and quantization granularities; based on the two-dimensional grid table, generating multiple code word sequences corresponding to the semantic vector, wherein the multiple code words in each code word sequence correspond to different quantization granularities and are sorted in order from coarse to fine according to the quantization granularity; encoding the multiple code word sequences to obtain multiple semantic encodings of the semantic vector.

5. The method of claim 4, wherein, After the two-dimensional grid table containing all code words is constructed based on the code table corresponding to the sub-vector of each semantic granularity, the method further comprises the following steps: encoding the first code word in each column in order from coarse to fine according to the semantic granularity corresponding to each column to obtain the semantic encoding of the first semantic vector.

6. The method of any one of claims 1-5, wherein, After the multiple semantic encodings of the semantic vector are obtained based on the code tables corresponding to the sub-vectors of different semantic granularities, the method further comprises the following steps: generate a plurality of fine-tuning data pairs based on the text corresponding to the semantic vector and the plurality of semantic encodings, wherein the text and one of the semantic encodings are included in one of the fine-tuning data pairs; fine-tune a generative model based on the plurality of fine-tuning data pairs.

7. A semantic coding apparatus characterized by comprising: The method comprises the following steps: determining a semantic vector to be processed and a semantic granularity level; acquiring a plurality of sub-vectors of different semantic granularities from the semantic vector based on the semantic granularity level; quantizing each of the sub-vectors of different semantic granularities to obtain a code table corresponding to the sub-vector of the semantic granularity, wherein the code table comprises a plurality of code words; encoding the semantic vector based on the code tables corresponding to the sub-vectors of different semantic granularities to obtain a plurality of semantic encodings of the semantic vector.

8. An electronic device, comprising: The method comprises the following steps: at least one processor; and a memory connected in communication with the at least one processor; wherein the memory stores instructions likely to be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1-6.

9. A non-transitory computer-readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to enable the computer to execute the method of any one of claims 1-6.

10. A computer program product comprising a computer program, characterized in that, The computer program, when executed by the processor, implements the method of any one of claims 1-6. The computer program, when executed by the processor, implements the method of any one of claims 1-6.