A method and model for obtaining legal provisions

By encoding the articles in the legal provision database and using the target reasoner, the problem of mismatch between keywords and articles in legal provision search is solved, and more accurate and efficient search results are achieved.

CN114756657BActive Publication Date: 2025-06-13BEIJING BEIDA SOFTWARE ENG DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210472515.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-29
Publication Date
2025-06-13
Estimated Expiration
2042-04-29

AI Technical Summary

Technical Problem

In legal provision search, the keywords corresponding to the problem entered by the user usually do not match the legal provision, resulting in inaccurate search results.

Method used

By encoding the articles in the legal article database, a semantic vector is generated, and the target inference is used to obtain a collection of candidate legal articles related to the problem based on the correlation between the problem semantic vector and the legal article semantic vector.

Benefits of technology

It improves the accuracy of legal provision search, reduces the search time, and provides more accurate legal provision results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114756657B_ABST
    Figure CN114756657B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides a method and a model for obtaining legal provisions. The method includes: encoding N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and storing the N legal provision semantic vectors; obtaining a problem semantic vector corresponding to a problem; inputting the N legal provision semantic vectors and the problem semantic vector into a target reasoner, and obtaining a set of candidate legal provisions corresponding to the problem through the target reasoner, where the set of candidate legal provisions includes N1 candidate legal provisions, N is an integer greater than 1, and N1 is an integer greater than or equal to 1 and less than N. Through some embodiments of the present application, it is possible to extract a set of candidate legal provisions related to a problem from multiple legal provisions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of natural language processing, and in particular, to a method and a model for obtaining legal provisions. Background Art

[0002] In the related art, information question answering related to information retrieval and natural language processing has gradually come into the public eye. After obtaining a question, keywords in the question are usually used for retrieval and matching. However, in the process of retrieving legal provisions, since the keywords corresponding to the question input by the user usually do not match the legal provisions, the retrieved results output are inaccurate.

[0003] Therefore, how to accurately retrieve legal provisions related to a question has become a problem to be solved. Summary of the Invention

[0004] The embodiments of the present application provide a method and a model for obtaining legal provisions. Through some embodiments of the present application, at least a candidate legal provision set related to the question can be accurately extracted from multiple legal provisions.

[0005] In a first aspect, the present application provides a method for obtaining legal provisions. The method includes: encoding N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and storing the N legal provision semantic vectors; obtaining a question semantic vector corresponding to the question; inputting the N legal provision semantic vectors and the question semantic vector into a target inference engine, and obtaining a candidate legal provision set corresponding to the question through the target inference engine, where the candidate legal provision set includes N 1 candidate legal provisions, N is an integer greater than 1, and N 1 is an integer greater than or equal to 1 and less than N.

[0006] Therefore, different from the method of using keywords in the question to retrieve legal provisions in the related art, the embodiments of the present application obtain the relevance between the question vector and N legal provision vectors through the target inference engine to obtain the candidate legal provision set, which can avoid the problem that the question keywords do not correspond to the expressions of the legal provisions, thereby improving the retrieval accuracy, reducing the retrieval time, and further providing more accurate legal provisions for users.

[0007] In combination with the first aspect, in some embodiments of the present application, before inputting the N legal provision semantic vectors and the problem semantic vector into the target inference engine, the method further includes: inputting the problem sample data, the labeled legal provision corresponding to the problem sample data, and the K-th negative sample legal provision into a trainer to obtain a weight K, where K is an integer greater than or equal to 1; inputting the weight K into the inference engine, and through the inference engine, reconstructing the N legal provision semantic vectors and updating the indexes of the N legal provision semantic vectors to obtain the (k + 1)-th negative sample; repeating the above steps until the (k + 1)-th negative sample meets the preset requirements to obtain the target inference engine.

[0008] Therefore, through the method of asynchronous index construction in the embodiments of the present application, the inference engine can encode N legal provisions, and increasing the negative sample set can enable the inference engine to improve efficiency and enhance learning ability during the training process.

[0009] In combination with the first aspect, in some embodiments of the present application, the step of inputting the problem sample data, the labeled legal provision corresponding to the problem sample data, and the K-th negative sample legal provision into a trainer to obtain a weight K includes: calculating, by the trainer, a first similarity value between the problem sample data and the labeled legal provision, and a second similarity value between the problem sample data and the K-th negative sample legal provision; inputting the first similarity value and the second similarity value into an objective function to obtain the weight K.

[0010] Therefore, by calculating the first similarity value and the second similarity value in the embodiments of the present application, according to the obtained loss function value, the parameter set (i.e., the weight K) in the learning process can be input into the inference engine, so that compared with the method of only calculating using the similarity value of positive samples, the learning ability of the inference engine can be increased, and the retrieval can be made more accurate.

[0011] In combination with the first aspect, in some embodiments of the present application, after obtaining the candidate legal provision set corresponding to the problem through the target inference engine, the method further includes: inputting the candidate legal provision set and the problem semantic vector into a target re-ranking module, and extracting N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module.

[0012] Therefore, by screening out N candidate legal provisions related to the problem from the candidate legal provision set in the embodiments of the present application, the retrieval range can be further narrowed, thereby improving the retrieval accuracy. 2 candidate legal provisions, which can further narrow the retrieval range, thereby improving the retrieval accuracy.

[0013] In combination with the first aspect, in some embodiments of the present application, the target re-ranking module includes a target question encoder and a target legal provision encoder; inputting the candidate legal provision set and the question semantic vector into the target re-ranking module, and extracting N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module, including: inputting the question semantic vector into the target question encoder, encoding the question semantic vector through the target question encoder to obtain a question encoding; performing regularization processing on the question encoding to obtain a regularized question encoding; inputting the candidate legal provision set into the target legal provision encoder, encoding the candidate legal provision set through the target legal provision encoder and then performing regularization processing to obtain a candidate legal provision set encoding; performing filtering processing on the candidate legal provision set encoding to obtain a filtered candidate legal provision set encoding; calculating a third similarity between the regularized question encoding and each provision encoding in the filtered candidate legal provision set encoding, and obtaining the N 2 candidate legal provisions according to the third similarity;

[0014] wherein, the target question encoder is obtained by compressing the hidden layer of the question encoder through a convolutional neural network, and the target legal provision encoder is obtained by compressing the hidden layer of the question encoder through the convolutional neural network.

[0015] Therefore, the embodiments of the present application realize the second ranking of the candidate legal provision set through the target re-ranking module, and can obtain a more accurate answer corresponding to the question.

[0016] In combination with the first aspect, in some embodiments of the present application, after extracting N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module, the method further includes: inputting the N 2 candidate legal provisions into a target reader, and extracting a start character and an end character from the N 2 candidate legal provisions through the target reader to obtain a target answer, where the target answer starts from the start character and ends at the end character.

[0017] Therefore, different from the related art where only legal provisions related to the question are output, the embodiments of the present application can obtain a more accurate target answer by extracting the start character and end character most relevant to the question from the candidate legal provisions through the target reader.

[0018] In combination with the first aspect, in some embodiments of the present application, when the N 2Before inputting the N candidate legal provisions into the target reader, the method further includes: inputting the question sample data and the N 1 candidate legal provisions into a re-ranking module to obtain the i-th similarity, the regularized question encoding, and the filtered candidate legal provision set encoding, where the i-th similarity is the similarity between the regularized question encoding and each encoding in the filtered candidate legal provision set encoding; calculating a re-ranking loss function value according to the i-th similarity, and adjusting the parameters of the re-ranking module based on the re-ranking loss function value; inputting the regularized question encoding and the filtered candidate legal provision set encoding into the reader to obtain a reader loss function value, and adjusting the parameters of the reader based on the reader loss function value; repeating the above process until the re-ranking loss function value and the reader loss function value meet the preset requirements, and obtaining a target re-ranking module and a target reader.

[0019] Therefore, through the joint training of the re-ranking module and the reader in the embodiments of the present application, the training process can focus on the extraction of the target answer, thereby optimizing the parameters in the re-ranking module and the reader, making them an integrated whole, and improving the accuracy of obtaining legal provisions.

