A semantic splicing method, system, electronic device, and storage medium
By identifying semantic boundary points for intelligent segmentation and splicing, a multi-dimensional semantic feature matrix is constructed. Combined with the keywords and grammatical structure of the query text, the problem of text fragmentation is solved, and the coherence and accuracy of the search results are improved.
Patent Information
- Application Number
- CN202511433255.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-09
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2045-10-09
AI Technical Summary
Existing text segmentation methods based on fixed windows result in a break in the context between text fragments, reducing the coherence of the text as a context.
Intelligent segmentation is performed by identifying semantic boundary points, constructing a multi-dimensional semantic feature matrix and generating a composite semantic vector. Combined with the keywords and grammatical structure of the query text, the semantic coherence between candidate text segments and adjacent text segments is calculated for intelligent splicing.
This solves the problem of context fragmentation caused by fixed window segmentation, and improves the contextual coherence and accuracy of search results.
Smart Images

Figure CN120930653B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, specifically to a semantic splicing method, system, electronic device, and storage medium. Background Technology
[0002] With the development of large language model technology, retrieval-enhanced generation techniques have been widely applied in document question answering and knowledge retrieval. This technique enhances the question answering capabilities of large language models by retrieving relevant content from documents as context, effectively improving the accuracy of the model's responses.
[0003] Currently, mainstream methods typically process documents using fixed-length windows or simple segmentation. Specifically, the system segments the document into multiple text fragments according to a preset fixed length, then retrieves fragments relevant to the user's query using vectorized retrieval, and directly inputs these fragments as context into a large language model to generate the answer.
[0004] However, in practical applications, this mechanical segmentation method based on a fixed window often leads to a break in the context between text fragments. Because the semantic structure of the document is not considered, the retrieved relevant text may cut off the original complete semantic expression, thereby reducing the coherence of the text as context. Summary of the Invention
[0005] This application provides a semantic splicing method, system, electronic device, and storage medium that can intelligently splice text, thereby improving the coherence of the context.
[0006] Firstly, this application provides a semantic concatenation method, including:
[0007] Obtain the original document to be processed, identify the semantic boundary points in the original document, and divide the original document into multiple text units based on the semantic boundary points;
[0008] Construct a multidimensional semantic feature matrix for each text unit, the multidimensional semantic feature matrix including local semantic features, global semantic features and structural association features, and perform weighted fusion on each multidimensional semantic feature matrix to obtain a composite semantic vector for each text unit;
[0009] Receive the user's query text, extract query keywords and grammatical structure from the query text, and generate an enhanced query vector containing intent weights;
[0010] Calculate the cosine similarity between the enhanced query vector and each of the composite semantic vectors, and select text units with a cosine similarity greater than a first preset threshold as candidate text segments;
[0011] Based on the position index information of each candidate text segment, find the adjacent text segments of each candidate text segment in the original document, and calculate the semantic coherence between each candidate text segment and the adjacent text segments. The adjacent text segments with the semantic coherence exceeding a preset threshold are identified as segments to be spliced.
[0012] According to the order of the location index information, each candidate text fragment is concatenated with the corresponding fragment to be concatenated, and overlapping content is removed to generate a context-coherent composite text fragment.
[0013] By adopting the above technical solution, the original text to be processed is acquired and intelligently segmented based on semantic boundary points, thus avoiding the semantic fragmentation problem caused by fixed window segmentation. By constructing a multi-dimensional semantic feature matrix containing local semantic features, global semantic features, and structural association features, and fusing them to generate a composite semantic vector, the semantic information of text units can be comprehensively characterized. By combining keywords and grammatical structures in the query text to generate an enhanced query vector, the accuracy of retrieval is improved. By calculating the semantic coherence between candidate text segments and adjacent text segments and intelligently splicing them, the contextual coherence of the retrieval results is ensured, thereby solving the contextual fragmentation problem caused by fixed window segmentation in existing technologies.
[0014] Optionally, based on the syntactic features in the original document, the positions of ending punctuation marks, transition conjunctions, and causal relation words in the original document are marked to obtain a first candidate boundary point set; named entities are extracted from the original document, and the beginning and end positions of each named entity are marked to obtain a second candidate boundary point set, wherein the named entities include people, time, place, and organization; the semantic relevance between adjacent sentences in the original document is calculated, and semantic transition positions are marked between sentences with semantic relevance below a relevance threshold to obtain a third candidate boundary point set; the first candidate boundary point set, the second candidate boundary point set, and the third candidate boundary point set are merged, and duplicate boundary points in adjacent positions are removed to obtain the semantic boundary points.
[0015] Optionally, the query text is part-of-speech tagging is performed to extract noun phrases, verb phrases, and modifiers as query keywords, and a preset grammar parsing algorithm is used to extract the grammatical structure of the query text. Based on a preset intent classification dictionary, the query keywords are mapped to the corresponding intent categories, and the intent weight of the intent category is determined according to the question word type, sentence structure features, and modifiers in the grammatical structure. The intent categories include fact queries, process queries, comparison queries, and reasoning queries. The query keywords are converted into word vectors through a pre-trained word vector model, and the grammatical structure is encoded into a structure vector through a graph neural network. The word vectors and the structure vectors are weighted and fused together with the intent weights to generate the enhanced query vector containing the intent weights.
[0016] Optionally, based on the position index information of each candidate text segment, the start and end positions of each candidate text segment in the original document are determined; for each candidate text segment, taking the candidate text segment as the center, several consecutive text units are searched forward in the original document as forward adjacent text segments, and several consecutive text units are searched backward as backward adjacent text segments, wherein the number of text units searched forward and backward is a preset number; when there are multiple candidate text segments with a position index interval less than a preset distance threshold in the original document, it is detected whether there is an overlapping area between adjacent text segments of each candidate text segment; if there is an overlapping area, the text units in the overlapping area are merged into a common adjacent text segment of each candidate text segment.
[0017] Optionally, for each candidate text segment, vector mapping is performed on the candidate text segment and adjacent text segments, and contextual related word pairs are extracted through a sliding window to construct a semantic dependency graph; based on a pre-trained bidirectional attention network, the attention weights of each related word pair in the semantic dependency graph are calculated; the attention weights of each related word pair are multiplied by the corresponding related word vectors to obtain the weighted semantic features of each related word pair; the length of the longest common subsequence of each weighted semantic feature is obtained, and an initial coherence score is generated by combining the topic word overlap of each related word pair; according to the relative positional relationship between the candidate text segment and adjacent text segments in the original document, a distance decay factor is set, and the product of the initial coherence score and the distance decay factor is used as the semantic coherence between the candidate text segment and adjacent text segments.
[0018] Optionally, the weighted semantic features are compared, and the occurrence position of the word elements in the candidate text segments is used as the reference number. The word element sequences with the same semantic components as the reference number and whose position numbers increase in the adjacent text segments are identified, and the length of the word element sequence is used as the length of the maximum common subsequence. The topic words in each of the associated word pairs are extracted, and the ratio of the number of topic words appearing in the adjacent text segments to the total number of topic words in the candidate text segments is calculated to obtain the topic word overlap. The maximum common subsequence length and the topic word overlap are weighted and calculated to obtain the initial coherence score.
[0019] Optionally, based on the length of the composite text fragment and the context window limitation of the large language model, the composite text fragment is segmented. When the total length of the composite text fragment exceeds a preset length threshold, the composite text fragment is truncated and compressed. An input prompt template is constructed, in which the query text is used as the question input, the composite text fragment is used as the reference material input, and role instructions and answer format requirements are added to the input prompt template to generate input prompts. The input prompts are then passed to the preset large language model to obtain initial question-and-answer results, and the initial question-and-answer results are scored with confidence using a preset answer quality evaluation algorithm. When the confidence score is lower than a preset quality threshold, the reference material input in the input prompts is adjusted, the candidate text fragments are reselected and / or the range of the fragment to be concatenated is expanded, and the information is re-passed into the preset large language model until the confidence score is greater than or equal to the preset quality threshold, and the question-and-answer results are generated.
[0020] A second aspect of this application provides a semantic splicing system, the system comprising:
[0021] The text unit segmentation module is used to acquire the original document to be processed, identify the semantic boundary points in the original document, and segment the original document into multiple text units based on the semantic boundary points;
[0022] The vector generation module is used to construct a multidimensional semantic feature matrix for each text unit. The multidimensional semantic feature matrix includes local semantic features, global semantic features, and structural association features. The module performs weighted fusion on each multidimensional semantic feature matrix to obtain a composite semantic vector for each text unit. The module receives the user's query text and extracts query keywords and grammatical structures from the query text to generate an enhanced query vector containing intent weights.
[0023] The segment to be spliced module is used to calculate the cosine similarity between the enhanced query vector and each of the composite semantic vectors, select text units with a cosine similarity greater than a first preset threshold as candidate text segments; based on the position index information of each candidate text segment, find the adjacent text segments of each candidate text segment in the original document, calculate the semantic coherence between each candidate text segment and the adjacent text segments, and determine the adjacent text segments with a semantic coherence exceeding a preset threshold as segments to be spliced.
[0024] The splicing module is used to splice each candidate text fragment with the corresponding fragment to be spliced according to the order of the position index information, and remove overlapping content to generate a context-coherent composite text fragment.
[0025] A third aspect of this application provides an electronic device including a memory, a processor, and a program stored in the memory and executable on the processor, the program being able to implement a semantic splicing method when loaded and executed by the processor.
[0026] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement a semantic concatenation method.
[0027] In summary, one or more technical solutions provided in this application have at least the following technical effects or advantages:
[0028] By adopting the above technical solution, the original text to be processed is acquired and intelligently segmented based on semantic boundary points, thus avoiding the semantic fragmentation problem caused by fixed window segmentation. By constructing a multi-dimensional semantic feature matrix containing local semantic features, global semantic features, and structural association features, and fusing them to generate a composite semantic vector, the semantic information of text units can be comprehensively characterized. By combining keywords and grammatical structures in the query text to generate an enhanced query vector, the accuracy of retrieval is improved. By calculating the semantic coherence between candidate text segments and adjacent text segments and intelligently splicing them, the contextual coherence of the retrieval results is ensured, thereby solving the contextual fragmentation problem caused by fixed window segmentation in existing technologies. Attached Figure Description
[0029] Figure 1 This is a flowchart illustrating a semantic splicing method provided in an embodiment of this application;
[0030] Figure 2 This is a schematic diagram of the structure of a semantic splicing system provided in an embodiment of this application;
[0031] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0032] Explanation of reference numerals in the attached drawings: 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. Detailed Implementation
[0033] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0034] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0035] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0036] This application provides a semantic concatenation method. In one embodiment, please refer to... Figure 1 , Figure 1 This is a flowchart illustrating the semantic concatenation method provided in this application embodiment. This method can be implemented using a computer program, which can be integrated into an application or run as a standalone utility application. The method can also be implemented using a microcontroller or run on a semantic concatenation system based on the von Neumann architecture. Specifically, the method may include the following steps:
[0037] Step 101: Obtain the original document to be processed, identify the semantic boundary points in the original document, and divide the original document into multiple text units based on the semantic boundary points.
[0038] The original document refers to the initial text content that needs to be semantically analyzed and processed, which can be a single or multiple complete document files; semantic boundary points are positional markers in the text that represent the boundaries of semantic units, used to divide text segments with relatively independent and complete semantics; text unit refers to the smallest text segment with semantic integrity obtained by dividing through semantic boundary points, and each text unit contains a semantically coherent content block composed of one or more sentences.
[0039] Specifically, before performing semantic analysis on the document, the original document needs to be preprocessed and semantically segmented. The system first receives and loads the original document to be processed, and preprocesses the document content, including removing special characters and standardizing the encoding format. Then, the system identifies semantic boundary points in the document by analyzing multiple dimensions such as syntactic structure, semantic association, and topic shifts. These boundary points may appear between paragraphs, at topic shifts, or at semantic scene shifts. After determining the semantic boundary points, the system segments the original document into multiple text units with semantic integrity, each text unit containing relatively independent and coherent semantic content.
[0040] Based on the above embodiments, as an optional embodiment, step 101, identifying semantic boundary points in the original document, may further include the following steps:
[0041] Step 201: Based on the syntactic features in the original document, mark the positions of the ending punctuation marks, transition words, and causal words in the original document to obtain the first candidate boundary point set.
[0042] Among them, syntactic features refer to the combination of words and sentence structure features in the text; ending punctuation marks include periods, question marks, and exclamation marks that indicate the end of a sentence; adversative conjunctions include words that indicate semantic transitions such as "but", "however", and "however"; causal conjunctions include words that indicate causal relationships such as "because", "therefore", and "due to"; the first candidate boundary point set refers to the set of positions that may have semantic transformations obtained through syntactic analysis.
[0043] Specifically, when performing semantic boundary recognition based on the syntactic features of the original document, the document is first segmented and part-of-speech tagged to identify all ending punctuation marks, transition words, and causal words. For ending punctuation marks, the position index of each period, question mark, and exclamation mark in the document is recorded. For transition words, the starting position of words such as "but," "however," "however," and "on the contrary" is marked. For causal words, the starting position of words such as "because," "therefore," "due to," and "lead to" is marked. These marked positions are arranged into a position index sequence according to their order in the document, forming the first candidate boundary point set. For example, for the text "Xiaoming studies very diligently. But he often forgets to do his homework because he is always addicted to games.", the system will mark the positions of the period, "but," and "because," obtaining position indices {7, 9, 17} as the first candidate boundary point set. These positions often represent the transition points of semantic content or the changes in logical relationships, providing important references for subsequent semantic boundary recognition. During the tagging process, different weights are assigned to different types of tag points: punctuation marks at the end of sentences have the highest weight, followed by conjunctions of contrast, and causal words have the lowest weight. These weight values will be used for subsequent boundary point merging and filtering. For complex sentences with nested structures, the position of the punctuation mark at the end of sentences is given priority to avoid excessive segmentation within clauses. This tagging method based on syntactic features provides preliminary candidate positions for semantic boundary identification, laying the foundation for subsequent semantic coherence analysis.
[0044] Step 202: Extract named entities from the original document and mark the beginning and end of each named entity to obtain a second set of candidate boundary points. Named entities include people, time, place and organization.
[0045] Named entities refer to words or phrases in the text that have a specific category, including names of people, time words, place names, and organization names; the first and last positions refer to the starting and ending character positions of named entities in the text; the second candidate boundary point set refers to the set of positions that may have semantic transformations obtained through named entity recognition.
[0046] Specifically, when extracting and tagging named entities in the original document, named entity recognition technology is used to process the document. First, the document is segmented and tagged with parts of speech to identify named entities of people, such as personal names like "Zhang San" and "Li Si"; named entities of time, such as time expressions like "October 2023" and "next Wednesday"; named entities of place, such as place names like "Beijing" and "Haidian District"; and named entities of organizations, such as institution names like "Tsinghua University" and "Chinese Academy of Sciences". For each identified named entity, its starting and ending character positions in the text are recorded. For example, for the text "Zhang San participated in a competition held by Tsinghua University in Beijing in October 2023", the first and last positions of "Zhang San" {0, 2}, "October 2023" {3, 12}, "Beijing" {13, 15}, and "Tsinghua University" {17, 21} are marked respectively. These position indices, arranged in chronological order within the document, form the second set of candidate boundary points: {0, 2, 3, 12, 13, 15, 17, 21}. During the tagging process, for nested named entities, such as "Beijing" within "Peking University," the boundary position of the longest entity is retained. For consecutively occurring named entities of the same type, such as "Zhang San and Li Si," the entire entity is treated as a single named entity block for tagging. The boundaries of named entities often signify shifts in semantic context or topic, and these boundary points provide crucial information for subsequent semantic segmentation. By marking the boundaries of named entities, it is ensured that the complete expression of named entities is not fragmented during subsequent text segmentation, thus maintaining semantic integrity.
[0047] Step 203: Calculate the semantic relevance between adjacent sentences in the original document, and mark the semantic transformation positions between sentences with semantic relevance below the relevance threshold to obtain the third candidate boundary point set.
[0048] Among them, semantic relevance refers to a numerical index that measures the degree of similarity between two sentences at the semantic level, with a value range of 0 to 1; relevance threshold refers to the critical value for judging the strength of semantic association between sentences; semantic transition position represents the sentence boundary position where the semantic content changes significantly; and the third candidate boundary point set refers to the set of semantic transition position indices obtained through semantic relevance analysis.
[0049] Specifically, when calculating the semantic relevance between adjacent sentences, the original document is first segmented into sentence sequences. For each sentence, a sentence vector representation is generated using a pre-trained language model. The cosine similarity between adjacent sentence pairs is calculated as the semantic relevance value. The specific calculation method is as follows: perform a dot product operation on the two sentence vectors, and then divide by the product of the magnitudes of the two vectors. For example, for the adjacent sentences "Today the weather is sunny" and "Suitable for going out for a trip," corresponding sentence vectors v1 and v2 are generated respectively. By calculating cos(v1, v2) = (v1·v2) / (|v1|·|v2|), a semantic relevance value of 0.85 is obtained. A semantic relevance threshold of 0.6 is set. When the calculated semantic relevance value is lower than 0.6, it indicates that the semantic association between the two sentences is weak, and the position between these two sentences is marked as a semantic transition position. The relevance calculation and threshold judgment are repeated for all adjacent sentence pairs in the document. The character indices of all semantic transition positions that meet the conditions are arranged according to their order in the document to form a third candidate boundary point set. During the calculation process, for longer sentences, a fixed-length text segment is extracted using a sliding window for vector representation, avoiding the impact of sentence length differences on relevance calculation. Simultaneously, when generating sentence vectors, an attention mechanism is used to highlight key semantic information within the sentence, improving the accuracy of relevance calculation. This semantic relevance-based boundary recognition method can capture semantic transition points in the text, providing a semantic basis for subsequent text segmentation.
[0050] Step 204: Merge the first set of candidate boundary points, the second set of candidate boundary points, and the third set of candidate boundary points, and remove duplicate boundary points in adjacent positions to obtain semantic boundary points.
[0051] Among them, the merge operation means combining multiple boundary point sets according to their position indices; adjacent positions refer to position points in the text that are less than a preset number of characters apart; repeated boundary points refer to multiple boundary points with similar position indices after merging; semantic boundary points refer to the final semantic segmentation positions obtained after merging and deduplication.
[0052] Specifically, during the boundary point set merging process, the position indices of the first, second, and third candidate boundary point sets are first arranged in ascending order and merged into a unified sequence. Duplicate boundary points are then identified and removed from the merged sequence. The specific implementation method is as follows: A threshold of 10 characters is set for determining adjacent positions. The merged boundary point sequence is traversed, and for any two adjacent boundary points, the positional distance between them is calculated. For example, for the text "Xiaoming studies very diligently. However, he often forgets to do his homework because he is always addicted to games.", the first candidate boundary point set contains {7, 9, 17}, the second candidate boundary point set contains {0, 2}, and the third candidate boundary point set contains {7, 16}. After merging, the sequence {0, 2, 7, 7, 9, 16, 17} is obtained. Calculating the positional distance between adjacent boundary points reveals a duplicate boundary point at position 7, and the distance between positions 16 and 17 is less than the threshold of 10. Weights are assigned based on the importance of boundary points from different sources: the first candidate boundary point has a weight of 0.4, the second candidate boundary point has a weight of 0.3, and the third candidate boundary point has a weight of 0.3. For duplicate or adjacent boundary points, the boundary point with the highest weight is retained. In this example, the boundary point from the first candidate set is retained at position 7, and position 17 from the first candidate set is retained at positions 16 and 17. The final semantic boundary point sequence is {0, 2, 7, 9, 17}. This method based on multi-source boundary point merging comprehensively considers information from syntactic features, named entity boundaries, and semantic transformation positions, and obtains more accurate semantic segmentation positions by removing redundant boundary points.
[0053] Step 102: Construct a multidimensional semantic feature matrix for each text unit. The multidimensional semantic feature matrix includes local semantic features, global semantic features, and structural association features. Then, perform weighted fusion on each multidimensional semantic feature matrix to obtain a composite semantic vector for each text unit.
[0054] Among them, the multidimensional semantic feature matrix represents a matrix structure composed of multiple dimensions of features used to describe the semantic information of text units; local semantic features refer to the semantic representation at the word and phrase level within a text unit; global semantic features refer to the semantic representation of a text unit in the entire document context; structural association features represent the degree of semantic association between a text unit and other units; and composite semantic vector refers to a unified semantic representation vector obtained through feature fusion.
[0055] Specifically, after completing text unit segmentation, semantic feature extraction and representation are required for each text unit. First, local semantic features are constructed for each text unit, including word vector features, part-of-speech features, and named entity features, forming a local feature matrix. Then, global semantic features of the text unit within the entire document are extracted, including topic distribution features and contextual association features, forming a global feature matrix. Next, structural association features between text units are analyzed, including positional relationship features and citation relationship features, forming a structural feature matrix. Finally, an attention mechanism is used to weightedly fuse these three types of feature matrices to obtain a composite semantic vector with unified dimensions. During feature fusion, weights are assigned according to the importance of different features to the semantic representation, and multi-dimensional features are integrated into a unified semantic vector representation through weighted summation.
[0056] In some embodiments, semantic feature extraction and fusion of text units can be achieved in a variety of ways:
[0057] Optionally, the text units are first encoded using the BERT model to obtain word-level contextual representations as local semantic features; then, the document-level representations of the text units are learned using the Doc2Vec model as global semantic features; next, a semantic dependency graph between text units is constructed, and node features are extracted using a graph neural network as structural association features; finally, a multi-head attention layer is designed to calculate the attention weights of the three types of features, and the final composite semantic vector is obtained by weighted summation. Alternatively, a pre-trained language model is first used to extract word vectors for each word in the text unit, and local semantic features are extracted using a convolutional neural network; then, the topic distribution of the text units is analyzed based on a topic model, and global semantic features are obtained by combining document-level semantic embeddings; next, the similarity matrix between the text unit and other units is calculated, and structural association features are obtained through matrix factorization; finally, a feature fusion network is designed to learn the optimal combination weights of the three types of features to generate a composite semantic vector. It is understood that other deep learning models or feature engineering methods can also be used to achieve semantic feature extraction and feature fusion of text units; this is not limited here.
[0058] Step 103: Receive the user's query text, extract query keywords and grammatical structure from the query text, and generate an enhanced query vector containing intent weights.
[0059] Among them, query text refers to the natural language text to be retrieved by the user; query keywords represent the core words and important entities in the query text; syntactic structure refers to the syntactic dependency relationship between words in the query text; intent weight is used to represent the importance of query keywords in the query intent; and enhanced query vector refers to the semantic vector representation of the query enhanced by keyword and syntactic structure information.
[0060] Specifically, after receiving the query text input by the user, semantic understanding and feature extraction are required. First, the query text is segmented and tagged with parts of speech to identify important words such as nouns, verbs, and adjectives as candidate keywords. Then, dependency parsing is used to obtain grammatical structure information from the query text, including subject-verb, verb-object, and modifier-head relationships. Next, the weight of each keyword in the query intent is calculated. The weight value is determined by the word's part-of-speech features, syntactic role, and positional information; for example, subjects and verbs have higher weight values, while modifiers have lower weight values. Finally, the keyword, grammatical structure, and intent weight information are integrated to generate an enhanced query vector representation. In the weight calculation process, the weight of subject-verb relation words is set to 0.8, the weight of verb-object relation words is set to 0.6, and the weight of other modifier relation words is set to 0.4, highlighting important information in the query intent through a weighted approach.
[0061] Based on the above embodiments, as an optional embodiment, step 103, which involves extracting query keywords and grammatical structures from the query text to generate an enhanced query vector containing intent weights, may further include the following steps:
[0062] Step 301: Tag the query text for parts of speech, extract noun phrases, verb phrases and modifiers as query keywords, and use a preset grammar parsing algorithm to extract the grammatical structure of the query text.
[0063] Among them, part-of-speech tagging refers to the process of identifying the grammatical function category of each word in the text; noun phrases refer to phrases composed of nouns and their modifiers; verb phrases refer to phrases composed of verbs and their related components; modifiers refer to adjectives and adverbs that modify nouns or verbs; grammatical structure refers to the syntactic dependency relationship between words; and pre-defined grammar parsing algorithms refer to specific algorithms used to analyze sentence structure.
[0064] Specifically, in the text semantic analysis stage, syntactic analysis and keyword extraction are performed on the query text. First, a词性标注 tool is used to label the词性 of each word in the query text, including nouns, verbs, adjectives, adverbs, etc. Then, noun phrases such as "smartphone" and "deep learning algorithm" are identified; verb phrases such as "run quickly" and "effectively solve"; as well as adjectives and adverbs that act as modifiers, such as "excellent" and "rapidly". These words and phrases serve as query keywords. Next, a dependency parsing algorithm is used to analyze the syntactic structure of the query text, construct a dependency parse tree, and identify syntactic dependency relationships such as subject-predicate relationship (SBV), verb-object relationship (VOB), and attributive-middle relationship (ATT). For the query text "The new type of smartphone quickly processes image data", after annotation, we get "new / adj smart / adj phone / n quickly / adv process / v image / n data / n", extract "smartphone" and "image data" as noun phrases, "quickly process" as a verb phrase, and "new" as a modifier. Through dependency parsing, it is obtained that "phone" and "process" form a subject-predicate relationship, "process" and "data" form a verb-object relationship, and "image" and "data" form an attributive-middle relationship.
[0065] Step 302: Based on a preset intention classification dictionary, map the query keywords to the corresponding intention categories, and determine the intention weights of the intention categories according to the types of interrogative words, syntactic features, and modal particles in the syntactic structure. The intention categories include fact query, process query, comparison query, and reasoning query.
[0066] Among them, the intention classification dictionary represents a dictionary of the corresponding relationships between pre-established keywords and query intentions; the intention category refers to the classification label of the query purpose; the intention weight is used to represent the importance of different intention categories; the type of interrogative word refers to interrogative expressions such as "what", "how", "why", etc.; the syntactic feature represents sentence types such as declarative sentences and interrogative sentences; the modal particle refers to words that express mood such as "ma", "ne", "ba", etc.; a fact query refers to a query for obtaining objective facts; a process query refers to a query for understanding operation steps; a comparison query refers to a query for comparative analysis; a reasoning query refers to a query for seeking causal explanations.
[0067] It should be noted that the term "词性标注" is a Chinese term for "part-of-speech tagging", and the translation here is for reference only. In the actual translation of patent texts, more accurate and standardized terms may be used according to the specific context and relevant industry norms.Specifically, in the stages of determining query intent and calculating weights, the query intent is first determined based on the mapping relationship of query keywords in the intent classification dictionary. By matching keyword patterns in the dictionary, query keywords are mapped to four intent categories: fact query, process query, comparison query, and inference query. For example, keywords such as "what" and "definition" are mapped to fact queries, "how" and "steps" are mapped to process queries, "difference" and "comparison" are mapped to comparison queries, and "reason" and "why" are mapped to inference queries. Then, the grammatical structure features of the query text are analyzed, including interrogative words, sentence patterns, and modal particles, and weights are assigned to different intent categories. For example, a fact query containing "what" has a weight of 0.8, a process query containing "how" has a weight of 0.7, a comparison query containing "comparison" has a weight of 0.6, and an inference query containing "why" has a weight of 0.9. When multiple intent features appear in the query text, the intent category with the highest weight is taken as the primary query intent. For example, the query "How does a deep learning algorithm recognize images?" contains the keywords "algorithm" and "how", which correspond to fact queries and process queries respectively. Through sentence structure analysis, it is determined to be a process query, and the final weight is set to 0.7.
[0068] Step 303: Convert the query keywords into word vectors using a pre-trained word vector model, encode the grammatical structure into a structure vector using a graph neural network, and combine the intent weights to weightedly fuse the word vectors and structure vectors to generate an enhanced query vector containing intent weights.
[0069] Among them, word vector model refers to a pre-trained model that maps words to low-dimensional dense vector representations; word vector refers to the vector representation of words in semantic space; graph neural network refers to a neural network model that processes graph structure data; structure vector refers to the vector representation of grammatical structure; and enhanced query vector refers to a comprehensive vector representation that integrates word vector, structure vector and intent weight.
[0070] Specifically, in the query vector generation stage, an enhanced query representation is constructed through the fusion of multiple features. First, pre-trained word vector models such as Word2Vec or BERT are used to convert query keywords into 300-dimensional word vector representations. For phrases containing multiple words, average pooling is used to average the word vectors to obtain the phrase vector. Then, the syntactic structure of the query text is constructed as a dependency graph, where words are nodes and dependencies are edges. A Graph Attention Network (GAT) is used to encode the dependency graph, with each node updating its representation by aggregating information from its neighbors. After three layers of GAT, a 128-dimensional structure vector is obtained. Next, feature fusion is performed, concatenating the word vector matrix with the structure vector to obtain a 428-dimensional basic feature vector. Finally, intent weights are introduced for weighting. Specifically, the basic feature vector is multiplied by the weight value of the corresponding intent category; for example, for a fact query intent with a weight of 0.8, each component of the basic feature vector is multiplied by 0.8. In this way, the query vector not only includes word semantics and structural information but also incorporates the importance of the query intent, forming a 428-dimensional enhanced query vector.
[0071] Step 104: Calculate the cosine similarity between the enhanced query vector and each composite semantic vector, and select text units with a cosine similarity greater than the first preset threshold as candidate text segments.
[0072] Among them, cosine similarity represents the cosine value of the angle between two vectors, which is used to measure the similarity of vector directions; enhanced query vector refers to a vector representation that integrates query keywords, syntactic structure and intent weight information; composite semantic vector represents a comprehensive vector representation of the semantic and structural features of text units; the first preset threshold refers to the similarity judgment standard used to filter similar texts; candidate text fragments refer to relevant text content filtered through similarity calculation.
[0073] Specifically, after obtaining the enhanced query vector, relevant text content needs to be retrieved from the text library. First, the enhanced query vector is compared with the composite semantic vector of each text unit to calculate similarity. The cosine similarity is calculated as the dot product of the two vectors divided by the product of their magnitudes, with a value between -1 and 1. In the calculation, the enhanced query vector q is multiplied by each composite semantic vector v to obtain the numerator, and the magnitudes of each vector are calculated to obtain the denominator. These are then divided to obtain the cosine similarity value: cos_sim = (q·v) / (|q|·|v|). Specifically, the dot product is obtained by multiplying the values of the corresponding dimensions and summing them, and the magnitude is obtained by taking the square root of the sum of the squares of each dimension. A first preset threshold of 0.8 is set. When the calculated cosine similarity is greater than 0.8, the corresponding text unit is added to the candidate text fragment set. In this way, through similarity calculation and threshold filtering, the text content most relevant to the query semantics is retained.
[0074] Step 105: Based on the position index information of each candidate text segment, find the adjacent text segments of each candidate text segment in the original document, and calculate the semantic coherence between each candidate text segment and its adjacent text segments. The adjacent text segments with semantic coherence exceeding the preset threshold are identified as segments to be spliced.
[0075] Among them, the location index information represents the location identifier of the text fragment in the original document; the adjacent text fragment refers to the text content that is adjacent to the candidate text fragment in the original document; the semantic coherence is used to represent the smoothness of the semantic connection between adjacent text fragments; the preset threshold is the standard value used to judge whether the text fragment is semantically coherent; the fragment to be spliced refers to the adjacent text content that meets the semantic coherence requirements and can be used to expand the candidate text fragment; and the original document represents the source document of the text fragment.
[0076] Specifically, after obtaining candidate text fragments, more complete text content needs to be obtained through context expansion. First, based on the position index information of the candidate text fragment, the position of the fragment in the original document is located. Then, the two paragraphs before and after it are obtained as adjacent text fragments. For each adjacent text fragment, its semantic coherence with the candidate text fragment is calculated. The semantic coherence calculation adopts a word co-occurrence-based method, counting the number of keywords that appear in both fragments and weighting it with the semantic similarity of the words. The specific calculation formula is: Coherence = Number of co-occurring words / Total number of words × Average word similarity. For example, for two fragments containing 10 keywords, if there are 4 common words and the average semantic similarity of these words is 0.8, then the coherence is 0.32. A preset threshold of 0.3 is set. When the calculated coherence exceeds 0.3, the adjacent text fragment is marked as a fragment to be spliced.
[0077] Based on the above embodiments, as an optional embodiment, step 105: finding the adjacent text segments of each candidate text segment in the original document based on the position index information of each candidate text segment, this step may further include the following steps:
[0078] Step 401: Determine the start and end positions of each candidate text segment in the original document based on the position index information of each candidate text segment.
[0079] The location index information represents the location identifier of the text fragment within the document; candidate text fragments refer to text content filtered through similarity matching; the original document refers to the source document of the text fragment; the start position indicates the position of the first character of the text fragment; and the end position indicates the position of the last character of the text fragment. The index information typically includes multi-level location information such as document ID, paragraph number, and sentence number. For example, "doc001_p02_s05" represents the 5th sentence of the 2nd paragraph in document 1.
[0080] Specifically, in the text fragment localization stage, it is necessary to accurately locate the specific position range of the candidate text fragment within the original document based on the position index information. First, the document identifier in the position index information is parsed to locate the corresponding original document. Then, the paragraph number and sentence number are parsed to locate the specific paragraph position within the document. Next, the character offset of the paragraph is obtained to determine the starting character position of the paragraph. Finally, based on the sentence's position within the paragraph, the starting and ending character positions of the sentence are calculated. For example, for the index "doc001_p02_s05", the document doc001 is first found, then the second paragraph is located, with a starting position of 1000. The fifth sentence has an offset of 200 within the paragraph and a length of 50 characters; therefore, the starting position of the sentence is 1200, and the ending position is 1250. In this way, the position of the candidate text fragment within the original document is accurately located, providing a positional reference for subsequent text expansion and splicing.
[0081] Step 402: For each candidate text segment, with the candidate text segment as the center, search forward in the original document for several consecutive text units as the forward adjacent text segments, and search backward for several consecutive text units as the backward adjacent text segments. The number of text units searched forward and backward is a preset number.
[0082] Among them, candidate text fragments represent text content filtered through similarity matching; text units refer to the basic text organization units in a document, such as sentences or paragraphs; forward adjacent text fragments refer to the continuous text content located before the candidate text fragments; backward adjacent text fragments refer to the continuous text content located after the candidate text fragments; preset quantity indicates the number of text units to be searched; original document refers to the source document of the text fragments; continuous means that they are adjacent in position and in complete order in the document.
[0083] Specifically, in the text expansion stage, it's necessary to obtain the contextual content of candidate text fragments to form more complete text fragments. First, determine the preset search count, typically set to two text units. Then, for each candidate text fragment, obtain its position in the original document. Next, traverse the document content backward from that position, sequentially obtaining two consecutive text units as the preceding adjacent text fragments. Similarly, traverse the document content backward from that position, sequentially obtaining two consecutive text units as the following adjacent text fragments. For example, for a candidate text fragment located at the 5th paragraph of the document, search backward to obtain the 3rd and 4th paragraphs as preceding adjacent text fragments, and search backward to obtain the 6th and 7th paragraphs as following adjacent text fragments. It's important to note that when a candidate text fragment is located at the beginning or end of the document, if a sufficient number of adjacent text units cannot be obtained, use the actual number of available text units. Through this bidirectional expansion method, complete contextual information of the candidate text fragments is obtained, providing a textual foundation for subsequent semantic coherence analysis.
[0084] Step 403: When there are multiple candidate text segments whose position index interval in the original document is less than a preset distance threshold, detect whether there is an overlapping area between adjacent text segments of each candidate text segment. If there is an overlapping area, merge the text units in the overlapping area into a common adjacent text segment of each candidate text segment.
[0085] The position index interval represents the distance between two candidate text segments in the original document; the preset distance threshold refers to the distance standard for judging whether text segments are adjacent; the overlapping area refers to the text content commonly contained in adjacent text segments of multiple candidate text segments; the text unit represents the basic text organization unit in the document, such as a sentence or paragraph; the common adjacent text segments refer to the context content shared by multiple candidate text segments. The position index interval is usually calculated in terms of the number of text units; for example, an interval of 2 means that there are 2 text units between two text segments.
[0086] Specifically, when processing the context expansion of adjacent text segments, it is necessary to address the issue of overlapping adjacent text segments. First, the position indices of all candidate text segments are checked, and the distance between adjacent segments is calculated. When the position index interval between any two candidate text segments is found to be less than a preset distance threshold (e.g., 3 text units), the overlap detection stage begins. In overlap detection, the forward and backward adjacent text segments of these candidate text segments are obtained respectively, and their overlapping areas are identified by comparing the position indices of the text units. For example, for two candidate text segments located in segments 5 and 7, their position index interval is 2, which is less than the threshold of 3. The backward adjacent text of the first segment includes segments 6 and 7, and the forward adjacent text of the second segment includes segments 5 and 6, where segment 6 is the overlapping area. For the identified overlapping areas, the text units within them are extracted as the common adjacent text segments of these candidate text segments. In this way, the repeated acquisition of the same context content is avoided, while ensuring the integrity and coherence of the text expansion.
[0087] Based on the above embodiments, as an optional embodiment, step 105, calculating the semantic coherence between each candidate text segment and its adjacent text segments, may further include the following steps:
[0088] Step 404: For each candidate text segment, perform vector mapping between the candidate text segment and its adjacent text segments, and extract contextual word pairs through a sliding window to construct a semantic dependency graph.
[0089] Vector mapping refers to converting text content into a vector representation; a sliding window refers to a fixed-size observation range that moves across a text sequence; related word pairs represent semantically related word combinations; a semantic dependency graph is a directed graph structure describing the semantic relationships between words; and adjacent text fragments refer to text content that is adjacent to candidate text fragments in the original document. Vector mapping typically uses a pre-trained language model to convert text into high-dimensional vectors, such as using the BERT model to map text into 768-dimensional vectors.
[0090] Specifically, in constructing semantic dependency relationships, the candidate text segments and adjacent text segments are first preprocessed and vector-mapped. A pre-trained language model is used to segment and vectorize the text, obtaining a vector representation for each word. Then, a sliding window size (e.g., 5 words) is set and slid across the text sequence to extract word combinations within the window. For each sliding window position, the semantic similarity between words within the window is calculated, and semantically related word pairs are selected based on a similarity threshold (e.g., 0.6). For example, in the sentence "Deep learning technology drives the development of artificial intelligence," a sliding window of size 3 can extract word pairs such as (deep learning, technology), (technology, drive), and (drive, artificial intelligence). Next, the selected related word pairs are used as nodes and edges to construct a semantic dependency graph. In the graph, nodes represent words, edges represent semantic relationships between words, and the weight of the edges is determined by the cosine similarity of the word vectors. In this way, the semantic structure of the text is explicitly represented as a graph structure, facilitating subsequent semantic coherence analysis.
[0091] Step 405: Calculate the attention weights of each associated word pair in the semantic dependency graph based on the pre-trained bidirectional attention network.
[0092] In this context, a pre-trained bidirectional attention network represents a neural network model with bidirectional encoding capabilities trained on a large-scale corpus; attention weights refer to the degree to which the network model pays attention to different input features; a semantic dependency graph is a directed graph structure describing the semantic relationships between words; and associated word pairs represent semantically related combinations of words in the graph. A typical structure of a bidirectional attention network includes an encoding layer, an attention layer, and an output layer. For example, the BERT model uses a Transformer structure to achieve bidirectional feature encoding.
[0093] Specifically, in the semantic association strength calculation stage, the semantic importance of associated word pairs is analyzed through a bidirectional attention network. First, each associated word pair in the semantic dependency graph is converted into an input sequence, containing the original text representation and positional encoding of the word pair. Then, the input sequence is encoded through a pre-trained bidirectional attention network to obtain the contextual representation of the word pair. In the attention calculation layer, the model simultaneously considers the mutual influence between word pairs and calculates an attention score. The attention score is calculated using a scaled dot product attention mechanism, specifically: Attention(Q, K, V) = softmax(QK^T / sqrt(d))V, where Q, K, and V represent the query vector, key vector, and value vector, respectively, and d is the vector dimension. For example, for the associated word pair ("deep learning", "technology"), the weight obtained through attention calculation might be 0.85, indicating a strong semantic association between the two words. The attention calculation process is repeated for all associated word pairs in the semantic dependency graph to obtain a complete attention weight matrix. These weights reflect the semantic association strength between word pairs, providing an important basis for subsequent semantic coherence evaluation.
[0094] Step 406: Multiply the attention weight of each associated word pair by the corresponding associated word vector to obtain the weighted semantic features of each associated word pair; obtain the length of the longest common subsequence of each weighted semantic feature, and combine it with the topic word overlap of each associated word pair to generate an initial coherence score.
[0095] In this context, attention weight represents the semantic association strength of the associated word pair; associated word vector is the vector representation of the word pair; weighted semantic feature is the product of attention weight and word vector; maximum common subsequence length represents the number of ordered elements commonly contained in two sequences; topic word overlap refers to the degree of overlap of topic-related words in the associated word pair; and initial coherence score represents the preliminary assessment of the semantic coherence of the text segment. For example, if the vector dimension of the associated word pair is 768 and the attention weight is 0.85, then the weighted semantic feature will be 768 dimensions.
[0096] Specifically, when calculating the coherence score, a weighting operation is first performed on each pair of related words. The attention weights are multiplied element-wise with the related word vectors to obtain a weighted semantic feature vector. Then, for all weighted semantic feature sequences, a dynamic programming algorithm is used to calculate the length of the longest common subsequence. The state transition equation of the dynamic programming is: dp[i][j] = dp[i-1][j-1] + 1 (when the elements of sequences i and j are the same) or max(dp[i-1][j], dp[i][j-1]) (when the elements are different), where dp[i][j] represents the length of the longest common subsequence of the first i elements of sequence i and the first j elements of sequence j. Simultaneously, the topic word overlap of the related word pairs is calculated by extracting the topic words from each pair (obtained through part-of-speech tagging or keyword extraction) and calculating the overlap ratio: overlap = 2 * number of overlapping topic words / (number of topic words in word pair 1 + number of topic words in word pair 2). Finally, the length of the longest common subsequence is standardized to the interval [0, 1], and then weighted and summed with the topic word overlap to obtain the initial coherence score. The calculation formula is: Initial score = α * Standardized longest common subsequence length + (1-α) * Topic word overlap, where α is the weight coefficient (e.g., 0.6). This score reflects the semantic coherence of the text fragment at both the word and topic levels.
[0097] Based on the above embodiments, as an optional embodiment, step 406, which involves obtaining the length of the longest common subsequence of each weighted semantic feature and combining it with the topic word overlap of each associated word pair to generate an initial coherence score, may further include the following steps:
[0098] Step 416: Compare each weighted semantic feature, take the position of word occurrence in the candidate text segment as the baseline number, identify word sequences in adjacent text segments that have the same semantic components as the baseline number and whose position numbers increase, and take the length of the word sequence as the length of the longest common subsequence.
[0099] Among them, weighted semantic features refer to word vector representations adjusted by attention weights; the baseline index represents the position number of lexical units in the candidate text segment; a lexical unit is the basic semantic unit of text, such as a word or phrase; identical semantic components refer to content with similar semantic expressions; the position index represents the sequential position of lexical units in the text; and a lexical sequence is a combination of lexical units that satisfy specific conditions. For example, in "development of artificial intelligence technology", the position index of "artificial intelligence" is 1, "technology" is 2, and "development" is 3.
[0100] Specifically, a position-based semantic matching method is used to calculate the length of the longest common subsequence. First, the position number of each word in the candidate text segment is obtained, and these numbers are used as the baseline sequence. Then, for each word in adjacent text segments, its semantic similarity to each word in the candidate text segment is calculated. The similarity is calculated using the cosine distance of word vectors: similarity = cos(v1, v2), where v1 and v2 are the weighted semantic feature vectors of the two words. A similarity threshold (e.g., 0.8) is set; words with similarity exceeding the threshold are considered to have the same semantic components. Next, word sequences that satisfy two conditions are searched in adjacent text segments: first, the words in the sequence have the same semantic components as the words corresponding to the baseline sequence numbers; second, the position numbers of the words in the sequence are incrementally increasing. For example, in the candidate segment "Deep learning drives the development of artificial intelligence" (sequences 1-4) and the adjacent segment "Machine learning promotes the progress of intelligent technology", we can find corresponding sequences such as {"learning"-"learning", "drives"-"promotes", "intelligent"-"intelligent"}, with position numbers {1, 2, 3} respectively, maintaining an increasing order. Therefore, the length of the maximum common subsequence is 3. This calculation method considers both the semantic similarity of lexical units and maintains the consistency of word order, and can more accurately reflect the structured semantic relationships between text segments.
[0101] Step 426: Extract the topic words from each pair of related words, calculate the ratio of the number of topic words appearing in adjacent text segments to the total number of topic words in the candidate text segments, and obtain the topic word overlap.
[0102] In this context, keywords refer to words in the text that carry core semantic information, typically nouns, verbs, and other content words; related words refer to related word combinations in the semantic dependency graph; and keyword overlap indicates the degree of overlap between two text segments in terms of topic expression. Keyword identification is usually based on part-of-speech tagging and keyword extraction. For example, the keywords in "artificial intelligence technology research" include "artificial intelligence," "technology," and "research."
[0103] Specifically, when calculating the topic word overlap, topic words are first extracted from candidate text segments and adjacent text segments. Part-of-speech tagging tools are used to perform part-of-speech analysis on the text, extracting content words such as nouns (N), verbs (V), and adjectives (ADJ). Simultaneously, keyword extraction algorithms such as TF-IDF are used to calculate the importance score of each word. Words with content words and an importance score exceeding a threshold (e.g., 0.1) are identified as topic words. Then, the total number of topic words in the candidate text segments (count1) and the number of times these topic words appear in adjacent text segments (count2) are counted. Topic word matching employs a combination of strict matching and fuzzy matching: strict matching requires identical word forms; fuzzy matching calculates the cosine similarity of word vectors, and a successful match is considered achieved when the similarity exceeds a threshold (e.g., 0.85). Finally, the topic word overlap is calculated: overlap = count2 / count1. For example, the candidate text segment "Deep Learning Algorithm Research" contains three keywords: "deep learning," "algorithm," and "research." In the adjacent text segment "Research Progress in Machine Learning Technology," word vector similarity matching reveals that "machine learning" is similar to "deep learning," and "research" is a perfect match. Therefore, count2 = 2, and the final keyword overlap is 2 / 3 ≈ 0.667. This value reflects the degree of consistency between the two text segments in terms of topic expression.
[0104] Step 436: Calculate the initial coherence score by weighting the length of the longest common subsequence and the keyword overlap.
[0105] The longest common subsequence length represents the number of ordered semantic components commonly contained in two text segments; the topic word overlap refers to the degree of overlap in the topic expression between text segments; the weighted calculation is a comprehensive operation that assigns weight coefficients to different features; and the initial coherence score represents a preliminary assessment of the semantic coherence between text segments. For example, if the longest common subsequence length is 4, the topic word overlap is 0.7, and the weights are 0.6 and 0.4 respectively, then the initial coherence score obtained by the weighted calculation will be a value between 0 and 1.
[0106] When calculating the initial coherence score, the length of the longest common subsequence is first standardized. Specifically, the original length is divided by the length of the shorter of the two text segments to obtain the standardized length value len_norm, ensuring it falls within the range [0, 1]. Then, weight coefficients are set for two features: sequence length weight α and topic overlap weight β, with α + β = 1. The weights are set based on the importance of the features; typically, the sequence length weight is slightly larger than the topic overlap weight, such as α = 0.6 and β = 0.4, because sequence length reflects both semantic and structural coherence. Finally, the initial coherence score is calculated using a weighted summation formula: score = α * len_norm + β * overlap, where overlap represents the topic word overlap. For example, when the length of the longest common subsequence is 4, the length of the shorter text fragment is 5, and the topic word overlap is 0.7, then len_norm = 4 / 5 = 0.8. Using a weight configuration of α = 0.6 and β = 0.4, the initial coherence score is calculated as: score = 0.6 * 0.8 + 0.4 * 0.7 = 0.48 + 0.28 = 0.76. This score comprehensively reflects the semantic coherence of the text fragment at both the structural and topical levels.
[0107] Step 407: Based on the relative positional relationship between the candidate text fragment and its adjacent text fragment in the original document, set a distance decay factor, and use the product of the initial coherence score and the distance decay factor as the semantic coherence between the candidate text fragment and its adjacent text fragment.
[0108] In this context, relative positional relationship represents the distance and order relationship between text segments; distance decay factor refers to the weighting coefficient calculated based on positional distance; initial coherence score is a preliminary evaluation value calculated through semantic features; and semantic coherence represents the final strength value of the semantic association between text segments. The distance decay factor is usually calculated using an exponential decay function, such as exp(-d / λ), where d is the positional distance and λ is the decay parameter.
[0109] Specifically, when calculating the final semantic coherence, the relative positions of candidate text segments and adjacent text segments are first determined. The difference in position indices of the two text segments in the original document is calculated to obtain their distance d (in terms of the number of text units). Then, a distance decay factor is designed based on this distance, using an exponential decay function: decay = exp(-d / λ), where λ is a decay control parameter (e.g., λ = 3). When d = 0, decay = 1, indicating adjacent segments; as d increases, decay gradually decreases, reflecting the weakening effect of distance on semantic coherence. For example, when the distance between two text segments is 2 units, λ = 3, then the decay factor is exp(-2 / 3) ≈ 0.513. Finally, the initial coherence score is multiplied by the calculated distance decay factor to obtain the final semantic coherence considering the influence of position. The calculation formula is: Semantic coherence = Initial coherence score * exp(-d / λ). This calculation method considers both the semantic relevance of the text content and the influence of positional distance on semantic coherence, resulting in a more accurate coherence assessment. For example, if the initial coherence score is 0.8 and the distance is 2, the final semantic coherence score is 0.8 * 0.513 = 0.410, which reflects the decrease in semantic coherence caused by the increase in distance.
[0110] Step 106: According to the order of the index information at each position, concatenate each candidate text fragment with the corresponding fragment to be concatenated and remove overlapping content to generate a contextually coherent composite text fragment.
[0111] The position index information indicates the position and order of the text fragments in the original document; candidate text fragments refer to the core text content to be merged; fragments to be concatenated are the text content adjacent to the candidate text fragments; text concatenation refers to combining multiple text fragments in a specific order; overlapping content refers to the identical or highly similar text parts existing in adjacent text fragments; and composite text fragments refer to the complete text content formed after concatenation and deduplication. For example, when the position index is [2, 5, 8], it means that the text fragments at the corresponding positions need to be processed in the order of 2, 5, 8.
[0112] Specifically, this text concatenation step is performed when multiple scattered text fragments need to be combined into a semantically coherent complete text. First, candidate text fragments and the fragments to be concatenated are sorted according to their positional index information to ensure the concatenation order matches the order in the original document. Then, adjacent text fragment pairs are processed sequentially, calculating their overlapping portions. Overlap detection uses a sliding window method, comparing characters one by one from back to front to find the longest common substring. After identifying overlapping content, only one overlapping portion is retained during concatenation to ensure the continuity and naturalness of the text. Finally, the processed text fragments are connected sequentially to form a complete composite text fragment.
[0113] In some embodiments, text fragment concatenation and deduplication can be implemented in several ways: Optionally, a character-level concatenation method can be used. First, adjacent text fragments are converted into character arrays. Starting from the end of the first text fragment, each character is compared with the beginning of the second text fragment. When a consecutive matching character length exceeds a preset threshold (e.g., 3 characters), it is marked as an overlapping area. The overlapping portion in the second text fragment is removed, and the remaining portion is then concatenated to the end of the first text fragment. This process is repeated for all text fragments to generate a deduplicated composite text. Optionally, a semantic similarity-based concatenation method can be used. First, the text fragments are segmented using a word segmentation tool. The semantic vectors of words in adjacent fragments are calculated. A sliding window is used to find word sequences with high semantic similarity at the intersection of two text fragments. The portion with similarity exceeding a threshold (e.g., 0.85) is marked as an overlapping area, retaining the more semantically complete version. Then, the text fragments are concatenated to form a semantically coherent composite text. It is understood that other methods, such as syntactic analysis and topic modeling, can also be used to achieve text fragment concatenation and deduplication; these are not limited here.
[0114] Based on the above embodiments, as an optional embodiment, step 106, which generates a context-coherent compound text fragment, may further include the following steps:
[0115] Step 501: Based on the length of the composite text fragment and the context window limitation of the large language model, the composite text fragment is segmented. When the total length of the composite text fragment exceeds the preset length threshold, the composite text fragment is truncated and compressed.
[0116] Among these, composite text fragments refer to complete text content that has been concatenated; the context window limit indicates the maximum text length that a large language model can process; segmentation refers to dividing a long text into multiple shorter texts according to specific rules; the preset length threshold refers to the maximum allowed text length; truncation refers to selecting a specific part from the text; and compression refers to reducing the text length by removing redundant content. For example, if a large language model's context window is limited to 2048 tokens, and the composite text fragment is 3000 tokens long, segmentation or compression is required.
[0117] Specifically, when using a large language model to process text, it's crucial to ensure the input text length doesn't exceed the model's processing capacity. First, the number of tokens for complex text segments is counted and compared to a preset length threshold. When the text length exceeds the threshold, two strategies are employed: For minor exceedances (e.g., within 20%), text length is reduced through compression, including removing duplicate expressions, merging similar content, and simplifying modifiers; for significant exceedances, the text is segmented according to semantic integrity, ensuring each segment's length remains within the context window limit. Segmentation prioritizes division at paragraph boundaries and natural sentence breaks to maintain text coherence.
[0118] Step 502: Construct an input prompt template. In the prompt template, the query text is used as the question input, the compound text fragment is used as the reference material input, and role instructions and answer format requirements are added to the input prompt template to generate input prompts.
[0119] The input prompt template refers to the text framework used to standardize the input format of a large language model; the query text represents the user's question or requirement description; the references refer to the background information used to assist in answering the question; the role instructions define the role the model should play and the tone it should adopt when answering; and the answer format requirements specify the structure, length, style, etc., of the answer. For example, the input prompt template might contain instructions such as "As a professional technical consultant, please answer the question based on the following references. The answer should be presented in points, each within 500 words."
[0120] Specifically, when preparing to submit a question to a large language model, it's necessary to construct standardized input prompts to obtain high-quality answers. First, determine the basic structure of the prompt template, including role definition, task description, references, specific questions, and output requirements. Then, organize these elements in a specific order to ensure logical clarity. In the role instruction section, clearly specify the role the model should play in answering the question, including its professional background and answering style. In the references section, embed complex text fragments in an appropriate format, adding separators or markers as needed to distinguish different parts. In the answer format requirements section, detail the specific requirements for the answer's organization, length limits, and argumentation style. Finally, incorporate the query text as the specific question into the template to form a complete input prompt.
[0121] Step 503: Input prompts are passed to a pre-set large language model to obtain initial question-and-answer results, and the confidence score of the initial question-and-answer results is obtained through a pre-set answer quality assessment algorithm.
[0122] Among them, input prompts refer to query content and instructions organized according to a specific format; large language model refers to the pre-trained model used for natural language processing; initial question-answering result is the original answer content generated by the model based on the input prompts; answer quality assessment algorithm refers to the calculation method used to evaluate the quality of the answer; confidence score represents the quantitative assessment of the reliability of the answer.
[0123] Specifically, a standardized processing procedure is required when obtaining and evaluating the answers from a large language model. First, the constructed input prompts are encoded according to the model's required format and passed to the pre-configured large language model via API or other interfaces. Appropriate generation parameters are set, including a temperature value (usually 0.7), maximum length limit, sampling strategy, etc. After obtaining the initial question-and-answer results returned by the model, a pre-defined evaluation algorithm is used to perform multi-dimensional analysis of the answers. Evaluation dimensions include the relevance, accuracy, completeness, and logicality of the answers. A score is calculated for each dimension, and a comprehensive score is calculated based on the dimension weights as the final confidence score.
[0124] In one specific embodiment, the pre-configured large language model is trained through the following process: First, a large-scale text corpus, including technical documents, academic papers, and professional textbooks, is collected. The text is then cleaned and normalized, including noise removal, format unification, and word segmentation. Next, a Transformer architecture is used to build the model, containing a 12-layer encoder and decoder, with 12 attention heads per layer and a hidden layer dimension of 768. Then, a two-stage training process is performed: the first stage uses a masked language modeling task for pre-training to learn the semantic representation ability of the text; the second stage uses a command fine-tuning dataset for supervised fine-tuning to improve the model's ability to handle specific tasks. During training, the Adam optimizer is used with a learning rate of 2e-5, a batch size of 32, and 3 training epochs. Gradient pruning and weight decay techniques are used to prevent overfitting. Finally, the model performance is evaluated using metrics such as perplexity and ROUGE score, and the checkpoint with the best performance is selected as the final model.
[0125] Step 504: When the confidence score is lower than the preset quality threshold, adjust the reference input in the input prompt, reselect candidate text fragments and / or expand the range of fragments to be concatenated, and re-input into the preset large language model until the confidence score is greater than or equal to the preset quality threshold, and generate the question-and-answer result.
[0126] The confidence score is a quantitative assessment of the quality of the question-and-answer result; the preset quality threshold represents the minimum acceptable quality standard; the reference input is the background information provided to the model; the candidate text fragment refers to the core text that can be used to answer the question; the fragment to be pieced together refers to the relevant text content that can be supplemented; and the question-and-answer result is the final answer that meets the quality requirements. For example, when the confidence score is 0.6, which is lower than the preset threshold of 0.8, the input content needs to be adjusted and the answer regenerated.
[0127] Specifically, to ensure the quality of question-and-answer sessions, the input content needs to be dynamically adjusted based on the evaluation results. First, the obtained confidence score is compared with a preset quality threshold. When the score is below the threshold, the specific reasons for the low score are analyzed, including insufficient relevance of the answer, lack of supporting evidence, and disorganized logical structure. Based on the analysis results, targeted adjustment strategies are adopted: increasing the completeness of background information by expanding the range of the fragments to be assembled; reselecting candidate text fragments more relevant to the question; and adjusting the order of the text fragments to improve logical coherence. After each adjustment, new input prompts are fed into the model to obtain the updated answer and score it. This process is repeated until the preset quality requirements are met, and the final question-and-answer result is output.
[0128] Reference Figure 2 This application provides a semantic splicing system, which includes: a text unit segmentation module, a vector generation module, a segment to be spliced determination module, and a splicing module, wherein:
[0129] The text unit segmentation module is used to acquire the original document to be processed, identify semantic boundary points in the original document, and segment the original document into multiple text units based on the semantic boundary points;
[0130] The vector generation module is used to construct a multidimensional semantic feature matrix for each text unit. The multidimensional semantic feature matrix includes local semantic features, global semantic features, and structural association features. The module then performs weighted fusion on each multidimensional semantic feature matrix to obtain a composite semantic vector for each text unit. The module receives the user's query text and extracts query keywords and grammatical structures from the query text to generate an enhanced query vector containing intent weights.
[0131] The module for determining the segments to be spliced is used to calculate the cosine similarity between the enhanced query vector and each composite semantic vector, and select text units with a cosine similarity greater than a first preset threshold as candidate text segments; based on the position index information of each candidate text segment, it searches for adjacent text segments in the original document for each candidate text segment, and calculates the semantic coherence between each candidate text segment and adjacent text segments, and determines adjacent text segments with semantic coherence exceeding a preset threshold as segments to be spliced.
[0132] The concatenation module is used to concatenate each candidate text fragment with its corresponding fragment to be concatenated according to the order of the index information at each position, and remove overlapping content to generate a contextually coherent composite text fragment.
[0133] Based on the above embodiments, the text unit segmentation module is further used to mark the positions of ending punctuation marks, transition words, and causal words in the original document based on the syntactic features in the original document, to obtain a first candidate boundary point set; extract named entities from the original document and mark the beginning and end positions of each named entity to obtain a second candidate boundary point set, where named entities include people, time, place, and organization; calculate the semantic relevance between adjacent sentences in the original document and mark the semantic transition positions between sentences with semantic relevance below the relevance threshold to obtain a third candidate boundary point set; merge the first, second, and third candidate boundary point sets and remove duplicate boundary points in adjacent positions to obtain semantic boundary points.
[0134] Based on the above embodiments, the vector generation module is also used to perform part-of-speech tagging on the query text, extract noun phrases, verb phrases, and modifiers as query keywords, and extract the grammatical structure of the query text using a preset grammar parsing algorithm; based on a preset intent classification dictionary, the query keywords are mapped to the corresponding intent categories, and the intent weights of the intent categories are determined according to the question word type, sentence features, and modifiers in the grammatical structure. The intent categories include fact queries, process queries, comparison queries, and reasoning queries; the query keywords are converted into word vectors through a pre-trained word vector model, the grammatical structure is encoded into structure vectors through a graph neural network, and the word vectors and structure vectors are weighted and fused together with the intent weights to generate an enhanced query vector containing intent weights.
[0135] Based on the above embodiments, the segment to be spliced determination module is further configured to determine the start and end positions of each candidate text segment in the original document according to the position index information of each candidate text segment; for each candidate text segment, taking the candidate text segment as the center, searching forward a number of consecutive text units in the original document as the forward adjacent text segments, and searching backward a number of consecutive text units as the backward adjacent text segments, wherein the number of text units searched forward and backward are both preset numbers; when there are multiple candidate text segments with a position index interval of less than a preset distance threshold, detecting whether there is an overlapping area between adjacent text segments of each candidate text segment, if there is an overlapping area, merging the text units in the overlapping area into a common adjacent text segment of each candidate text segment.
[0136] Based on the above embodiments, the segment to be spliced segment determination module is further configured to perform vector mapping on each candidate text segment and its adjacent text segments, and extract contextual related word pairs through a sliding window to construct a semantic dependency graph; calculate the attention weight of each related word pair in the semantic dependency graph based on a pre-trained bidirectional attention network; multiply the attention weight of each related word pair by the corresponding related word vector to obtain the weighted semantic features of each related word pair; obtain the length of the longest common subsequence of each weighted semantic feature, and generate an initial coherence score by combining the topic word overlap of each related word pair; set a distance decay factor according to the relative positional relationship between the candidate text segment and its adjacent text segments in the original document, and use the product of the initial coherence score and the distance decay factor as the semantic coherence between the candidate text segment and its adjacent text segments.
[0137] Based on the above embodiments, the segment to be spliced segment determination module is also used to compare each weighted semantic feature, take the occurrence position of word elements in the candidate text segment as the reference number, identify word element sequences in adjacent text segments that have the same semantic components as the reference number and whose position numbers increase, and take the length of the word element sequence as the length of the maximum common subsequence; extract the topic words in each associated word pair, calculate the ratio of the number of topic words appearing in adjacent text segments to the total number of topic words in the candidate text segments to obtain the topic word overlap; and perform weighted calculation on the maximum common subsequence length and the topic word overlap to obtain the initial coherence score.
[0138] Based on the above embodiments, the splicing module is also used to segment the composite text fragment according to its length and the context window limitation of the large language model. When the total length of the composite text fragment exceeds a preset length threshold, the composite text fragment is truncated and compressed. An input prompt template is constructed, in which the query text is used as the question input and the composite text fragment is used as the reference material input. Role instructions and answer format requirements are added to the input prompt template to generate input prompts. The input prompts are then passed to a preset large language model to obtain initial question-and-answer results, and the confidence score of the initial question-and-answer results is calculated using a preset answer quality assessment algorithm. When the confidence score is lower than a preset quality threshold, the reference material input in the input prompts is adjusted, candidate text fragments are reselected and / or the range of the fragment to be spliced is expanded, and the input is passed back to the preset large language model until the confidence score is greater than or equal to the preset quality threshold, and question-and-answer results are generated.
[0139] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0140] This application also discloses an electronic device. (See reference...) Figure 3 , Figure 3 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. The electronic device 300 may include: at least one processor 301, at least one network interface 304, a user interface 303, a memory 305, and at least one communication bus 302.
[0141] The communication bus 302 is used to enable communication between these components.
[0142] The user interface 303 may include a display interface and a camera interface. Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.
[0143] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0144] The processor 301 may include one or more processing cores. The processor 301 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 305, and by calling data stored in the memory 305. Optionally, the processor 301 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 301 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface graphics, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 301 and may be implemented as a separate chip.
[0145] The memory 305 may include random access memory (RAM) or read-only memory. Optionally, the memory 305 may include a non-transitory computer-readable storage medium. The memory 305 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 305 may also be at least one storage device located remotely from the aforementioned processor 301. (Refer to...) Figure 3 The memory 305, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program for a semantic splicing method.
[0146] exist Figure 3In the illustrated electronic device 300, the user interface 303 is mainly used to provide an input interface for the user and to acquire user input data; while the processor 301 can be used to call an application program storing a semantic concatenation method in the memory 305. When executed by one or more processors 301, the electronic device 300 performs one or more methods as described in the above embodiments. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0147] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0148] In the various embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.
[0149] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0150] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0151] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0152] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will be readily apparent to those skilled in the art upon consideration of the specification and practical disclosure.
[0153] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only.
Claims
1. A method of semantic stitching, the method comprising: The method comprises the following steps: acquiring an original document to be processed, identifying semantic boundary points in the original document, and cutting the original document into multiple text units based on the semantic boundary points; constructing a multi-dimensional semantic feature matrix of each text unit, the multi-dimensional semantic feature matrix comprising local semantic features, global semantic features, and structural correlation features, and respectively performing weighted fusion on each multi-dimensional semantic feature matrix to obtain a composite semantic vector of each text unit; receiving a query text of a user, extracting query keywords and a syntax structure from the query text, and generating an enhanced query vector comprising an intent weight; calculating a cosine similarity between the enhanced query vector and each composite semantic vector, and selecting a text unit with a cosine similarity greater than a first preset threshold as a candidate text segment; based on position index information of each candidate text segment, finding adjacent text segments of each candidate text segment in the original document, and calculating a semantic coherence between each candidate text segment and the adjacent text segments, and determining adjacent text segments with a semantic coherence exceeding a preset threshold as to-be-spliced segments; in accordance with an order of each position index information, performing text splicing on each candidate text segment and the corresponding to-be-spliced segment and removing overlapping content, and generating a composite text segment with coherent context; the identification of the semantic boundary points in the original document comprises: based on the syntax features in the original document, marking the positions of end punctuation marks, transition conjunctions, and causal relationship words in the original document to obtain a first candidate boundary point set; extracting named entities from the original document and marking the beginning and end positions of each named entity to obtain a second candidate boundary point set, the named entities including persons, times, places, and organizations; calculating the semantic correlation between adjacent sentences in the original document, and marking semantic transition positions between sentences with a semantic correlation lower than a correlation threshold to obtain a third candidate boundary point set; merging the first candidate boundary point set, the second candidate boundary point set, and the third candidate boundary point set, and removing duplicate boundary points at adjacent positions to obtain the semantic boundary points.
2. The semantic stitching method of claim 1, wherein, The extraction of query keywords and a syntax structure from the query text and the generation of an enhanced query vector comprising an intent weight comprise: performing part-of-speech tagging on the query text, extracting noun phrases, verb phrases, and modifier words as query keywords, and extracting the syntax structure of the query text using a preset syntax parsing algorithm; based on a preset intent classification dictionary, mapping the query keywords to corresponding intent categories, and determining an intent weight of the intent categories according to interrogative word types, sentence features, and mood words in the syntax structure, the intent categories including factual queries, process queries, comparison queries, and reasoning queries; converting the query keywords into word vectors through a pre-trained word vector model, encoding the syntax structure into a structure vector through a graph neural network, and performing weighted fusion on the word vectors and the structure vector in combination with the intent weight to generate the enhanced query vector comprising the intent weight.
3. The semantic stitching method of claim 1, wherein, The position index information of each candidate text segment is used to find the adjacent text segments of each candidate text segment in the original document, including: The position index information of each candidate text segment is used to determine the start position and end position of each candidate text segment in the original document. For each candidate text segment, a plurality of text units in front of the candidate text segment are found as forward adjacent text segments, and a plurality of text units behind the candidate text segment are found as backward adjacent text segments, wherein the number of text units found in front and behind is a preset number. When the interval between the positions of multiple candidate text segments in the original document is less than a preset distance threshold, it is detected whether the adjacent text segments of each candidate text segment overlap, and if there is an overlapping area, the text units in the overlapping area are merged into adjacent text segments common to each candidate text segment.
4. The semantic stitching method of claim 1, wherein, The semantic coherence of each candidate text segment and the adjacent text segments is calculated, including: For each candidate text segment, the candidate text segment and the adjacent text segment are vector mapped, and the associated word pairs of the context are extracted through a sliding window to construct a semantic dependency graph. Based on a pre-trained bidirectional attention network, the attention weights of each associated word pair in the semantic dependency graph are calculated. The attention weights of each associated word pair are multiplied by the corresponding associated word vectors to obtain the weighted semantic features of each associated word pair. The maximum common subsequence length of each weighted semantic feature is obtained, and the initial coherence score is generated in combination with the theme word overlap degree of each associated word pair. According to the relative position relationship between the candidate text segment and the adjacent text segment in the original document, a distance decay factor is set, and the product of the initial coherence score and the distance decay factor is taken as the semantic coherence of the candidate text segment and the adjacent text segment.
5. The semantic stitching method of claim 4, wherein, The maximum common subsequence length of each weighted semantic feature is obtained, and the initial coherence score is generated in combination with the theme word overlap degree of each associated word pair, including: Each weighted semantic feature is compared, the occurrence position of the word unit in the candidate text segment is taken as the reference sequence number, the word unit sequence with the same semantic component and increasing position sequence number in the adjacent text segment is identified, and the length of the word unit sequence is taken as the maximum common subsequence length. The theme words in each associated word pair are extracted, the ratio of the number of theme words appearing in the adjacent text segment to the total number of theme words in the candidate text segment is calculated to obtain the theme word overlap degree. The maximum common subsequence length and the theme word overlap degree are weighted to obtain the initial coherence score.
6. The semantic stitching method of claim 1, wherein, After the context-coherent composite text segment is generated, it further includes: According to the length of the composite text segment and the context window limit of the large language model, the composite text segment is segmented, and when the total length of the composite text segment exceeds a preset length threshold, the composite text segment is truncated and compressed; An input prompt template is constructed, in which the query text is input as a question and the composite text segment is input as reference material, and a role instruction and an answer format requirement are added to the input prompt template to generate an input prompt; The input prompt is input into a pre-set large language model to obtain an initial question and answer result, and a confidence score of the initial question and answer result is calculated by a pre-set answer quality evaluation algorithm; When the confidence score is lower than a preset quality threshold, the reference material input in the input prompt is adjusted, the candidate text segment is reselected and / or the range of the to-be-spliced segment is expanded, and the pre-set large language model is re-input until the confidence score is greater than or equal to the preset quality threshold, thereby generating the question and answer result.
7. A semantic stitching system, comprising: The system comprises: A text unit segmentation module configured to obtain an original document to be processed, identify semantic boundary points in the original document, and segment the original document into a plurality of text units based on the semantic boundary points; A vector generation module configured to construct a multi-dimensional semantic feature matrix of each text unit, the multi-dimensional semantic feature matrix comprising local semantic features, global semantic features, and structural correlation features, and to obtain a composite semantic vector of each text unit by separately weighting and fusing the multi-dimensional semantic feature matrix; receive a query text from a user, and extract query keywords and a syntax structure from the query text to generate an enhanced query vector comprising an intent weight; A to-be-spliced segment determination module configured to calculate a cosine similarity between the enhanced query vector and each composite semantic vector, select a text unit with a cosine similarity greater than a first preset threshold as a candidate text segment; based on position index information of each candidate text segment, find adjacent text segments of each candidate text segment in the original document, and calculate a semantic coherence between each candidate text segment and the adjacent text segments, and determine adjacent text segments with a semantic coherence exceeding a preset threshold as to-be-spliced segments; A splicing module configured to splice each candidate text segment with a corresponding to-be-spliced segment in the order of each position index information and remove overlapping content to generate a contextually coherent composite text segment. The identification of the semantic boundary points in the original document comprises: Based on the syntax features in the original document, marking the positions of the end punctuation marks, transition conjunctions, and causal relationship words in the original document to obtain a first candidate boundary point set; Extracting named entities from the original document and marking the beginning and end positions of each named entity to obtain a second candidate boundary point set, the named entities including persons, times, places, and organizations; calculating semantic correlation between adjacent sentences in the original document, and marking a semantic transition position between sentences with a semantic correlation lower than a correlation threshold, to obtain a third candidate boundary point set; merging the first candidate boundary point set, the second candidate boundary point set and the third candidate boundary point set, and removing repeated boundary points at adjacent positions, to obtain the semantic boundary points.
8. An electronic device, comprising: The electronic device comprises a processor, a memory, a user interface and a network interface. The memory is configured to store instructions. The user interface and the network interface are configured to communicate with other devices. The processor is configured to execute the instructions stored in the memory, so that the electronic device performs the semantic splicing method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores instructions, and when the instructions are executed by a processor, the semantic splicing method according to any one of claims 1-6 is implemented.
Citation Information
Patent Citations
Retrieval method and device based on document segmentation and document retrieval system
CN120561238A
Intelligent text retrieval method and system, storage medium and program product
CN120723896A