A method for rapid adaptation and generation of lawyer's letters for a small number of samples
By constructing support and query sets using meta-learning methods and training the model with a dual-tower encoder and adversarial discriminator, the semantic gap problem in generating lawyer's letters with a small number of samples is solved. This enables rapid adaptation and high-matching generation of lawyer's letters from unstructured evidence, improving the model's generalization ability and the interpretability of the generated content.
Patent Information
- Application Number
- CN202611178753.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-05
- Publication Date
- 2026-11-17
AI Technical Summary
Existing end-to-end generation methods struggle to bridge the semantic gap between colloquial original evidence and formal legal documents with a limited number of high-quality labeled samples. They also lack interpretable control over the gaps in legal requirements, resulting in poor factual consistency or incorrect legal basis in the generated content. Furthermore, they have weak generalization ability, especially when facing new cases.
A meta-learning method is used to construct support sets and query sets. A dual-tower encoder generates the difference between the refined representation and the original representation and projects it onto the legal elements space. The model is trained by combining an adversarial discriminator and a loss function to achieve rapid adaptation from unstructured evidence to high-quality lawyer's letters.
With a small sample size, it significantly improved the matching degree between the generated content and the strength of evidence, reduced the workload of lawyers in manual extraction and writing, and improved the generalization ability of the model and the interpretability of the generated content.
Smart Images