[0020] In combination with the first aspect, in some embodiments of the present application, before encoding the N legal provisions in the legal provision database, the method further includes: obtaining multi-source legal provision data; dividing the multi-source legal provision data into M types of data through regular expressions, where M is an integer greater than or equal to 1; splitting at least one type of the M types of data according to a preset rule to obtain the legal provision database.

[0021] Therefore, through the given multiple legal provisions and parsing based on the preset rule in the embodiments of the present application, the multi-source legal provision data can be divided into M types of data, and thus a structured legal provision database for accurate query can be constructed.

[0022] In combination with the first aspect, in some embodiments of the present application, the splitting at least one type of the M types of data according to a preset rule to obtain the legal provision database includes: traversing the at least one type of data, and extracting the content corresponding to the preset trigger word when the preset trigger word is confirmed to exist; storing the content to obtain the legal provision database.

[0023] Therefore, through the preset trigger word in the embodiments of the present application, structured information can be extracted from the unstructured legal provision data, so as to accurately divide the legal provisions and store them according to different fields.

[0024] In combination with the first aspect, in some embodiments of the present application, obtaining the legal provision database includes: when there is an increment requirement for obtaining multi-source legal provision data, determining the increment position; adding the multi-source text data to be updated according to the increment position to obtain the legal provision database.

[0025] Therefore, the embodiments of the present application can align the legal provisions at different time nodes of the same legal provision through the increment of legal provisions, thereby realizing the evolution of legal provisions.

[0026] In a second aspect, the present application provides a model for obtaining legal provisions. The model includes a target initial sorting module, and the target initial sorting module is configured to: encode N legal provisions in the legal provision database to obtain N legal provision semantic vectors, and store the N legal provision semantic vectors; obtain the problem semantic vector corresponding to the problem; input the N legal provision semantic vectors and the problem semantic vector into a target inference engine, and obtain a set of candidate legal provisions corresponding to the problem through the target inference engine, where the set of candidate legal provisions includes N 1 candidate legal provisions, N is an integer greater than 1, and N 1 is an integer greater than or equal to 1 and less than N.

[0027] In combination with the second aspect, in some embodiments of the present application, the model further includes a target re-sorting module, and the target re-sorting module is configured to: input the set of candidate legal provisions and the problem semantic vector into the target re-sorting module, and extract N 2 candidate legal provisions from the set of candidate legal provisions through the target re-sorting module.

[0028] In combination with the second aspect, in some embodiments of the present application, the model further includes a target reader, and the target reader is further configured to: input the N 2 candidate legal provisions into the target reader, and extract a start character and an end character from the N 2 candidate legal provisions through the target reader to obtain a target answer, where the target answer starts from the start character and ends at the end character.

[0029] In a third aspect, the present application provides a device for obtaining legal provisions. The device includes: an encoding module configured to encode N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and store the N legal provision semantic vectors; an acquisition module configured to acquire a problem semantic vector corresponding to a problem; a calculation module configured to input the N legal provision semantic vectors and the problem semantic vector into a target inference engine, and obtain a set of candidate legal provisions corresponding to the problem through the target inference engine, where the set of candidate legal provisions includes candidate legal provisions, N is an integer greater than 1, and is an integer greater than or equal to 1 and less than N.

[0030] In combination with the third aspect, in some embodiments of the present application, the calculation module is further configured to input the problem sample data, the labeled legal provision corresponding to the problem sample data, and the K-th negative sample legal provision into a trainer to obtain a weight K, where K is an integer greater than or equal to 1; input the weight K into an inference engine, and reconstruct the N legal provision semantic vectors through the inference engine and update the index of the N legal provision semantic vectors to obtain the (k + 1)-th negative sample; repeat the above steps until the (k + 1)-th negative sample meets a preset requirement to obtain a target inference engine.

[0031] In combination with the third aspect, in some embodiments of the present application, the calculation module is further configured to calculate a first similarity value between the problem sample data and the labeled legal provision, and a second similarity value between the problem sample data and the K-th negative sample legal provision through the trainer; input the first similarity value and the second similarity value into an objective function to obtain the weight K.

[0032] In combination with the third aspect, in some embodiments of the present application, the calculation module is further configured to input the set of candidate legal provisions and the problem semantic vector into a target reordering module, and extract N 2 candidate legal provisions from the set of candidate legal provisions through the target reordering module.

[0033] In combination with the third aspect, in some embodiments of the present application, the target re-ranking module includes a target question encoder and a target legal provision encoder; the calculation module is further configured to: input the question semantic vector into the target question encoder, encode the question semantic vector through the target question encoder to obtain a question encoding; perform regularization processing on the question encoding to obtain a regularized question encoding; input the candidate legal provision set into the target legal provision encoder, encode the candidate legal provision set through the target legal provision encoder and then perform regularization processing to obtain a candidate legal provision set encoding; perform filtering processing on the candidate legal provision set encoding to obtain a filtered candidate legal provision set encoding; calculate the third similarity between the regularized question encoding and each provision encoding in the filtered candidate legal provision set encoding, and obtain the N 2 candidate legal provisions;

[0034] Wherein, the target question encoder is obtained by compressing the hidden layer of the question encoder through a convolutional neural network, and the target legal provision encoder is obtained by compressing the hidden layer of the question encoder through the convolutional neural network.

[0035] In combination with the third aspect, in some embodiments of the present application, the calculation module is further configured to: input the N 2 candidate legal provisions into the target reader, and extract a start character and an end character from the N 2 candidate legal provisions by the target reader to obtain a target answer, where the target answer starts from the start character and ends at the end character.

[0036] In combination with the third aspect, in some embodiments of the present application, the calculation module is further configured to: input the question sample data and the N 1 candidate legal provisions into the re-ranking module to obtain the i-th similarity, the regularized question encoding, and the filtered candidate legal provision set encoding, where the i-th similarity is the similarity between the regularized question encoding and each encoding in the filtered candidate legal provision set encoding; calculate a re-ranking loss function value according to the i-th similarity, and adjust the parameters of the re-ranking module based on the re-ranking loss function value; input the regularized question encoding and the filtered candidate legal provision set encoding into the reader to obtain a reader loss function value, and adjust the parameters of the reader based on the reader loss function value; repeat the above process until the re-ranking loss function value and the reader loss function value meet the preset requirements to obtain a target re-ranking module and a target reader.

[0037] In combination with the third aspect, in some embodiments of the present application, the encoding module is further configured to: obtain multi-source legal provision data; divide the multi-source legal provision data into M types of data through regular expressions, where M is an integer greater than or equal to 1; split at least one type of the M types of data according to a preset rule to obtain the legal provision database.

[0038] In combination with the third aspect, in some embodiments of the present application, the encoding module is further configured to: traverse the at least one type of data, and when a preset trigger word exists, extract the content corresponding to the preset trigger word; store the content to obtain the legal provision database.

[0039] In combination with the third aspect, in some embodiments of the present application, the encoding module is further configured to: when an increment is required for obtaining the multi-source legal provision data, confirm the increment position; add the multi-source text data to be updated according to the increment position to obtain the legal provision database.

[0040] Fourth aspect, the present application provides an electronic device, including: a processor, a memory, and a bus; the processor is connected to the memory through the bus, and the memory stores computer-readable instructions, which are used to implement the method described in any embodiment of the first aspect when executed by the processor.

[0041] Fifth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed, it implements the method described in any embodiment of the first aspect. Description of the Drawings

[0042] Figure 1 It is a scenario diagram of obtaining legal provisions shown in an embodiment of the present application;

[0043] Figure 2 It is one of the method flowcharts of obtaining legal provisions shown in an embodiment of the present application;

[0044] Figure 3 It is the method flowchart of establishing a legal provision database shown in an embodiment of the present application;

[0045] Figure 4 It is the method flowchart of training a target reasoner shown in an embodiment of the present application;

[0046] Figure 5 It is the method flowchart of training a target re-ranking module shown in an embodiment of the present application;

[0047] Figure 6Schematic diagram of the model structure of a target reader shown in the embodiments of the present application;

[0048] Figure 7 Flowchart II of a method for obtaining legal provisions shown in the embodiments of the present application;

