File semantic similarity calculation method based on improved DeBERTa model
By improving the structural role coupling and energy spectrum dynamic resonance mechanism of the DeBERTa model, the problems of semantic hierarchy confusion and cross-domain expression differences in long text files are solved, and high-precision and stable file semantic similarity calculation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-03-31
AI Technical Summary
When dealing with long, complex, and semantically diverse documents, the existing DeBERTa model struggles to accurately reflect the hierarchical relationships and logical threads of the overall semantics. Furthermore, it suffers from semantic drift and feature mismatch issues in cross-domain corpora or heterogeneous document scenarios, resulting in insufficient accuracy and stability in similarity calculation.
By introducing a structural role coupling attention module, a main vein topology reconstruction module, and a self-correcting consistency module, and combining a semantic energy spectrum dynamic resonance mechanism and a semantic field curvature function, hierarchical modeling of files and dynamic matching across semantic spaces are achieved. The similarity between files is calculated through semantic energy resonance spectrum features.
It improves the accuracy and stability of semantic similarity calculation for long text files, maintains the integrity of semantic structure and cross-domain robustness, and enhances the semantic understanding accuracy and interpretability of the model in complex application scenarios.
Smart Images

Figure CN121328568B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing, and in particular to a method for calculating the semantic similarity of documents based on an improved DeBERTa model. Background Technology
[0002] With the rapid development of natural language processing technology and pre-trained language models, deep learning-based semantic understanding methods have gradually become the mainstream approach for document content analysis and similarity calculation. Among them, bidirectional encoding structures, represented by BERT and its improved model DeBERTa, have achieved high accuracy in short text semantic modeling. However, when faced with long, complex, and semantically diverse documents, existing models generally divide the document into independent segments for local encoding, and then obtain a global semantic representation through averaging or concatenation. This approach easily leads to the loss of structural information and the break in semantic connections in long texts, making it difficult to accurately reflect the hierarchical relationship and logical thread of the overall semantics of the document.
[0003] While existing DeBERTa models improve word-level semantic capture capabilities to some extent by decoupling positional encoding and attention distribution, they are still primarily optimized for sentence-level or paragraph-level short text tasks, lacking a modeling mechanism for internal document structural roles (such as titles, body text, introductions, and summaries). Traditional semantic similarity calculations often rely on cosine similarity or dot product operations in vector spaces, failing to consider the transmission patterns of textual semantic energy across different levels, and also failing to capture the dynamic balance relationships of semantic structures across layers, resulting in insufficient accuracy in document similarity calculations at complex semantic levels.
[0004] Existing technologies commonly suffer from semantic drift and feature mismatch issues in cross-domain corpora or heterogeneous file scenarios. Models lack self-alignment capabilities across different semantic spaces; when file content originates from different genres, domains, or formats, semantic representations shift, leading to distorted similarity calculations. The lack of constraints on semantic stability and consistency easily results in unstable model outputs and insufficient interpretability, making it difficult to support complex application scenarios such as high-precision semantic retrieval and knowledge reasoning.
[0005] Therefore, how to provide a method for calculating the semantic similarity of files based on the improved DeBERTa model is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] One objective of this invention is to propose a document semantic similarity calculation method based on an improved DeBERTa model. This invention fully integrates deep semantic modeling, semantic energy field analysis, and semantic self-alignment mechanisms. Addressing the issues of missing structural information, chaotic semantic hierarchy, and cross-domain expression differences leading to similarity distortion in long text files, it designs an improved DeBERTa semantic modeling structure and energy spectrum alignment calculation framework. This invention achieves hierarchical modeling of document semantics by introducing a structural role coupling attention module, a main vein topology reconstruction module, and a self-correcting consistency module; calculates the internal semantic energy distribution and hierarchical resonance law of the document through a semantic energy spectrum dynamic resonance mechanism; and achieves dynamic matching across semantic spaces by combining a semantic field curvature function and a gravitational self-alignment mechanism. This invention can maintain the integrity of semantic structure and cross-domain robustness in the semantic similarity calculation of long text files, and has the advantages of high semantic understanding accuracy, strong stability of similarity calculation, and good interpretability of results.
[0007] The document semantic similarity calculation method based on the improved DeBERTa model according to embodiments of the present invention includes:
[0008] The files to be compared are preprocessed by hierarchical text structure, which involves segmenting the files by chapters, paragraphs, and sentences and labeling them with structural role tags. The text content is then denoised, segmented, and encoded with sub-words to generate a hierarchical input sequence containing structural role information.
[0009] The hierarchical input sequence is fed into the improved DeBERTa model, which includes a structural role coupling attention module, a main vein topology reconstruction module, and a counterfactual self-correcting consistency module, and outputs a file semantic representation vector.
[0010] The semantic representation vector of the file is input into the semantic energy spectrum dynamic resonance module. A semantic energy resonance graph is constructed based on the semantic vectors at different levels. By calculating the energy transmission path and coupling strength between semantic nodes at each level, a semantic energy resonance spectrum of the file is formed, and semantic energy resonance spectrum features are generated.
[0011] Based on the semantic energy resonance spectrum features, the energy distribution pattern and resonance correlation strength of the document semantics at different levels are calculated to form a semantic energy spectrum feature vector.
[0012] The semantic energy spectrum feature vector and the file semantic representation vector are jointly mapped to a continuous and variable semantic field space. By constructing a semantic field curvature function, the spatial curvature and distance metric between semantic representations are dynamically adjusted to obtain a file-level semantic alignment representation.
[0013] The semantic energy resonance spectrum features and the file-level semantic alignment representation are weighted and fused to calculate the comprehensive semantic similarity score between files, and the final file semantic similarity result is output.
[0014] Optionally, the step of segmenting the file by chapters, paragraphs, and sentences and labeling them with structural role tags specifically refers to performing structured layering processing on the file content, dividing the text into chapter-level units based on the file's format features and semantic boundaries, then dividing each chapter-level unit into paragraph-level units, and further refining them into sentence-level units, then performing semantic analysis on each level of unit, and labeling the corresponding structural role tags according to the functional role of each level of unit in the document.
[0015] Optionally, the denoising, word segmentation, and sub-word encoding of the text content specifically refers to cleaning the file text, removing non-semantic characters, redundant spaces, headers and footers, formatting symbols, and special markers, segmenting the cleaned text according to linguistic rules, dividing the continuous text into words or symbols with independent meaning, and then performing sub-word-level encoding based on the model vocabulary, further dividing low-frequency words or out-of-vocabulary words into sub-word units and mapping them to corresponding indexes or vector representations.
[0016] Optionally, the output file semantic representation vector includes:
[0017] Receive a hierarchical input sequence, establish a correspondence between content representation, structural role label, relative position and hierarchical distance for each tag, initialize the role coupling graph and hierarchical parameters for the current document, and obtain the initial encoding sequence;
[0018] In the structural role coupling attention module, the attention weights of the tag pairs are calculated based on the query vector, key vector and value vector generated from the initial encoding sequence. The role coupling graph is updated online in combination with the intra-layer statistical results, and the value vectors are weighted and aggregated to obtain the tag-level hidden state set and the corresponding attention weight distribution.
[0019] Bidirectional hierarchical refinement is performed on the tag-level hidden state set. First, sentence-level, paragraph-level, and chapter-level pooling is performed from bottom to top to form hierarchical vectors. Then, chapter and title information is fed back to sentence-level and tag-level from top to bottom to correct local representations, resulting in the fed-back tag-level hidden state set, hierarchical representation set, and role-level semantic representation.
[0020] In the main vein topology reconstruction module, each paragraph is scored as a candidate main vein based on the segment-level and chapter-level vectors. A fixed number of main vein segments are selected according to the scores and the order in the text is determined to form a main vein set and generate a main vein-level semantic representation.
[0021] Asymmetric recalibration of attention weight distribution is performed using the main vein set as control point to enhance the main vein-related connections and connections within adjacent chapters while suppressing cross-chapter noisy connections. Based on the recalibrated attention weights, the document-level representation guided by the main vein and the updated tag-level hidden state set are obtained.
[0022] In the self-correcting consistency module, high-contribution segments are identified based on attention weight and contribution measurement. Counterfactual inputs such as occlusion, same-role replacement and cross-main-pulse exchange are constructed respectively. Alternative representations are generated using role prototype memory. Consistency constraints are applied to the original representation, counterfactual representation and alternative representation, and parameters are updated by joint comparison constraints to obtain the stabilized tag-level hidden state set and hierarchical representation set.
[0023] The semantic representations at the sentence, paragraph, role, and main line levels are adaptively weighted and pooled. At the same time, the document-level representation guided by the main line is embedded and integrated with the overall file structure to generate a full-text semantic representation. Then, the semantic representations at the sentence, paragraph, role, main line, and full-text levels are combined to form a hierarchical semantic vector set, and the file semantic representation vector is output.
[0024] Optionally, the generation of semantic energy resonance spectrum features includes:
[0025] Receive the file semantic representation vector and the hierarchical semantic vector set, establish a hierarchical index and order consistent with the structural role label, and construct a semantic energy spectrum dynamic resonance module composed of hierarchical energy flow construction unit, cross-layer phase-locked coordination unit and resonance stability and debiasing unit;
[0026] In the hierarchical energy flow construction unit, the energy metric of each vector is calculated based on the hierarchical semantic vector. A directed energy transmission graph is generated based on the cosine similarity between vectors and the structural role compatibility relationship. Only the transmission edges with the highest weights are retained for each node, and a decay factor consistent with the hierarchical distance is embedded in the edge weights to obtain the initial energy flow.
[0027] In the cross-layer phase-locked coordination unit, energy propagation iteration is performed in a fixed order of sentence level, paragraph level, role level, main vein level, and full text level. Energy propagation iteration is performed along the directed transmission edge of the initial energy flow, the energy aggregation amount and rate of change of each level are calculated, and the transmission coefficient of adjacent levels is synchronously calibrated according to the main vein level as the anchor point, and the initial resonance spectrum is output.
[0028] In the resonant stabilization and debiasing unit, the propagation path formed by the initial energy flow is used as the basis for resonant iteration, and the initial resonant spectrum is subjected to triple stabilization:
[0029] First, high-weighted noise edges that are irrelevant to the main vein are removed based on the main vein consistency test.
[0030] Second, redundant nodes with high similarity are merged according to the near-repetition suppression strategy;
[0031] Third, high-contribution nodes are masked and resonance spectrum shifts are detected using the counterfactual perturbation test.
[0032] When the resonance spectrum shift exceeds the threshold, the corresponding edge weights are recovered to obtain stable semantic energy resonance spectrum features;
[0033] The stable semantic energy resonance spectrum features are arranged in a fixed order of sentence level, paragraph level, role level, main theme level, and full text level to form a semantic energy spectrum feature vector.
[0034] Optionally, forming the semantic energy spectrum feature vector includes:
[0035] It receives semantic energy spectrum feature vectors, directed energy transmission graphs, and hierarchical semantic vector sets;
[0036] The hierarchical semantic vector set is statistically analyzed by level, and the energy measurement of all nodes in each level is summarized to obtain the total energy of each level. The total energy of all levels is then proportionalized to form the energy ratio distribution of each level.
[0037] Based on the edge weights between nodes in the directed energy transmission graph, the total number of cross-layer connection edge weights is accumulated by pairing them up at each level to obtain the resonance correlation strength between each level pair. The edge weights are the result of weighting node semantic similarity and structural role compatibility.
[0038] The energy proportion distribution and resonance correlation intensity are normalized and calibrated at the same scale, and the energy dispersion within each level is calculated. The energy dispersion is obtained by comparing the deviation of the energy of each node within the level from the average energy of the level.
[0039] The energy proportion distribution of each level, the resonance correlation strength with other levels, and the energy dispersion of each level are weighted and combined to obtain semantic energy spectrum feature vectors arranged in the order of sentence level, paragraph level, role level, main line level, and full text level.
[0040] Optionally, obtaining the file-level semantic alignment representation includes:
[0041] Receive semantic energy spectrum feature vectors, directed energy transmission graphs, and hierarchical semantic vector sets. Set the main vein level vectors and full text level vectors as field anchors, and set the sentence level, paragraph level, and role level vectors as field particles. Establish a one-to-one correspondence between field anchors and field particles.
[0042] Based on the semantic energy spectrum feature vector, the field anchor point and field particle are assigned weights. The main direction and feedback direction of the field are determined along the outgoing and incoming edges of the directed semantic energy transmission graph. An initial semantic field distribution is generated in the vector space, and a directional field channel is formed with the main pulse level vector as the center.
[0043] Construct a semantic field curvature function, and dynamically adjust the hierarchical semantic vectors based on the semantic field curvature function:
[0044] Centered on the semantic vectors at the main vein level and the full text level, a semantic field reference coordinate system is established along the main direction and feedback direction determined by the field channel. Multiple sets of equidistant sampling layers are divided in the main direction and feedback direction. Sampling nodes corresponding to the layered semantic vectors are arranged in each sampling layer, and the semantic field intensity and inter-layer difference data of each node are recorded.
[0045] Second-order difference is performed on the field intensity difference between adjacent sampling layers to obtain the interlayer curvature scalar. The directional curvature is calculated along the principal direction and the feedback direction respectively. The difference between directions is extracted to form anisotropic parameters. The interlayer curvature scalar and directional curvature are summarized in hierarchical order to generate a curvature sequence.
[0046] Using the curvature sequence of each file in the self-aligned semantic field as the baseline, a one-to-one correspondence is established according to the hierarchy and structural role. The curvature sequences of the two files are normalized and phase-aligned. The difference sequence at the corresponding position is calculated, the semantic field curvature function is output, and zero-bias calibration is completed.
[0047] Optionally, the final output of the file semantic similarity result includes:
[0048] It receives the semantic energy spectrum feature vector and the file-level semantic alignment representation of the two files, performs unified scaling on the semantic energy spectrum feature vector, and performs unit length standardization on the file-level semantic alignment representation;
[0049] The fusion weight vector is generated by comparing the component-wise features of the semantic energy spectrum of two files. It is stipulated that when the spectrum values of the two files at the same level are close, the level weight is increased, and when the difference is large, the level weight is decreased. The weight of each level is limited to between zero and one and is standardized as a whole.
[0050] Three types of similarity are calculated: spectral similarity is calculated based on the directional similarity of the semantic energy spectrum feature vectors of the two files; alignment representation similarity is calculated based on the directional similarity of the file-level semantic alignment representations of the two files; and fusion similarity is calculated based on the directional similarity after weighting the semantic energy spectrum feature vectors and the file-level semantic alignment representations according to the fusion weight vector.
[0051] By setting non-negative weighting coefficients and summing all coefficients to one, the spectral similarity, alignment representation similarity, and fusion similarity are weighted and summed to obtain the comprehensive semantic similarity score between documents.
[0052] The beneficial effects of this invention are:
[0053] This invention achieves deep modeling and accurate representation of document-level semantic structure by introducing a multi-layered semantic enhancement mechanism into the DeBERTa model structure. By setting up a structure-role coupling attention module, the model can establish dynamic interaction relationships between sentence, paragraph, role, and main thread levels, enabling the adaptive construction of hierarchical semantics within the document. This effectively solves the problems of semantic structure information loss and weakened contextual dependencies in traditional pre-trained models in long text scenarios, significantly improving the completeness and consistency of document semantic representation.
[0054] The semantic energy spectrum dynamic resonance mechanism constructed in this invention can capture the distribution and transmission patterns of semantic energy within a file in a multi-layered semantic space, quantify the resonance intensity and energy stability between different semantic levels, thereby achieving hierarchical recognition of semantic structures and global feature aggregation. Compared with traditional methods that rely solely on vector space similarity, this invention not only focuses on the semantic content itself but also reflects the inter-layer coupling and dynamic balance characteristics of semantic information, making the semantic similarity calculation between files more consistent with actual semantic associations and improving the accuracy and discriminative ability of long text similarity calculation.
[0055] This invention dynamically maps document-level semantic representations using a semantic field curvature function and a gravitational self-alignment mechanism. This enables documents from different domains and structural types to achieve nonlinear self-alignment within a unified semantic space, reducing bias caused by differences in cross-semantic domain representations. During the alignment process, the balance and curvature stability of the semantic field are maintained, resulting in higher robustness and adaptability in similarity calculations for heterogeneous texts or cross-domain documents. This invention balances semantic accuracy with computational stability and interpretability, making it highly valuable for application and promotion. Attached Figure Description
[0056] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0057] Figure 1 This is a flowchart of the document semantic similarity calculation method based on the improved DeBERTa model proposed in this invention;
[0058] Figure 2 This is a schematic diagram of the structure of the improved DeBERTa model, which is based on the improved DeBERTa model for calculating file semantic similarity proposed in this invention. Detailed Implementation
[0059] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0060] refer to Figure 1 and Figure 2 A document semantic similarity calculation method based on the improved DeBERTa model includes:
[0061] The files to be compared are preprocessed by hierarchical text structure, which involves segmenting the files by chapters, paragraphs, and sentences and labeling them with structural role tags. The text content is then denoised, segmented, and encoded with sub-words to generate a hierarchical input sequence containing structural role information.
[0062] The hierarchical input sequence is fed into the improved DeBERTa model, which includes a structural role coupling attention module, a main vein topology reconstruction module, and a counterfactual self-correcting consistency module, and outputs a file semantic representation vector.
[0063] The semantic representation vector of the file is input into the semantic energy spectrum dynamic resonance module. A semantic energy resonance graph is constructed based on the semantic vectors at different levels. By calculating the energy transmission path and coupling strength between semantic nodes at each level, a semantic energy resonance spectrum of the file is formed, and semantic energy resonance spectrum features are generated.
[0064] Based on the semantic energy resonance spectrum features, the energy distribution pattern and resonance correlation strength of the document semantics at different levels are calculated to form an energy spectrum feature vector.
[0065] The semantic energy spectrum feature vector and the file semantic representation vector are jointly mapped to a continuous and variable semantic field space. By constructing a semantic field curvature function, the spatial curvature and distance metric between semantic representations are dynamically adjusted to obtain a file-level semantic alignment representation.
[0066] The semantic energy resonance spectrum features and the file-level semantic alignment representation are weighted and fused to calculate the comprehensive semantic similarity score between files, and the final file semantic similarity result is output.
[0067] In this embodiment, the step of segmenting the file by chapters, paragraphs, and sentences and labeling them with structural role tags specifically refers to performing structured layering processing on the file content, dividing the text into chapter-level units based on the file's format features and semantic boundaries, then dividing each chapter-level unit into paragraph-level units, and further refining them into sentence-level units. Subsequently, semantic analysis is performed on each level of unit, and corresponding structural role tags are labeled according to the functional role of each level of unit in the document.
[0068] In this embodiment, the denoising, word segmentation, and sub-word encoding of the text content specifically refers to cleaning the file text, removing non-semantic characters, redundant spaces, headers and footers, formatting symbols, and special markers, segmenting the cleaned text according to linguistic rules, dividing the continuous text into words or symbols with independent meaning, and then performing sub-word-level encoding based on the model vocabulary, further dividing low-frequency words or out-of-vocabulary words into sub-word units and mapping them to corresponding indexes or vector representations.
[0069] In this embodiment, the output file semantic representation vector includes:
[0070] Receive a hierarchical input sequence, establish a correspondence between content representation, structural role label, relative position and hierarchical distance for each tag, initialize the role coupling graph and hierarchical parameters for the current document, and obtain the initial encoding sequence. The role coupling graph is a directed weighted graph used to represent the semantic relationship between different structural roles in the document. Nodes correspond to the semantic representation of different role units, and the weight of the edges reflects the strength of the semantic dependency and hierarchical distance between roles.
[0071] In the structural role coupling attention module, the attention weights of the tag pairs are calculated based on the query vector, key vector and value vector generated from the initial encoding sequence. The role coupling graph is updated online in combination with the intra-layer statistical results, and the value vectors are weighted and aggregated to obtain the tag-level hidden state set and the corresponding attention weight distribution.
[0072] Bidirectional hierarchical refinement is performed on the tag-level hidden state set. First, sentence-level, paragraph-level, and chapter-level pooling is performed from bottom to top to form hierarchical vectors. Then, chapter and title information is fed back to sentence-level and tag-level from top to bottom to correct local representations, resulting in the fed-back tag-level hidden state set, hierarchical representation set, and role-level semantic representation.
[0073] In the main vein topology reconstruction module, each paragraph is scored as a main vein candidate based on segment-level and chapter-level vectors. A fixed number of main vein segments are selected according to the scores, and their order within the text is determined to form a main vein set and generate a main vein-level semantic representation. Specifically, the scoring of each paragraph as a main vein candidate based on segment-level and chapter-level vectors is as follows:
[0074] Calculate the semantic relevance between each paragraph vector and the chapter center vector. The higher the semantic relevance, the closer the paragraph is to the core content in the chapter's semantic structure.
[0075] Assess the structural importance of paragraphs within the document hierarchy, assigning higher weights to paragraphs that contribute significantly to the structure based on their position, role labels, and the strength of their association with the title or abstract.
[0076] By combining semantic relevance and structural importance scores with contextual continuity constraints, a candidate score for the main vein of each paragraph is generated to determine the priority and selection order of the main vein segments.
[0077] Asymmetric recalibration of attention weight distribution is performed using the main vein set as control point to enhance the main vein-related connections and connections within adjacent chapters while suppressing cross-chapter noisy connections. Based on the recalibrated attention weights, the document-level representation guided by the main vein and the updated tag-level hidden state set are obtained.
[0078] In the self-correcting consistency module, high-contribution segments are identified based on attention weight and contribution measurement. Counterfactual inputs for occlusion, same-role substitution, and cross-main-pulse exchange are constructed respectively. Alternative representations are generated using role prototype memory. Consistency constraints are applied to the original representation, counterfactual representation, and alternative representation, and parameters are updated by combining comparison constraints, resulting in a stable set of labeled hidden states and a hierarchical representation set. Specifically, the generation of alternative representations using role prototype memory involves:
[0079] During the training of the DeBERTa model, a character prototype memory unit is established for each structural character to store the stable semantic center vectors learned by the character in multiple documents, which are used to represent the typical semantic features of the character.
[0080] After constructing counterfactual input, for the high-contribution fragments that are obscured or replaced, the closest prototype vector is retrieved from the character prototype memory unit based on the original character label, and interpolation and fusion are performed in combination with the current context semantic information to generate an alternative representation that is consistent with the semantics of the original fragment.
[0081] The generated alternative representation, the original representation, and the counterfactual representation are all input into the consistency constraint unit to minimize the semantic deviation among the three.
[0082] The semantic representations at the sentence, paragraph, role, and main line levels are adaptively weighted and pooled. At the same time, the document-level representation guided by the main line is embedded and integrated with the overall file structure to generate a full-text semantic representation. Then, the semantic representations at the sentence, paragraph, role, main line, and full-text levels are combined to form a hierarchical semantic vector set, and the file semantic representation vector is output.
[0083] In this embodiment, the generation of semantic energy resonance spectrum features includes:
[0084] Receive the file semantic representation vector and the hierarchical semantic vector set, establish a hierarchical index and order consistent with the structural role label, and construct a semantic energy spectrum dynamic resonance module composed of hierarchical energy flow construction unit, cross-layer phase-locked coordination unit and resonance stability and debiasing unit;
[0085] In the hierarchical energy flow construction unit, the energy metric of each vector is calculated based on the hierarchical semantic vector. A directed energy transmission graph is generated based on the cosine similarity and structural role compatibility between vectors. For each node, only the highest weighted transmission edges are retained, and a decay factor consistent with the hierarchical distance is embedded in the edge weights to obtain the initial energy flow. Specifically, the calculation of the energy metric of each vector based on the hierarchical semantic vector is as follows:
[0086] Semantic strength is calculated for semantic vectors at the sentence, paragraph, role, main thread, and full-text levels. Semantic strength is determined by the norm of the vector in the semantic space or the information entropy level.
[0087] By combining structural role labels and hierarchical positions, hierarchical weighting coefficients are applied to semantic vectors at different levels, so that the energy metric of higher levels has a higher weight in the overall calculation.
[0088] The energy measurement results of each semantic vector are normalized to ensure that the energy is comparable across different levels.
[0089] In the cross-layer phase-locked coordination unit, energy propagation iterations are performed in a fixed order: sentence level, paragraph level, role level, main vein level, and full text level. Energy propagation iterations are executed along the directed transmission edge of the initial energy flow, calculating the energy aggregation amount and rate of change at each level. The transmission coefficients of adjacent levels are synchronously calibrated using the main vein level as the anchor point, and the initial resonance spectrum is output. Specifically, the calculation of the energy aggregation amount and rate of change at each level involves:
[0090] In each energy propagation iteration, the total amount of energy input received by each level of nodes at the sentence level, paragraph level, role level, main thread level and full text level is counted, and the energy convergence value within the current iteration cycle is accumulated.
[0091] The energy aggregation amount of the same level in two adjacent iterations is compared, the energy increase or decrease ratio is calculated, and the result is used as the energy change rate of the level to reflect the dynamic equilibrium state of energy during the propagation process.
[0092] By combining the energy change rate and aggregation trend of all levels, an inter-layer energy conduction matrix is established to record the energy flow direction and intensity between each level.
[0093] In the resonant stabilization and debiasing unit, the propagation path formed by the initial energy flow is used as the basis for resonant iteration, and the initial resonant spectrum is subjected to triple stabilization:
[0094] First, high-weighted noise edges that are irrelevant to the main vein are removed based on the main vein consistency test.
[0095] Second, redundant nodes with high similarity are merged according to the near repetition suppression strategy. The near repetition suppression strategy refers to merging nodes with highly similar semantic content and close positions in the semantic energy transmission graph by comparing the semantic similarity and structural distance between nodes, retaining representative nodes and re-labeling their energy weights and connection relationships to form a set of semantic nodes without redundancy.
[0096] Third, high-contribution nodes are masked and resonance spectrum shifts are detected based on counterfactual perturbation tests, specifically:
[0097] Nodes with high energy contribution during semantic energy transmission are selected as target nodes for testing, and corresponding counterfactual perturbation inputs are generated based on structural role labels. Perturbation samples are constructed through semantic substitution.
[0098] The semantic energy resonance spectrum is recalculated under the input of perturbation sample. The energy distribution and resonance intensity changes of the node's level and adjacent levels before and after perturbation are compared, and the energy shift value and spectrum shape difference are recorded.
[0099] The stability of a node is determined based on the offset magnitude and the degree of spectral difference. When the offset exceeds a set threshold, it is marked as an unstable node, and the node connection edge weights and energy weights are corrected to keep the semantic energy resonance spectrum balanced and consistent.
[0100] When the resonance spectrum shift exceeds the threshold, the corresponding edge weights are recovered to obtain stable semantic energy resonance spectrum features;
[0101] The stable semantic energy resonance spectrum features are arranged in a fixed order of sentence level, paragraph level, role level, main theme level, and full text level to form a semantic energy spectrum feature vector.
[0102] In this embodiment, forming the energy spectrum feature vector includes:
[0103] It receives semantic energy spectrum feature vectors, directed energy transmission graphs, and hierarchical semantic vector sets;
[0104] The hierarchical semantic vector set is statistically analyzed by level, and the energy measurement of all nodes in each level is summarized to obtain the total energy of each level. The total energy of all levels is then proportionalized to form the energy ratio distribution of each level.
[0105] Based on the edge weights between nodes in the directed energy transmission graph, the total number of cross-layer connection edge weights is accumulated by pairing them up at each level to obtain the resonance correlation strength between each level pair. The edge weights are the result of weighting node semantic similarity and structural role compatibility.
[0106] The energy proportion distribution and resonance correlation intensity are normalized and calibrated at the same scale, and the energy dispersion within each level is calculated. The energy dispersion is obtained by comparing the deviation of the energy of each node within the level from the average energy of the level.
[0107] The energy proportion distribution of each level, the resonance correlation strength with other levels, and the energy dispersion of each level are weighted and combined to obtain semantic energy spectrum feature vectors arranged in the order of sentence level, paragraph level, role level, main line level, and full text level.
[0108] In this embodiment, obtaining the file-level semantic alignment representation includes:
[0109] Receive semantic energy spectrum feature vectors, directed energy transmission graphs, and hierarchical semantic vector sets. Set the main vein level vectors and full text level vectors as field anchors, and set the sentence level, paragraph level, and role level vectors as field particles. Establish a one-to-one correspondence between field anchors and field particles.
[0110] Based on the semantic energy spectrum feature vector, the field anchor point and field particle are assigned weights. The main direction and feedback direction of the field are determined along the outgoing and incoming edges of the directed semantic energy transmission graph. An initial semantic field distribution is generated in the vector space, and a directional field channel is formed with the main pulse level vector as the center.
[0111] Construct a semantic field curvature function, and dynamically adjust the hierarchical semantic vectors based on the semantic field curvature function:
[0112] Centered on the semantic vectors at the main vein level and the full text level, a semantic field reference coordinate system is established along the main direction and feedback direction determined by the field channel. Multiple sets of equidistant sampling layers are divided in the main direction and feedback direction. Sampling nodes corresponding to the layered semantic vectors are arranged in each sampling layer, and the semantic field intensity and inter-layer difference data of each node are recorded.
[0113] A second-order difference is performed on the field intensity difference between adjacent sampling layers to obtain the interlayer curvature scalar. The directional curvature is then calculated along both the principal and feedback directions. The differences between directions are extracted to form anisotropic parameters. The interlayer curvature scalar and directional curvature are summarized in hierarchical order to generate a curvature sequence. Specifically, the calculation of directional curvature along the principal and feedback directions involves:
[0114] Starting with the main vein-level semantic representation, several consecutive sampling layers are selected along the main direction of semantic propagation. The rate of change of semantic field intensity between adjacent sampling layers is calculated, and the cumulative difference of the rate of change reflects the curvature change trend of the direction.
[0115] Starting with the full-text semantic representation, the same sampling and rate of change calculation are performed along the feedback direction opposite to the main direction to obtain the convergence and diffusion characteristics of the semantic field intensity during the reverse semantic propagation process;
[0116] By comparing the curvature change magnitude and gradient difference between the principal direction and the feedback direction, the difference parameters between the two directions are extracted and recorded as anisotropy indices to describe the spatial curvature characteristics of the semantic field in different propagation directions.
[0117] Using the curvature sequence of each file in the self-aligned semantic field as the baseline, a one-to-one correspondence is established according to the hierarchy and structural role. The curvature sequences of the two files are normalized and phase-aligned. The difference sequence at the corresponding position is calculated, the semantic field curvature function is output, and zero-bias calibration is completed.
[0118] The dynamic adjustment of the hierarchical semantic vector based on the semantic field curvature function is specifically as follows:
[0119] The positions of field particles are updated in small steps along the direction of lowest curvature, so that the curvature difference between the two files at the same level and with the same role gradually decreases.
[0120] The side length ratio, main vein order and chapter adjacency relationship of the directed energy transmission graph are used as constraints to limit the displacement amplitude, direction deviation and sequence consistency of each update until the curvature difference and displacement amplitude meet the preset convergence conditions.
[0121] The converged hierarchical semantic vectors are weighted and converged according to the weights in the semantic energy spectrum feature vectors to generate a file-level semantic alignment representation.
[0122] In this embodiment, the output of the final file semantic similarity result includes:
[0123] It receives the semantic energy spectrum feature vector and the file-level semantic alignment representation of the two files, performs unified scaling on the semantic energy spectrum feature vector, and performs unit length standardization on the file-level semantic alignment representation;
[0124] The fusion weight vector is generated by comparing the component-wise features of the semantic energy spectrum of two files. It is stipulated that when the spectrum values of the two files at the same level are close, the level weight is increased, and when the difference is large, the level weight is decreased. The weight of each level is limited to between zero and one and is standardized as a whole.
[0125] Three types of similarity are calculated: spectral similarity is calculated based on the directional similarity of the semantic energy spectrum feature vectors of the two files; alignment representation similarity is calculated based on the directional similarity of the file-level semantic alignment representations of the two files; and fusion similarity is calculated based on the directional similarity after weighting the semantic energy spectrum feature vectors and the file-level semantic alignment representations according to the fusion weight vector.
[0126] By setting non-negative weighting coefficients and summing all coefficients to one, the spectral similarity, alignment representation similarity, and fusion similarity are weighted and summed to obtain the comprehensive semantic similarity score between documents.
[0127] Example 1:
[0128] To verify the feasibility of this invention in practice, it was applied to the document semantic retrieval system of a large architectural design and consulting firm's document management center. This firm undertakes numerous engineering projects nationwide, including subway lines, urban complexes, and bridge structures. It internally stores over 100,000 documents, including contracts, design specifications, construction plans, and meeting minutes. These documents are lengthy, hierarchical, and often contain cross-disciplinary terminology differences. Traditional semantic retrieval models based on BERT or TF-IDF exhibit significant biases in long text similarity calculations, especially in cases with different document structures or cross-domain semantic expressions, easily leading to misjudgments or omissions of high similarity. This invention is specifically proposed to address the technical problems of missing semantic structure in long texts, hierarchical semantic confusion, and large alignment errors across semantic spaces.
[0129] In practical applications, the system first performs hierarchical preprocessing on the documents, dividing the content into chapters, paragraphs, and sentences. It then automatically identifies structural roles such as titles, abstracts, main text, and appendices through text structure analysis, generating input sequences labeled with these roles. Subsequently, an improved DeBERTa model encodes the input sequences: the model includes a structural role-coupled attention module to identify semantic interactions between different text roles; a main thread topology reconstruction module to extract the core semantic thread of the document; and a self-correcting consistency module to perturb and learn consistency constraints on high-contribution semantic segments, thus forming a stable set of hierarchical semantic representations. Next, a semantic energy spectrum dynamic resonance module calculates the energy transmission and resonance intensity at the sentence, paragraph, role, main thread, and full-text levels, obtaining semantic energy spectrum feature vectors. Finally, in the semantic gravity field self-alignment mechanism, a semantic field curvature function is constructed. Using the main thread and full-text semantic representations as anchors, curvature calibration and gravity alignment are performed on the semantic representation spaces of the two documents, outputting the final document-level semantic similarity score.
[0130] The experiment selected 5,000 contracts and technical solution documents from the company between 2022 and 2024 as a sample. The average document length was 7,200 words. Technical solution documents accounted for 54%, design specification documents for 28%, and contracts and reports for 18%. 1,200 semantically relevant document pairs and 800 semantically unrelated document pairs were randomly selected as the test set. The traditional BERT-based model, the original DeBERTa model, and the improved model of this invention were compared. The models were run in the same hardware environment, and the response speed, accuracy, recall, and consistency with human evaluation were statistically analyzed in a real retrieval system.
[0131] Experimental results show that the model of this invention significantly outperforms the comparative model in semantic similarity calculation of long text files. Especially in structurally complex design scheme files, the main vein topology reconstruction mechanism effectively identifies the core technical content of the document, improving the recall rate of the model in identifying "partially semantically similar files" by more than 10%. The semantic energy spectrum dynamic resonance mechanism effectively reduces the imbalance of semantic weights at different levels, ensuring a reasonable proportion of sentence-level and paragraph-level semantic information in the overall similarity calculation. The introduction of the semantic field curvature function makes the model stable in cross-domain semantic alignment, significantly improving the accuracy of similarity determination in scenarios with significant stylistic differences, such as engineering contracts and design reports.
[0132] Table 1. Comparison of experimental results for document semantic similarity calculation methods based on the improved DeBERTa model.
[0133]
[0134] As shown in Table 1, the proposed document semantic similarity calculation method based on the improved DeBERTa model significantly outperforms existing mainstream models across multiple performance metrics. In terms of average accuracy, the proposed model achieves 93.8%, an improvement of approximately 11.2 percentage points compared to the traditional BERT-based model and nearly 5 percentage points compared to the original DeBERTa-v3 model. This indicates that the introduced structural role coupling attention mechanism and main vein topology reconstruction mechanism effectively improve the recognition capability of document semantic levels, enabling the model to more accurately capture the core semantic relationships in long texts.
[0135] The recall rate and F1 score of this invention's model reached 92.7%, and the F1 score was 0.93, both significantly higher than the comparison model. This indicates that the method achieves better performance in terms of coverage and balance in similar file identification. Especially in scenarios with complex file structures or cross-domain text comparison, traditional models tend to miss files that are semantically similar but have different expressions. However, this invention, through a dynamic resonance mechanism of semantic energy spectrum, realizes energy coupling and feedback between semantic levels, improving the model's comprehensive recognition ability under multi-layer semantics.
[0136] In terms of system efficiency, the average response time of the model in this invention is only 1.97 seconds per pair, representing a performance improvement of nearly 40% compared to the response speed of other models, which is generally over 3 seconds. This is attributed to the hierarchical aggregation of semantic representations and the dynamic adjustment mechanism of semantic field curvature within the model, making long text processing more efficient. The long text bias rate of the model in this invention is only 3.6%, far lower than the 8%-11% range of traditional models, indicating that it maintains high semantic stability when processing ultra-long documents. The expert consensus score reached 9.2 points, significantly higher than the average of 7.7 points of the comparison models, indicating that the semantic judgment results of this invention are closer to human understanding and have stronger interpretability and practicality. In summary, this invention not only significantly improves the accuracy and recall rate of semantic similarity calculation, but also demonstrates excellent engineering feasibility in terms of computational efficiency and result stability.
[0137] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1.A method for calculating file semantic similarity based on an improved DeBERTa model, characterized in that, The method comprises the following steps: text-level preprocessing is performed on the files to be compared, the files are divided into chapters, paragraphs and sentences, and structural role labels are marked, the text content is denoised, segmented and subword encoded, and a hierarchical input sequence containing structural role information is generated; the hierarchical input sequence is input into an improved DeBERTa model, the improved DeBERTa model comprises a structural role coupling attention module, a main vein topology reconstruction module and a counterfactual self-correction consistency module, and a file semantic representation vector is output; the file semantic representation vector is input into a semantic energy spectrum dynamic resonance module, a semantic energy resonance graph is constructed according to semantic vectors at different levels, an energy transmission path and coupling strength between semantic nodes at different levels are calculated, a file semantic energy resonance spectrum is formed, and a semantic energy resonance spectrum feature is generated; according to the semantic energy resonance spectrum feature, the energy distribution law and resonance correlation strength of the file semantic at different levels are calculated, and a semantic energy spectrum feature vector is formed; the semantic energy spectrum feature vector and the file semantic representation vector are jointly mapped to a continuous variable semantic field space, the spatial curvature and distance metric between semantic representations are dynamically adjusted by constructing a semantic field curvature function, and a file-level semantic alignment representation is obtained; the semantic energy resonance spectrum feature and the file-level semantic alignment representation are weighted and fused, the comprehensive semantic similarity score between files is calculated, and the final file semantic similarity result is output. 2.The method of claim 1, wherein, The file is divided into chapters, paragraphs and sentences, and structural role labels are marked, which means that the file content is structured and layered, the text is divided into chapter-level units according to the format characteristics and semantic boundaries of the file, each chapter-level unit is divided into paragraph-level units, and then further refined into sentence-level units, and then semantic analysis is performed on each hierarchical unit, and the corresponding structural role labels are marked according to the function of each hierarchical unit in the document. 3.The method of claim 1, wherein, The text content is denoised, segmented and subword encoded, which means that the file text is cleaned, non-semantic characters, redundant spaces, headers and footers, format symbols and special marks are removed, the cleaned text is segmented into words or symbols with independent meaning according to linguistic rules, and then subword-level encoding is performed according to the model vocabulary, low-frequency words or unregistered words are further divided into subword units, and are mapped to corresponding index or vector representation. 4.The method of claim 1, wherein, The file semantic representation vector is output, which comprises: receiving the hierarchical input sequence, establishing the corresponding relationship among content representation, structural role label, relative position and hierarchical distance for each token, initializing the role coupling graph and hierarchical parameters facing the current document, and obtaining the initial encoding sequence; in the structural role coupling attention module, the token attention weight is calculated according to the query vector, key vector and value vector generated from the initial encoding sequence, the role coupling graph is updated online combined with the intra-layer statistical result, the value vector is weighted and aggregated, the token-level hidden state set and the corresponding attention weight distribution are obtained; Perform bidirectional hierarchical refinement on the token-level hidden state set, first from bottom to top to perform sentence-level, paragraph-level and chapter-level pooling to form hierarchical vectors, and then from top to bottom to backfill chapter and title information to sentence and token level to correct local representation, to obtain backfilled token-level hidden state set, hierarchical representation set and role-level semantic representation; In the main vein topology reconstruction module, according to the paragraph-level and chapter-level vectors, the main vein candidate score of each paragraph is calculated, and a fixed number of main vein paragraphs are selected according to the score and the order in the document is determined to form a main vein set and generate a main vein-level semantic representation; Take the main vein set as the control point to asymmetrically re-label the attention weight distribution, enhance the connection of the main vein and the adjacent chapter, and suppress the cross-chapter noise connection, and based on the re-labeled attention weight, re-aggregate to obtain the main vein guided document-level representation and the updated token-level hidden state set; In the self-correcting consistency module, according to the attention weight and contribution degree, identify high-contribution segments, construct counterfactual inputs of masking, same-role replacement and cross-main vein exchange respectively, generate replacement representation using role prototype memory, impose consistency constraints between original representation, counterfactual representation and replacement representation, and update parameters jointly according to comparison constraints to obtain stabilized token-level hidden state set and hierarchical representation set; Adaptively pool the sentence-level, paragraph-level, role-level, main vein-level semantic representations, embed and fuse the main vein guided document-level representation and the overall file structure to generate a full-text-level semantic representation, and then combine the sentence-level, paragraph-level, role-level, main vein-level and full-text-level semantic representations to form a hierarchical semantic vector set, and output the file semantic representation vector. 5.The method of claim 1, wherein, The generated semantic energy resonance spectrum feature includes: Receive the file semantic representation vector and the hierarchical semantic vector set, establish a hierarchical index and order consistent with the structural role label, and construct a semantic energy spectrum dynamic resonance module composed of a hierarchical energy flow construction unit, a cross-layer phase-locked coordination unit, and a resonance stability and debiasing unit; In the hierarchical energy flow construction unit, calculate the energy measure of each vector according to the hierarchical semantic vector, generate a directed energy transmission graph according to the cosine similarity between vectors and the structural role compatibility relationship, and only keep a few transmission edges with the highest weight for each node, and embed an attenuation factor consistent with the hierarchical distance in the edge weight to obtain an initial energy flow; In the cross-layer phase-locked coordination unit, perform energy propagation iteration in the fixed order of sentence-level, paragraph-level, role-level, main vein-level and full-text-level, perform energy propagation iteration along the directed transmission edges of the initial energy flow, calculate the energy aggregation amount and change rate of each level, and synchronize the transmission coefficients of adjacent levels according to the main vein level as an anchor point, and output the initial resonance spectrum; In the resonance stability and debiasing unit, take the propagation path formed by the initial energy flow as the basis for resonance iteration, and perform threefold stabilization processing on the initial resonance spectrum: First, remove high-weight noise edges unrelated to the main vein according to the main vein consistency check; Second, merge redundant nodes with high similarity according to the near-duplicate suppression strategy; Third, mask high-contribution nodes and detect resonance spectrum deviation according to the counterfactual disturbance check; When the resonance spectrum deviation exceeds the threshold, recover the corresponding edge weight to obtain a stable semantic energy resonance spectrum feature. The stable semantic energy resonance spectrum features are arranged in a fixed order of sentence level, section level, role level, main vein level and whole text level to form a semantic energy spectrum feature vector. 6.The method for calculating file semantic similarity based on the improved DeBERTa model according to claim 1, wherein, The semantic energy spectrum feature vector is formed by: receiving the semantic energy spectrum feature vector, the directed energy conduction graph and the hierarchical semantic vector set; statistically processing the hierarchical semantic vector set by level, respectively collecting energy metrics of all nodes in each level to obtain total energy of each level, and performing proportional processing based on total energy of all levels to form energy proportion distribution of each level; according to edge weights between nodes in the directed energy conduction graph, accumulating total edge weights of cross-layer connections by pairing levels two by two to obtain resonance correlation strength between levels, the edge weight being a result of weighting node semantic similarity and structural role compatibility relationship; normalizing and same-scale calibrating the energy proportion distribution and the resonance correlation strength, and calculating energy dispersion degree within each level, the energy dispersion degree being obtained by comparing deviation degrees of energy of each node within the level and average energy of the level; weighting and combining the energy proportion distribution of each level, the resonance correlation strength with other levels and the energy dispersion degree of the level to obtain the semantic energy spectrum feature vector arranged in the order of sentence level, section level, role level, main vein level and whole text level. 7.The method of claim 1, wherein the improved DeBERTa model is based on a DeBERTa model. The file-level semantic alignment representation is obtained by: receiving the semantic energy spectrum feature vector, the directed energy conduction graph and the hierarchical semantic vector set, setting the main vein level vector and the whole text level vector as field anchor points, setting the sentence level vector, the section level vector and the role level vector as field particles, and establishing a one-to-one correspondence between the field anchor points and the field particles; allocating weights to the field anchor points and the field particles according to the semantic energy spectrum feature vector, determining main direction and feedback direction of the field along outgoing edges and incoming edges of the directed semantic energy conduction graph, generating an initial semantic field distribution in a vector space, and forming a directional field channel with the main vein level vector as the center; constructing a semantic field curvature function, and dynamically adjusting the hierarchical semantic vector based on the semantic field curvature function: establishing a semantic field reference coordinate system along the main direction and the feedback direction determined by the field channel with the main vein level vector and the whole text level vector as the center, dividing a plurality of equidistant sampling layers in the main direction and the feedback direction, arranging sampling nodes corresponding to the hierarchical semantic vector in each sampling layer, and recording semantic field intensity and interlayer difference data of each node; performing second-order difference on the field intensity difference of adjacent sampling layers to obtain interlayer curvature scalar, calculating directional curvature along the main direction and the feedback direction respectively, extracting differences between directions to form anisotropy parameters, and collecting the interlayer curvature scalar and the directional curvature in order of level to generate a curvature sequence; taking the curvature sequence of each file in the self-alignment semantic field as a baseline, establishing a one-to-one correspondence according to level and structural role, normalizing and phase aligning the curvature sequences of two files, calculating a difference sequence of corresponding positions, outputting the semantic field curvature function and completing zero bias calibration. 8.The method for calculating file semantic similarity based on the improved DeBERTa model according to claim 1, wherein, The final file semantic similarity result is output by: receiving the semantic energy spectrum feature vector and the file-level semantic alignment representation of two files, performing uniform scaling processing on the semantic energy spectrum feature vector, and performing unit length normalization on the file-level semantic alignment representation; The fusion weight vector is generated based on the component-wise comparison of the semantic energy spectrum feature vectors of the two files, which specifies that the hierarchical weight is increased when the spectrum values of the two files are close, and the hierarchical weight is decreased when the difference is large, and each hierarchical weight is limited between zero and one and is overall normalized; Three types of similarity are calculated, wherein the spectrum similarity is calculated based on the direction similarity of the semantic energy spectrum feature vectors of the two files, the alignment representation similarity is calculated based on the direction similarity of the file-level semantic alignment representation of the two files, and the fusion similarity is calculated based on the direction similarity after the semantic energy spectrum feature vectors and the file-level semantic alignment representation are combined by weighting according to the fusion weight vector; Non-negative weighting coefficients are set and the sum of the coefficients is one, and the spectrum similarity, the alignment representation similarity and the fusion similarity are weighted and summed to obtain the comprehensive semantic similarity score between the files.
Citation Information
Patent Citations
Data association maintenance processing method and system based on file reference
CN120296021A
Text sentiment analysis method and system based on dynamic semantic segmentation and feature perception
CN120562424A