Figure CN123117019A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing technology, specifically relating to a method for rapidly adapting and generating lawyer's letters for a small number of samples. Background Technology
[0002] The drafting of lawyer's letters requires transforming unstructured raw evidence (such as chat logs, scanned copies of contracts, and transfer vouchers) into logically rigorous and legally complete standardized legal documents. Currently, this process heavily relies on practicing lawyers manually sorting out evidence, defining its legal nature, and drafting documents, which is time-consuming, labor-intensive, and inefficient. Especially when faced with a large number of similar cases (such as financial loan disputes and property fee collection), the varying degrees of colloquial language used in the evidence presentation and the vague descriptions of key legal elements in different cases necessitate lawyers to repeatedly perform format conversions and restatements of legal language, severely restricting the capacity for large-scale processing of legal services.
[0003] With the development of natural language processing technology, the industry has begun to explore the use of sequence-to-sequence models for the automated generation of legal documents. However, existing end-to-end generation methods have significant limitations: First, models struggle to effectively bridge the huge semantic gap between "colloquial original evidence" and "standard legal documents" when only a small number of high-quality labeled samples (excerpts from exemplary lawyer's letters) are available, resulting in poor factual consistency or incorrect citation of legal basis in the generated content. Second, conventional supervised learning methods have weak generalization capabilities; when faced with new causes of action or unseen evidence description styles, the quality of the model's output drops sharply, easily producing text that does not match the strength of the original evidence. Third, existing methods are mostly black-box operations, lacking interpretable control over gaps in legal elements (such as time accuracy, basis for monetary calculations, and level of legal citation), and cannot guide the model to specifically fill in evidentiary deficiencies.
[0004] Therefore, how to provide a method for generating lawyer's letters that can quickly adapt to a small number of samples, has a high generalization ability, and whose generated content is highly matched with the strength of evidence has become a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0005] The purpose of this invention is to provide a method for rapidly adapting and generating lawyer's letters for a small number of samples, so as to achieve rapid adaptation and high matching degree generation from unstructured original evidence to high-quality lawyer's letters under the condition of a small number of historical samples.
[0006] A method for rapidly adapting and generating lawyer's letters for a small sample size includes the following steps: S1: Construct meta-learning tasks based on historical case samples. Each task includes a support set and a query set. The support set samples provide original evidence text, refined evidence summary, and high-quality lawyer's letter paragraphs. The query set samples only provide original evidence text and high-quality lawyer's letter paragraphs. The cases in the two sets do not overlap. S2: A dual-tower encoder that shares weights with the refined evidence summary of the support set and the original text input of the support set for the same case obtains the refined representation and the original representation. The difference between the original representation and the refined representation of the same case is calculated and projected onto the preset legal element space to obtain the legal element gap vector. S3: Model-independent meta-learning training of the dual-tower encoder and text generator: the inner loop updates task-specific parameters based on the support set, and the outer loop summarizes the loss based on the query set to update global parameters; the loss function includes at least contrastive loss, generative loss and adversarial loss. S4: Obtain the original evidence text of the current case, generate the current original representation using the trained dual-tower encoder, calculate the current legal element gap vector by combining the average refined representation of similar cases, input the current original representation and gap vector into the generator, and generate the lawyer's letter text under the constraint of the adversarial discriminator. S5: Output Text. This method constructs a meta-learning task and utilizes a two-layer optimization training with support and query sets, enabling the model to quickly adapt to the characteristics of evidence in new cases with only a small number of historical samples. After training, the dual-tower encoder can effectively extract the implicit gap between the original evidence text and the refined evidence summary, and project this gap onto a preset legal element space to form an interpretable control signal. In the generation stage, the legal element gap vector is calculated by combining the current original representation with the average refined representation of similar cases, guiding the text generator to produce lawyer's letter text under the constraint of an adversarial discriminator. The above mechanism significantly improves the end-to-end generation generalization ability from unstructured original evidence to high-quality lawyer's letters, ensures the matching degree between the generated content and the strength of evidence, and reduces the workload of lawyers in manual refinement and writing. The "implicit gap" refers to the vector difference in the high-dimensional semantic space between the two representation vectors obtained after representing the original evidence text and the refined evidence summary of the same case through the dual-tower encoder. This difference, encoded in the form of a distributed vector, encodes the degree of deviation of the original evidence from its refined state at the semantic level, encompassing comprehensive deviation information across multiple dimensions, including the standardization of legal terminology, the accuracy of factual description, and the completeness of logical structure.
[0007] Optionally, the dual-tower encoder in step S2 is a conjoined network built based on the pre-trained language model BERT. The two encoding towers share all weight parameters, and different cue word prefixes are added to the input layer to distinguish between the evidence tower function and the refinement tower function. This method employs a conjoined dual-tower encoder built based on BERT and sharing all weight parameters. By using differentiated cue word prefixes to distinguish between the evidence tower function and the refinement tower function at the input layer, it achieves accurate alignment of the original evidence representation and the refined evidence representation within the same semantic space. This shared weight mechanism reduces the model parameter scale while ensuring the consistency of feature extraction from the two encoding paths, making subsequent difference calculations and legal element projections semantically comparable. This effectively supports the accurate capture and quantification of the legal semantic gap between the original and refined texts within the meta-learning framework.
[0008] Optionally, the legal requirement space in step S2 includes multiple preset dimensions, each of which corresponds to at least one of the following legal requirement feature categories: accuracy of time description, sufficiency of basis for amount calculation, level of legal provision citation, intensity of subjective fault description, completeness of evidence chain, and degree of standardization of the characterization of breach of contract.
[0009] The time description accuracy dimension measures the degree of deviation of the time description in the original evidence from vague language to specific dates. The larger the difference, the more ambiguous the original time information, requiring specific supplementation during the generation stage. The sufficiency of the basis for amount calculation assesses the formulaic breakdown and supporting documentation of the amount composition. The larger the difference, the more the original amount information lacks clear basis for principal and interest breakdown or calculation. The legal citation level dimension determines the normative level of the legal basis cited. The larger the difference, the more the original text lacks precise legal references down to the clause level. The intensity of subjective fault description quantifies the strength of the description of the breaching party's subjective state. The larger the difference, the more neutral the original description, requiring stronger condemnation and legal characterization in the generated letter. The completeness of the evidence chain dimension assesses whether the types of evidence supporting the claim form a closed loop. The larger the difference, the more the original material lacks explicit mention of key evidence types. The standardization of the breach of contract characterization dimension measures whether the expression of the legal nature of the behavior conforms to legal language requirements. The larger the difference, the more colloquial the original description, requiring elevation to the level of standardized legal terminology. The synergistic effect of the above dimensions enables the model to accurately identify the specific types and degrees of defects in the original evidence at the level of legal requirements, thereby providing precise directions for supplementation and reinforcement for subsequent text generation, and significantly improving the completeness of legal requirements and the standardization of expression of the generated lawyer's letter.
[0010] Furthermore, in step S2, the difference vector is projected onto the legal elements space, which is achieved through a trainable projection matrix W, whose number of rows is the dimension of the encoder output vector and whose number of columns is the dimension of the legal elements space. The projection matrix W is initialized before training as follows: For the k-th dimension in the legal element space, a set of legal element anchor words is preset. A dual-tower encoder is used to calculate the high-frequency context representation vectors corresponding to the anchor words. Based on these representation vectors, the initial weights of the k-th column of the projection matrix W are constructed, so that the untrained difference vector possesses preliminary legal element orientation after projection. The "legal element orientation" refers to a clear semantic correspondence between the numerical values of each dimension in the legal element difference vector and the preset legal element feature categories (including but not limited to the accuracy of time description, the sufficiency of the basis for monetary calculation, the level of legal provision citation, the strength of subjective fault description, the completeness of the evidence chain, and the standardization of the characterization of breach of contract), so that the magnitude of a certain dimension can reflect the degree of deficiency or completeness of the original evidence in the corresponding legal element dimension. The initialization of the projection matrix based on legal element anchor words before training ensures that the untrained difference vector possesses preliminary legal element orientation after projection. Specifically, a set of anchor words is pre-defined for each dimension of the legal element space. A dual-tower encoder is used to calculate the high-frequency contextual representation vectors corresponding to the anchor words, which serve as the initial weights for the corresponding columns of the projection matrix. This initialization strategy constrains the projection direction to the vicinity of the preset legal semantic direction in the early stages of training, effectively reducing the risk of the projection matrix converging to an irrelevant semantic direction during end-to-end black-box training. This significantly accelerates the loss reduction speed and improves convergence stability during meta-learning training. After training convergence, the difference values of each dimension not only possess mathematical separability but also form a clear semantic correspondence with the corresponding legal element features, thereby enhancing the interpretability of the legal element difference vector and providing more guiding control signals for the generation stage.
[0011] Optionally, the inner loop training loss function L in step S3 i =L c +L g +β·L a The outer loop loss function L o =L s +L g +β·L a , where L c To narrow the gap between the original representation vector and the refined representation vector, the comparison loss L g To generate losses targeting high-quality lawyer's letter paragraphs, L a The generator's adversarial loss is β, where β is the balance coefficient, and L is the inequality loss. s To calculate the semantic similarity loss between the generated paragraph and the sample lawyer's letter paragraph, the inner loop simultaneously uses L... c L g L aThis allows the model to achieve latent space alignment between the original and refined representations under the supervision of refined evidence summaries provided by the support set, and simultaneously optimizes the lexical accuracy and adversarial realism of the generated text. The outer loop uses L... s Replace L c This allows the model to update its parameters based on the semantic consistency between the generated paragraphs and high-quality templates, even when the query set lacks refined evidence summaries, thus avoiding information leakage during the meta-learning process. The introduction of β suppresses excessive interference from the discriminator on the generator, maintaining a balance between the semantic coherence of the generated text and the degree of evidence matching. Through a combination of inner and outer loop differential losses, the model can output text of comparable quality to high-quality lawyer's letter paragraphs during the inference phase, relying solely on the original evidence text.
[0012] Furthermore, in step S3, the inner loop parameter update includes: Calculate the inner loop loss function based on the support set. For the current global encoder parameters The gradient, and For the current global generator parameters The gradient; Using a preset inner loop learning rate , set the current global encoder parameters Update one step in the opposite direction of the gradient to obtain the encoder parameters specific to this meta-learning task. ; Using the inner loop learning rate global generator parameters Update one step in the opposite direction of the gradient to obtain the generator parameters specific to this meta-learning task. .
[0013] The specific formula is as follows: ; ; Where θ represents the encoder's global parameters, and ϕ represents the generator's global parameters. , These are the encoder-specific parameters and generator-specific parameters for task i after being updated with the support set, respectively. For the inner loop learning rate, Let be the support set for task i. For each meta-learning task, the model obtains task-specific parameters by performing a single-step gradient descent based on only a small number of samples from the support set. , This mechanism eliminates the need for extensive iterative optimization. It enables the encoder and generator to quickly adapt to the legal requirements of the current task while preserving global knowledge, efficiently extracting mapping patterns from the original evidence text, refined evidence summaries, and high-quality lawyer's letter paragraphs provided by the support set. Through joint optimization of the inner loop and subsequent outer loop, when faced with new cases with only original evidence during the inference phase, the model can directly generate high-quality lawyer's letter text that meets the strength of evidence, significantly reducing its dependence on the number of historical samples.
[0014] Furthermore, the outer loop parameter update process in step S3 includes: For all meta-learning tasks, utilize the specific encoder parameters. and specific generator parameters The outer loop loss function is calculated on the query set. ; Accumulate the outer loop loss function corresponding to each task Regarding encoder global parameters The gradient is calculated, and a preset outer loop learning rate is used. Update the global encoder parameters in the opposite direction of the gradient. ; The outer loop loss function for each task is accumulated with respect to the generator's global parameters. The gradient is calculated, and the generator's global parameters are updated in the reverse direction of the gradient using the outer loop learning rate. .
[0015] The specific formula is as follows: ; ; Where η is the outer loop learning rate. This is the query set for task i. The technical effect of this outer loop parameter update step is that the model updates the task-specific parameters using the inner loop. , Starting with the query set, the loss is computed only on the query set, and gradients are backpropagated to update the global parameters θ and φ, without providing a refined evidence summary. This mechanism forces the encoder and generator to directly generate outputs of comparable quality to premium lawyer's letter paragraphs, relying solely on the original evidence text, even without access to refined intermediate representations. By aggregating query set gradients from multiple meta-learning tasks, the global parameters learn cross-task shared feature extraction and text generation patterns, thereby improving the model's generalization ability to unseen cases. Simultaneously, the outer and inner loop updates form a two-layer optimization structure: the inner loop allows the model to quickly adapt to the legal requirements distribution of a specific case, while the outer loop ensures that this adaptation process does not impair the model's initial performance on entirely new cases. This design significantly enhances the end-to-end robustness of generation from raw unstructured evidence to high-quality lawyer's letters and reduces reliance on refined evidence summary annotation data.
[0016] Furthermore, during the outer loop parameter update process in step S3, the model starts with the updated parameters from the inner loop, reads only the original evidence text of the samples in the query set as input, generates candidate lawyer letter paragraphs, and calculates the loss with the high-quality lawyer letter paragraphs of the samples in the query set, without providing the model with refined evidence summaries of the query set samples. When the model propagates forward on the query set, it only reads the original evidence text as input, does not obtain refined evidence summaries, and generates candidate lawyer letter paragraphs starting with the updated parameters from the inner loop, calculating the loss with the high-quality lawyer letter paragraphs. This constraint design forces the encoder and generator to learn the end-to-end mapping of high-quality lawyer letters directly from the original unstructured evidence under the condition of lacking intermediate supervision of refined evidence summaries. This avoids information leakage during the meta-learning training process and prevents the model from over-relying on refined evidence summaries, thus weakening the training of the ability to extract features from the original evidence. By simulating the information-deficient state in real reasoning scenarios in the outer loop, the model adapts to the input conditions of actual deployment during the training phase, significantly improving the generalization ability to directly generate standardized lawyer letters for unseen cases and reducing the dependence on manually labeled refined evidence summary data.
[0017] Optionally, the adversarial discriminator in step S4 is a binary classification network. Its input is the concatenation of the candidate paragraphs output by the generator and the current gap vector, and its output is an evidence support score s∈[0,1]. The evidence support score is used to quantitatively evaluate the degree of factual matching between the candidate lawyer's letter paragraphs output by the generator and the original input evidence. The higher the score, the more the factual claims in the generated text are supported by the original evidence, and the fewer statements deviate from the content of the original evidence. The adversarial discriminator inputs the concatenation of the candidate paragraphs output by the generator and the current legal element gap vector into the binary classification network. The discriminator can dynamically evaluate the degree of matching between the generated text and the original evidence based on the control signals at the legal element level, and output a fine-grained continuous score s. This scoring mechanism provides a quantifiable evaluation index for the generation quality, enabling the model to filter or regenerate candidate texts based on a preset threshold during the inference stage, ensuring that the evidence support of the output lawyer's letter meets professional requirements. During the training phase, the discriminator and generator engage in an adversarial game. The accuracy of the discriminator's output score forces the generator to optimize semantic fluency while also considering evidence matching, thereby suppressing the illusion that the generated content deviates from the original evidentiary facts. By using the current gap vector as a conditional input, the discriminator's evaluation criteria are correlated with various dimensions of the legal elements space, improving the consistency between the scoring results and legal professional requirements.
[0018] Optionally, the average refined vector in step S4 is obtained by retrieving all historical samples with the same cause of action as the current case and averaging their refined vectors. In the absence of a true refined evidence summary for the current case during the reasoning stage, an alternative latent space baseline vector is obtained by retrieving all historical samples with the same cause of action as the current case and averaging their refined vectors. The evidence structures of different cases under the same cause of action are highly homogeneous at the legal requirements level, and their refined vectors exhibit a clear clustering distribution after convergence of meta-learning training. The vector obtained by the arithmetic average can effectively approximate the latent space center of the complete legal requirements state under that cause of action. Using this mean vector to replace the true refined representation of the current case for calculating the legal requirements gap vector avoids the dilemma of being unable to generate control signals due to the lack of a refined evidence summary. Simultaneously, the averaging operation suppresses extra-case noise in individual historical samples, improving the stability and representativeness of the baseline vector. This design allows the model to complete end-to-end generation from original evidence to lawyer's letters without needing to pre-prepare manually written refined evidence summaries for each new case in actual deployment, significantly reducing the data annotation cost for practical application.
[0019] Optionally, the text generator is a BART sequence-to-sequence model. The current gap vector is mapped via a feedforward network and then injected into the control token embedding layer of the BART decoder. The BART sequence-to-sequence model is used as the text generator, and the current legal requirement gap vector is mapped via a feedforward network and injected into the control token embedding layer of the BART decoder. This injection mechanism allows the low-dimensional legal requirement gap vector to be upsized to a dimensional space matching the BART hidden layer through the feedforward network and superimposed on the original embedding of the decoder's starting token. Due to the decoder's self-attention mechanism, this control signal propagates from the starting token position to each subsequent time step, continuously guiding the decoder to perform targeted completion and reinforcement of the defect dimension indicated by the legal requirement gap vector during the word selection process. The BART encoder simultaneously receives the semantic representation of the original evidence text, complementing the injected control signal: the encoder provides factual content information, and the decoder's control token embedding layer provides generation constraints at the legal requirement level. The above configuration avoids semantic redundancy or feature interference caused by simply splicing control signals into the input sequence, and achieves precise control over the generated lawyer's letter text in three dimensions: completeness of legal requirements, standardization of expression, and matching degree of evidence.
[0020] The core advantage of this invention lies in its significantly improved adaptability to a small number of labeled samples and cross-case generalization performance through the construction of a meta-learning dual-layer optimization framework and a legal element projection mechanism. Specifically, the dual-tower encoder with shared weights, guided by differentiated prompts, achieves precise alignment between original evidence and refined evidence summaries within the same semantic space. Furthermore, the implicit gap is mapped to a six-dimensional legal element space, including time accuracy, sufficiency of monetary evidence, and legal citation hierarchy, through a projection matrix, thus endowing the model with interpretability for the generated control signals. In addition, the differentiated loss function design of the inner and outer loops allows the model to output text relying solely on original evidence in the outer loop, simulating real-world reasoning scenarios, effectively reducing reliance on the refined evidence summary annotation data. The adversarial discriminator scores evidence support based on the gap vector, constraining the generator to maintain semantic fluency while suppressing factual deviations. This enables end-to-end stable output in practical applications such as financial loan contract disputes, from colloquial, unstructured original materials to high-quality lawyer's letter paragraphs with complete legal elements and high evidence matching. Attached Figure Description
[0021] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.
[0022] Figure 1 This is a flowchart of the overall method of the present invention.
[0023] Figure 2 This is a diagram of the meta-learning training mechanism of the present invention.
[0024] Figure 3 The core link flowchart for the inference generation of this invention is provided. Detailed Implementation
[0025] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0026] The concepts involved in this application will first be described with reference to the accompanying drawings. It should be noted that the following descriptions of various concepts are only for the purpose of making the content of this application easier to understand and do not constitute a limitation on the scope of protection of this application; furthermore, the embodiments and features in the embodiments of this application can be combined with each other unless otherwise specified. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0027] Example 1: This embodiment provides a specific application example of a method for rapidly adapting and generating lawyer's letters for a small number of samples. Taking a financial loan contract dispute as an example, it describes in detail the entire process from model training to actual reasoning and generating lawyer's letters.
[0028] S1. Sample Data Preparation and Meta-Learning Task Construction 1. Data Acquisition and Labeling This embodiment retrieved 100 samples of closed financial loan contract disputes from the historical case management system of a law firm. Each sample was manually compiled by lawyers. The sample data used in this embodiment were all taken from real closed case files that had undergone anonymization processing. Each complete sample contains three related fields: original evidence text, refined evidence summary, and a sample lawyer's letter paragraph. The original evidence text directly comes from the OCR recognition results of scanned copies of legal documents such as "Loan Contracts," "IOUs," and "Guarantee Letters," text from screenshots of electronic bank transfer receipts, exported content from screenshots of WeChat / SMS collection records, and factual statements from copies of complaints. This part of the data has not been artificially deleted or embellished, and fully preserves the colloquial expressions, inconsistent formats, OCR recognition errors, and unstructured noise characteristics of real business scenarios.
[0029] Based on this, practicing lawyers manually refine and restate the original evidence text in accordance with legal document drafting standards to form a concise evidence summary. This summary unifies the vague time expressions in the original text to specific dates, breaks down scattered monetary items into structured lists according to the legal elements of lending and provides calculation basis, and transforms colloquial descriptions of breach of contract into legal qualitative expressions such as "fundamental breach of contract" and "failure to perform as agreed." At the same time, it lists the types of evidence supporting each factual claim and their core content in a standardized manner, and strictly limits itself to the scope of facts reflected in the original evidence, without adding any new facts not found in the original materials.
[0030] The exemplary lawyer's letter paragraphs are independently drafted by senior lawyers with over five years of experience, based on the original evidence and concise evidence summaries of the corresponding cases, and in accordance with the format of civil litigation documents and common standards in the legal profession. Their content features precise legal citations down to the article, clause, and item level; each factual claim clearly corresponds to the original evidence; the legal consequences are expressed in a standardized and complete manner; and the tone and format meet the serious requirements of a lawyer's letter. A progressive mapping relationship is formed between the concise evidence summaries and the exemplary lawyer's letter paragraphs, from factual organization to legal expression. Each sample is cross-checked by two lawyers to ensure consistency in annotation quality, providing a stable and reliable high-quality monitoring signal for subsequent meta-learning and training.
[0031] 2. Meta-learning task construction Based on the aforementioned pool of 100 samples, multiple meta-learning tasks T are constructed. i Each meta-learning task simulates a scenario of "handling a new case after learning from a small number of similar cases and their complete writing experience." For each task T... i Processing to obtain the support set and query set .
[0032] Support set The system randomly selects N (ideally 5) complete samples from the sample pool. Each sample contains three fields: (original evidence text, refined evidence summary, and a sample lawyer's letter paragraph). It supports using aggregated data for the inner loop, allowing the model to access all three fields to quickly learn the mapping from the original expression to the refined evidence summary and then to the sample lawyer's letter.
[0033] query set Additionally, A (ideally 2) case samples different from the support set are randomly selected. Each sample contains only two fields: (original evidence text) and (premium lawyer's letter paragraph), without providing a refined evidence summary. In the outer loop, the model starts with the parameters updated in the inner loop and generates candidate lawyer's letter paragraphs using only the original evidence text from the query set as input. The loss function is calculated by comparing the generated text with the premium lawyer's letter paragraphs provided in the query set.
[0034] Through this construction, the inner loop enables the model to perform rapid semantic alignment using a small number of samples, while the outer loop forces the model to learn the generalization ability to generate high-quality lawyer's letters only from the original noisy evidence, thus avoiding information leakage in the meta-learning process.
[0035] During training, the system constructs a large number of meta-learning tasks Episodes through repeated random sampling. Since the sample pool contains 100 cases, the combination of support set and query set is extremely rich, which can fully support the convergence of global parameters of dual tower encoder and text generator.
[0036] S2: The dual-tower encoder generates a representation vector and projects it onto the legal requirements space to obtain a gap vector. 1. Construction of a dual-tower encoder Model selection: The pre-trained language model BERT-base-chinese is used as the backbone network of the dual-tower encoder. The two encoding towers (evidence tower and quality tower) share all weight parameters (i.e., a conjoined network structure).
[0037] The system uses a prefix injection feature (for differentiation). When the original evidence text is input, the prefix "[CLS] Evidence Content" is appended to its header. When a refined evidence summary is input, the prefix "[CLS] Legal Requirements Summary" is appended to its header. The 768-dimensional vector at the "[CLS]" position is extracted as the representation vector. Let V be the original evidence representation vector. raw The refined evidence representation vector is V. refined .
[0038] 2. Calculation and Projection of the Legal Requirements Gap Vector Calculate the difference V between the two in the latent space. diff =V raw- V refined V diff Each component in the vector represents the degree of deviation between the original and refined text on a certain abstract semantic dimension of BERT. To assign interpretable legal meaning to the difference vector, this embodiment presupposes a 6-dimensional legal element space. Each dimension in this space corresponds to the key legal features that must be considered when drafting a lawyer's letter in a financial loan contract dispute case. The specific definitions and judgment criteria for each dimension are as follows: Dimension number Dim1, legal requirement feature category is time description accuracy, which measures the degree of time expression from vague to precise. Low score (0): "end of last year", "recent"; high score (1): "March 1, 2022", "as of March 1, 2023". The larger the difference, the more vague the time expression in the original evidence is, and it needs to be specified when generating the lawyer's letter.
[0039] Dimension number Dim2, legal requirement feature category is sufficiency of the basis for calculating the amount, which measures whether there is a clear calculation formula or supporting evidence for the composition of the amount. Low score (0): "Still owes hundreds of thousands"; High score (1): "Principal of 500,000 yuan, interest calculated at an annual interest rate of 14.8%, from March 1, 2022 to March 1, 2023, the interest is 74,000 yuan". The larger the difference, the more it indicates that the original evidence lacks a clear breakdown of principal and interest.
[0040] Dimension number Dim3, the legal element feature category is the legal provision citation level, which measures the degree of standardization of the legal basis citation. Low score (0): "violated the Contract Law"; high score (1): "according to Article 675 of the Civil Code of the People's Republic of China". The larger the difference, the more it indicates that the original text lacks precise legal provision reference.
[0041] Dimension number Dim4, the legal requirement feature category is the intensity of subjective fault description, which measures the strength of the description of the breaching party's subjective state. Low score (0): "temporarily not paid"; High score (1): "refused to perform after repeated reminders, showing obvious malicious intent to default". The larger the difference, the more necessary it is to strengthen the condemnatory tone and legal characterization of the lawyer's letter.
[0042] Dimension number Dim5, the legal requirement feature category is the completeness of the evidence chain, which measures whether the types of evidence supporting the claim are complete. Low score (0): only oral statements; high score (1): closed-loop evidence including written contracts, transfer vouchers, and collection records. The larger the difference, the more likely that the original text is missing mentions of key evidence types.
[0043] Dimension number Dim6, the legal element feature category is the degree of standardization in the characterization of breach of contract, which measures whether the judgment of the nature of the legal act uses standard legal language. Low score (0): "No money was paid"; High score (1): "Constitutes a fundamental breach of contract". The larger the difference, the more colloquial the description of the behavior is.
[0044] To achieve the mapping from the 768-dimensional BERT latent space to the 6-dimensional legal elements space, this embodiment introduces a trainable projection matrix W∈R. 768×6 This matrix is jointly optimized with the dual-tower encoder during meta-learning training, and each column w... k (k=1,2,3...,6) can be understood as a linear detector used to extract the signal related to the k-th legal element dimension from the BERT latent vectors. The projection operation is defined as: V gap =V diff ·W; where V gap ∈R 6 This is the legal requirement gap vector.
[0045] To ensure that the dimensions learned by the projection matrix W truly correspond to the predefined legal requirements features, rather than relying entirely on end-to-end black-box fitting, an initialization guidance method based on a legal lexicon can be chosen. Taking Dim1 (time description precision) as an example, the predefined anchor lexicon is {"year", "month", "day", "specific date", "vague time"}. Before training begins, the average value v of the contextual representation vectors of these words in a large corpus of legal documents is calculated using a pre-trained BERT model. time ∈R 768 v time This serves as the initial value for the first column of the projection matrix W. The other dimensions follow the same logic. For example, the anchor terminology for Dim3 (legal citation level) can be preset as {"Article...", "According to the Civil Code", "Provisions", "In accordance with the law"}, and the calculated value is v. law This serves as the initial value for the corresponding column. Through this initialization strategy, even in the early stages of training, the numerical values of each dimension after the difference vector projection initially reflect the semantic shift direction of the original text in the corresponding legal dimension. With the contrastive loss L during meta-learning training... c With the introduction of W, the weights of W will be fine-tuned around the direction of legal semantics, so that after training convergence, the differences of each dimension not only have mathematical separability, but also clear legal semantic interpretability.
[0046] S3: Model-independent meta-learning training This embodiment uses the Model Independent Meta-Learning (MAML) algorithm framework for optimization. For example, the hyperparameters are set as follows: inner loop learning rate α = 0.01, outer loop learning rate η = 0.001, and balance coefficient β = 0.1.
[0047] The loss function used in this embodiment differs depending on whether it's an inner or outer loop. The inner loop (support set) provides the original evidence text, refined evidence summary, and a high-quality lawyer's letter paragraph simultaneously, thus allowing for the complete calculation of all three losses. Therefore, the formula for the inner loop loss function is L. i =L c +L g +β·L a .
[0048] Among them, L c To compare the losses, for each sample in the support set, its refined representation vector V is calculated. refined With the original representation vector V raw The algorithm aims to minimize the "1-cosine similarity" between the two elements in the latent space, thereby reducing their distance. Its mathematical expression is: ; Among them, V raw With V refinedThese are the original evidence representation vector and the refined evidence representation vector for the same case, respectively. Using this loss function, the deviation between the original evidence representation and the refined legal requirements representation in the semantic space can be quantified. This deviation is then minimized through gradient descent, thereby guiding the encoder to implicitly learn the mapping knowledge from non-normative text to normative text.
[0049] The outer loop (query set) query set does not provide a refined evidence summary, therefore L cannot be directly computed. c To maintain the advantages of contrastive learning, this embodiment replaces the contrastive loss with the semantic similarity loss L between the generated paragraph and the sample lawyer's letter paragraph. s Specifically, the generated candidate lawyer's letter paragraphs and the high-quality lawyer's letter paragraphs provided in the query set are respectively input into the high-quality tower of the dual-tower encoder (sharing weights with the evidence tower), and their respective [CLS] vectors are extracted. The cosine distance between them is then calculated. The outer loop loss function L... o =L s +L g +β·L a This design allows the model to learn the mapping from the original text to a high-quality lawyer's letter by comparing the semantic consistency between the generated result and a high-quality template, even when a refined evidence summary is unavailable. This is consistent with the L in the inner loop. c It serves a similar guiding role.
[0050] Regarding the remaining parameters, L g To generate the loss, we calculate the cross-entropy loss between the lawyer's letter text predicted by the text generator and the sample high-quality lawyer's letter paragraphs. The goal is to minimize the difference between the generated content and the high-quality templates at the word level.
[0051] L a For the adversarial loss of generator G, L a =-log(D(G(input))), where D is the discriminator, which is trained using both real high-quality lawyer's letter paragraphs (label 1) and generated paragraphs (label 0) for binary classification. The generator minimizes L... a This causes the discriminator to judge the generated paragraph as real.
[0052] Support set data for task i Perform one step of gradient descent and calculate the loss on the support set. Generate temporary parameters and .
[0053] ; ; The specific process involves the model quickly learning "how to transform a refined evidence summary into a formal lawyer's letter" using only three case summaries and high-quality templates.
[0054] query set data for task i (i.e., the original text of the evidence): In the forward propagation phase of the outer loop, the model only reads the original evidence text fields from the query set samples as input, and uses the temporary parameters updated by the inner loop. and Generate candidate lawyer letter paragraphs. Then, compare the generated paragraphs with the sample lawyer letter paragraphs provided in the query set (used only for loss calculation and not included in the forward input) to calculate the generated loss L. g and countermeasures against losses L a Because the query set does not provide a refined evidence summary, the outer loop cannot directly calculate the contrastive loss L. c Therefore, L will not be calculated in this step. c Instead, it uses the semantic similarity loss L between the generated paragraph and the paragraph of a high-quality lawyer's letter. s Effective substitutions are performed to maintain semantic constraints on the generated results. The query set loss gradients from all meta-learning tasks are summed, and the global parameters are updated via backpropagation. and The principle behind this design is that the outer loop simulates a real-world application scenario. When faced with a completely new case, the model can only generate a lawyer's letter based on the original evidence text, without having prior knowledge of the ideal, refined evidence summary for that case. The optimization goal of meta-learning is precisely to minimize the gap between the generated content in this scenario and the high-quality template.
[0055] ; ; The purpose of this step is to enable the model to learn the ability to extract features from raw, messy evidence, rather than simply mimicking refined evidence summaries.
[0056] In the meta-learning framework, the learning rates of the inner and outer loops are not arbitrarily chosen, but rather based on the mathematical structure and long-term engineering practices of the model-independent meta-learning algorithm itself. In the practice of model-independent meta-learning algorithms such as MAML, the inner loop learning rate is usually set to be an order of magnitude larger than the outer loop learning rate to accommodate the gradient flow constraints of the two-layer optimization. Referring to the common configuration in classic MAML implementations, this embodiment exemplarily sets α to 0.01 and η to 0.001. On the other hand, the setting of the balance coefficient β=0.1 is based on the problem of matching the magnitudes of adversarial loss and master generation loss in multi-task learning. Contrastive loss L c Cosine similarity is used for calculation, and its value typically ranges from 0.0 to 2.0; the generation loss L...g Cross-entropy is used, with values typically ranging from 1.5 to 5.0; while adversarial loss L... a The binary cross-entropy between the discriminator's output score and the ideal score (1.0) is set, with an ideal initial value of approximately 0.693. In adversarial training, the discriminator typically converges faster than the generator. If β is too large, the discriminator's backpropagation gradient will excessively interfere with the generator's learning of semantic coherence, leading to incoherent generated text (pattern collapse). If β is too small, the discriminator becomes ineffective and cannot effectively constrain the evidence matching degree of the generated text. In GAN training, even small changes in the learning rate can fundamentally alter the training process. The generator hopes the discriminator will misclassify the generated data as real data, while the discriminator aims to accurately distinguish between real and generated data; a dynamic balance needs to be maintained between the two. Therefore, setting β to 0.1 can effectively utilize adversarial signals to improve evidence support while maintaining generation quality.
[0057] S4: Obtain the original evidence text of the current case and generate a lawyer's letter. This step describes how the system processes a new case after model training is complete, from the initial input of raw evidence text to the generation of a lawyer's letter. The entire process requires no manual intervention and relies solely on the global parameters obtained during training. (Dual tower encoder) and (Text generator and discriminator).
[0058] The user inputs the relevant materials for the case requiring a lawyer's letter into the system. In this embodiment, the input is a piece of original evidence text described in natural language (with a brief description provided by the user). An example is as follows: "Zhang San borrowed RMB 500,000 from our company (XX Microfinance Co., Ltd.) at the end of December 2022. The two parties agreed on a monthly interest rate of 1.5% (i.e., an annual interest rate of 18%), which was supposed to be repaid in full by the end of March 2023. The repayment deadline has now passed. Despite our company's repeated requests for payment via WeChat and telephone, Zhang San has not paid any principal or interest, and we have been unable to contact him recently. Our company has a scanned copy of the loan agreement, electronic bank transfer receipts, and screenshots of WeChat collection chat records." The text contains colloquial expressions, vague time points, and an unstructured list of evidence, consistent with input characteristics in real-world business scenarios. The original evidence text is input into the evidence tower part of a dual-tower encoder trained using meta-learning. A function prompt prefix, [CLS] followed by the evidence content, is appended to the text header. The Chinese BERT segmenter is then used to segment the appended text into a Token ID sequence of length L. curThe Token ID sequence is input into the dual-tower encoder (both encoders use the global parameters θ after training convergence; since no comparison task is involved, only the computation path of the evidence tower is enabled). After layer-by-layer computation through 12 Transformers, the 768-dimensional output vector corresponding to the [CLS] position of the last layer is extracted as the original representation vector of the current case.
[0059] V raw-cur =BERT θ (Original evidence text)∈R 768 ; V raw-cur This is the original representation vector for the current case. This vector encodes all the semantic information of the original evidence text in the form of a distributed representation, including the identities of the parties, monetary amounts, time statements, descriptions of breach of contract, and indications of the type of evidence. Furthermore, because the encoder has been trained through meta-learning, this vector implicitly contains a "gap-perception" tendency between the original evidence and the refined evidence.
[0060] To calculate the legal requirement gap between the current original evidence and the "ideal refined state," the system needs to obtain a baseline vector. This embodiment uses the arithmetic mean of refined vectors from historical samples of similar case types as this baseline. The system determines the current case's cause of action as "financial loan contract dispute" based on user input or automatic text classification. It retrieves the refined vector library established during the training phase, which stores the refined representation vectors of all 100 historical samples after training (i.e., the output vector of the dual-tower encoder for each refined evidence summary during the training phase). All samples labeled "financial loan contract dispute" are selected, assuming a total of M samples (e.g., M=80). The arithmetic mean of each element of the selected K 768-dimensional refined vectors is calculated to obtain the average refined vector. : ; This average vector represents the typical position in the latent space of an evidentiary summary that meets the "complete legal requirements" under the cause of action of a financial loan contract dispute. During the training phase, the legal requirement gap vector V... gap It is obtained by subtracting the original representation vector from the refined representation vector of the same case. During the reasoning stage, since there is no "ideal refined evidence summary" for this case, this method uses the arithmetic mean of the refined representation vectors of historical cases with similar causes. As an alternative frame of reference.
[0061] The aforementioned approximation strategy of using the average of historical refined vectors for similar causes of action to replace the true refined representation of the current case is reasonable based on the following fact: the evidentiary structure of different cases under the same cause of action is highly homogeneous at the level of legal requirements. Taking financial loan contract disputes as an example, the evidentiary elements in each case consistently revolve around five dimensions: loan agreement, payment, interest rate agreement, repayment period, and default. The composition of evidence types and the framework for factual description exhibit significant pattern reuse characteristics. Meta-learning training enables the dual-tower encoder to encode the legal requirement structure information of the above-mentioned cause of action level into the latent space distribution of the refined representation. Therefore, the arithmetic mean of the refined vectors for similar causes of action can serve as an effective latent space proxy reference for the "average completeness state" of the current case, providing a semantically correct benchmark for the calculation of the gap vector.
[0062] The reliability of this proxy strategy is further guaranteed by the latent space clustering effect exhibited by the encoder after training convergence. Experiments show that the average cosine similarity between refined representation vectors of the same cause of action can reach over 0.65, significantly higher than that of cross-cause of action samples. Its mean vector can effectively capture the core features of the complete expression of the legal requirements of the cause of action. The error introduced by replacing the true refined representation with the mean is mainly concentrated in the dimensions of surface variables such as amount and date. The deviation in the projection direction of the abstract legal requirements dimension is limited. The fluctuation of the legal requirements completeness index of the generated text is within a controllable range and does not affect the standardization and usability of the final output.
[0063] Using the current original representation vector V raw-cur Average refined vector And the projection matrix W learned during the training phase, to calculate the gap vector of the current case in the legal elements space.
[0064] 1. Calculate the current latent space difference V diff_cur =V raw-cur - ∈R 768 .
[0065] 2. Project onto the legal elements space, using the converged projection matrix W∈R. 768×6 The current legal requirement gap vector V is obtained. gap_cur : V gap_cur =V diff_cur ·W∈R 6 ; We obtain the 6-dimensional current legal requirement gap vector V. gap_cur The physical meaning of each dimension is consistent with the definition in the training phase (time accuracy, monetary basis, legal provisions level, fault intensity, completeness of the evidence chain, and breach of contract characterization).
[0066] Example calculation of V gap_cur as follows:
[0067] This vector will guide the generator in subsequent steps to selectively supplement and strengthen the legal expressions of the corresponding dimensions. The current original representation vector V... raw-cur The vector V of the gap between legal requirements gap_cur The text generator (BART) is trained using common input to generate a lawyer's letter text. The 6-dimensional V... gap_cur Input a two-layer feedforward neural network (FFN), which has been jointly optimized with the generator during the training phase.
[0068]
[0069] We obtain a 768-dimensional control vector c∈R 768 This vector has been aligned to the hidden layer dimension of BART. When the BART decoder generates each word, the first position of its input sequence is the start token s, and its corresponding embedding vector is e. bos ∈R 768 This embodiment employs an embedding layer replacement strategy, modifying the embedding vector of the starting token to be the element-wise sum of the original embedding and the control vector. : ; Due to the self-attention mechanism, the modified starting token embedding propagates to other positions in the sequence at each layer of the decoder, thereby continuously imposing control signals at the legal requirements level throughout the generation process. The BART encoder reads the token sequence of the original evidence text, generating the encoder's hidden state. The BART decoder uses the modified starting token embedding... Starting with the encoder's hidden state, the generator produces lawyer's letter text word by word using an autoregressive approach. A beam search strategy is employed during generation, with a beam width of 5 being optimal to balance fluency and diversity. The generator outputs a complete lawyer's letter text (candidate paragraphs), for example: To Mr. Zhang San: XX Microfinance Co., Ltd. (hereinafter referred to as "our company") hereby formally authorizes you to formally address your overdue loan principal and interest as follows: I. Basic Facts Upon investigation, it was found that your company borrowed RMB 500,000 (¥500,000.00) from Xiaosi in December 2022, with an agreed monthly interest rate of 1.5% (annual interest rate of 18%), which was to be repaid in full by the end of March 2023. The above facts are evidenced by the Loan Agreement, bank transfer vouchers, and WeChat chat records.
[0070] II. Circumstances of Breach of Contract As of the date of this letter, your company has failed to repay any principal and interest as agreed, and has ignored our repeated reminders. This constitutes a fundamental breach of contract and seriously infringes upon our company's legitimate property rights.
[0071] III. Legal Basis According to Articles 675 and 676 of the Civil Code of the People's Republic of China, borrowers shall repay loans and pay interest within the agreed period. Your failure to repay on time violates the aforementioned legal provisions.
[0072] IV. Our Company's Position and Requirements In light of the foregoing facts, our company hereby demands that you immediately repay the entire principal of the loan, RMB 500,000, plus all interest up to the date of actual repayment, within five days of receiving this letter. Failure to comply within the stipulated time will result in our company initiating legal proceedings in the People's Court. In such cases, in addition to bearing all debts, you will face additional litigation costs, preservation fees, and corresponding penalty interest, which may also have a significant adverse impact on your credit record.
[0073] We urge you to handle this matter with caution to avoid legal trouble.
[0074] This is to inform you.
[0075] XX Microfinance Co., Ltd. [Date] To further ensure the matching degree between the generated text and the strength of evidence, this step introduces the adversarial discriminator obtained during the training phase to evaluate the quality of the candidate paragraphs. The candidate paragraphs are input into the text encoder of the discriminator (which can share some low-level parameters with the generator or use a separate BERT encoder) to extract the paragraph representation vector V. para ∈R 768 V para The control vector c (or the dimensionally aligned control vector c) is concatenated to obtain the comprehensive input vector V of the discriminator. in : V in =[V para ;c]∈R 1536 ; The concatenated vector is fed into the discriminator's feedforward classification network (which has converged during training). After passing through the sigmoid activation function, a score s between 0 and 1 is output. The score s represents the degree of matching between the generated content and the current evidence strength and legal requirements. The closer the score s is to 1, the more the generated paragraph meets the expected quality level of a lawyer's letter under the given evidence conditions. If s ≥ 0.8, the candidate paragraph is accepted and proceeds to the S5 output stage. If s < 0.8, a regeneration mechanism is triggered, adjusting the generator's decoding parameters (e.g., increasing the beamwidth to 8), and returning to S4-5 to regenerate a new candidate paragraph. This process is repeated until a paragraph that meets the scoring threshold is generated, or the preset maximum number of retries (e.g., 5 times) is reached, and the paragraph with the highest score is output. In this example, the candidate paragraph passes the verification directly with a discriminator score s ≥ 0.8, without needing to be regenerated.
[0076] S5: Output the text This step marks the end of the entire method, delivering the verified lawyer's letter text to the user in a structured format. This completes a full meta-learning-driven lawyer's letter comparison and generation process. Through the specific implementation steps S4 to S5 described above, the system achieves fully automated transformation from raw, messy evidence text to high-quality, highly matched lawyer's letter text, significantly improving the efficiency and standardization of lawyer's letter drafting.
[0077] The embodiments and / or implementation methods described above are merely preferred embodiments and / or implementation methods for implementing the technology of the present invention, and are not intended to limit the implementation methods of the technology of the present invention in any way. Any person skilled in the art may make some modifications to other equivalent embodiments without departing from the scope of the technical means disclosed in the content of the present invention, but these should still be regarded as the technology or embodiments that are substantially the same as the present invention.
[0078] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. The above descriptions are only preferred embodiments of this application. It should be noted that due to the limitations of written expression, while there are objectively infinite specific structures, those skilled in the art can make several improvements, modifications, or changes without departing from the principles of this application, and can also combine the above technical features in an appropriate manner. These improvements, modifications, changes, or combinations, or the direct application of the inventive concept and technical solution to other situations without modification, should all be considered within the scope of protection of this application.
Claims
1. A method for rapidly adapting and generating lawyer's letters for a small number of samples, characterized in that, Includes the following steps: S1: Construct meta-learning tasks based on historical case samples. Each task includes a support set and a query set. The support set samples provide original evidence text, refined evidence summary, and high-quality lawyer's letter paragraphs. The query set samples only provide original evidence text and high-quality lawyer's letter paragraphs. The cases in the two sets do not overlap. S2: A dual-tower encoder that shares weights with the refined evidence summary of the support set and the original text input of the support set for the same case obtains the refined representation and the original representation. The difference between the original representation and the refined representation of the same case is calculated and projected onto the preset legal element space to obtain the legal element gap vector. S3: Perform model-independent meta-learning training on the dual-tower encoder and text generator: the inner loop updates task-specific parameters based on the support set, and the outer loop summarizes the loss based on the query set to update global parameters; the loss function includes at least contrastive loss, generative loss and adversarial loss. S4: Obtain the original evidence text of the current case, generate the current original representation using the trained dual-tower encoder, calculate the current legal element gap vector by combining the average refined representation of similar cases, input the current original representation and gap vector into the generator, and generate the lawyer's letter text under the constraint of the adversarial discriminator. S5: Output the text.
2. The method for rapidly adapting and generating lawyer's letters for a small number of samples according to claim 1, characterized in that, The dual-tower encoder in step S2 is a conjoined network built based on the pre-trained language model BERT. The two encoding towers share all weight parameters, and different prompt word prefixes are added to the input layer to distinguish between the evidence tower function and the premium tower function.
3. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 1, characterized in that, The legal requirement space in step S2 includes multiple preset dimensions, each of which corresponds to at least one of the following legal requirement feature categories: accuracy of time description, sufficiency of basis for monetary calculation, level of legal provision citation, intensity of subjective fault description, completeness of evidence chain, and degree of standardization of the characterization of breach of contract.
4. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 3, characterized in that, In step S2, the difference vector is projected onto the legal elements space, which is achieved through a trainable projection matrix W, whose number of rows is the dimension of the encoder output vector and whose number of columns is the dimension of the legal elements space. The projection matrix W is initialized before training in the following manner: for the k-th dimension in the legal element space, a set of legal element anchor words are preset, the high-frequency context representation vector corresponding to the anchor words is calculated using the dual-tower encoder, and the initial weight of the k-th column of the projection matrix W is constructed based on the representation vector, so that the untrained difference vector has a preliminary legal element orientation after projection.
5. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 1, characterized in that, The inner loop training loss function L in step S3 i =L c +L g +β·L a The outer loop loss function L o =L s +L g +β·L a , where L c To narrow the gap between the original representation vector and the refined representation vector, the comparison loss L g To calculate the generation loss targeting a high-quality lawyer's letter paragraph under the guidance of the aforementioned legal element gap vector, L a The generator's adversarial loss is β, where β is the balance coefficient, and L is the inequality loss. s The semantic similarity loss between the paragraphs generated under the guidance of the legal requirements gap vector and the paragraphs of the premium lawyer's letter.
6. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 5, wherein the inner loop parameter update in step S3 includes: Based on the support set, calculate the inner loop loss function. For the current global encoder parameters The gradient, and For the current global generator parameters The gradient; Using a preset inner loop learning rate The current global encoder parameters Update one step in the opposite direction of the gradient to obtain the encoder parameters specific to this meta-learning task. ; Using the inner loop learning rate The global generator parameters Update one step in the opposite direction of the gradient to obtain the generator parameters specific to this meta-learning task. .
7. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 6, characterized in that, The outer loop parameter update process in step S3 includes: For all meta-learning tasks, utilize the specific encoder parameters. and specific generator parameters The outer loop loss function is calculated on the query set. ; Accumulate the outer loop loss function corresponding to each task Regarding encoder global parameters The gradient is calculated, and a preset outer loop learning rate is used. Update the global encoder parameters in the opposite direction of the gradient. ; The outer loop loss function for each task is accumulated with respect to the generator's global parameters. The gradient is calculated, and the generator's global parameters are updated in the reverse direction of the gradient using the outer loop learning rate. . The specific formula is as follows: ; ; Where η is the outer loop learning rate. Let i be the query set for task i.
8. The method for rapidly adapting and generating lawyer's letters for a small number of samples according to claim 7, characterized in that, During the outer loop parameter update process in step S3, the model takes the parameters updated by the inner loop as the starting point, reads only the original evidence text of the sample in the query set as input, generates candidate lawyer letter paragraphs, calculates the loss with the high-quality lawyer letter paragraphs of the sample in the query set, and does not provide the model with a refined evidence summary of the sample in the query set.
9. The method for rapidly adapting and generating lawyer's letters for a small number of samples according to claim 1, characterized in that, The adversarial discriminator in step S4 is a binary classification network. Its input is the concatenation of the candidate paragraphs output by the generator and the current gap vector, and its output is the evidence support score s∈[0,1], which represents the matching degree between the generated content and the evidence strength.
10. The method for rapid adaptation and generation of lawyer's letters for a small number of samples according to claim 1, characterized in that, The average refined vector in step S4 is obtained by retrieving all historical samples with the same cause of action as the current case and calculating the arithmetic mean of their refined vectors.