[0049] Figure 8 A model for obtaining legal provisions shown in the embodiments of the present application;

[0050] Figure 9 Flowchart III of a method for obtaining legal provisions shown in the embodiments of the present application;

[0051] Figure 10 A device for obtaining legal provisions shown in the embodiments of the present application;

[0052] Figure 11 An electronic device shown in the embodiments of the present application. Detailed implementation manners

[0053] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some, but not all, of the embodiments of the present application. Usually, the components of the embodiments of the present application described and illustrated in the accompanying drawings herein can be arranged and designed in various different configurations. Therefore, the detailed description of the embodiments of the present application provided in the accompanying drawings below is not intended to limit the scope of the claimed present application, but is only intended to represent the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts fall within the protection scope of the present application.

[0054] The embodiments of the present application can be applied to the scenario of extracting legal provisions matching the problem according to the user input problem. To improve the problems in the background technology, in some embodiments of the present application, N legal provisions are screened by a target inference engine to obtain N 1 candidate legal provisions related to the problem. For example: in some embodiments of the present application, the electronic device is at least configured to: first, encode N legal provisions in the legal provision database to obtain N legal provision semantic vectors, then, obtain the problem semantic vector corresponding to the problem, and finally, input the N legal provision semantic vectors and the problem semantic vector into the target inference engine to obtain N 1 candidate legal provisions. Through the above implementation manners in the present application, the problem of inaccurate retrieval caused by the mismatch between keywords and legal provisions in the related technology can be solved.

[0055] The method steps in the embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0056] Figure 1 FIG. 2 provides a schematic diagram of the scenario composition for obtaining legal provisions in some embodiments of the present application. This scenario includes user 110, client terminal 120, and server 130. Specifically, user 110 enters a question in client terminal 120, and client terminal 120 sends this question to server 130. After obtaining the question, server 130 outputs a set of candidate legal provisions through a model for obtaining legal provisions and sends it to client terminal 120, and client terminal 120 displays it after receiving the set of candidate legal provisions.

[0057] It should be noted that server 130 can output multiple retrieval results, Figure 1 which are only examples. In one implementation manner of the present application, server 130 outputs a set of candidate legal provisions. In another implementation manner of the present application, server 130 outputs N 2 candidate legal provisions. In another implementation manner of the present application, server 130 outputs N 2 candidate legal provisions and a target answer. In another implementation manner of the present application, server 130 outputs a target answer.

[0058] Different from the embodiments of the present application, in the related art, keywords in the question are usually used for retrieval and matching. However, during the retrieval of legal provisions, since the keywords corresponding to the question entered by the user usually do not match the legal provisions, the output retrieval results are inaccurate. In the embodiments of the present application, a model for obtaining legal provisions is used to directly perform encoding and matching on the question (instead of the extracted keywords) and N legal provisions for retrieval. Therefore, the embodiments of the present application do not need to extract keywords in the question to obtain legal provisions as in the related art.

[0059] The following describes the solution for obtaining legal provisions executed by the server in the embodiments of the present application.

[0060] To at least solve the above problems, as Figure 2 shown, some embodiments of the present application provide a method for obtaining legal provisions, and this method includes:

[0061] S210, encoding N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and storing the N legal provision semantic vectors.

[0062] In an implementation manner of the present application, a legal provision database needs to be established before S210, including: obtaining multi-source legal provision data, dividing the multi-source legal provision data into M types of data through regular expressions, and splitting at least one type of data among the M types of data according to preset rules to obtain the legal provision database. Specifically, as Figure 3 shown:

[0063] S310, obtain multi-source legal provision data.

[0064] That is to say, first obtain the original legal provision data of different types and sources, and then perform text cleaning on the original legal provision data, including the conversion between full-width and half-width, special character replacement, etc., to obtain the cleaned original legal provision data. Finally, integrate the cleaned original legal provision data into the TXT text format to obtain multi-source legal provision data.

[0065] S320, split the multi-source legal provision data according to preset rules and an automatic state machine.

[0066] That is to say, S320 includes two stages, namely:

[0067] The first stage: divide the multi-source legal provision data into M types of data through regular expressions, and split at least one type of data among the M types of data according to preset rules.

[0068] Specifically, match the text boundaries through regular expressions, that is, split the titles, subtitles and main texts in the multi-source legal provision data, that is, the M types of data include titles, subtitles and main texts.

[0069] For example, extract the title (for example: Patent Law) through the first regular expression. Extract the subtitle (for example: Passed at the meeting on X year X month X day) through the second regular expression. Extract the main text through the third regular expression.

[0070] The second stage: traverse at least one type of data, and extract the content corresponding to the preset trigger word when it is confirmed that there is a preset trigger word; store the content to obtain the legal provision database.

[0071] That is to say, at least one type of data includes one or more of a title, a subtitle, and the main text. The basic elements of the automatic state machine include: state, event, trigger condition, and action. Among them, the state refers to the classification corresponding to the data. For example, initial, part, chapter, section, article, paragraph, item, sub-item, and content; the event refers to the current character of the data during the traversal process; the trigger condition refers to the keyword that can trigger the division action during the traversal process. For example, part, chapter, section, article, paragraph, item, sub-item, and content; the action refers to the start and end during the division process. For example, part - chapter, chapter - section, section - article, article - paragraph, paragraph - item, item - sub-item, article - content, paragraph - content, sub-item - content, content - content, content - part, content - chapter, content - section, content - article, content - paragraph, content - item, and content - sub-item.

[0072] As a specific embodiment of the present application, traverse the text data included in the main text. The starting state is "initial", and then traverse the main text word by word. When the trigger condition is met, select the corresponding action and change the current state at the same time. For example, if the main text is "... Article 2", and the trigger condition is "content", then trigger the action of "content - article" to split the main text. If there is no trigger condition, the "content - content" action is default selected, that is, the current main text is saved in the "content" field.

[0073] Therefore, through preset trigger words, the embodiments of the present application can extract structured information from unstructured legal provision data, thereby accurately dividing legal provisions and storing them according to different fields.

[0074] S330, Parse the incremental modification of legal provisions and perform legal provision evolution.

[0075] That is to say, in the case where the multi-source legal provision data needs to be incremented, confirm the incremental position, add the multi-source text data to be updated according to the incremental position, and obtain the legal provision database.

[0076] Specifically, when the legal provisions are updated, determine the state of the multi-source text data to be updated. For example: Article 2, Paragraph 1. After finding the storage location (i.e., the incremental position) corresponding to the multi-source text data to be updated in the legal provision database, add the multi-source text data to be updated to the legal provision database correspondingly. For example, add an article after Article 133.1, and the extraction method includes, action: add, item: Article 133, position: after.

[0077] Therefore, the embodiments of the present application can align the legal provisions at different time nodes of the same legal provision through the increment of legal provisions, and thus realize legal provision evolution.

[0078] S340, Perform multi-source fusion to construct a legal provision database.

[0079] That is to say, various types of legal provisions are split and integrated to complete the construction of a legal provision database.

[0080] Therefore, through the given multiple legal provisions in the embodiments of the present application, based on preset rules for parsing, multi-source legal provision data can be divided into M types of data, and thus a structured legal provision database for precise query can be constructed.

[0081] In an implementation manner of the present application, after establishing the legal provision database, through an encoding model (for example: a pre-trained semantic representation model (Bidirectional Encoder Representation from Transformers, BERT)), N legal provisions included in the legal provision database are encoded to obtain N legal provision semantic vectors.

[0082] S220, obtain the problem semantic vector corresponding to the problem.

[0083] That is to say, after obtaining the problem input by the user, through an encoding model (for example: the BERT model), the problem input by the user is encoded to obtain the problem semantic vector.

[0084] S230, input the N legal provision semantic vectors and the problem semantic vector data into the target inference engine, and obtain a set of candidate legal provisions corresponding to the problem through the target inference engine.

[0085] In an implementation manner of the present application, as Figure 3 shown, before S230, an asynchronous index construction method is used to train the inference engine to obtain the target inference engine, and the specific steps are as follows:

[0086] Step 1: Input the problem sample data, the labeled legal provisions corresponding to the problem sample data, and the K-th negative sample legal provisions into the trainer 410 to obtain the weight K.

