A text semantic hashing method, device, equipment and storage medium supporting extensible categories
The text feature autoencoder and language model autoencoder are used to construct an extensible hierarchical category information representation sequence and embed category and keyword information, which solves the problem of difficulty in supporting extended category encoding in the existing technology and realizes text semantic hashing. Scalability and efficient retrieval.
Patent Information
- Application Number
- CN202410888364.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-07-04
AI Technical Summary
Existing text semantic hashing technology is difficult to support extended category encoding and cannot meet the scalable category encoding requirements for text semantic hashing under new categories in real applications.
Using text feature autoencoder and language model autoencoder of tag text sequence, a scalable hierarchical category information representation sequence is constructed, and category and keyword information are embedded into the hash code through the document content hash module and tag sequence hash module. , implements textual semantic hashing that supports extensible categories.
Without the need to refit and train new category data, it supports users to freely define category retrieval, reduces model update resource overhead, and improves the coding ability and hash retrieval efficiency of extended category information.
Smart Images

Figure CN118410773B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing and information retrieval, and in particular to a text semantic hashing method, device, equipment and storage medium supporting extensible categories. Background Art
[0002] Text semantic hashing is an encoding technology that maps documents from the original high-dimensional symbolic feature space to a low-dimensional binary address space through hashing. It can map semantically similar documents to similar address spaces, so that the distance between hash codes can be measured by the Hamming distance, that is, semantics can be embedded in the text encoding. Compared with the traditional expensive computing power and time consumption of calculating similarity in Euclidean space, text semantic hashing only needs to calculate the Hamming distance to evaluate the semantic similarity between documents, which significantly improves the retrieval efficiency.
[0003] Usually, the category, keyword and other labels of the text can be used to assist in the construction of hash codes, that is, to embed information such as categories and keywords into the text encoding, so that texts with close distances are not only semantically close, but also have the same or similar categories. In an era of explosive growth in data volume, the category information of information retrieval systems is constantly updated and added. Therefore, text semantic hashing technology that supports scalable categories has important practical value in the field of large-scale information retrieval.
[0004] In the prior art, there have been many explorations in the direction of text semantic hashing:
[0005] Chinese patent document CN113449849A discloses a learning text semantic hashing method based on an autoencoder. The method uses a hash model of an autoencoder structure to complete the construction of a text semantic hashing model. However, the method only reconstructs the semantic information of the text itself and does not embed the category information of the document into the hash code.
[0006] Chinese patent document CN113821527A discloses a method, device, computer equipment and storage medium for generating a hash code, which obtains an initial hash code by encoding a text, samples the initial hash code according to the sampling probability distribution of the initial hash code, obtains a posterior probability distribution of a semantic hash model, and corrects the initial hash code according to the posterior distribution. However, the method does not embed the category information of the document into the hash code.
[0007] Chinese patent document CN110955745A discloses a text hash retrieval method based on deep learning, which uses a classification layer to classify the encoded hash codes to incorporate category information. However, this method does not establish a clear similarity constraint relationship in the hash space, and only considers the integration of flat categories rather than hierarchical category information, and does not study the text semantic hash under the extended category.
[0008] Chinese patent document CN116662490B discloses a deobfuscated text hashing algorithm and device that integrates hierarchical label information. This method uses the class semantic center to represent the implicit intra-class semantic association of the sample, thereby constraining semantically similar heterogeneous samples to stay away from the center. Although this method removes the influence of ambiguous samples under hierarchical category labels, it is difficult to support text semantic hashing encoding under scalable categories.
[0009] In summary, although the existing text semantic hashing technology can generally realize hash embedding of text semantics and fixed categories, it is difficult to support extended category coding and cannot meet the scalable category coding requirements of text semantic hashing with newly added categories in real applications. Summary of the invention
[0010] The purpose of the present invention is to provide a text semantic hashing method, device, equipment and storage medium that supports scalable categories. The method can solve the shortcomings of the prior art and adopt a text feature autoencoder and a language model autoencoder of a label text sequence to achieve maximizing the retention of semantics in text encoding while embedding categories, keywords and other information, and support user-defined category retrieval.
[0011] To achieve the above object, the present invention adopts the following technical solutions:
[0012] In a first aspect of the present invention, a text semantic hashing method supporting scalable categories is disclosed, the method comprising the following steps:
[0013] S1. Obtaining surface features of text .
[0014] S2. Constructing a scalable hierarchical category information representation sequence ; The scalable hierarchical category information representation sequence It is a text sequence consisting of multiple category labels and multiple keywords set in sequence.
[0015] S3, constructing a text semantic hash model, wherein the text semantic hash model includes a document content hash module and a tag sequence hash module; using the document content hash module to Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
[0016] According to the preferred embodiment of the present invention, in step S1, the surface features of the text are obtained ,include:
[0017] S11. Use the coarse-grained word segmenter of the open source word segmentation tool HanLP to segment the text in the corpus.
[0018] S12. Remove Chinese stop words from the word segmentation results and sort the word list from high to low according to the word frequency , according to the vocabulary Calculate the word frequency-inverse document frequency statistic TF-IDF for each text and use TF-IDF as the surface feature .
[0019] Preferably, according to the present invention, in step S2, the multiple category labels are arranged in sequence from front to back in a descending order of hierarchy, and the hierarchy is calculated by the category labels; wherein, if a directory tree is given, the root directory is the highest level, i.e., level one, the sublevel of the root directory is level two, and subsequent levels are successively lowered; the multiple keywords are located at the back of the multiple category labels, and the multiple keywords are sorted according to the importance given by the TextRank tool.
[0020] Preferably, in step S3, a text semantic hash model is constructed, wherein the text semantic hash model includes a document content hash module and a tag sequence hash module; the document content hash module is used to convert the surface features into Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories ,include:
[0021] S31, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded as an embedded representation of the document , and embedding representation of the document Hierarchical category similarity constraints, regularity constraints and leaf category similarity constraints are imposed to reconstruct surface features and leaf category vectors, and the document content hash module is optimized during the reconstruction process.
[0022] S32, construct a label sequence hash module for the category semantic space, and use the label sequence hash module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence ,The label sequence hashing module is optimized during the reconstruction process.
[0023] S33, encoding the document content hash module and the tag sequence hash module and Perform threshold conversion respectively to obtain the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
[0024] According to the preferred embodiment of the present invention, in step S31, a document content hash module integrating hierarchical category information is constructed, and the surface features are converted into Encoded as an embedded representation of the document , and embedding representation of the document Apply hierarchical category similarity constraints, regularity constraints, and leaf category similarity constraints to reconstruct surface features and leaf category vectors. During the reconstruction process, optimize the document content hash module, including:
[0025] S311, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded into document embedding representation .
[0026] The document content hash module uses a multi-layer perceptron as a document encoder , using the document encoder shown in formula (1) Encoded as an embedded representation of the document , and after the text semantic hash model is trained, the document embedding representation is expressed using formula (2) Pass Threshold Converted to document hash code:
[0027] (1);
[0028] (2);
[0029] In formula (1) and formula (2), is the embedded representation of the document; is a document encoder; Hash code for the document No. Dimension value; For embedding representation No. Dimension value; is the binarization function; It is a threshold value that can be adjusted according to actual conditions.
[0030] S312. Using formula (3)-formula (5), embed the document Hierarchical category similarity constraints are imposed, and random sampling is used to model the document similarity based on hierarchical categories for the training set data. The established model is optimized using the objective function of hierarchical category similarity embedding shown in formula (6):
[0031] (3);
[0032] (4);
[0033] (5);
[0034] In formula (3)-formula (5), For two different documents and Hierarchical category similarity scores; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; For Documentation The number of levels of the category label. The value of the number of levels is equivalent to the level of the leaf directory of the directory tree; It is an indicator function, which takes the value 1 when the two variables are equal and 0 otherwise; are any two category labels; for Corresponding to Control coefficient of the layer; for Corresponding to -1 layer control coefficient.
[0035] (6);
[0036] In formula (6), for any surface feature satisfy ; is the objective function for hierarchical category similarity embedding; is an exponential function; and Corresponding to and Embedding representation of ; Negative samples gather.
[0037] S313: Embedding representation into document Apply a regularization term that is close to binary to perform regularization constraints: During training, the regularization term shown in formula (7) is used to make Close to the result after binarization to give Binary properties:
[0038] (7);
[0039] In formula (7), represents the regularization term; Surface characteristics Embedding representation of ; is the binarization function.
[0040] S314, using the loss function shown in formula (8) , the embedding representation of the document Imposing similarity constraints on leaf categories:
[0041] (8);
[0042] In formula (8), is the loss function for the leaf category similarity constraint; Documents in the same training batch matrix; for The transposed matrix of is the document hash code length; is the leaf category similarity matrix.
[0043] S315, using formula (9), through the document decoding network Reconstructing surface features , in reconstructing surface features In the process, the text hash module is optimized using the objective function shown in formula (10):
[0044] (9);
[0045] In formula (9), The reconstructed surface features output by the model; Decode the network for the document; Surface characteristics Embedding representation of; In the text semantic hashing model, the embedding representation of the document Input document decoding network , and output the original features .
[0046] (10);
[0047] In formula (10), Surface characteristics The reconstruction loss is For surface characteristics, It is the reconstructed surface features output by the model.
[0048] S316, using formula (11), through the category decoding network Reconstruct the leaf category vector to represent the embedding of the document The leaf category information is introduced in the process of reconstructing the leaf category vector, and the optimization loss of the process of reconstructing the leaf category vector is used as shown in formula (12):
[0049] (11);
[0050] (12);
[0051] In formula (11) and formula (12), To reconstruct the leaf category vector; Decode the network for the category; is the embedded representation of the document; The optimization loss for the process of reconstructing the leaf category vector; Surface characteristics The corresponding category vector.
[0052] According to a preferred embodiment of the present invention, in step S32, the label sequence hash module for constructing the category semantic space uses the label sequence hash module to represent the scalable hierarchical category information sequence. Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence , optimize the label sequence hash module during the reconstruction process, including:
[0053] S321, build a label sequence hash module, the label sequence hash module uses BART as the backbone network and uses a sequence encoder Scalable hierarchical category information representation sequence for input Encode to get the embedded representation of the sequence ; Sequence Encoder Use BART encoder to represent the scalable hierarchical category information of the input sequence Encode and reduce the dimension based on the linear transformation network, using the formula (13) Corresponding embeddings of tags As input sequence The embedding representation of :
[0054] (13);
[0055] In formula (13), for Corresponding embedding representation of the tokens; It is a special marker for the BART model; is a sequence encoder.
[0056] S322, embedding and displaying the sequence Regularization constraints , so that it is close to the binary hash value.
[0057] S323. Use formula (14) to obtain the keyword sequence The embedding representation of , and use formula (15) to add the keyword sequence The embedding representation of Embedding representation of sequences Regular constraints that are close to each other:
[0058] (14);
[0059] (15);
[0060] In formula (14) and formula (15), It is a special marker for the BART model; k 1 is the first keyword, k 2 is the second keyword; is a sequence encoder; For keyword sequence The embedding representation of and scalable hierarchical category information representation sequence The embedding representation of Regular constraints that are close to each other; For keyword sequence The embedding representation of is the embedding representation of the sequence.
[0061] S324, using sequence decoder Embedding representation of sequence Decode and reconstruct the scalable hierarchical category information representation sequence , the reconstructed scalable hierarchical category information representation sequence is used The process is shown in formula (16):
[0062] (16);
[0063] In formula (16), is the output probability of the decoding process; Represents a sequence of scalable hierarchical category information representation No. The predicted probability of a word; is the embedding representation of the sequence; Represents a sequence of scalable hierarchical category information representation Before The predicted probability of a word.
[0064] S325, in the sequence decoder In the above example, we first use linear transformation to embed the sequence The dimension is upgraded and the result is input into the BART decoder for decoding. During the decoding process, a mask strategy in which only [CLS] is visible is adopted. It is a special marker for the BART model.
[0065] S326. Use the objective function shown in formula (17) to obtain the sequence embedding representation Maximize embedding The semantic similarity information of is used to optimize the label sequence hashing module:
[0066] (17);
[0067] In formula (17), To reconstruct the sequence The optimization objective function of is the cross entropy calculation function; Represents an extensible hierarchical category information representation sequence; Represents the sequence of reconstructed scalable hierarchical category information.
[0068] Preferably, in step S3, the text semantic hash model is optimized independently in modules, and the document content hash module is optimized by using the objective function shown in formula (18), and the label sequence hash module remains unchanged; the label sequence hash module is optimized by using the objective function shown in formula (19), and the document content hash module remains unchanged:
[0069] (18);
[0070] (19);
[0071] In formulas (18) and (19), Optimize the objective function for the overall network of the document content hashing module; Surface characteristics The reconstruction loss is The objective function for hierarchical category similarity embedding The weights control the hyperparameters, is the weight hyperparameter for embedding leaf category information, is the optimization loss for the process of reconstructing the leaf category vector, is the loss function for the leaf category similarity constraint The weight hyperparameters are Regularization control for embedding representation and The weight hyperparameters are The overall network optimization objective function for the sequence hashing module, To reconstruct the sequence The optimization objective function is For embedding representation and embedding representation Mutual proximity constraints The weight hyperparameters of .
[0072] In a second aspect of the present invention, a text semantic hashing device supporting extensible categories is disclosed, which includes a surface feature acquisition module, an extensible hierarchical category information representation sequence construction module and a text semantic hashing module.
[0073] The surface feature acquisition module is used to acquire the surface features of the text .
[0074] The extensible hierarchical category information representation sequence construction module is used to construct an extensible hierarchical category information representation sequence ; The scalable hierarchical category information representation sequence It is a text sequence consisting of multiple category labels and multiple keywords set in sequence.
[0075] The text semantic hash module includes a document content hash module and a tag sequence hash module; the document content hash module is used to convert the surface features Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
[0076] In a third aspect of the present invention, an electronic device is disclosed, comprising: at least one processor; and a memory, wherein the memory stores instructions, which, when executed by the at least one processor, enable the at least one processor to execute the above-mentioned text semantic hashing method supporting extensible categories.
[0077] In a fourth aspect of the present invention, a machine-readable storage medium is disclosed, which stores executable instructions, and when the instructions are executed, the machine executes the above-mentioned text semantic hashing method supporting extensible categories.
[0078] Compared with the prior art, the advantages of the present invention are:
[0079] (1) The present invention uses the document word frequency inverse document word frequency to represent the document content, and uses category labels and keyword sequences to represent hierarchical category information. An autoencoder is used to encode the document content representation to retain the original semantics of the text in the hash code to the greatest extent; at the same time, contrastive learning is used to optimize the document encoder to embed the category information into the hash code. An autoencoder based on a pre-trained language model is used to encode the category information and keyword sequence, supporting semantic encoding of the original category and the extended category label sequence in a unified space, thereby supporting scalable dynamic hierarchical category information. During the use stage, the combined encoding of the document content and the category label sequence is used as the document semantic encoding, thereby supporting text semantic hash retrieval of categories and keywords freely defined by users.
[0080] (2) The present invention adopts an autoencoder to encode the document content, which can retain the original semantics of the document to the greatest extent, and adopts contrastive learning to optimize the encoder. Compared with the prior art which is limited to a fixed number of levels of categories, the optimization method adopted by the present invention can embed a more general number of levels, thereby better adapting to freely defined hierarchical categories.
[0081] (3) The present invention uses a pre-trained language model autoencoder to encode the label sequence. Compared with the prior art that does not consider the semantics of category labels, the present invention can describe categories and keyword sequences in a unified category semantic space, thereby better semantically encoding the extended category.
[0082] (4) The present invention uses the combination of document encoding and label sequence encoding as the hash result of the document. Compared with the prior art that integrates category information into document hash encoding, the present invention can decouple the document content semantics, category and keyword semantics, and better support hash similarity retrieval of user-defined categories and keywords.
[0083] (5) The present invention can be used on other similar tasks in the field of natural language processing, such as hierarchical text representation learning, hierarchical text classification and other related tasks based on hierarchical labeling scenarios, and has a very wide range of applications. The application scenario of the present invention is text encoding and retrieval scenarios, and can be applied to downstream tasks such as information retrieval and interest recommendation. The present invention enables the text semantic hash model to have the ability to encode new category information without re-fitting and training the data under the new category, that is, it supports the ability to encode expandable category information, thereby reducing the resource overhead caused by repeated training of the text semantic hash model and online system operation model updates. Extended category encoding refers to encoding categories outside the training set. The present invention enables the model to have the ability to encode new category information without re-training the data under the new category. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] Figure 1 It is a schematic diagram of the text semantic hashing method supporting extensible categories in the present invention;
[0085] Figure 2 It is a schematic diagram of the modification of the pre-trained network in the present invention;
[0086] Figure 3 The performance comparison between the present invention and the prior art is shown in FIG. Figure 1 ;
[0087] Figure 4 The performance comparison between the present invention and the prior art is shown in FIG. Figure 2 ;
[0088] Figure 5 The performance comparison between the present invention and the prior art is shown in FIG. Figure 3 ;
[0089] Figure 6 The performance comparison between the present invention and the prior art is shown in FIG. Figure 4 ;
[0090] Figure 7 The performance comparison between the present invention and the prior art is shown in FIG. Figure 5 ;
[0091] Figure 8 The performance comparison between the present invention and the prior art is shown in FIG. Figure 6 ;
[0092] Among them, Figure 3-Figure 8 In the figure, the horizontal axis represents the indicator category, and the specific category has been marked in the figure; the vertical axis represents the evaluation value. DETAILED DESCRIPTION
[0093] The present disclosure is further described below with reference to the accompanying drawings and embodiments:
[0094] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.
[0095] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0096] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.
[0097] The following is an introduction to the terms involved in the embodiments of the present disclosure:
[0098] (1) Text semantic hashing: refers to an encoding technology that maps documents from their original high-dimensional symbolic feature space to a low-dimensional binary address space through hashing. It can map semantically similar documents to similar address spaces, so that the distance between hash codes can be measured by the Hamming distance.
[0099] (2) Hamming distance: The number of different bit values in two strings is called the Hamming distance. Perform an XOR operation on two hash codes and count the number of bits that are 1. The result is the Hamming distance.
[0100] (3) Similarity retrieval: Also known as nearest neighbor search, its purpose is to find the most similar items in a large-scale database based on the user's query statement. Similarity retrieval has important applications in large-scale data retrieval.
[0101] (4) Neural network: In the field of machine learning and cognitive science, it is a mathematical model or computational model that imitates the structure and function of biological neural networks (the central nervous system of animals, especially the brain) and is used to estimate or approximate functions.
[0102] Some commonly used symbols in the present invention are described below:
[0103] Represents the original document; TF-IDF represents the term frequency-inverse document frequency statistics, which is usually used as a statistical representation vector of the document; Represents the vocabulary used to calculate document representation, that is, considering the words in the vocabulary to represent the document; Represents the surface features corresponding to the document, that is, the TF-IDF vector corresponding to the document, in the vocabulary Calculate the TF-IDF feature values of all words and form the vector; Indicates the hash code corresponding to the original document X, consisting of 0 and 1; Indicates the continuous vector before the hash code is binarized, which is used in the training and optimization process of the model; Indicates the hierarchical category vector to which the original document belongs, consisting of 0 and 1; represents the exponential function; Represents the loss term, which is used to optimize the neural network.
[0104] The present invention belongs to the field of natural language processing technology, and the field is explained as follows: Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, language understood by humans, so it is closely related to the study of linguistics. Natural language processing technology generally includes text processing, semantic understanding, machine translation, robot question answering, knowledge graphs and other technologies.
[0105] Example 1
[0106] This embodiment provides a text semantic hashing method supporting scalable categories, which mainly designs a dimensionality reduction network and a mask strategy that is only visible to CLS.
[0107] like Figure 1As shown, the text semantic hashing method supporting extensible categories includes the following steps:
[0108] S1. Obtaining surface features of text .
[0109] The English name of the surface feature is obvious feature. Preferably, the surface feature is characterized by using the term frequency-inverse document frequency statistic TF-IDF.
[0110] In step S1, the surface features of the text are obtained ,include:
[0111] S11. Use the coarse-grained word segmenter of the open source word segmentation tool HanLP to segment the text in the corpus.
[0112] S12. Remove Chinese stop words from the word segmentation results and sort the word list from high to low according to the word frequency , according to the vocabulary Calculate the word frequency-inverse document frequency statistic TF-IDF for each text and use TF-IDF as the surface feature Surface characteristics As input to the document content hashing module of the text semantic hashing model.
[0113] S2. Constructing a scalable hierarchical category information representation sequence .
[0114] The scalable hierarchical category information representation sequence It is a text sequence consisting of multiple category tags and multiple keywords set in sequence. The multiple category tags are arranged from front to back in order from high to low, and the hierarchy is calculated by the category tags; wherein, if a directory tree is given, the root directory is the highest level, that is, level one, the sublevel of the root directory is level two, and the subsequent levels are successively lower. The multiple keywords are located at the back of the multiple category tags, and the multiple keywords are sorted according to the importance given by the TextRank tool, which can be considered to be automatically arranged according to the TextRank tool. Serves as input to the sequence hashing module of the text semantic hashing model.
[0115] Specifically, the scalable hierarchical category information representation sequence It is a constructed text sequence. The high-level category labels are placed at the front of the sequence, and the subsequent category labels are arranged in sequence.
[0116] For any two documents, as long as their corresponding scalable hierarchical category information representation sequence is given, their category semantic similarity can be measured in a feature space that uniformly describes the hierarchical category semantics.
[0117] Therefore, for the updated category information, the text semantic hash model can still encode it in the corresponding category description semantic space, so that the text semantic hash model has the hash encoding capability of scalable category information.
[0118] S3, constructing a text semantic hash model, wherein the text semantic hash model includes a document content hash module and a tag sequence hash module; using the document content hash module to Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
[0119] Construct a text semantic hash model and make the model work well in the training dataset Train( ) after training, we have the dataset Base( )Good hash encoding capabilities on text data.
[0120] For an original document X , the document is an unstructured document, let For Documentation The corresponding tag set, For the Layer category labels; For Documentation The corresponding keyword set, For the Keywords.
[0121] The text semantic hashing task is to learn a hash function to convert unstructured documents into Encoded as length The hash code , formally expressed as , its hash code needs to satisfy the similarity of hierarchical categories and keywords, that is, for any two documents, the more the same categories and semantically similar keywords are, the closer the Hamming distance of their corresponding hash codes is. In addition, since the category label information of the query document is usually not available in real scenarios, its keywords are obtained through methods such as Text-Rank. The present invention does not limit the method of obtaining keywords. In the retrieval stage, the i-th keyword of the retrieval document is used Replace the i-th level category label Hash encoding is performed. Text-Rank is an open source keyword extraction tool commonly used in the field of natural language.
[0122] For example, for the text semantic hashing task supporting scalable categories, let the category label set Label Set ,in, l i1 For the i1 The class labels of the layers, l i2 For the i2 The class labels of the layers, l j1 For the j1 The class labels of the layers, l j2 For the j2 The category label of the layer. Given a training dataset Train( ), the label set to which it belongs is , the dataset to be retrieved Base( ), the label set to which it belongs is , that is, the data set to be retrieved contains all the category labels in the training data set and contains additional category label information.
[0123] The problem solved by the present invention is to construct a text semantic hash model so that the model can be used in a training data set Train ( ) after training, we have the dataset Base( )Good hash encoding capabilities on text data.
[0124] S31, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded as an embedded representation of the document , and embedding representation of the document Hierarchical category similarity constraints, regularity constraints and leaf category similarity constraints are imposed to reconstruct surface features and leaf category vectors, and the document content hash module is optimized during the reconstruction process.
[0125] To preserve unstructured documents The basic goal of text semantic hashing technology is to serve large-scale information retrieval systems. In large-scale corpora, different documents have different lengths, and there may be too long documents. Using plain text input will bring difficulties in calculation and processing. Therefore, surface features are used. As the input of the document content hash module of the text semantic hash model. The advantage of retrieval is that it can express the semantic information of documents of arbitrary length in a specific space and support keyword retrieval.
[0126] In order to retain the semantic information of the document to the greatest extent, the present invention adopts a text feature autoencoder to complete the semantic embedding of the document content, that is, the input of the document content hash module is the surface feature , the output is the reconstructed surface features The text feature autoencoder consists of two parts: encoder and decoder.
[0127] S311, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded into document embedding representation .
[0128] Taking into account the characteristics of statistical feature vectors, the document content hash module in the present invention uses a multi-layer perceptron as a document encoder. , using the document encoder shown in formula (1) Encoded as an embedded representation of the document , and after the text semantic hash model is trained, formula (2) is used to pass the threshold Converted to document hash code:
[0129] (1);
[0130] (2);
[0131] In formula (1) and formula (2), is the embedded representation of the document; is a document encoder; Hash code for the document No. Dimension value; For embedding representation No. Dimension value; is the binarization function; It is a threshold value that can be adjusted according to actual conditions, such as "0".
[0132] S312: Embedding representation of document Imposing hierarchical category similarity constraints.
[0133] In order to maximize the use of the existing hierarchical category label information in the training data set, documents with similar label information are made close, and dissimilar documents are made far away.
[0134] The present invention designs To express two different documents and The hierarchical category similarity score of , the detailed calculation process is introduced below:
[0135] Given two documents and , similarity can be measured by the corresponding weighted label overlap, and the similarity function corresponds to the following formula (3). For example, for a set of hierarchical category labels "sports ball sports basketball", the number of levels of its category labels is The value of is equivalent to the level of basketball, which is "3":
[0136] (3);
[0137] (4);
[0138] (5);
[0139] In formula (3)-formula (5), For two different documents and Hierarchical category similarity scores; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; For Documentation The number of levels of the category label. The value of the number of levels is equivalent to the level of the leaf directory of the directory tree; It is an indicator function, which takes the value 1 when the two variables are equal and 0 otherwise; are any two category labels; for Corresponding to Control coefficient of the layer; for Corresponding to -1 layer control coefficient.
[0140] Based on the hierarchical category similarity scores calculated above, the present invention embeds the similarity in the hash space. Similarity constraints are imposed. Random sampling is used to model the document similarity based on hierarchical categories in the training set data.
[0141] The objective function of hierarchical category similarity embedding is shown in formula (6). For any surface feature satisfy :
[0142] (6);
[0143] In formula (6), for and Hierarchical category similarity scores; for and Hierarchical category similarity scores; is the objective function for hierarchical category similarity embedding; is an exponential function; and Corresponding to and Embedding representation of ; Negative samples gather.
[0144] S313: Embedding representation into document A regularization term close to binary is applied to perform regularization constraints. During training, the regularization term shown in formula (7) is used to make Close to the result after binarization, thus giving Binary properties:
[0145] (7);
[0146] In formula (7), represents the regularization term, Surface characteristics Embedding representation of ; is the binarization function.
[0147] S314. Using formula (8), embedding representation of the document Similarity constraints on leaf categories are imposed to enhance the performance of hash code exact query.
[0148] Using leaf class constraint loss Function to embed leaf category similarity information. First, construct the leaf category similarity matrix , where for the input document set of the same training time step, if any document and Documentation belong to the same leaf category, then the matrix Middle i OK j Column value is 1, otherwise it is zero.
[0149] Using the loss function shown in formula (8) , for surface features The embedding representation of Imposing leaf category similarity constraints:
[0150] (8);
[0151] In formula (8), is the loss function for the leaf category similarity constraint; Documents in the same training batch matrix; for The transposed matrix of is the document hash code length; is the leaf category similarity matrix.
[0152] S315, using formula (9), through the document decoding network Reconstructing surface features , and reconstruct the surface features In the process, the document content hash module is optimized by the objective function shown in formula (10). Reconstruct surface features well ,So Can well characterize semantic information.
[0153] In the text semantic hashing model, the document embedding representation Input document decoding network , and output the original features :
[0154] (9);
[0155] In formula (9), The reconstructed surface features output by the model; Decode the network for the document; is the embedding representation of the document.
[0156] In order to reconstruct the surface features output by the text semantic hashing model during training Surface features Close, so that the document embedding representation It can retain the semantic similarity of the original document to the greatest extent possible and optimize the text semantic hash model using the objective function shown in formula (10):
[0157] (10);
[0158] In formula (10), Surface characteristics The reconstruction loss is For surface characteristics, It is the reconstructed surface features output by the model.
[0159] S316, using formula (11), through the category decoding network Reconstruct the leaf category vector to represent the embedding of the document The leaf category information is introduced in the process of reconstructing the leaf category vector, and the optimization loss of the process of reconstructing the leaf category vector is used as shown in formula (12):
[0160] (11);
[0161] (12);
[0162] In formula (11) and formula (12), To reconstruct the leaf category vector; Decode the network for the category; is the embedded representation of the document; The optimization loss for the process of reconstructing the leaf category vector; Surface characteristics The corresponding category vector.
[0163] S32, construct a label sequence hash module for the category semantic space, and use the label sequence hash module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence ,The label sequence hashing module is optimized during the reconstruction process.
[0164] The construction idea of the label sequence hashing module is to organize them in sequence according to the category similarity level and combine them with document keywords to form a serialized expression.
[0165] The present invention uses the commonly used pre-trained language model BART as the backbone network of the tag sequence hashing module, and the overall architecture of the network is an encoder-decoder structure. Based on the self-attention mechanism, the network can learn the interactive semantic relationship between tags in the construction sequence, and can encode and perceive the position information of each tag, so as to learn to measure the semantic similarity of the text description between any two tag sequences.
[0166] Extensible Category Information Representation Sequence In the implementation, the input form is organized into a BART network: ,in, and is a special marker for the BART model. is the label of the corresponding level, For the Keywords.
[0167] S321, using sequence encoder Scalable hierarchical category information representation sequence for input Encode to get the embedded representation of the sequence .
[0168] Use BART encoder to represent the scalable hierarchical category information of the input sequence Encode and reduce the dimension based on the linear transformation network, such as Figure 2 As shown, and using formula (13) Corresponding embeddings of tags As input sequence The embedding representation of :
[0169] (13);
[0170] In formula (13), for The corresponding embedding representation of the tag, is a sequence encoder.
[0171] S322. Embedding representation of sequence Regularization constraints , making it close to the binary hash value.
[0172] S323. Use formula (14) to obtain the keyword sequence The embedding representation of , and use formula (15) to add the keyword sequence The embedding representation of Embedding representation of sequences Regular constraints that are close to each other:
[0173] (14);
[0174] (15);
[0175] In formula (14) and formula (15), It is a special marker for the BART model; k1 is the first keyword, k 2 is the second keyword; is a sequence encoder; For keyword sequence The embedding representation of and scalable hierarchical category information representation sequence The embedding representation of Regular constraints that are close to each other; For keyword sequence The embedding representation of Representing Sequences for Scalable Hierarchical Category Information The embedded representation of .
[0176] The significance of step S323 is that if the query document does not carry hierarchical category information in the retrieval stage, the regular term can enable the user to better find documents under the keyword-related category.
[0177] S324, using sequence decoder Embedding Decode and reconstruct the scalable hierarchical category information representation sequence , the reconstructed scalable hierarchical category information representation sequence is used The process is shown in formula (16):
[0178] (16);
[0179] In formula (16), is the output probability of the decoding process, Represents a sequence of scalable hierarchical category information representation No. The predicted probability of a word, Representing Sequences for Scalable Hierarchical Category Information The embedding representation of Represents a sequence of scalable hierarchical category information representation Before The predicted probability of a word.
[0180] S325, in the sequence decoder In the above example, we first use linear transformation to embed the sequence Then input into the BART decoder as Figure 2 shown.
[0181] During the decoding process, the present invention designs a mask strategy that is only visible to [CLS], so that only the sequence is embedded in the representation As a sequence decoder Input information, so that only the relevant encoding information of the pooling representation [CLS] is used in the decoding process, so that it can better represent the entire label sequence. It is a special marker for the BART model.
[0182] S326. Use the objective function shown in formula (17) to obtain the sequence embedding representation Maximize embedding The semantic similarity information of is used to optimize the label sequence hashing module:
[0183] (17);
[0184] In formula (17), To reconstruct the sequence The optimization objective function of is the cross entropy calculation function; Represents an extensible hierarchical category information representation sequence; is the reconstructed scalable hierarchical category information representation sequence. The goal of the sequence hash module in the decoding process is to reconstruct the scalable hierarchical category information representation sequence , thus the embedding representation Maximize embedding The semantic similarity information of is realized through the objective function shown in formula (17).
[0185] S33, encoding the document content hash module and the tag sequence hash module and Splice to get the document semantic hash implicit code that supports extensible categories , document semantic hashing implicit coding Transformation to document semantic hash codes with scalable categories via thresholding .
[0186] Through the above discussion, the text semantic hash model proposed in the present invention is optimized independently by modules through the following objective function, that is, when optimizing the document content hash module, the sequence hash module can remain unchanged, and vice versa:
[0187] (18);
[0188] (19);
[0189] In formulas (18) and (19), Optimize the objective function for the overall network of the document content hashing module; Surface characteristics The reconstruction loss of The objective function for hierarchical category similarity embedding The weights of control hyperparameters; The weight hyperparameter for embedding leaf category information; The optimization loss for the process of reconstructing the leaf category vector; is the loss function for the leaf category similarity constraint The weight hyperparameters of Regularization control for embedding representation and The weight hyperparameters of Optimize the objective function for the overall network of the sequence hashing module; To reconstruct the sequence The optimization objective function of For embedding representation and embedding representation Mutual proximity constraints The weight hyperparameters of .
[0190] The document content hash module and sequence hash module proposed in the present invention can be optimized independently, using the corresponding objective function and That's it.
[0191] Example 2
[0192] This embodiment provides a text semantic hashing device supporting scalable categories, which can apply the above-mentioned text semantic hashing method supporting scalable categories. The device includes a surface feature acquisition module, an scalable hierarchical category information representation sequence construction module and a text semantic hashing module. The surface feature acquisition module is used to acquire the surface features of the text. . Scalable hierarchical category information representation sequence construction module, used to construct scalable hierarchical category information representation sequence .
[0193] (1) The document content hashing module is implemented based on the autoencoder framework.
[0194] The encoder uses a multilayer perceptron, or MLP for short. The MLP consists of a neural network and an activation function that can calculate input features.
[0195] The surface features of the document Mapped into a continuous hidden distribution space, and after training, the hash code is obtained through threshold conversion. The encoding process is:
[0196] Using formula (20) the surface characteristics Input the multi-layer perceptron for encoding to obtain the embedded representation of the document :
[0197] (20);
[0198] In formula (20), is the embedding representation of the document, It is a multi-layer perceptron.
[0199] Using formula (21)-formula (24), the document decoder uses linear transformation to obtain the latent vector corresponding to document reconstruction and category label prediction, and then reconstructs the original feature representation through the activation function and predicts the corresponding label:
[0200] (twenty one);
[0201] (twenty two);
[0202] In formula (21) and formula (22), Represents the corresponding position in the document decoder output vector Output: is the embedded representation of the document; is the decoding network parameter matrix; For the corresponding One-hot vector of dimension ; is the network bias term; Represents the corresponding position in the prediction network output vector Output: is the prediction network parameter matrix; For the corresponding One-hot vector of dimension ; is the network bias term;
[0203] (twenty three);
[0204] (twenty four);
[0205] In formula (23) and formula (24), express The result after Softmax calculation on the document decoder output vector; Represents the corresponding position in the document decoder output vector Output: Represents the corresponding position in the document decoder output vector Output: express The result after Softmax calculation on the leaf category vector; Represents the corresponding position in the prediction network output vector Output: Represents the corresponding position in the prediction network output vector Output: is a set of leaf categories; Represents an exponential function.
[0206] (2) Label sequence hashing module, implemented based on the BART network.
[0207] use represents a sequence encoder, Represents a sequence decoder. Use BART encoder to represent the scalable hierarchical category information of the input sequence Encode and reduce the dimension based on the linear transformation network, such as Figure 2 As shown. Use Corresponding embeddings of tags As input sequence The embedding representation of :
[0208] (25);
[0209] In formula (25), for Corresponding embedding representation of the tokens; is a sequence encoder; Represents an extensible hierarchical category information representation sequence; It is a special marker for the BART model.
[0210] During the decoding process, the present invention only Visible mask strategy, achieving only the embedding representation of the sequence As a sequence decoder Input information, so that only pooling representation is used in the decoding process The relevant encoding information of , so that it can better represent the entire label sequence. Sequence decoder In the specific implementation, the sequence will be embedded and displayed first. Perform linear transformation to increase dimension, and then input the result of the dimension increase into the BART decoder.
[0211] The goal of the model proposed in this invention in the decoding process is to reconstruct the sequence , thus showing the embedding of the sequence Maximize embedding Semantic similarity information:
[0212] (27);
[0213] In formula (27), Representing the sequence of scalable hierarchical category information after reconstruction; is the embedding representation of the sequence; Represents a sequence decoder.
[0214] Reconstruction sequence The process is shown in formula (28):
[0215] (28);
[0216] In formula (28), is the output probability of the decoding process; Represents an extensible hierarchical category information representation sequence; Represents a sequence of scalable hierarchical category information representation No. The predicted probability of a word; Representing Sequences for Scalable Hierarchical Category Information Embedding representation of ; Represents a sequence of scalable hierarchical category information representation Before The predicted probability of a word.
[0217] Using formula (29), the document embedding representation obtained by encoding the above two modules is and the sequence embedding representation Using formula (30) through the threshold Convert to the corresponding hash code and ,Will and Concatenate documents with semantic hash codes that support extensible categories :
[0218] (29);
[0219] (30);
[0220] In formula (29) and formula (30), Combination of embedding representations encoded for the document content hash module and the sequence hash module; is the embedding representation of the corresponding document Binarized hash code; Embedding representation for the corresponding label sequence Binarized hash code; is the hash code of the corresponding embedded representation Dimension value; For embedding representation No. Dimension value; is the binarization function; It is a threshold value that can be adjusted according to actual conditions, such as "0".
[0221] In the retrieval stage, there are two cases, depending on whether the category label of the document is known or not. First, if the category label of the query document is known, a sequence with the same structure as the training set can be constructed. Second, if the category label of the query document is unknown, the keyword is used as the category label to construct a label sequence similar to the training set through automatic keyword extraction. Considered as Complete the encoding process. Get the constructed label sequence Then, combined with the document surface features , which can query documents Hash encoding.
[0222] In addition, since the goal of text semantic hashing is to achieve document semantic compression and introduce similarity information that is difficult to reflect in semantic representation based on labels such as categories, the present invention designs a weighted hash distance to respectively encode the document content hash module. and the tag sequence hash module encoding Perform weighted similarity measurement. For documents in the corpus , which is related to the query document The weighted Hamming distance The calculation is as follows:
[0223] (31);
[0224] In formula (31), is the weighted Hamming distance; is an adjustable weight parameter; is the Hamming distance calculation function; The document hash encoding result corresponding to the query document; The document hash encoding result corresponding to the result document; Hash encoding result of the sequence corresponding to the query document; The sequence hash encoding result corresponding to the result document is obtained. According to the weighted Hamming distance, the text semantic hash model in the present invention returns the retrieved documents with similar distance, so that the documents with the most relevant semantic and category information can be retrieved.
[0225] In the specific implementation details, the Pytorch framework is used as the basic code framework for model implementation. The encoder of the document hashing part uses MLP, and each layer has 1000 neurons and Leaky ReLU activation units. The present invention uses Dropout technology after the second layer to prevent overfitting problems, and sets the Dropout probability to 0.1. The weights of all network layers are initialized using the Xavier method, and the gradient is updated using a twin network. The model architecture of the sequence hashing part is based on the BART-base open source pre-trained model, and the encoded output is reduced in dimension and customized with a mask. Among them, in order to avoid overfitting the model to existing data during the fine-tuning stage, improve the training speed, and retain the original pre-training knowledge as much as possible, the weights of the first 4 layers of the BART encoder are frozen during training. After multiple rounds of hyperparameter tuning, the training learning rates of the document content hashing module and the sequence hashing module are set to 1e-3 and 1e-5, respectively, the batch size is set to 100, the number of rounds is 50 and 25, respectively, and the loss weight hyperparameter + number is set to , and It increases by 0.002 in each training step until the maximum value is 5. In order to fully retain the original document information and embed sufficient label information in the hash code, the ratio of the original document hash code length and the sequence hash code length is set to 3:1, that is, under a 64-bit hash code, the document hash code occupies 48 bits and the sequence hash code occupies 16 bits.
[0226] The overall framework principle diagram of the hash method and hash device described in the present invention is as follows: Figure 1 As shown, the modification diagram of the pre-trained network of the present invention is as follows Figure 2 shown.
[0227] In Example 1 and Example 2, a 64-bit hash code is used to quantitatively analyze the performance of the hash model proposed in the present invention.
[0228] The hash model of the present invention is trained and tested on the constructed Chinese data set, wherein the Chinese data set uses a plurality of supplementary teaching books and some news corpora collected, which are arranged into a hierarchical directory structure such as {Computer Science and Technology, Data Structure, Python Data Structure and Algorithm Analysis}. The data set is named BookCorpus. After the basic corpus sample is constructed, the present invention extracts multiple categories from it as data part A, which are all leaf categories under the first-level categories "Economics and Finance" and "News", as well as leaf categories "{Psychology, Experimental Psychology, Memory and Learning}" and "{Computer Science and Technology, Computer Network, Computer Network Original Book, Transport Layer}". The remaining directory categories divide the remaining samples into data part B and data part C in a ratio of 4:6. After the above processing, the number of samples of data part A is 3871, and the number of samples of part B and part C are 6717 and 4478 respectively.
[0229] In order to verify the model performance from different angles, the present invention constructs two evaluation data sets Ext Set and Cob Set on Book Corpus. In these two data sets, data part B is used as the training set. In the performance test, the construction method of the test set and the retrieved set is as follows:
[0230] In order to verify the model's encoding ability for extended categories, the data part A is used as the test set Test(X), and the combination of part A, part B and part C is used as the retrieved set Base(X), and the extensibility evaluation dataset Ext Set is constructed.
[0231] In order to verify the compatibility of the model for training set categories and extended categories, the data parts A and C are used as the test set Test(X), and parts A, B and C are used as the retrieved set Base(X), and the compatibility evaluation dataset CobSet is constructed.
[0232] The effectiveness of the model is verified from multiple perspectives, an evaluation strategy based on hierarchical categories and semantics is designed, and relevant comparison methods are introduced.
[0233] In order to better evaluate the similarity search performance of the model of the present invention, the present invention designs the following multi-angle evaluation performance:
[0234] (1) In order to evaluate the performance of precise query, the precision evaluation index is used . The retrieved result documents and the query documents Documents belonging to the same label (topic) are related (documents with the same label are considered related documents, that is, for related documents and , ) is scored as 1, otherwise it is 0. Before The average precision of search results:
[0235] (33);
[0236] In formula (33), and Respectively represent the document pair and The leaf category to which it belongs.
[0237] (2) In order to evaluate the performance of hierarchical category retrieval, define the hierarchical category evaluation index . Evaluate the retrieved documents and query documents The hierarchical correlation score of Before of search results Average value of the indicator. The calculation is as follows, where To query documents The number of levels of the category label. The value of the number of levels is equivalent to the directory level where the leaf category of the directory tree is located. For example, for a set of hierarchical category labels "sports ball sports basketball", the number of levels of its category labels is The value of is equivalent to the level of "basketball", which is "3":
[0238] (34);
[0239] In formula (34), Represents a query document No. Hierarchical category labels, Represents the result document No. Hierarchical category labels, For Documentation The number of levels of category labels, For the corresponding Control coefficient for layer class labels.
[0240] (3) In order to evaluate the hierarchical semantic similarity of the label set, the following evaluation indicators are defined: Among them, SP evaluates the maximum semantic similarity score average of the keywords of each search document and the label words of the result document (including keywords and category words after word segmentation), thereby measuring the maximum semantic match between the query and the result. SR, in turn, starts from the label words of the result document to find the similarity score of the search word with the maximum semantic match with each label word, thereby measuring the maximum semantic match between the result and the query. The harmonic mean of SP and SR is combined to evaluate the result document and the query document. Specifically, the semantic similarity is converted into a semantic matching score as shown in formula (35)-formula (37). is the semantic embedding of the keywords in the query, is the semantic embedding of the category and keywords of the result document, let Before The average semantic similarity of search results:
[0241] (35);
[0242] (36);
[0243] (37);
[0244] In formula (35) to formula (37), is the sum of the hierarchical label words of the result document, N is the sum of the keywords of the query document, Calculates the cosine similarity function.
[0245] To ensure evaluation fairness, this paper uses open-source Chinese pre-trained word embeddings for semantic evaluation, which comes from https: / / github.com / Embedding / Chinese-Word-Vectors.
[0246] Most of the existing text semantic hashing technologies are difficult to adapt to the task scenarios proposed in this section. Most methods only consider flat categories. The existing methods of integrating hierarchical category information to model text hashing are also limited to fixed category divisions and do not have general hierarchical category characteristics. In addition, these methods have not explored the scalability of the model, so the reference value is limited. Therefore, in this section, only two classic semantic hashing technologies under flat categories and an existing text semantic hashing technology that integrates two layers of categories are compared. The relevant information is Variational Deep Semantic Hashing (VDSH). The VDSH model adopts a variational self-encoding framework, which is the first successful application of this framework in text semantic hashing. It designs two versions that integrate flat categories, VDSH-S, and a modular network fusion version, VDSH-SP. Since it is set as a text semantic hashing technology under a flat category, the present invention trains the leaf category as its flat category. Neural Architecture for Semantic Hashing (NASH). This method regards the distribution of latent semantic representations learned by traditional VAE as a multivariate Bernoulli distribution, and proposes data-dependent noise decoding in NASH-DN-S, whose unsupervised versions are the NASH model and NASH-DN. Since it is set as a text semantic hashing technology under a flat category, the present invention trains the leaf category as its flat category. Intra-Category Aware HierarchicalSupervised Document Hashing (IHDH). IHDH is the first method to introduce hierarchical categories in the field of text semantic hashing. It uses a loss that associates parent and child class predictions to achieve a lower parent class error rate while improving the child class accuracy. In this experiment, the parent class of this method is replaced by the first-level category, and the child class is replaced by the leaf category. Ours (Ours-S) is used to represent the method of the present invention.
[0247] Based on the related technology of the present invention, the text is encoded into a 64-bit hash code, and the hash code of the query text is used to retrieve the hash code of the text to be queried to obtain the test results in Table 1. Due to space reasons, only the keywords and hierarchical category information related to the document are analyzed.
[0248] Table 1 Retrieval results on the Ext evaluation set
[0249]
[0250] The results in Table 1 show that the hash retrieval based on the model of the present invention has good semantic similarity performance and has a good recall effect on the extended category. Specifically, for the hash retrieval of the model of the present invention using the samples under the hierarchical "News Sports News", the result documents in the Top5 also belong to the hierarchical category, while the retrieval results of the comparison method contain documents of other categories and less semantically relevant documents such as "Probabilistic Graphical Model", which proves that the encoding ability of the method of the present invention for extended category information is better than that of the comparison method.
[0251] In the above embodiment, the retrieval performance of the text semantic hash model proposed in the present invention is evaluated on the 64-bit hash code using the H@K, P@K, and S@K indicators based on the constructed Chinese data set. Figure 3 , Figure 4 , Figure 5 , Figure 6 , Figure 7 , Figure 8 As shown, Figure 3 , Figure 4 , Figure 5 The evaluation performance on the Ext set is shown. Figure 6 , Figure 7 , Figure 8 The evaluation performance on the Cob set is shown. Figure 3-Figure 8 In the figure, the ordinate represents the evaluation value after percentage division.
[0252] The results show that the performance of the hashing technology of the present invention surpasses other existing technologies in all evaluation indicators, which fully proves the advantages of the text semantic hashing model proposed by the present invention. The results show that the model proposed by the present invention has better extended category encoding ability and better compatible retrieval ability in extended category information than the comparison method. Figure 3 , Figure 4 , Figure 5 The results show that the model of the present invention performs better than the baseline model in terms of the hierarchical category hit rate index H@K, the semantic similarity index S@K and the precise category hit rate index P@K, which shows that the model of the present invention has better encoding ability for category information not seen in training and better results in hash retrieval in extended categories. Similarly, it can be observed that Figure 6 , Figure 7 , Figure 8 The results show that after the documents of extended categories and known categories are reorganized, the model of the present invention can still maintain better performance than the comparison method, indicating that it has better compatible retrieval capabilities of extended categories and known categories.
[0253] Example 3
[0254] The present embodiment also provides an electronic device, comprising: at least one processor; and a memory, wherein the memory stores instructions, and when the instructions are executed by the at least one processor, the at least one processor executes the text semantic hashing method supporting extensible categories as described above. In the present embodiment, the electronic device may include but is not limited to: a personal computer, a server computer, a workstation, a desktop computer, a laptop computer, a notebook computer, a mobile computing device, a smart phone, a tablet computer, a cellular phone, a personal digital assistant (PDA), a handheld device, a messaging device, a wearable computing device, a consumer electronic device, and the like.
[0255] Example 4
[0256] This embodiment also provides a machine-readable storage medium, which stores executable instructions, and when the instructions are executed, the machine executes the text semantic hashing method supporting extensible categories as described above. Specifically, a system or device equipped with a readable storage medium can be provided, on which a software program code that implements the functions of any of the above embodiments is stored, and the computer or processor of the system or device reads and executes the instructions stored in the readable storage medium. In this case, the program code read from the readable medium itself can implement the functions of any of the above embodiments, so the machine-readable code and the readable storage medium storing the machine-readable code constitute a part of this specification. Embodiments of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the program code can be downloaded from a server computer or a cloud by a communication network. It should be understood by those skilled in the art that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0257] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The above embodiments are only descriptions of the preferred implementation modes of the present invention, and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made by ordinary technicians in this field to the technical solution of the present invention should fall within the protection scope determined by the claims of the present invention.
Claims
1. A text semantic hashing method supporting scalable categories, characterized in that: The method comprises the following steps: S1. Obtaining surface features of text ; S2. Constructing a scalable hierarchical category information representation sequence ; The scalable hierarchical category information representation sequence A text sequence consisting of multiple category labels and multiple keywords set in sequence; S3, constructing a text semantic hash model, wherein the text semantic hash model includes a document content hash module and a tag sequence hash module; using the document content hash module to Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories ; In step S3, a text semantic hash model is constructed, wherein the text semantic hash model includes a document content hash module and a tag sequence hash module; the surface features are converted into Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories ,include: S31, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded as an embedded representation of the document , and embedding representation of the document Apply hierarchical category similarity constraints, regularity constraints, and leaf category similarity constraints to reconstruct surface features and leaf category vectors, and optimize the document content hash module during the reconstruction process; S32, construct a label sequence hash module for the category semantic space, and use the label sequence hash module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence , optimize the label sequence hash module during the reconstruction process; S33, encoding the document content hash module and the tag sequence hash module and Perform threshold conversion respectively to obtain the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
2. The text semantic hashing method supporting scalable categories according to claim 1, characterized in that: In step S1, the surface features of the text are obtained ,include: S11. Use the coarse-grained word segmenter of the open source word segmentation tool HanLP to segment the text in the corpus; S12. Remove Chinese stop words from the word segmentation results and sort the word list from high to low according to the word frequency , according to the vocabulary Calculate the word frequency-inverse document frequency statistic TF-IDF for each text and use TF-IDF as the surface feature .
3. The text semantic hashing method supporting scalable categories according to claim 1, characterized in that: In step S2, the multiple category tags are arranged from front to back in order from high to low, and the hierarchy is calculated by the category tags; wherein, if a directory tree is given, the root directory is the highest level, i.e., level one, the sublevel of the root directory is level two, and subsequent levels decrease in sequence; the multiple keywords are located at the back of the multiple category tags, and the multiple keywords are sorted according to the importance given by the TextRank tool.
4. The text semantic hashing method supporting scalable categories according to claim 1, characterized in that: In step S31, a document content hash module integrating hierarchical category information is constructed, and the surface features are converted into Encoded as an embedded representation of the document , and embedding representation of the document Apply hierarchical category similarity constraints, regularity constraints, and leaf category similarity constraints to reconstruct surface features and leaf category vectors. During the reconstruction process, optimize the document content hash module, including: S311, construct a document content hash module that integrates hierarchical category information, and use the document content hash module to convert surface features Encoded into document embedding representation ; The document content hash module uses a multi-layer perceptron as a document encoder , using the document encoder shown in formula (1) Encoded as an embedded representation of the document , and after the text semantic hash model is trained, the document embedding representation is expressed using formula (2) Pass Threshold Converted to document hash code: (1); (2); In formula (1) and formula (2), is the embedded representation of the document; is a document encoder; Hash code for the document No. Dimension value; For embedding representation No. Dimension value; is the binarization function; is a threshold value that can be adjusted according to actual conditions; S312. Using formula (3)-formula (5), embed the document Hierarchical category similarity constraints are imposed, and random sampling is used to model the document similarity based on hierarchical categories for the training set data. The established model is optimized using the objective function of hierarchical category similarity embedding shown in formula (6): (3); (4); (5); In formula (3)-formula (5), For two different documents and Hierarchical category similarity scores; Representation Document No. Hierarchical category labels; Representation Document Category labels at level 1; Representation Document No. Hierarchical category labels; Representation Document No. Hierarchical category labels; For Documentation The number of levels of the category label. The value of the number of levels is equivalent to the level of the leaf directory of the directory tree; It is an indicator function, which takes the value 1 when the two variables are equal and 0 otherwise; are any two category labels; for Corresponding to Control coefficient of the layer; for Corresponding to -1 layer control coefficient; (6); In formula (6), for any surface feature satisfy is the objective function for hierarchical category similarity embedding; is an exponential function; and Corresponding to and Embedded representation of ; Negative samples gather; S313: Embedding representation into document Apply a regularization term that is close to binary to perform regularization constraints: During training, the regularization term shown in formula (7) is used to make Close to the result after binarization to give Binary properties; (7); In formula (7), represents the regularization term; Surface characteristics Embedding representation of ; is the binarization function; S314, using the loss function shown in formula (8) , the embedding representation of the document Imposing similarity constraints on leaf categories: (8); In formula (8), is the loss function for the leaf category similarity constraint; Documents in the same training batch matrix; for The transposed matrix of is the document hash code length; is the leaf category similarity matrix; S315, using formula (9), through the document decoding network Reconstructing surface features , in reconstructing surface features In the process, the text hash module is optimized using the objective function shown in formula (10): (9); In formula (9), The reconstructed surface features output by the model; Decode the network for the document; is the embedding representation of the document; in the text semantic hashing model, the embedding representation of the document Input document decoding network , and output the original features ; (10); In formula (10), Surface characteristics The reconstruction loss is For surface characteristics, The reconstructed surface features output by the model; S316, using formula (11), through the category decoding network Reconstruct the leaf category vector to represent the embedding of the document The leaf category information is introduced in the process of reconstructing the leaf category vector, and the optimization loss of the process of reconstructing the leaf category vector is used as shown in formula (12): (11); (12); In formula (11) and formula (12), To reconstruct the leaf category vector; Decode the network for the category; is the embedded representation of the document; The optimization loss for the process of reconstructing the leaf category vector; Surface characteristics The corresponding category vector.
5. The text semantic hashing method supporting scalable categories according to claim 1, characterized in that: In the step S32, the label sequence hash module for constructing the category semantic space uses the label sequence hash module to represent the scalable hierarchical category information sequence. Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence , optimize the label sequence hash module during the reconstruction process, including: S321, build a label sequence hash module, the label sequence hash module uses BART as the backbone network and uses a sequence encoder Scalable hierarchical category information representation sequence for input Encode to get the embedded representation of the sequence ; Sequence Encoder Use BART encoder to represent the scalable hierarchical category information of the input sequence Encode and reduce the dimension based on the linear transformation network, using the formula (13) Corresponding embeddings of tags As input sequence The embedding representation of : (13); In formula (13), for The corresponding embedding representation of the tag, is a sequence encoder; It is a special marker for the BART model; S322, embedding and displaying the sequence Regularization constraints , so that it is close to the binary hash value; S323. Use formula (14) to obtain the keyword sequence The embedding representation of , and use formula (15) to add the keyword sequence The embedding representation of Embedding representation of sequences Regular constraints that are close to each other: (14); (15); In formula (14) and formula (15), It is a special marker for the BART model; k 1 is the first keyword, k 2 is the second keyword; is a sequence encoder; For keyword sequence The embedding representation of and scalable hierarchical category information representation sequence The embedding representation of Regular constraints that are close to each other; For keyword sequence The embedding representation of Representing Sequences for Scalable Hierarchical Category Information Embedded representation of ; S324, using sequence decoder Embedding representation of sequence Decode and reconstruct the scalable hierarchical category information representation sequence , the reconstructed scalable hierarchical category information representation sequence is used The process is shown in formula (16): (16); In formula (16), is the output probability of the decoding process; Represents a sequence of scalable hierarchical category information representation No. The predicted probability of a word; is the embedding representation of the sequence; Represents a sequence of scalable hierarchical category information representation Before The predicted probability of a word; S325, in the sequence decoder In the above example, we first use linear transformation to embed the sequence Perform dimensionality upgrade, and then input the dimensionality upgrade result into the BART decoder for decoding. During the decoding process, a mask strategy that only [CLS] is visible is adopted; It is a special marker for the BART model; S326. Use the objective function shown in formula (17) to obtain the sequence embedding representation Maximize embedding The semantic similarity information of is used to optimize the label sequence hashing module: (17); In formula (17), To reconstruct the sequence The optimization objective function of is the cross entropy calculation function; Represents an extensible hierarchical category information representation sequence; Represents the sequence of reconstructed scalable hierarchical category information.
6. The text semantic hashing method supporting scalable categories according to claim 1, characterized in that: In step S3, the text semantic hash model is optimized independently in modules. The document content hash module is optimized using the objective function shown in formula (18), and the label sequence hash module remains unchanged. The label sequence hash module is optimized using the objective function shown in formula (19), and the document content hash module remains unchanged: (18); (19); In formulas (18) and (19), Optimize the objective function for the overall network of the document content hashing module; Surface characteristics The reconstruction loss is The objective function for hierarchical category similarity embedding The weights control the hyperparameters, is the weight hyperparameter for embedding leaf category information, is the optimization loss for the process of reconstructing the leaf category vector, is the loss function for the leaf category similarity constraint The weight hyperparameters are Regularization control for embedding representation and The weight hyperparameters are The overall network optimization objective function for the sequence hashing module, To reconstruct the sequence The optimization objective function is For embedding representation and embedding representation Mutual proximity constraints The weight hyperparameters of .
7. A text semantic hashing device supporting scalable categories, characterized in that: The device includes a surface feature acquisition module, an expandable hierarchical category information representation sequence construction module and a text semantic hash module; The surface feature acquisition module is used to acquire the surface features of the text ; The extensible hierarchical category information representation sequence construction module is used to construct an extensible hierarchical category information representation sequence ; The scalable hierarchical category information representation sequence A text sequence consisting of multiple category labels and multiple keywords set in sequence; The text semantic hash module includes a document content hash module and a tag sequence hash module; Use document content hashing module to convert surface features Encoded as an embedded representation of the document , using the label sequence hashing module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation ,Will and Convert the threshold into the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories Specifically, we construct a document content hash module that integrates hierarchical category information and use the document content hash module to convert surface features into Encoded as an embedded representation of the document , and embedding representation of the document Apply hierarchical category similarity constraints, regularity constraints, and leaf category similarity constraints to reconstruct surface features and leaf category vectors, and optimize the document content hash module during the reconstruction process; construct a label sequence hash module for the category semantic space, and use the label sequence hash module to represent the scalable hierarchical category information sequence Encoding as a sequence embedding representation , and embedding representation of the sequence Imposing regularization constraints to reconstruct scalable hierarchical category information representation sequence , optimize the label sequence hash module during the reconstruction process; Encode the document content hash module and the tag sequence hash module and Perform threshold conversion respectively to obtain the corresponding hash code and , splicing and Get the semantic hash code of the document supporting extensible categories .
8. An electronic device, characterized in that: include: at least one processor; and a memory storing instructions, which, when executed by the at least one processor, enable the at least one processor to execute the text semantic hashing method supporting extensible categories as described in any one of claims 1 to 6.
9. A machine-readable storage medium, characterized in that: The machine stores executable instructions, which, when executed, enable the machine to perform the text semantic hashing method supporting extensible categories as claimed in any one of claims 1 to 6.
