Long text semantic similarity matching method, device, electronic device and storage medium
By preprocessing and pooling long and short texts, and combining the entity recognition model to determine the paragraph type, the problem of semantic similarity matching of long and short texts is solved, and more accurate semantic similarity calculation is achieved.
Patent Information
- Application Number
- CN202011042061.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-28
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-09-28
AI Technical Summary
Existing natural language processing technology is difficult to achieve semantic similarity matching between long texts and short texts.
By preprocessing the long text and the benchmark text, the respective word vectors are obtained, and then pooling is performed to obtain the semantic vector. The paragraph type is determined and the weight is calculated based on the entity recognition model, and finally the semantic similarity between the long text and the benchmark text is calculated.
Accurate matching of semantic similarities between long and short texts is achieved, and the obtained similarity is related to the paragraph type of the text, thereby improving the accuracy of matching.
Smart Images

Figure CN112183111B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a method, device, electronic device and storage medium for long text semantic similarity matching. Background Art
[0002] 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, the language people use in daily life, so it is closely related to the study of linguistics. In natural language processing, sometimes it is necessary to match the semantic similarity between different texts.
[0003] The existing semantic matching is the semantic matching between short texts, and none of the existing solutions can achieve semantic matching between long texts and short texts. Summary of the invention
[0004] The purpose of this application is to solve at least one of the above technical defects, and the following technical solutions are proposed:
[0005] In a first aspect, a method for long text semantic similarity matching is provided, the method comprising:
[0006] Preprocessing the long text and the reference text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text, wherein the long text includes a plurality of sentences and the reference text includes a sentence;
[0007] Performing pooling processing on the multiple first word vectors and the multiple second word vectors respectively, so as to obtain multiple first semantic vectors corresponding to multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the second text;
[0008] Inputting the plurality of first semantic vectors into a preset entity recognition model to determine the paragraph types of the paragraphs included in the long text;
[0009] Determine a weight corresponding to a first semantic vector in each paragraph according to the paragraph type;
[0010] Based on the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector, a similarity between the long text and the reference text is calculated.
[0011] In a second aspect, a device for long text semantic similarity matching is provided, the device comprising:
[0012] A preprocessing module, used to preprocess the long text and the reference text respectively, so as to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text;
[0013] A pooling module, used for performing pooling processing on the multiple first word vectors and the multiple second word vectors respectively, so as to obtain multiple first semantic vectors corresponding to multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the second text;
[0014] A classification module, used for determining the paragraph type of the paragraph included in the long text according to a preset entity recognition model and the plurality of first semantic vectors;
[0015] A weight module, used for determining a weight corresponding to the first semantic vector in each paragraph according to the paragraph type;
[0016] A similarity calculation module is used to calculate the similarity between the long text and the reference text based on the first semantic vector, the weight corresponding to the first semantic vector, the second semantic vector and a preset algorithm model.
[0017] In a third aspect, an electronic device is provided, the electronic device comprising:
[0018] one or more processors;
[0019] Memory;
[0020] One or more applications, wherein the one or more applications are stored in a memory and configured to be executed by one or more processors, and the one or more programs are configured to: execute the long text semantic similarity matching method shown in the first aspect of the present application.
[0021] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the long text semantic similarity matching method shown in the first aspect of the present application is implemented.
[0022] The beneficial effect brought about by the technical solution provided by the present application is: first obtain the first word vector corresponding to the long text and the second word vector corresponding to the benchmark text, and after pooling the first word vector and the second word vector respectively, obtain the first semantic vector corresponding to each sentence of the long text and the second semantic vector corresponding to the benchmark text, and determine the paragraph type of each paragraph to determine the weight of each sentence in the long text, so as to obtain the semantic similarity between the long text and the benchmark text, and the obtained similarity is related to the paragraph type of the text, so that the obtained similarity is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.
[0024] Figure 1 A flowchart of a long text semantic similarity matching method provided in an embodiment of the present application;
[0025] Figure 2 for Figure 1 Detailed flow chart of step S101;
[0026] Figure 3 A schematic diagram of the structure of a long text semantic similarity matching device provided in an embodiment of the present application;
[0027] Figure 4 A schematic diagram of the structure of an electronic device for long text semantic similarity matching provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present invention.
[0029] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0030] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0031] The long text semantic similarity matching method, device, electronic device and computer-readable storage medium provided in this application are intended to solve the above technical problems in the prior art.
[0032] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0033] Technicians in this technical field can understand that the "terminal" used in this application can be a mobile phone, a tablet computer, a PDA (Personal Digital Assistant), a MID (Mobile Internet Device), etc.; the "server" can be implemented with an independent server or a server cluster consisting of multiple servers.
[0034] See also Figure 1 In an embodiment of the present application, a long text semantic similarity matching method is provided. The long text semantic similarity matching method can be applied to a terminal or a server. The method includes:
[0035] S101: Preprocessing a long text and a benchmark text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the benchmark text, wherein the long text includes a plurality of sentences and the benchmark text includes a single sentence.
[0036] Long text is a text with long sentences. Long text includes at least two paragraph types, each paragraph type includes at least one paragraph, and each paragraph includes one or more sentences. The paragraph types included in long text are not limited, and the classification method of paragraph types is also not limited. For example, the paragraph types of long text can include summary paragraphs and ordinary paragraphs. Paragraph types can also be classified in other ways to be divided into different paragraph types. The benchmark text includes a sentence, which is a complete meaning. The benchmark text may include sentences separated by punctuation marks. For example, a sentence in the benchmark text is "I love my father, and I love my mother too.", or a sentence in the benchmark text is "I love my motherland."
[0037] The purpose of preprocessing is to vectorize the long text and the reference text. During preprocessing, the long text and the reference text can be segmented and vectorized respectively to obtain multiple first word vectors corresponding to multiple sentences of the long text, and multiple second word vectors corresponding to a sentence of the reference text. Each sentence of the long text includes one or more first word vectors.
[0038] It can be understood that when the long text and the reference text are respectively vectorized, the same preset vectorization model is used for vectorization processing, so that the dimensions of the first word vector and the second word vector are consistent.
[0039] S102: Performing pooling processing on the multiple first word vectors and the multiple second word vectors respectively to obtain multiple first semantic vectors corresponding to multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the second text.
[0040] When the multiple first word vectors and the multiple second word vectors are pooled respectively, the multiple first word vectors and the multiple second word vectors can be pooled respectively through a maximum pooling layer or an average pooling layer. The maximum pooling layer is the Max-Pooling layer, and the average pooling layer is the Average-Pooling layer. Processing multiple word vectors through a maximum pooling layer or an average pooling layer is a prior art, and this application will not be described in detail. If the multiple first word vectors are pooled through an average pooling layer, the multiple first word vectors can be pooled through the following formula:
[0041]
[0042] Among them, Z is the first semantic vector corresponding to a sentence in the long text, K is the number of first word vectors included in the sentence, and v i is the i-th word vector in the sentence. Each first semantic vector corresponding to each sentence of the long text can be obtained, where one sentence corresponds to one semantic vector, thereby obtaining multiple semantic vectors. Similarly, a second semantic vector corresponding to a sentence of the second text can also be obtained. How to perform pooling processing on multiple first word vectors and the multiple second word vectors respectively through the maximum pooling layer is not further described in this application.
[0043] S103: Inputting the plurality of first semantic vectors into a preset entity recognition model to determine paragraph types of paragraphs included in the long text.
[0044] The entity recognition model includes any of the following models: a long short-term memory (LSTM)-conditional random field (CRF) model; or a bidirectional long short-term memory BiLSTM (Bi-directional Long-Short Term Memory)-conditional random field CRF model. Both the LSTM-CRF model and the BiLSTM-CRF model are prior art, and this application only briefly describes them. A basic entity recognition model can be established through a large number of samples, and then the basic entity recognition model is trained to obtain an entity recognition model. The paragraph type of the determined long text is not limited. For example, the long text includes a first paragraph and a second paragraph, and the probability of determining that the first paragraph is a summary paragraph is 0.9, and the probability 0.9 is greater than a preset probability threshold, such as 0.6, then the first paragraph is determined to be a summary paragraph, and the probability of the second paragraph being a normal paragraph is 0.8, and the probability 0.8 is greater than a preset probability threshold, such as 0.6, then the second paragraph is determined to be a normal paragraph. Each paragraph of the long text corresponds to a paragraph type, and different paragraphs can correspond to the same paragraph type. For example, a long text includes 5 paragraphs, of which 1 paragraph is a summary paragraph and 4 paragraphs are ordinary paragraphs.
[0045] S104: Determine a weight corresponding to the first semantic vector in each paragraph according to the paragraph type.
[0046] A type weight correspondence table may be preset, the type weight correspondence table including a mapping relationship between paragraph types and weights, and each paragraph type corresponds to a weight. The weight corresponding to the paragraph type may be set according to needs or experience. That is, the weight corresponding to the first semantic vector in each paragraph is determined according to the paragraph type, including: determining the weight corresponding to the first semantic vector in each paragraph according to the preset type weight correspondence table and the paragraph type, the type weight correspondence table including a mapping relationship between the paragraph type and the weight.
[0047] Different paragraph types correspond to different weights. For example, the weight corresponding to the summary paragraph is 1, and the weight corresponding to the ordinary paragraph is 0.6. After the weight corresponding to a paragraph type is determined, the weight corresponding to a paragraph is also determined, and the weights corresponding to all sentences in a paragraph are also determined. The weight corresponding to a sentence in a paragraph is the weight corresponding to the paragraph type of the paragraph. The solution of the present application can be applied to search engines, question-and-answer dialogues, repeated text matching and other fields.
[0048] Specifically, the weight corresponding to the summary paragraph is 1, and the weight corresponding to the ordinary paragraph is 0.6. When a paragraph D1 is a summary paragraph, the weights of all sentences in the paragraph D1 are 1, and when a paragraph D2 is an ordinary paragraph, the weights of all sentences in the paragraph D2 are 0.6.
[0049] S105: Calculate the similarity between the long text and the reference text based on the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector.
[0050] After the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector are determined, the similarity of the long text to the reference text can be calculated. The similarity of the long text to the reference text can be calculated based on the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector according to the following formula:
[0051]
[0052] Wherein, N is the second semantic vector of the reference text, M is a plurality of first semantic vectors of the long text, L is the number of sentences in the long text, and m is i is the first semantic vector of the i-th sentence in the long text, and the λ mi is the weight corresponding to the first semantic vector of the i-th sentence in the long text.<N,M> That is to find the cosine similarity between N and M.<N,M> The obtained value is in the range [-1,1].<N,M> The value calculated by is S. The closer S is to 1, the more similar the long text is to the reference text. The closer S is to -1, the less similar the long text is to the reference text. It can be understood that s can also be normalized to indicate the similarity in another way. Specifically, the similarity can be
[0053]
[0054] For example, when s is 0.5, the similarity is 75%.
[0055] cos <N,m i >, for each cos<N,m> , cos is calculated based on the following formula<N,m> ,
[0056]
[0057] Among them, k is the dimension of the vector, and N j is the projection vector of the second semantic vector in the jth dimension, and the m jis the projection vector of the first semantic vector in the jth dimension.<N,m> is the cosine similarity between a sentence in the long text and the sentence in the benchmark text.
[0058] It can be understood that when determining the similarity of a long text relative to a reference text, a calculation model can be preset by the above formula to quickly determine the similarity of the long text relative to the reference text. When the calculation model is used, in order for the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector to conform to the preset format so as to be able to enter the calculation model, after determining the paragraph type of the paragraph included in the long text and the weight corresponding to the first semantic vector in each paragraph of the long text, the paragraphs of the long text are re-segmented. Each paragraph needs to include a preset first number of words, such as 512. After the number of words in a paragraph exceeds 512, the paragraph is separated, that is, re-segmented, so that the number of words in the paragraph is less than or equal to 512. If the number of words in a paragraph is less than a preset second number of words, such as 256, the paragraph following the paragraph is added to the paragraph, so that the number of words in the paragraph is greater than the second number and less than or equal to the first number. And fill the paragraphs with 0s that are less than the first number of words, so that in a paragraph, the number of words plus the number of 0s is equal to the first number.
[0059] The embodiment of the present application provides a long text semantic similarity matching method, which first obtains a first word vector corresponding to the long text and a second word vector corresponding to the benchmark text, and then performs pooling processing on the first word vector and the second word vector respectively, to obtain a first semantic vector corresponding to each sentence of the long text and a second semantic vector corresponding to the benchmark text, and determines the paragraph type of each paragraph to determine the weight of each sentence in the long text, so as to obtain the semantic similarity between the long text and the benchmark text. The obtained similarity is related to the paragraph type of the text, so that the obtained similarity is more accurate.
[0060] See also Figure 2 The embodiment of the present application also provides a possible implementation method, wherein the preprocessing of the long text and the reference text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text includes:
[0061] S201: performing word segmentation processing on the long text and the reference text respectively by using a preset word segmentation algorithm to obtain a plurality of first word segments corresponding to the long text and a plurality of second word segments corresponding to the reference text.
[0062] The word segmentation algorithm is not limited, for example, the word segmentation algorithm may include the Jieba word segmentation algorithm, NLPIR, etc. The Jieba word segmentation algorithm and NLPIR are prior arts, and this application will not describe them in detail. Among them, in the aforementioned re-segmentation of paragraphs of long texts, the number of words refers to the number of word segments. For example, in a paragraph, the number of word segments cannot exceed the first number.
[0063] S202: Perform vectorization processing on the first word segmentation and the second word segmentation respectively through a preset vectorization model to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the benchmark text.
[0064] The vectorization model includes a Word2vec model, a Glove model or a Bert model. In the present application, when the first word segmentation and the second word segmentation are respectively vectorized, the same vectorization model is used. If the Word2vec model is used to vectorize the first word segmentation and the second word segmentation respectively, the dimensions of the first word vector and the second word vector obtained are consistent. The parameters in the Word2vec model, the Glove model or the Bert model are set as needed and are not limited in the present application.
[0065] By performing word segmentation and vectorization processing on the long text and the benchmark text respectively, it is easier to subsequently determine the semantic vector of the text and the weight of the sentences in each paragraph, so that the similarity can be determined more accurately.
[0066] See also Figure 3 The embodiment of the present application provides a long text semantic similarity matching device 30, and the long text semantic similarity matching device 30 may include:
[0067] A preprocessing module 301 is used to preprocess the long text and the reference text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text;
[0068] A pooling module 302 is used to perform pooling processing on the multiple first word vectors and the multiple second word vectors respectively, so as to obtain multiple first semantic vectors corresponding to multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the second text;
[0069] A classification module 303, configured to determine the paragraph type of the paragraph included in the long text according to a preset entity recognition model and the plurality of first semantic vectors;
[0070] A weight module 304 is used to determine a weight corresponding to the first semantic vector in each paragraph according to the paragraph type;
[0071] The similarity calculation module 305 is used to calculate the similarity between the long text and the reference text based on the first semantic vector, the weight corresponding to the first semantic vector, the second semantic vector and a preset algorithm model.
[0072] The long text semantic similarity matching device provided by the embodiment of the present application first obtains a first word vector corresponding to the long text and a second word vector corresponding to the benchmark text, and after pooling the first word vector and the second word vector respectively, obtains a first semantic vector corresponding to each sentence of the long text and a second semantic vector corresponding to the benchmark text, and determines the paragraph type of each paragraph to determine the weight of each sentence in the long text, so as to obtain the semantic similarity between the long text and the benchmark text. The obtained similarity is related to the paragraph type of the text, so that the obtained similarity is more accurate.
[0073] The weight module 304 is specifically used to determine the weight corresponding to the first semantic vector in each paragraph according to a preset type weight correspondence table and the paragraph type, wherein the type weight correspondence table includes a mapping relationship between the paragraph type and the weight.
[0074] Among them, the pooling module 302 is specifically used to perform pooling processing on the multiple first word vectors and the multiple second word vectors respectively through a maximum pooling layer or an average pooling layer.
[0075] Wherein, the preprocessing module 301 includes:
[0076] A word segmentation unit, used to perform word segmentation processing on the long text and the reference text respectively by using a preset word segmentation algorithm to obtain a plurality of first word segments corresponding to the long text and a plurality of second word segments corresponding to the reference text;
[0077] A vectorization unit is used to vectorize the first word segmentation and the second word segmentation respectively through a preset vectorization model to obtain multiple first word vectors corresponding to multiple sentences of the long text and multiple second word vectors corresponding to a sentence of the benchmark text.
[0078] See also Figure 4 In an optional embodiment, an electronic device is provided, and the electronic device 4000 includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
[0079] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0080] The bus 4002 may include a path for transmitting information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0081] The memory 4003 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.
[0082] The memory 4003 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the application code stored in the memory 4003 to implement the contents shown in the above method embodiment.
[0083] Among them, electronic devices include but are not limited to: terminals and servers.
[0084] An electronic device is provided in an embodiment of the present application, and the electronic device includes: a memory and a processor; at least one program, stored in the memory, for implementing the corresponding content in the aforementioned method embodiment when executed by the processor, and compared with the prior art, it can be achieved: first obtain a first word vector corresponding to a long text and a second word vector corresponding to a reference text, and after pooling the first word vector and the second word vector respectively, obtain a first semantic vector corresponding to each sentence of the long text and a second semantic vector corresponding to the reference text, and determine the paragraph type of each paragraph to determine the weight of each sentence of the long text, so that the semantic similarity between the long text and the reference text can be obtained, and the obtained similarity is related to the paragraph type of the text, so that the obtained similarity is more accurate.
[0085] The embodiment of the present application provides a storage medium, which is a computer-readable storage medium, and the computer-readable storage medium stores a computer program, which, when running on a computer, enables the computer to execute the corresponding content in the aforementioned method embodiment. Compared with the prior art, the first word vector corresponding to the long text and the second word vector corresponding to the benchmark text are first obtained, and the first word vector and the second word vector are pooled respectively to obtain the first semantic vector corresponding to each sentence of the long text and the second semantic vector corresponding to the benchmark text, and the paragraph type of each paragraph is determined to determine the weight of each sentence of the long text, so that the semantic similarity between the long text and the benchmark text can be obtained, and the obtained similarity is related to the paragraph type of the text, so that the obtained similarity is more accurate.
[0086] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0087] The above are only some embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A long text semantic similarity matching method, characterized in that: The method comprises: Preprocessing the long text and the reference text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text, wherein the long text includes a plurality of sentences and the reference text includes a sentence; Performing pooling processing on the multiple first word vectors and the multiple second word vectors respectively, so as to obtain multiple first semantic vectors corresponding to multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the benchmark text; Inputting the plurality of first semantic vectors into a preset entity recognition model to determine the paragraph types of the paragraphs included in the long text; Determine a weight corresponding to a first semantic vector in each paragraph according to the paragraph type; Calculating the similarity of the long text to the reference text based on the first semantic vector, the weight corresponding to the first semantic vector, and the second semantic vector; According to the following formula, based on the first semantic vector, the weight corresponding to the first semantic vector and the second semantic vector, the similarity of the long text to the reference text is calculated: Wherein, N is the second semantic vector of the reference text, M is a plurality of first semantic vectors of the long text, L is the number of sentences in the long text, and m is i is the first semantic vector of the i-th sentence in the long text, is the weight corresponding to the first semantic vector of the i-th sentence in the long text; Among them, cos is calculated based on the following formula<N,m> , Among them, k is the dimension of the vector, and N j is the projection vector of the second semantic vector in the jth dimension, and the m j is the projection vector of the first semantic vector in the jth dimension; the cos<N,m> is the cosine similarity between a sentence in the long text and a sentence in the benchmark text.
2. The long text semantic similarity matching method according to claim 1, characterized in that: The entity recognition model includes any of the following models: Long Short-Term Memory (LSTM)-Conditional Random Field (CRF) model; or Bidirectional long short-term memory BiLSTM-conditional random field CRF model.
3. The long text semantic similarity matching method according to claim 1, characterized in that: The step of determining the weight corresponding to the first semantic vector in each paragraph according to the paragraph type includes: The weight corresponding to the first semantic vector in each paragraph is determined according to a preset type weight correspondence table and the paragraph type, wherein the type weight correspondence table includes a mapping relationship between the paragraph type and the weight.
4. The long text semantic similarity matching method according to claim 1, characterized in that: The performing pooling processing on the plurality of first word vectors and the plurality of second word vectors respectively includes: The multiple first word vectors and the multiple second word vectors are respectively pooled through a maximum pooling layer or an average pooling layer.
5. The long text semantic similarity matching method according to claim 1, characterized in that: The preprocessing of the long text and the reference text respectively to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text includes: Using a preset word segmentation algorithm, the long text and the reference text are respectively subjected to word segmentation processing to obtain a plurality of first word segments corresponding to the long text and a plurality of second word segments corresponding to the reference text; The first word segmentation and the second word segmentation are respectively vectorized by a preset vectorization model to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the benchmark text.
6. The long text semantic similarity matching method according to claim 5, characterized in that: The word segmentation algorithm includes the Jieba word segmentation algorithm, and the vectorization model includes the Word2vec model, the Glove model or the Bert model.
7. A long text semantic similarity matching device, characterized in that: include: A preprocessing module, used to preprocess the long text and the reference text respectively, so as to obtain a plurality of first word vectors corresponding to a plurality of sentences of the long text and a plurality of second word vectors corresponding to a sentence of the reference text; A pooling module, used for performing pooling processing on the multiple first word vectors and the multiple second word vectors respectively, so as to obtain multiple first semantic vectors corresponding to the multiple sentences of the long text, and a second semantic vector corresponding to a sentence of the reference text; A classification module, used for determining the paragraph type of the paragraph included in the long text according to a preset entity recognition model and the plurality of first semantic vectors; A weight module, used for determining a weight corresponding to the first semantic vector in each paragraph according to the paragraph type; A similarity calculation module, used to calculate the similarity of the long text with respect to the reference text based on the first semantic vector, the weight corresponding to the first semantic vector, the second semantic vector and a preset algorithm model; According to the following formula, based on the first semantic vector, the weight corresponding to the first semantic vector and the second semantic vector, the similarity of the long text to the reference text is calculated: Wherein, N is the second semantic vector of the reference text, M is a plurality of first semantic vectors of the long text, L is the number of sentences in the long text, and m is i is the first semantic vector of the i-th sentence in the long text, is the weight corresponding to the first semantic vector of the i-th sentence in the long text; Among them, cos is calculated based on the following formula<N,m> , Among them, k is the dimension of the vector, and N j is the projection vector of the second semantic vector in the jth dimension, and the m j is the projection vector of the first semantic vector in the jth dimension; the cos<N,m> is the cosine similarity between a sentence in the long text and a sentence in the benchmark text.
8. An electronic device, characterized in that: It includes: one or more processors; Memory; One or more application programs, wherein the one or more application programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs are configured to: execute the long text semantic similarity matching method according to any one of claims 1 to 6.
9. A storage medium, which is a computer-readable storage medium, storing a computer program, characterized in that: When the program is executed by a processor, the long text semantic similarity matching method described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Multi-document auto-abstracting method facing to inquiry
CN101620596A
Document recommendation method and device
CN107273391A
Identification method and device for low-quality news resource, computer equipment and readable medium
CN107463605A
News sentence clustering method based on semantic similarity, device and storage medium
CN107679144A
Man-machine interaction method based on semantic matching, man-machine interaction system based on semantic matching and intelligent story machine
CN108256539A