[0087] First, the trainer 410 calculates the first similarity value between the problem sample data and the labeled legal provisions.

[0088] It can be understood that the labeled legal provisions are multiple legal provisions that are most relevant to the problem obtained through the annotation method.

[0089] That is to say, the encoder (e.g., BERT model) is used to encode the problem sample data and the labeled legal provisions, where the labeled legal provisions are the positive sample set corresponding to the problem sample data. For example, the labeled legal provisions include the three legal provisions most similar to the problem sample data, and [CLS] is used for marking in the last layer of the encoder. Then, the dot product calculation is performed on each provision in the problem sample data and the labeled legal provisions to obtain the first similarity value f(q, d + ), as shown in formula (1):

[0090]

[0091] where q represents the problem sample data, and d + represents each provision in the labeled legal provisions, f(q, d + ) represents the first similarity value, BERT represents the BERT model, and MLP represents the fully connected layer.

[0092] After that, the second similarity value between the problem sample data and the K-th negative sample legal provision is calculated.

[0093] That is to say, the dot product calculation is performed on the problem sample data and the K-th negative sample legal provision to obtain the second similarity f(q, d - ), as shown in formula (2):

[0094]

[0095] where q represents the problem sample data, and d - represents each provision in the K-th negative sample legal provision, f(q, d - ) represents the second similarity, BERT represents the BERT model, and MLP represents the fully connected layer.

[0096] It can be understood that the K-th negative sample legal provision is a negative sample set, which includes multiple legal provisions negatively correlated with the problem sample data (i.e., multiple legal provisions in the legal provision database that are not relevant to the problem sample data). K is an integer greater than or equal to 1.

[0097] Finally, the weight K is obtained according to the first similarity value and the second similarity value input into the objective function.

[0098] After the trainer 410 calculates the first similarity f(q, d + ) and the second similarity f(q, d - ), according to f(q, d + ) and f(q, d -)Calculate the objective function to obtain the weight K. The objective function is shown in formula (3):

[0099]

[0100] where θ * represents the weight K, D + represents the labeled legal provision, D - represents the K-th negative sample legal provision, and l(f(q, d + ), f(q, d - )) represents the loss value between the first similarity and the second similarity.

[0101] It can be understood that D - = INDEX f(q,d) \ D + , D - is the negative sample of the problem sample data q, that is, at the first input (i.e., when K = 1), D - is the set obtained by subtracting the labeled legal provision from N legal provisions; INDEX f(q,d) represents using the asynchronous indexing method. The inference engine constructs a vector index for N legal provisions based on the latest checkpoint at the current moment.

[0102] This loss value is obtained through the following formula (4):

[0103] l(f(q, d + ), f(q, d - )) = l(q, d + , d - ) = NLL(q, d + , d - ) d + (4)

[0104] where l(f(q, d + ), f(q, d - )) represents the loss value between the first similarity and the second similarity, q represents the problem sample data, d - represents each provision in the K-th negative sample legal provision, d + represents each provision in the labeled legal provision, and NLL represents the natural logarithm algorithm.

[0105] Therefore, by calculating the first similarity value and the second similarity value in the embodiments of the present application, the parameter set (i.e., the weight K) in the learning process can be input into the inference engine according to the obtained loss function value, so that compared with the method of only calculating using the similarity value of the positive sample, the learning ability of the inference engine can be increased, and thus the retrieval can be made more accurate.

[0106] Step 2: Input the weight K into the inference engine. The inference engine reconstructs the semantic vectors of N legal provisions and updates the indexes of the semantic vectors of N legal provisions to obtain the (k + 1)-th negative sample.

[0107] That is to say, the internal structure of the inference engine 420 is the same as that of the trainer 410. After receiving the weight K sent by the trainer, the inference engine uses the latest checkpoint f K to reconstruct N legal provisions. Specifically, as Figure 4 shown, after receiving the weight K, the inference engine 420 executes S421 to reconstruct the semantic vectors of legal provisions, that is, recalculate and sort the semantic vectors of legal provisions according to the weight K to obtain the reconstructed semantic vectors of N legal provisions, and then executes S422 for index update, that is, updates the indexes of the reconstructed semantic vectors of N legal provisions to obtain the (K + 1)-th negative sample legal provisions, and returns the (K + 1)-th negative sample legal provisions to the trainer 410. The trainer 410 then recalculates according to the (K + 1)-th negative sample legal provisions and updates the parameters. The parameter update of the trainer 410 is as shown in formula (5):

[0108]

[0109] where, θ * represents the weight K, θ K+1 represents the weight K + 1, η represents the learning rate (hyperparameter), represents the number of provisions of the K-th negative sample legal provisions, l(d + , d - ) represents the loss value between d + and d - , represents the change of model parameters in the K-th loop.

[0110] It can be understood that the (k + 1)-th negative sample is selected from the similarity degree sorted list obtained in the K-th loop, and the most similar but labeled "dissimilar" provisions are selected. The similarity degree sorted list is used to sort the K-th negative sample according to the similarity degree during the K-th loop. The most similar provisions are the provisions ranked at the top in the similarity degree sorted list.

[0111] It should be noted that indexing is the process in which the inference engine reorders the semantic vectors of N legal provisions according to the weight K during the K-th training loop, that is, the process of sorting according to the relevance between each vector in the semantic vectors of N legal provisions and the problem sample data.

[0112] Step 3: Repeat the above steps until the (k + 1)-th negative sample meets the preset requirements to obtain the target inference engine.

[0113] That is to say, the preset requirement can be that the loss function value between the second similarity corresponding to the (k + 1)-th negative sample and the first similarity reaches the minimum or is less than the preset loss function value, then the training is ended to obtain the target inference engine. If the loss function value does not reach the minimum or is greater than the preset loss function value, the training continues.

[0114] Therefore, through the method of asynchronous index construction in the embodiments of the present application, the inference engine can encode N legal provisions, and increasing the negative sample set can improve the efficiency of the inference engine during training and enhance the learning ability.

[0115] Therefore, after obtaining the target inference engine by using the method of the above step 1 to step 3, input the semantic vectors of N legal provisions and the semantic vector of the question into the target inference engine, and obtain N 1 candidate legal provisions through the target inference engine.

[0116] After S230, input the N 1 candidate legal provisions into the target re-ranking module and the target reader, and the target answer can be obtained. First, the training process of the target re-ranking module and the target reader in the embodiments of the present application is described below.

[0117] In some embodiments of the present application, the re-ranking module and the reader are jointly trained to obtain the target re-ranking module and the target reader. The specific steps are as follows:

[0118] S1: Input the question sample data and N 1 candidate legal provisions into the re-ranking module to obtain the i-th similarity, the regularized question encoding, and the filtered candidate legal provision set encoding.

[0119] That is to say, the re-ranking module includes a question encoder and a legal provision encoder. The question encoder is used to encode the question sample data to obtain the regularized question encoding. The legal provision encoder is used to encode N 1 candidate legal provisions to obtain the filtered candidate legal provision set encoding. It can be understood that the filtered candidate legal provision set encoding includes N 1 encodings. Then, use the maximum cosine similarity algorithm to calculate the i-th similarity between the regularized question encoding and each encoding in the N 1 encodings.

[0120] Specifically, as Figure 5 shown, first, the steps of inputting the question sample data into the question encoder 510 to obtain the regularized question encoding are as follows:

[0121] Step 1: Perform word segmentation representation on the question sample data.

[0122] Specifically, the problem sample data is input into the problem encoder 510, and the problem encoder tokenizes the problem sample data to obtain q 0 , q 1 , …, q t , and adds the problem token [Q] in front of the token set. Preset the length N of the token set q . If the length of the token set is less than N q , use the mark token to complete it. If the length of the token set is greater than N q , truncate it.

[0123] Step 2: Encode the tokens to obtain the regularized problem encoding.

[0124] Specifically, the problem encoder 510 encodes each token in the token set and uses a convolutional neural network to compress the representation dimension of the hidden layer to obtain the compressed problem encoding. Then, perform regularization processing on the compressed problem encoding to obtain the regularized problem encoding for facilitating subsequent calculation of the cosine similarity.

[0125] The process of obtaining the regularized problem encoding is shown by the following expression (6):

[0126] E q = Normalize(CNN(BERT(“[Q]q 0 q 1 …q t ##…#”))) (6)

[0127] Among them, E q represents the regularized problem encoding, Normalize represents the regularization process, CNN represents the convolutional neural network, BERT represents the BERT model, [Q] represents the problem token, q 0 q 1 …q t ##…# represents the token set of the problem sample data.

[0128] Then, input N 1 candidate legal provisions into the legal provision encoder 520. The specific steps to obtain the filtered candidate legal provision set encoding are as follows:

[0129] Step 1: Perform token representation on N 1 candidate legal provisions.

[0130] That is to say, for N 1 candidate legal provisions, also divide them into multiple tokens to obtain the token set of N 1 candidate legal provisions, that is, the token set includes d 0 , d 1 , …, dn After that, add N 1 legal provision tags [D] of candidate legal provisions to the front of the word segmentation set.

[0131] Step 2: Encode the word segmentation to obtain the encoded filtered candidate legal provision set.

[0132] That is to say, first, use the BERT model to encode the word segmentation set of N 1 candidate legal provisions, and use a convolutional neural network to compress the representation dimension of the hidden layer. After that, perform regularization processing to obtain the encoded candidate legal provision set. Then, since the content of N 1 candidate legal provisions is relatively large compared with the problem sample data, therefore, after obtaining the encoded candidate legal provision set, perform a filtering operation on it to remove punctuation marks and stop words to obtain the encoded filtered candidate legal provision set.

[0133] The process of obtaining the encoded filtered candidate legal provision set is shown by the following expression (7):

[0134] E d = Filter(Normalize(CNN(BERT(“[D]d 0 ,d 1 ,…,d n ”)))) (7)

[0135] where E d represents the encoded filtered candidate legal provision set, Normalize represents the regularization process, CNN represents the convolutional neural network, BERT represents the BERT model, [D] represents the legal provision tags of N 1 candidate legal provisions, and d 0 ,d 1 ,…,d n represents the word segmentation set of N 1 candidate legal provisions.

[0136] Next, execute S530 similarity calculation to obtain the i-th similarity. Specifically, calculate the similarity between the encoded regularization problem and each encoding in the encoded filtered candidate legal provision set. That is to say, since all word segmentations are regularized during the encoding process in the above steps, therefore, during the similarity calculation process, the inner product between two vectors is the cosine similarity. Calculate the maximum cosine similarity between the word segmentations corresponding to the encoded regularization problem and the word segmentations corresponding to the encoded filtered candidate legal provision set, and sum up each maximum cosine similarity to obtain the i-th similarity. It can be understood that the i-th similarity is the similarity between the encoded regularization problem and each encoding in the encoded filtered candidate legal provision set.

[0137] The expression for obtaining the i-th similarity is as shown in formula (8) below:

[0138]

[0139] Where S q,d : represents the i-th similarity, E d represents the encoding of the filtered candidate legal provision set, E q represents the encoding of the regularization problem, represents any word segmentation encoding in the encoding of the regularization problem, represents any word segmentation encoding in the encoding of the filtered candidate legal provision set.

[0140] It can be understood that the BERT model used in S1 is a model that has been preliminarily trained, and parameter fine-tuning can be performed through S1, S2, and S3.

[0141] S2: Calculate the re-ranking loss function value according to the i-th similarity, and adjust the parameters of the re-ranking module based on the re-ranking loss function value.

[0142] That is to say, after calculating the i-th similarity, calculate the re-ranking loss function value according to the following formula (9). When the re-ranking loss function value does not reach the minimum, adjust the parameters of the re-ranking module, and continue to train the re-ranking module based on these parameters.

[0143]

[0144] Where L represents the re-ranking loss function value, represents whether the j-th candidate legal provision can answer the question sample data i. It can be understood that is a boolean type label, represents the similarity between the question sample data i and the j-th candidate legal provision. It can be understood that the j-th candidate legal provision represents any one of the N 2 candidate legal provisions, and N represents the number of training samples.

[0145] S3: Input the encoding of the regularization problem and the encoding of the filtered candidate legal provision set into the reader to obtain the reader loss function value, and adjust the parameters of the reader based on the reader loss function value.

[0146] That is to say, since the re-ranking module and the reader are jointly trained, the encoding of the regularization problem and the encoding of the filtered candidate legal provision set are input into the reader to train the reader. The training process is as follows:

[0147] It should be noted that the reader in the embodiments of the present application is composed of a bidirectional attention mechanism, a bidirectional long short-term memory network (LSTM), and a fully connected layer. Specifically, as Figure 6 shown, N 2 candidate legal provisions and regularization problem encodings are input into the attention mechanism 610 to obtain the interaction information between the N 2 candidate legal provisions and regularization problem encodings. Then, the interaction information is input into the Bi-LSTM model 620 to obtain the features of the interaction information. After that, the features of the interaction information are respectively input into the fully connected layer 630 and the LSTM network 640. Finally, the starting character is output by the fully connected layer 630, and the ending character is output by the LSTM network 640.

[0148] Step 1: First, after the regularization problem encoding and the filtered candidate legal provision set encoding enter the reader, a similarity matrix between the regularization problem encoding and the filtered candidate legal provision set encoding is established. Then, the bidirectional attention mechanism models the interaction information between the two to obtain the relevant information between the regularization problem encoding and the filtered candidate legal provision set encoding.

[0149] Specifically, the similarity matrix between the regularization problem encoding and the filtered candidate legal provision set encoding is established by the following formula (10).

[0150] S tj = α(H t , U ij ) ∈ R (10)

[0151] Among them, S tj represents the similarity value between the t-th column vector h in the filtered candidate legal provision set encoding H and the j-th column vector u in the regularization problem encoding U. H t represents the t-th column vector h in the filtered candidate legal provision set encoding, and U ij represents the j-th column vector u in the regularization problem encoding U. It can be understood that α represents a mapping function.

[0152] In the process of the bidirectional attention mechanism modeling the interaction information between the two, the calculation is performed through the following formulas (11) to (14).

[0153] In the process of calculating the attention mechanism from the filtered candidate legal provision set encoding to the regularization problem encoding, for each token in the filtered candidate legal provisions, it is calculated which tokens in the regularization problem encoding are most relevant to it, as shown in the following formulas (11) and (12):

[0154] at = softmax(S t: ) ∈ R J (11)

[0155]

[0156] where a t represents the normalized weight of the token at position t encoding the regularization problem, S t: represents the similarity from the current word to the words at the end, represents the similarity from the words from position 0 to the current word, a tj represents the weight of the token at position t encoding the regularization problem for position j, U :j represents the vector corresponding to the words from position 0 to the j-th position in the filtered candidate legal provision set encoding.

[0157] In the process of calculating the attention mechanism from the regularization problem encoding to the filtered candidate legal provision set encoding, for each token in the regularization problem encoding, it is calculated which tokens in the filtered candidate legal provision set encoding are most relevant to it, as shown in the following formulas (13) and (14):

[0158]

[0159]

[0160] where b represents the weight corresponding to the tokens in each filtered candidate legal provision after normalizing each token in the regularization problem encoding, represents taking the maximum value of each column of the similarity matrix S (i.e., representing for each token in each filtered candidate legal provision, which token of which problem is most relevant to it), represents the vector of the token in the regularization problem encoding, H :t represents the vector corresponding to the words from position 0 to the j-th position in the regularization problem encoding.

[0161] Step 2: Output the offsets of the start and end positions, and calculate the reader loss function value according to the start position vector p1 and the end position vector p2.

[0162] Specifically, the calculation formulas for the start position vector p1 and the end position vector p2 are as follows:

[0163]

[0164]

[0165] where p1 represents the start position vector and p2 represents the end position vector, Denote the trainable weights corresponding to the start position vector, Denote the trainable weights corresponding to the end position vector, Denote the concatenated result to obtain the question-aware context text representation, where M represents the representation of G after passing through a BiLSTM layer.

[0166] The loss function is:

[0167]

[0168] Among them, L(θ) represents the value of the reader loss function, Denote the starting position of the labeled answer, Denote the ending position of the labeled answer, Denote the probability of the starting position of the labeled answer, Denote the probability of the ending position of the labeled answer, and N represents the number of training samples.

[0169] S4: Repeat the above process until the values of the re-ranking loss function and the reader loss function meet the preset requirements, and obtain the target re-ranking module and the target reader.

[0170] That is to say, in the case where the values of the re-ranking loss function and the reader loss function do not meet the preset values, or do not reach the minimum value, repeat the above process of training the re-ranking module and the reader. If the values of the re-ranking loss function and the reader loss function meet the preset values, or reach the minimum value, end the training to obtain the target re-ranking module and the target reader.

[0171] It should be noted that, different from the related technology that outputs one or more legal articles related to the question, the input of the target reader in the embodiments of the present application is the N 2 candidate legal articles output by the target re-ranking module. Then, extract the most relevant paragraph of text (starting from the starting character and ending with the ending character) from the N 2 candidate legal articles, and output the target answer corresponding to the question (that is, the most relevant paragraph of text). That is to say, the target answer can be part of the text in the most relevant legal article to the question.

[0172] For example, if the question input by the user is "What is the punishment for a motor vehicle running a red light", the target answer is "Deduct X points from the driver's license and fine X yuan".

[0173] Therefore, through the joint training of the re-ranking module and the reader in the embodiments of the present application, the training process can focus on the extraction of the target answer, thereby optimizing the parameters in the re-ranking module and the reader, making them an integrated whole, and improving the accuracy of obtaining legal articles.

[0174] In some embodiments of the present application, after S230, S230 further includes: inputting the candidate legal provision set and the question semantic vector into the target re-ranking module, and extracting N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module.

[0175] Therefore, the embodiment of the present application realizes the second ranking of the candidate legal provision set through the target re-ranking module, and can obtain a more accurate answer corresponding to the question.

[0176] The following will describe the specific process of extracting N 2 candidate legal provisions through the target re-ranking module:

[0177] It can be understood that different from the method of simultaneous information interaction in coding in the related art, the target re-ranking module in the embodiment of the present application encodes the candidate legal provision set output by the target reasoner and the question semantic vector and then conducts information interaction, which can improve the retrieval accuracy and reduce the calculation amount at the same time.

[0178] It should be noted that the target re-ranking module includes a target question encoder and a target legal provision editor.

[0179] Step 1: Input the question semantic vector into the target question encoder, and encode the question semantic vector through the target question encoder to obtain a question encoding.

[0180] Step 2: Perform regularization processing on the question encoding to obtain a regularized question encoding.

[0181] That is to say, as Figure 7 shown, input the question semantic vector into the target question encoder 710 obtained through the above training method, encode multiple word segments corresponding to the question semantic vector, and obtain a question encoding. It can be understood that the question encoding is obtained by compressing the representation dimension of the hidden layer of the target question encoder 710 through a convolutional neural network, that is, the representation dimension of the question encoding is relatively small. Then, for the convenience of subsequent similarity calculation, the question encoding is subjected to regularization processing to obtain a regularized question encoding.

[0182] Step 3: Input the candidate legal provision set (N 1 candidate legal provisions) into the target legal provision encoder, and perform regularization processing after encoding the candidate legal provision set through the target legal provision encoder to obtain a candidate legal provision set encoding.

[0183] Step 4: Perform filtering processing on the candidate legal provision set encoding to obtain a filtered candidate legal provision set encoding.

[0184] That is to say, asFigure 7 As shown, the target reasoner outputs N 1 candidate legal provisions, and then inputs the N 1 candidate legal provisions into the target legal provision encoder 720. First, encode the N 1 candidate legal provisions, and then perform regularization processing. Since the number of N 1 candidate legal provisions is relatively large compared to the problem semantic vector, a filtering operation is required to remove punctuation marks and stop words to obtain the encoded set of filtered candidate legal provisions.

[0185] Step Five: Calculate the third similarity between the regularized problem encoding and each legal provision encoding in the encoded set of filtered candidate legal provisions, and obtain N 2 candidate legal provisions based on the third similarity.

[0186] That is to say, after obtaining the regularized problem encoding and the encoded set of filtered candidate legal provisions, execute S730 to calculate the similarity, that is, calculate the third similarity between each encoding in the regularized problem encoding and the encoded set of filtered candidate legal provisions.

[0187] For example: The encoded set of filtered candidate legal provisions includes the encoding of Legal Provision A, the encoding of Legal Provision B, the encoding of Legal Provision C, and the encoding of Legal Provision D. The calculated third similarity between the regularized problem encoding and the encoding of Legal Provision A is 95%, the third similarity between the regularized problem encoding and the encoding of Legal Provision B is 60%, the third similarity between the regularized problem encoding and the encoding of Legal Provision C is 80%, and the third similarity between the regularized problem encoding and the encoding of Legal Provision D is 50%. Therefore, the similarities between each encoding in the encoded set of filtered candidate legal provisions and the regularized problem encoding from high to low are the encoding of Legal Provision A, the encoding of Legal Provision C, the encoding of Legal Provision B, and the encoding of Legal Provision D. Then, according to the preset quantity of N 2 (for example, N 2 = 3), filter the encoded set of candidate legal provisions to select N 2 candidate legal provisions, that is, the encoding of Legal Provision A, the encoding of Legal Provision C, and the encoding of Legal Provision B.

[0188] It should be noted that the target problem encoder is obtained by compressing the hidden layer of the problem encoder through a convolutional neural network, and the target legal provision encoder is obtained by compressing the hidden layer of the problem encoder through a convolutional neural network.

[0189] Therefore, the embodiment of the present application can further narrow the retrieval range by screening out N 2 candidate legal provisions related to the problem from the set of candidate legal provisions, thereby improving the retrieval accuracy.

[0190] In one implementation of the present application, N is obtained through the above method 2 After the candidate legal provisions, then extract the target answer from the N 2 candidate legal provisions. That is to say, extract the starting character and the ending character that can answer the question from the N 2 candidate legal provisions.

[0191] Specifically, as Figure 7 shown, input the N 2 candidate legal provisions into the target reader 740, and the target reader extracts the starting character and the ending character from the N 2 candidate legal provisions to obtain the target answer, where the target answer starts from the starting character and ends at the ending character.

[0192] It can be understood that the target reader is obtained by training the reader through the above method, and the application steps of the target reader will not be elaborated here.

[0193] Therefore, different from the related art where only the legal provisions related to the question are output, the embodiment of the present application extracts the starting character and the ending character most relevant to the question from the candidate legal provisions through the target reader, and can obtain a more accurate target answer.

[0194] The above describes the model training process and the implementation steps of the method for obtaining legal provisions in the embodiment of the present application. The following will describe a model for obtaining legal provisions in the embodiment of the present application.

[0195] In some implementations of the present application, as Figure 8 shown, the model for obtaining legal provisions includes: a target initial sorting module 810 (including a target reasoner), a target re-sorting module 820 (including a target question encoder 710 and a target legal provision encoder 720), and a target reader 740.

[0196] Specifically, the target initial sorting module 810 is configured to:

[0197] Step 1: Encode the N legal provisions in the legal provision database to obtain N legal provision semantic vectors, and store the N legal provision semantic vectors. Obtain the question semantic vector corresponding to the question.

[0198] Step 2: Input the N legal provision semantic vectors and the question semantic vector into the target reasoner, and obtain a set of candidate legal provisions corresponding to the question through the target reasoner, where the set of candidate legal provisions includes N 1 candidate legal provisions, N is an integer greater than 1, and N 1 is an integer greater than or equal to 1 and less than N.

[0199] The target re-ranking module 820 is configured to:

[0200] Input the candidate legal provision set and the question semantic vector into the target re-ranking module, and extract N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module.

[0201] The target reader 830 is further configured to:

[0202] Input the N 2 candidate legal provisions into the target reader, and extract the starting character and the ending character from the N 2 candidate legal provisions through the target reader to obtain the target answer, where the target answer starts from the starting character and ends at the ending character.

[0203] The above describes a model for obtaining legal provisions in an embodiment of the present application. The following will describe a specific embodiment of obtaining legal provisions in an embodiment of the present application.

[0204] As Figure 9 shown, a specific implementation step of obtaining legal provisions includes:

[0205] S910, preprocess the multi-source legal provision data to obtain a legal provision database.

[0206] S920, obtain the question input by the user.

[0207] S930, retrieve a candidate legal provision set from the legal provision database.

[0208] S940, calculate the similarity between the question and the candidate legal provision set to obtain N 2 candidate legal provisions and a regularized question encoding.

[0209] S950, obtain the target answer according to the N 2 candidate legal provisions and the regularized question encoding.

[0210] S960, return the target answer.

[0211] Therefore, the embodiment of the present application uses a preliminary ranking module based on the BERT model to respectively obtain the vector representations of the question and the legal provision set, and uses the asynchronous indexing method to dynamically obtain negative samples, and then continues training. After the training is completed, a target preliminary ranking module is obtained. The vector of the legal provision set is pre-cached in the target preliminary ranking module, and a candidate legal provision set is filtered out from the pre-cached vector of the legal provision set based on the input question (for example: the candidate legal provision set includes 1000 candidate legal provisions). Then, the target re-ranking module is used to screen out N 2candidate legal provisions. Finally, the target reader is used to select the target answer most relevant to the question from the N 2 candidate legal provisions.

[0212] Therefore, different from the method of retrieving legal provisions using keywords in related art usage problems, in the embodiments of the present application, the target reasoner learns the features in the question and N legal provisions to obtain a set of candidate legal provisions, which can avoid the problem of non-corresponding expressions between the question keywords and the legal provisions, thereby improving the retrieval accuracy, and further providing more accurate legal provisions for users.

[0213] The specific embodiments of obtaining legal provisions are described above. A device for obtaining legal provisions will be described below.

[0214] As Figure 10 shown, a device 100 for obtaining legal provisions includes: an encoding module 101, an acquisition module 102, and a calculation module 103.

[0215] The present application provides a device 100 for obtaining legal provisions. The device includes: the encoding module 101 is configured to encode N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and store the N legal provision semantic vectors; the acquisition module 102 is configured to acquire a question semantic vector corresponding to the question; the calculation module 103 is configured to input the N legal provision semantic vectors and the question semantic vector into a target reasoner, and obtain a set of candidate legal provisions corresponding to the question through the target reasoner, where the set of candidate legal provisions includes candidate legal provisions, N is an integer greater than 1, and is an integer greater than or equal to 1 and less than N.

[0216] In some embodiments of the present application, the calculation module 103 is further configured to input the question sample data, the labeled legal provision corresponding to the question sample data, and the K-th negative sample legal provision into a trainer to obtain a weight K, where K is an integer greater than or equal to 1; input the weight K into the reasoner, and reconstruct and update the index of the N legal provision semantic vectors through the reasoner to obtain the (k + 1)-th negative sample; repeat the above steps until the (k + 1)-th negative sample meets the preset requirements to obtain a target reasoner.

[0217] In some embodiments of the present application, the calculation module 103 is further configured to calculate a first similarity value between the question sample data and the labeled legal provision, and a second similarity value between the question sample data and the K-th negative sample legal provision through the trainer; input the first similarity value and the second similarity value into an objective function to obtain the weight K.

[0218] In some embodiments of the present application, the computing module 103 is further configured to: input the candidate legal provision set and the problem semantic vector into a target re-ranking module, and extract N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module.

[0219] In some embodiments of the present application, the target re-ranking module includes a target problem encoder and a target legal provision encoder; the computing module 103 is further configured to: input the problem semantic vector into the target problem encoder, encode the problem semantic vector through the target problem encoder to obtain a problem encoding; perform regularization processing on the problem encoding to obtain a regularized problem encoding; input the candidate legal provision set into the target legal provision encoder, perform regularization processing after encoding the candidate legal provision set through the target legal provision encoder to obtain a candidate legal provision set encoding; perform filtering processing on the candidate legal provision set encoding to obtain a filtered candidate legal provision set encoding; calculate a third similarity between the regularized problem encoding and each provision encoding in the filtered candidate legal provision set encoding, and obtain the N 2 candidate legal provisions according to the third similarity;

[0220] wherein, the target problem encoder is obtained by compressing the hidden layer of the problem encoder through a convolutional neural network, and the target legal provision encoder is obtained by compressing the hidden layer of the problem encoder through the convolutional neural network.

[0221] In some embodiments of the present application, the computing module 103 is further configured to: input the N 2 candidate legal provisions into a target reader, and extract a start character and an end character from the N 2 candidate legal provisions through the target reader to obtain a target answer, where the target answer starts from the start character and ends at the end character.

[0222] In some embodiments of the present application, the computing module 103 is further configured to: input the problem sample data and the N 1Input the candidate legal provisions into the re-ranking module to obtain the i-th similarity, the regularized problem encoding, and the encoded set of filtered candidate legal provisions. Among them, the i-th similarity is the similarity between the regularized problem encoding and each encoding in the encoded set of filtered candidate legal provisions. Calculate the re-ranking loss function value according to the i-th similarity, and adjust the parameters of the re-ranking module based on the re-ranking loss function value. Input the regularized problem encoding and the encoded set of filtered candidate legal provisions into the reader to obtain the reader loss function value, and adjust the parameters of the reader based on the reader loss function value. Repeat the above process until the re-ranking loss function value and the reader loss function value meet the preset requirements to obtain the target re-ranking module and the target reader.

[0223] In some embodiments of the present application, the encoding module 101 is further configured to: obtain multi-source legal provision data; divide the multi-source legal provision data into M types of data through regular expressions, where M is an integer greater than or equal to 1; split at least one type of the M types of data according to preset rules to obtain the legal provision database.

[0224] In some embodiments of the present application, the encoding module 101 is further configured to: traverse the at least one type of data, and extract the content corresponding to the preset trigger word when the preset trigger word is confirmed to exist; store the content to obtain the legal provision database.

[0225] In some embodiments of the present application, the encoding module 101 is further configured to: confirm the incremental position when the acquisition of multi-source legal provision data needs to be incremented; add the multi-source text data to be updated according to the incremental position to obtain the legal provision database.

[0226] In the embodiments of the present application, Figure 10 the modules shown can implement Figures 1 to 9 each process in the method embodiments. Figure 10 the operations and / or functions of each module in Figures 1 to 9 are respectively for implementing the corresponding processes in the method embodiments in

[0227] As Figure 11As shown in the figure, an embodiment of the present application provides an electronic device 104, including: a processor 105, a memory 106, and a bus 107. The processor is connected to the memory through the bus. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, they are used to implement the method described in any one of the above embodiments. For details, please refer to the description in the above method embodiments. To avoid repetition, the detailed description is omitted here.

[0228] Among them, the bus is used to realize the direct connection and communication of these components. Among them, the processor in the embodiment of the present application may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0229] The memory may be, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the methods described in the above embodiments can be executed.

[0230] It can be understood that Figure 11 the structure shown is only for illustration, and it may also include more or fewer components than Figure 11 shown in the figure, or have a different configuration from Figure 11 shown in the figure. Figure 11 Each component shown in the figure may be implemented by hardware, software, or a combination thereof.

[0231] The embodiments of the present application further provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a server, the methods described in any of the above embodiments are implemented. For details, reference may be made to the descriptions in the above method embodiments. To avoid repetition, the detailed descriptions are appropriately omitted here.

[0232] The above are only the preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numerals and letters indicate similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.

[0233] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, and all of them should be covered by the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A method for obtaining legal provisions, characterized in that, the method includes: Encoding N legal provisions in a legal provision database to obtain N legal provision semantic vectors, and storing the N legal provision semantic vectors; Obtaining a problem semantic vector corresponding to the problem; Input the N legal provision semantic vectors and the problem semantic vector into the target reasoner, and obtain a set of candidate legal provisions corresponding to the problem through the target reasoner, where the set of candidate legal provisions includes N 1 candidate legal provisions, N is an integer greater than 1, and N 1 is an integer greater than or equal to 1 and less than N; Before inputting the N legal provision semantic vectors and the problem semantic vector into a target inference engine, the method further includes: Inputting problem sample data, a labeled legal provision corresponding to the problem sample data, and a K-th negative sample legal provision into a trainer to obtain a weight K, where K is an integer greater than or equal to 1. Inputting the weight K into the inference engine, and reconstructing the N legal provision semantic vectors by the inference engine and updating the index of the N legal provision semantic vectors to obtain a (k + 1)-th negative sample; repeating the above steps until the (k + 1)-th negative sample meets a preset requirement to obtain a target inference engine; The step of inputting problem sample data, a labeled legal provision corresponding to the problem sample data, and a K-th negative sample legal provision into a trainer to obtain a weight K includes: Calculating a first similarity value between the problem sample data and the labeled legal provision by the trainer; calculating a second similarity value between the problem sample data and the K-th negative sample legal provision; inputting the first similarity value and the second similarity value into an objective function to obtain the weight K; The first similarity value is obtained by the following formula: Among them, q represents the problem sample data, and d + represents each article in the label legal provisions, and f(q, d + ) represents the first similarity value, BERT represents the BERT model, and MLP represents the fully connected layer; The second similarity value is obtained by the following formula: Among them, q represents the problem sample data, and d - represents each article in the legal articles of the K-th negative sample, and f(q, d - ) represents the second similarity, BERT represents the BERT model, and MLP represents the fully connected layer; The weight k is obtained by the following formula: Among them, θ * represents the weight K, D + represents the label legal provision, D - represents the K-th negative sample legal provision, l(f(q, d + ), f(q, d - )) represents the loss value between the first similarity and the second similarity.

2. The method according to claim 1, characterized in that, after obtaining a candidate legal provision set corresponding to the problem by the target inference engine, the method further includes: Input the candidate legal provision set and the problem semantic vector into the target re-ranking module, and extract N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module.

3. The method according to claim 2, characterized in that, the target re-ranking module includes a target problem encoder and a target legal provision encoder; Inputting the candidate legal provision set and the problem semantic vector into the target re-ranking module, and extracting N 2 candidate legal provisions from the candidate legal provision set through the target re-ranking module, including: Inputting the problem semantic vector into the target problem encoder, and encoding the problem semantic vector by the target problem encoder to obtain a problem encoding; Performing regularization processing on the problem encoding to obtain a regularized problem encoding; Inputting the candidate legal provision set into the target legal provision encoder, and encoding and then performing regularization processing on the candidate legal provision set by the target legal provision encoder to obtain a candidate legal provision set encoding; Performing filtering processing on the candidate legal provision set encoding to obtain a filtered candidate legal provision set encoding; Calculate the third similarity between the encoded regularization problem and each legal provision code in the encoded set of filtered candidate legal provisions, and obtain the N 2 candidate legal provisions based on the third similarity; wherein, the target problem encoder is obtained by compressing the hidden layer of the problem encoder through a convolutional neural network, and the target legal provision encoder is obtained by compressing the hidden layer of the problem encoder through the convolutional neural network.

4. The method according to claim 3, characterized in that, After N candidate legal provisions are extracted from the candidate legal provision set by the target reordering module, the method further includes: 2 After N candidate legal provisions are extracted from the candidate legal provision set by the target reordering module, the method further includes: Input the N 2 candidate legal provisions into the target reader, and extract the starting character and the ending character from the N 2 candidate legal provisions through the target reader to obtain a target answer, where the target answer starts from the starting character and ends at the ending character.

5. The method according to claim 4, characterized in that, Before inputting the N 2 candidate legal provisions into the target reader, the method further includes: Input the problem sample data and the N 1 candidate legal provisions into the re-ranking module to obtain the i-th similarity, the regularized problem encoding, and the filtered candidate legal provision set encoding, where the i-th similarity is the similarity between the regularized problem encoding and each encoding in the filtered candidate legal provision set encoding; Calculating a re-ranking loss function value according to the i-th similarity, and adjusting parameters of the re-ranking module based on the re-ranking loss function value; Encode the regularization problem and input the encoded set of candidate legal provisions into a reader to obtain a reader loss function value, and adjust the parameters of the reader based on the reader loss function value; Repeat the above process until the re-ranking loss function value and the reader loss function value meet the preset requirements to obtain a target re-ranking module and a target reader.

6. The method according to claim 1, wherein, before encoding the N legal provisions in the legal provision database, the method further includes: obtaining multi-source legal provision data; dividing the multi-source legal provision data into M types of data through regular expressions, where M is an integer greater than or equal to 1; splitting at least one type of the M types of data according to a preset rule to obtain the legal provision database.

7. The method according to claim 6, wherein, the splitting at least one type of the M types of data according to a preset rule to obtain the legal provision database includes: traversing the at least one type of data, and extracting the content corresponding to the preset trigger word when a preset trigger word exists; storing the content to obtain the legal provision database.

8. The method according to claim 7, wherein, the obtaining the legal provision database includes: confirming an increment position when the multi-source legal provision data needs to be incremented; adding the multi-source text data to be updated according to the increment position to obtain the legal provision database.

9. A model for obtaining legal provisions, wherein, the model includes a target initial ranking module configured to: encode N legal provisions in the legal provision database to obtain N legal provision semantic vectors and store the N legal provision semantic vectors; obtain a problem semantic vector corresponding to the problem; Input the semantic vectors of the N legal provisions and the semantic vector of the question into the target reasoner, and obtain a set of candidate legal provisions corresponding to the question through the target reasoner, where the set of candidate legal provisions includes N 1 candidate legal provisions, N is an integer greater than 1, and N 1 is an integer greater than or equal to 1 and less than N; before inputting the N legal provision semantic vectors and the problem semantic vector into a target inference engine to obtain a set of candidate legal provisions corresponding to the problem through the target inference engine, the target initial ranking module is further configured to: input problem sample data, the labeled legal provision corresponding to the problem sample data, and the k-th negative sample legal provision into a trainer to obtain a weight K, where K is an integer greater than or equal to 1; input the weight K into the inference engine, and reconstruct the N legal provision semantic vectors through the inference engine and update the index of the N legal provision semantic vectors to obtain the (k + 1)-th negative sample; repeat the above steps until the (k + 1)-th negative sample meets the preset requirements to obtain a target inference engine; Inputting the problem sample data, the labeled legal provisions corresponding to the problem sample data, and the K-th negative sample legal provisions into a trainer to obtain the weight K includes: calculating, by the trainer, a first similarity value between the problem sample data and the labeled legal provisions; calculating a second similarity value between the problem sample data and the K-th negative sample legal provisions; and inputting the first similarity value and the second similarity value into an objective function to obtain the weight K; The first similarity value is obtained through the following formula: Among them, q represents the question sample data, and d + represents each article in the label legal provisions, and f(q, d + ) represents the first similarity value, BERT represents the BERT model, and MLP represents the fully connected layer; The second similarity value is obtained through the following formula: Among them, q represents the question sample data, and d - represents each article in the legal articles of the K-th negative sample, and f(q, d - ) represents the second similarity, BERT represents the BERT model, and MLP represents the fully connected layer; The weight k is obtained through the following formula: Among them, θ * represents the weight K, D + represents the label legal provision, D - represents the K-th negative sample legal provision, l(f(q, d + ), f(q, d - )) represents the loss value between the first similarity and the second similarity.

10. According to the model of claim 9, wherein, the model further includes an objective re-ranking module, and the objective re-ranking module is configured to: input the candidate legal provision set and the problem semantic vector into the objective re-ranking module, and extract N2 candidate legal provisions from the candidate legal provision set by the objective re-ranking module.

11. According to the model of claim 10, wherein, the model further includes an objective reader, and the objective reader is further configured to: Input the N 2 candidate legal provisions into the target reader, and extract the starting character and the ending character from the N 2 candidate legal provisions through the target reader to obtain the target answer, where the target answer starts from the starting character and ends at the ending character.

Citation Information

Patent Citations

  • Legal provision recommendation method and device and storage medium

    CN110569350A

  • answer text-based answer processing method and answer recommendation method

    CN113010657A