Text matching method and device and storage medium
By constructing a text matching dictionary and calculating multi-dimensional feature similarity, the problem of large text matching errors in existing technologies is solved, achieving more accurate and efficient text matching and improving user experience.
Patent Information
- Application Number
- CN202410454012.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-15
- Publication Date
- 2025-10-28
AI Technical Summary
In existing technologies, text matching methods only consider a single text feature and ignore the correlation between text features, resulting in large matching errors and an inability to accurately understand user intent.
By constructing a text matching dictionary, we obtain the feature sets of the text to be matched and the candidate texts. Using multi-dimensional feature similarity calculation methods, including word order similarity and cosine similarity, we determine the similarity value of the candidate texts and select the best matching text.
It improves the accuracy and efficiency of text matching, enabling a more comprehensive description of the similarity between text content and structure, thus enhancing the user experience.
Smart Images

Figure CN120849572A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a text matching method, device, and storage medium. Background Art
[0002] With the rapid development of information technology, natural language processing technology has been widely applied in various fields. Especially in scenarios such as refrigerator food management and intelligent answering. Therefore, it is crucial to accurately understand and match the user's intention and make a response.
[0003] Currently, text matching is achieved by calculating and based on the similarity between two texts. However, the existing similarity calculation methods are mainly based on the simple cosine similarity algorithm, which has a relatively single dimension of consideration and fails to fully take into account key factors such as the semantics, word order, and structure of the text, resulting in a large error in text matching. For example, in the scenario of refrigerator food management, although vegetables, fruits, and beverages are not synonyms or near-synonyms in terms of meaning, they play the same role in the recognition of user intentions ("added vegetables / added fruits / added beverages" are the same intention).
[0004] In addition, although some marker words have very different meanings and词性 (the original text might have a typo here, assuming it means "grammatical categories"), they have similar functional values in terms of marking intention categories. For example, "是不是" in "冰箱里是不是有食材过期了?" and "吗" in "冰箱里有食材过期了吗?" They have different meanings and grammatical categories, but they are both a marking means for "yes-no questions". The two sentences have the same intention, but if these marking means are not processed, the subsequent similarity calculation will consider that the similarity of such two sentences is not high. These cannot be solved by simple cosine similarity, synonym tables, and other means. Summary of the Invention
[0005] One of the purposes of the present invention is to provide a text matching method to solve the technical problem in the prior art that only single text features are considered, ignoring the correlation between text features, resulting in low accuracy and large error in the matched text, and being unable to accurately and efficiently reflect the original meaning of the text.
[0006] One of the purposes of the present invention is to provide a refrigeration device.
[0007] One of the purposes of the present invention is to provide a computer storage medium.
[0008] To achieve one of the above-mentioned objectives, the present invention provides a text matching method, comprising: obtaining a set of features to be matched for the text to be matched, and a corresponding set of several candidate features; determining the similarity between the set of candidate features and the set of features to be matched based on the similarity between the features to be matched and the corresponding candidate features, thereby obtaining several overall similarity values; and determining a candidate text that matches the text to be matched based on the several overall similarity values and the corresponding set of candidate features.
[0009] As a further improvement of one embodiment of the present invention, the step of "obtaining the set of features to be matched of the text to be matched, and the corresponding set of several candidate features" specifically includes: constructing a text matching dictionary; obtaining the set of features to be matched of the text to be matched, and determining the corresponding set of several candidate features based on the text matching dictionary.
[0010] As a further improvement to one embodiment of the present invention, the "construction of a text matching dictionary" specifically includes:
[0011] Obtain several text information, perform word segmentation and part-of-speech tagging on each text information to obtain several corresponding text features; use non-empty text features as keys and the set of text information containing the corresponding non-empty text features as values to construct a text matching dictionary.
[0012] As a further improvement of one embodiment of the present invention, the step of "determining a number of candidate feature sets according to the text matching dictionary" specifically includes: querying the text matching dictionary according to the non-empty features to be matched, and determining a set of candidate texts corresponding to the text to be matched; and determining a number of candidate feature sets according to the set of candidate texts.
[0013] As a further improvement of one embodiment of the present invention, the step of "querying the text matching dictionary based on non-empty matching features to determine the candidate text set corresponding to the text to be matched" specifically includes: querying the text matching dictionary based on several non-empty matching features to determine several intermediate candidate text sets; and determining the candidate text set corresponding to the text to be matched based on the intersection of several intermediate candidate text sets.
[0014] As a further improvement of one embodiment of the present invention, the step of "obtaining the set of features to be matched of the text to be matched, and the corresponding set of several candidate features" specifically includes: calculating the absolute value of the length difference between the features to be matched in the set of features to be matched and the candidate features in the corresponding set of candidate features; sorting the features according to the absolute value of the length difference from largest to smallest, selecting a preset number of candidate features to update the set of candidate features, and obtaining the updated set of several candidate features.
[0015] As a further improvement of one embodiment of the present invention, the set of features to be matched is formed into a feature matrix to be matched, including a plurality of column vectors of the matrix to be matched corresponding to the features to be matched; the set of candidate features is formed into a candidate feature matrix, including a plurality of column vectors of the candidate matrix corresponding to the candidate features; the step of "determining the similarity between the candidate feature set and the set of features to be matched based on the similarity between the features to be matched and the corresponding candidate features, and obtaining a plurality of overall similarity values" specifically includes: obtaining a plurality of partial similarity values based on the similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix; determining the similarity between the feature matrix to be matched and the corresponding candidate feature matrix based on the preset weights of the feature matrix columns and the plurality of partial similarity values, and obtaining a plurality of overall similarity values.
[0016] As a further improvement to one embodiment of the present invention, the step of "obtaining several partial similarity values based on the similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix" specifically includes: obtaining several word order weight values based on the word order similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix; determining the feature similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix based on the cosine similarity algorithm, and obtaining several cosine similarity values; and determining the corresponding partial similarity value based on each cosine similarity value and the corresponding word order weight value.
[0017] As a further improvement to one embodiment of the present invention, the step of "obtaining several word order weight values based on the word order similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix" specifically includes:
[0018] For each element in the short matrix vector, determine the number of elements projected onto the long matrix vector according to their arrangement order in the short matrix vector to obtain several ordered repetition numbers; based on each ordered repetition number and the corresponding long matrix vector, obtain several word order weight values.
[0019] As a further improvement of one embodiment of the present invention, the step of "obtaining several word order weight values based on each ordered repetition number and the corresponding long matrix vector" specifically includes: obtaining non-ordered repetition values based on the difference between the length of the long matrix vector and the corresponding ordered repetition number; determining the corresponding word order weight value based on the ratio of the non-ordered repetition value to the length of the long matrix vector; wherein the word order weight value is equal to the product of the ratio and a preset weight coefficient.
[0020] As a further improvement of one embodiment of the present invention, the step of "determining the corresponding partial similarity value based on each cosine similarity value and the corresponding word order weight value" specifically includes: calculating the difference between the cosine similarity value and the word order weight value, adding 1, and then dividing by 2 to obtain the corresponding partial similarity value.
[0021] As a further improvement of one embodiment of the present invention, the step of "determining the similarity between the feature matrix to be matched and the corresponding candidate feature matrix based on the preset weights of the feature matrix columns and several partial similarity values, and obtaining several overall similarity values" specifically includes: calculating the preset weights of the feature matrix columns and the weighted average of several partial similarity values corresponding to each candidate feature matrix to obtain several overall similarity values.
[0022] As a further improvement of one embodiment of the present invention, the step of "determining candidate text that matches the text to be matched based on several overall similarity values and corresponding candidate feature sets" specifically includes: sorting several overall similarity values in descending order to determine the maximum overall similarity value; determining whether the maximum overall similarity value is greater than or equal to a preset minimum similarity threshold; if so, then taking the candidate text corresponding to the maximum overall similarity value as the best candidate text that matches the text to be matched; if not, then returning a prompt that no best candidate text was found.
[0023] To achieve one of the above-mentioned objectives, the present invention also provides a cooling device, comprising: at least one processor; and a memory storing a computer program executable on the processor, wherein the processor executes the program to perform the steps of any one of the text matching methods described above.
[0024] To achieve one of the above-mentioned objectives, the present invention also provides a computer storage medium, comprising: at least one processor; and a memory storing a computer program executable on the processor, wherein the processor executes the program to perform the steps of any one of the text matching methods described above.
[0025] Compared with the prior art, the embodiments of the present invention have at least one of the following beneficial effects:
[0026] This invention employs a text matching method that effectively integrates the multi-dimensional features of text by acquiring a set of features to be matched containing multiple features to be matched and a set of candidate features containing multiple candidate features. This allows text features to capture similar information of text in different dimensions from local to comprehensive, avoiding the bias caused by single feature matching. As a result, it more comprehensively and accurately describes the similarity between text content and structure, improves the accuracy and efficiency of text matching, and enhances the user experience. Attached Figure Description
[0027] Figure 1 This is a schematic diagram of the steps of a text matching method in one embodiment of the present invention.
[0028] Figure 2 This is a schematic diagram of a two-dimensional table generated by feature extraction in one embodiment of the present invention.
[0029] Figure 3 This is a schematic diagram of a two-dimensional table generated by the semantic disambiguation rules in one embodiment of the present invention.
[0030] Figure 4 This is a schematic diagram of the structure of the rule module in one embodiment of the present invention.
[0031] Figure 5 This is a schematic diagram of step S1 in one embodiment of the present invention.
[0032] Figure 6 This is a schematic diagram of the steps of a text matching method in another embodiment of the present invention.
[0033] Figure 7 This is a schematic diagram of step S21 in one embodiment of the present invention.
[0034] Figure 8 This is a schematic diagram of step S3 in one embodiment of the present invention.
[0035] Figure 9 This is a flowchart illustrating the "training" phase of the text matching method in a preferred embodiment of the present invention.
[0036] Figure 10 This is a flowchart illustrating the "inference" stage of the text matching method in a preferred embodiment of the present invention. Detailed Implementation
[0037] The present invention will now be described in detail with reference to the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present invention, and any structural, methodological, or functional modifications made by those skilled in the art based on these embodiments are included within the scope of protection of the present invention.
[0038] It should be noted that the term "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Furthermore, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0039] In question-answering systems, the diversity and differences in syntax, semantics, and word order of natural language lead to biases in semantic understanding during human-computer interaction, resulting in low accuracy in text matching and poor interaction effects. Therefore, text matching has significant practical importance in the field of natural language processing.
[0040] Based on this, such as Figure 1As shown, one embodiment of the present invention provides a text matching method, which includes the following steps.
[0041] Step S1: Obtain the set of features to be matched for the text to be matched, and the corresponding set of several candidate features;
[0042] Step S2: Based on the similarity between the feature to be matched and the corresponding candidate feature, determine the similarity between the candidate feature set and the feature set to be matched, and obtain several overall similarity values;
[0043] Step S3: Based on several overall similarity values and the corresponding candidate feature set, determine the candidate text that matches the text to be matched.
[0044] In this way, by acquiring a set of features to be matched containing multiple features to be matched and a set of candidate features containing multiple candidate features, the multi-dimensional features of the text can be effectively integrated into one, enabling the text features to capture similar information of the text in different dimensions from local to comprehensive, avoiding the bias caused by single feature matching, thereby more comprehensively and accurately describing the similarity between text content and structure, improving the accuracy and efficiency of text matching, and enhancing the user experience.
[0045] In one embodiment, the text to be matched and the candidate text can be received directly in the form of text corpus; in another embodiment, they can also be received as voice or video data, and the voice or video data can be converted into text to obtain the corresponding voice-text corpus or video-text corpus; of course, the above two embodiments can also be used in combination, which can expand the processing scope.
[0046] The set of features to be matched is constructed based on the content and structure of the text to be matched, aiming to highlight the key information of the text. Specifically, the text to be matched is acquired and parsed, and the text features of the text to be matched are extracted to determine the set of features to be matched. The text features include at least one of keywords, grammatical structures, and semantic tags. Similarly, the set of candidate features is also constructed based on the content and structure of the corresponding candidate text, aiming to highlight the key information of the candidate text. Refer to the technical solution disclosed later; it will not be elaborated here.
[0047] In one specific embodiment, to efficiently process the features to be matched and candidate features, this invention can convert them into a more easily operable form, namely, a feature matrix. Specifically, each feature to be matched in the set of features to be matched is used as a column of the feature matrix, and the specific value of each feature to be matched is used as a row of the feature matrix, forming the feature matrix to be matched. Similarly, each set of candidate features can form a corresponding candidate feature matrix. In this way, discrete feature sets can be converted into corresponding structured feature matrices, facilitating data processing and similarity calculation.
[0048] In a preferred embodiment, the feature matrix to be matched can be generated according to the processing flow of "text to be matched - feature to be matched - set of feature to be matched - feature matrix to be matched". Similarly, the candidate feature matrix can also be generated according to the processing flow of "candidate text - candidate feature - set of candidate feature - candidate feature matrix".
[0049] To improve the efficiency of text matching, this invention also provides a preprocessing mechanism, which performs in-depth processing on massive amounts of text data and stores the processing results in a database in advance, facilitating rapid retrieval during subsequent matching processes, thereby significantly improving matching efficiency and response speed.
[0050] In one embodiment, step S1 may specifically include the following steps.
[0051] Step S11: Construct a text matching dictionary;
[0052] Step S12: Obtain the set of features to be matched for the text to be matched, and determine several candidate feature sets according to the text matching dictionary.
[0053] In this way, by constructing a text matching dictionary, the system can quickly respond to query requests for text to be matched, improve the efficiency and accuracy of text matching, and achieve rapid feature filtering and extraction.
[0054] In one embodiment, step S11 may specifically include the following steps.
[0055] Step S111: Obtain several text information, and perform word segmentation and part-of-speech tagging on each text information to obtain several corresponding text features;
[0056] Step S112: Using non-empty text features as keys, construct a text matching dictionary by taking the set of text information containing the corresponding non-empty text features as values.
[0057] In this way, by constructing a text matching dictionary, a clear mapping relationship is established between text features (keys) and their corresponding text information (values), which helps in the management and organization of text features and facilitates subsequent text analysis and processing.
[0058] Among them, a text matching dictionary is constructed based on a large amount of text information, which makes the text matching dictionary contain rich text features and semantic information. At the same time, the text matching dictionary can be continuously updated as new text information or text data appears, so as to reflect the latest text information and features in real time, making the matching results more accurate and reliable.
[0059] In one embodiment, the value of the text matching dictionary is a set of text information.
[0060] In one specific embodiment, the text information set refers to the text number corresponding to the text information. Subsequently, the matching text information is determined by querying a database based on the text number, thus improving processing efficiency and reducing storage space.
[0061] For example, based on the mapping table between text information and text number, if the text number corresponding to the first text information is determined to be 1 and the text number corresponding to the second text information is determined to be 2, then the value of the corresponding text matching dictionary is {1, 2}.
[0062] In one embodiment, the text matching dictionary contains a set of text information and a corresponding set of text features.
[0063] In one specific embodiment, the values of the text matching dictionary can be stored in a composite structure, and the values of the text matching dictionary are determined according to the mapping relationship between text information, text number and corresponding text features.
[0064] Of course, this invention does not exclude other combinations of values for the text matching dictionary, and can adjust them according to the actual situation, and does not impose specific restrictions on the storage format of the values.
[0065] In one specific embodiment, the text information in step S111 may include a pre-edited question-and-answer knowledge base (i.e., a knowledge base corresponding to candidate texts), in the form of question-and-answer pairs (one question and one answer), for example:
[0066]
[0067] Of course, this invention is not limited to question-and-answer knowledge bases, but may also include other corpora, which are not specifically limited here.
[0068] In one embodiment, text information is determined based on a question-and-answer knowledge base, and preprocessing operations are performed on it to obtain preprocessed text information. The preprocessing operations include replacing or filtering content unrelated to the text information, such as greetings like "hello" or "thank you," using keywords and / or regular expressions.
[0069] In one embodiment, word segmentation and part-of-speech tagging are performed on the text information based on a pre-defined rule model to extract the features of the text information and form a two-dimensional table (i.e., a two-dimensional matrix). The two-dimensional table contains word segmentation and part-of-speech tagging features, and also reserves storage space to accommodate features such as business tags and relationship tags, which is convenient for subsequent feature expansion.
[0070] like Figure 2 As shown, assuming the text information is "How to set the refrigerator temperature", feature extraction is performed on the text information based on the pre-set rule model to obtain the feature matrix (displayed in the form of a two-dimensional table).
[0071] It should be noted that the pre-set rule model contains multiple rules. The basic logic of the rules is to search for data that meets the conditions in the two-dimensional table generated by feature extraction and perform corresponding modification operations on it. In the entire model, the rules provide guiding principles for screening, positioning, and modifying data (existing in the form of a two-dimensional table), while the two-dimensional table is the object of rule operations and the carrier for result display.
[0072] Specifically, the two-dimensional table is the data basis for rule operations. It contains feature information in multiple dimensions. By traversing and screening the two-dimensional table, the data rows that meet the conditions are determined, and corresponding modification operations are performed on these data rows. The rules play a role similar to a "controller". It traverses and screens the data in the two-dimensional table according to the pre-set conditions, first locates the reference row, and then continues to locate other rows forward or backward based on the reference row. The conditions defined in the rules are the basis for locating the rows or data ranges that meet the conditions. Once the rules locate the data rows that meet the conditions, the corresponding operations will be triggered.
[0073] Therefore, the writing of the rules needs to have a certain degree of logic and accuracy to ensure that the data rows that meet the conditions can be correctly located, and more complex operations can also be performed, such as semantic disambiguation, slot extraction, etc.
[0074] As Figure 3 shown, assuming the text information is "Play a song Little Apple", where "Little Apple" may be either a song name or a food ingredient name. By performing feature extraction operations on it using the rules of semantic disambiguation, the corresponding two-dimensional table (i.e., feature matrix) is obtained.
[0075] Continue to refer to Figure 3 shown, Figure 3 On the left is the rule. The rule locates the reference row. The word segmentation of the reference row is "Little Apple" or "Chinese Hawthorn", which means that in the two-dimensional table, the row containing one of these word segmentations needs to be found as the starting point; after determining the reference row, the rule defines to continue searching upward within a range of two rows to determine whether there is a row with the word segmentation "Play" or "Playback". This process is a relative positioning process that depends on the position of the reference row to determine the upward search range; if both of the above conditions are met, it is determined that the reference row that meets the conditions and the data rows that meet the conditions within two rows above it are found, and the modification operation is performed to change the business label of the reference row to "music".
[0076] Continue to refer to Figure 3 shown, Figure 3On the right is the corresponding two-dimensional table. There are three rows of indexed data in the table. Among them, the word segmentation corresponding to index 2 is "Little Apple", which meets the positioning conditions of the reference row. At the same time, look up two rows upward (that is, the rows with indexes 0 and 1). There is a word segmentation "put" in the row with index 0, which meets the condition of looking up upward in the rule. Thus, Figure 3 All the rules defined on the left are satisfied in the table. Then the rule will perform a modification operation, changing the service label corresponding to the row with index 2 from a null value to "music", indicating that the data in this row is recognized by the rule as content related to music and is marked accordingly.
[0077] As Figure 4 shown, in one embodiment, the present invention can also encapsulate rules with the same function into a rule module and run them in sequence according to a set order (for example, rule module 1, rule module 2, rule module 3, etc.). Thus, it is convenient for sharing and reuse between different projects, improving the utilization rate of rules and reducing a large amount of repetitive work. Each rule module processes the data row by row to ensure that each row of data in the data table will be processed by multiple rules (such as rule 1, rule 2, rule 3, etc.) in the rule module, ensuring that all eligible entity words and entity relationships are identified. To avoid rule conflicts, priorities can also be forcibly set for multiple rules, such as strictly following Figure 4 the order of rule 1, rule 2, rule 3 shown.
[0078] In one embodiment, the part of "determining corresponding several candidate feature sets according to the text matching dictionary" in step S12 involved in the present invention may specifically include the following steps.
[0079] Step S121, query the text matching dictionary according to the non-empty to-be-matched features to determine a candidate text set corresponding to the to-be-matched text;
[0080] Step S122, determine corresponding several candidate feature sets according to the candidate text set.
[0081] Thus, by querying the text matching dictionary, the text information set containing specific text features can be quickly and accurately located, greatly improving the processing speed and efficiency.
[0082] In a specific embodiment, step S121 may specifically include the following steps.
[0083] Step S1211, query the text matching dictionary according to several non-empty to-be-matched features to determine several intermediate candidate text sets;
[0084] Step S1212, determine a candidate text set corresponding to the to-be-matched text according to the intersection of several intermediate candidate text sets.
[0085] In this way, it can capture texts that are similar to the text to be matched in multiple dimensions, filter out texts that meet some dimensional features but are not completely matched, and further enhance the accuracy and relevance of the matching.
[0086] In one embodiment, if the candidate text set is empty, the system will directly return that no best candidate text was found.
[0087] For example, suppose the text to be matched has two non-empty features (i.e., keys): "FD_slots" and "verb_put". Querying the text matching dictionary using "FD_slots" and "verb_put" respectively yields the following results: {"FD_slots": {1, 2, 3}, "verb_put": {2, 3, 4}}. Based on these results, a first intermediate candidate text set {1, 2, 3} and a second intermediate candidate text set {2, 3, 4} are determined. The intersection of the first and second intermediate candidate text sets is calculated, resulting in the candidate text set {2, 3}. Here, 1, 2, 3, and 4 are the text numbers of the candidate texts. Based on these text numbers and the corresponding mapping table, the corresponding candidate texts and / or candidate feature sets (candidate feature matrix) can be easily obtained.
[0088] Understandably, candidate questions with similar word segmentation sequence lengths to the text to be matched are likely to be more similar in content and thus have a greater degree of similarity to the text to be matched. Therefore, this invention can reduce the computational load of subsequent similarity calculations by comparing candidate texts whose feature sequence lengths differ significantly from the text to be matched.
[0089] like Figure 5 As shown, in one embodiment, step S1 of the present invention may include the following steps.
[0090] Step S11': Calculate the absolute value of the length difference between the feature to be matched in the feature set to be matched and the candidate feature in the corresponding candidate feature set;
[0091] Step S12': Sort the candidate features from largest to smallest according to the absolute value of the length difference, select a preset number of candidate features to update the candidate feature set, and obtain an updated set of candidate features.
[0092] This allows for a further reduction in the size of the candidate feature set and a decrease in computational cost.
[0093] In one embodiment, the preset number can be set to 30, that is, retaining the top 30 candidate texts with the smallest differences. Of course, the preset number can be adjusted according to actual needs, and no specific limitation is made here.
[0094] Steps S11' to S12' can be set after step S1 to further optimize the candidate feature set obtained in step S1, or they can be set before step S1 to perform preliminary screening based on length information in order to reduce the number of candidate texts that need to be processed.
[0095] In one embodiment, the set of features to be matched is formed as a feature matrix to be matched, including a plurality of column vectors of the matrix corresponding to the features to be matched; the set of candidate features is formed as a candidate feature matrix, including a plurality of column vectors of the matrix corresponding to the candidate features. Of course, this invention does not exclude other types of storage formats, such as arrays.
[0096] like Figure 6 As shown, in this embodiment, the text matching method provided by the present invention includes the following steps.
[0097] Step S1: Obtain the set of features to be matched for the text to be matched, and the corresponding set of several candidate features;
[0098] Step S21: Based on the similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix, obtain several partial similarity values;
[0099] Step S22: Based on the preset weights of the feature matrix columns and several partial similarity values, determine the similarity between the feature matrix to be matched and the corresponding candidate feature matrix, and obtain several overall similarity values;
[0100] Step S3: Based on several overall similarity values and the corresponding candidate feature set, determine the candidate text that matches the text to be matched.
[0101] In this way, local and global information can be combined, allowing us to understand the similarity of matrices in their overall structure as well as the similarity between their column vectors, providing a more comprehensive and in-depth analysis.
[0102] For each feature to be matched (i.e., the column vector of the feature matrix to be matched) in the feature set to be matched, the similarity is calculated with each feature at the corresponding position in each candidate feature set (i.e., the column vector of the candidate feature matrix). There are various ways to calculate similarity, such as cosine similarity, Euclidean distance, etc., and no specific restrictions are imposed here.
[0103] like Figure 7 As shown, in one specific embodiment, step S21 of the present invention may include the following steps.
[0104] Step S211: Based on the word order similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix, several word order weight values are obtained;
[0105] Step S212: Based on the cosine similarity algorithm, determine the feature similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix, and obtain several cosine similarity values;
[0106] Step S213: Determine the corresponding partial similarity value based on each cosine similarity value and the corresponding word order weight value.
[0107] Thus, by calculating word order similarity, we can more accurately capture the relationship between the structure and semantics of the text to be matched and the candidate text, thereby improving the accuracy of similarity measurement.
[0108] In this embodiment, based on the cosine similarity algorithm, the cosine value of the angle between the column vector of the matrix to be matched and the corresponding candidate matrix column vector is calculated. The similarity between the two matrix vectors is determined based on the cosine value of the angle, thereby determining the degree of similarity between the text to be matched and the candidate text. The closer the cosine similarity value is to 1, the higher the similarity between the two texts, and the better the match.
[0109] In one specific embodiment, step S212 may include the following steps.
[0110] Step S2121: Based on each element in the short matrix vector, determine the number of elements projected onto the long matrix vector according to their arrangement order in the short matrix vector, and obtain a number of ordered repetitions.
[0111] Step S2122: Based on each ordered repetition number and its corresponding long matrix vector, several word order weight values are obtained.
[0112] Thus, by calculating the ordered repetition count of short and long matrix vectors, the original textual order information can be preserved, which is beneficial for emphasizing or highlighting relatively important elements in the matrix vectors, giving them greater weight in subsequent analysis or calculation.
[0113] Among them, the short matrix vector refers to the shorter (fewer elements) matrix column vector among the column vectors of the matrix to be matched and the corresponding candidate matrix column vectors; the long matrix vector refers to the longer (more elements) matrix column vector among the column vectors of the matrix to be matched and the corresponding candidate matrix column vectors.
[0114] In one specific example, the column vector of the matrix to be matched is a short matrix vector, and the corresponding candidate matrix column vector is a long matrix vector; in another specific example, the column vector of the matrix to be matched is a long matrix vector, and the corresponding candidate matrix column vector is a short matrix vector.
[0115] In one specific embodiment, step S2122 may include the following steps.
[0116] Step S212211: Obtain the non-ordered repetition value based on the difference between the length of the long matrix vector and the corresponding ordered repetition number;
[0117] Step S212212, determine the corresponding word order weight value according to the ratio of the non-ordered repeated value to the length of the long matrix vector; wherein, the word order weight value is equal to the product of the ratio and a preset weight coefficient.
[0118] In this way, determining the corresponding word order weight value according to the ordered repetition number, the calculation method is simple and easy to understand.
[0119] On the one hand, the ordered repetition number needs to consider whether the elements in the short matrix vector exist in the long matrix vector, which is the premise for determining the ordered repetition number; on the other hand, on the basis of determining the existence of the elements, check whether the elements maintain their relative order in the short matrix vector in the long matrix vector. In other words, even if the elements in the short matrix vector exist in the long matrix vector, if the relative order of the elements in the two matrix vectors is inconsistent, the elements cannot be counted into the ordered repetition number.
[0120] For example, for the short matrix vector [a, b] and the long matrix vector [b, a, c], although both the elements a and b exist in the long matrix vector, the position of the element b in the long matrix vector (on the left side of a) does not maintain its order in the short matrix vector (on the right side of a). Therefore, the ordered repetition number of the short matrix vector and the long matrix vector is 1.
[0121] In a specific embodiment, define the short matrix vector as M, the long matrix vector as N, and the ordered repetition number as C, then the word order weight value W at least satisfies:
[0122]
[0123] where, |N| is the length of the long matrix vector, and k is the weight coefficient, which can be adjusted according to the actual situation.
[0124] For example, the short matrix vector is ['verb_put', 'particle_le1', 'FDunit', 'FD_slots'], and the long matrix vector is ['verb_put', 'particle_le1', 'FDquanity', 'FD_slots', '呢']. According to the arrangement order of each element in the short matrix vector, the number of elements projected onto the long matrix vector is 3, that is, the ordered repetition number is 3, which are respectively:'verb_put', 'particle_le1', 'FD_slots'. According to the ordered repetition number, determine its corresponding word order weight value as W = (5 - 3) / 5 * k = 0.4k.
[0125] In one specific embodiment, step S213 includes: calculating the difference between the cosine similarity value and the word order weight value, adding 1, and then dividing by 2 to obtain the corresponding partial similarity value.
[0126] In this embodiment, each column vector of the matrix to be matched is processed individually to obtain the corresponding cosine similarity value and word order weighted value. Define the cosine similarity value as Cos, then the partial similarity value S must at least satisfy:
[0127]
[0128] Where W is the word order weight value of the column vector of the matrix to be matched.
[0129] In one embodiment, step S22 includes: calculating the preset weights of the feature matrix columns and the weighted average of several partial similarity values corresponding to each candidate feature matrix to obtain several overall similarity values.
[0130] In this way, the similarity of different matrix columns can be comprehensively considered, thereby more comprehensively evaluating the similarity of the entire feature matrix and improving the accuracy and reliability of matching.
[0131] In one specific embodiment, a preset column name weight mapping table is obtained, which includes the names of matrix column vectors and their corresponding weight values.
[0132] In one exemplary embodiment, the matrix to be matched is defined as comprising n matrix column vectors, and the weights of these n matrix column vectors are determined as w1, w2, ..., w based on a column name weight mapping table. n Based on the technical solution described above, the partial similarities of the column vectors of the n matrices are determined to be S1, S2, ..., S... n Then the overall similarity T between the matrix to be matched and the candidate matrix must at least satisfy:
[0133]
[0134] In one specific embodiment, the column name weight mapping table can be stored in the form of a dictionary, with the column name as the key and the weight value as the value. For example: {column name: weight value} = {"word segmentation": 1.0, "part-of-speech": 1.0, "pinyin": 0.1, "feature tag 1": 1.5, "feature tag 1": 1.1, "feature tag 1": 1.2}. The column name weight mapping table can be updated in real time, facilitating adjustments based on actual needs.
[0135] like Figure 8 As shown, in one embodiment, step S3 of the present invention may include the following steps.
[0136] Step S31: Sort several overall similarity values in descending order and determine the maximum overall similarity value;
[0137] Step S32: Determine whether the maximum overall similarity value is greater than or equal to the preset minimum similarity threshold;
[0138] If so, proceed to step S33A and take the candidate text corresponding to the maximum overall similarity value as the best candidate text that matches the text to be matched.
[0139] If not, proceed to step S33B and return with the message "No best candidate text found".
[0140] In this way, by sorting the overall similarity values and filtering out the maximum value, we can ensure that the most matching candidate text is found; at the same time, by filtering by setting a minimum similarity threshold, we can avoid selecting texts with too low similarity as matching results.
[0141] In one specific embodiment, the preset minimum similarity threshold is set to a value in the range of 0.8 to 0.95.
[0142] The various embodiments, examples, or specific embodiments provided by the present invention can be combined with each other to ultimately form multiple better embodiments.
[0143] This invention may include two phases: "training" and "inference". For example... Figure 9 As shown, the "training" phase is the process of constructing a text matching dictionary. Specifically, it involves acquiring text information from a database, performing text preprocessing (data cleaning, deduplication, stop word filtering, etc.) to obtain text data, performing structured analysis on the preprocessed text data (including word segmentation and part-of-speech tagging), extracting text features using a rule-based model based on the analysis results, removing duplicate text features, and obtaining a candidate feature set (or candidate feature matrix); and constructing a text matching dictionary based on the candidate feature set and saving it to the database. This avoids redundant calculations in the subsequent "inference" phase.
[0144] like Figure 10 As shown, the "reasoning" stage refers to the process of retrieving and calculating the best candidate text from the corpus based on the results stored in the text matching dictionary when receiving the text to be matched. This will be illustrated using a question-answering system as an example.
[0145] Continue to refer to Figure 10 As shown, the process involves obtaining the user question (text to be matched), parsing the user question, determining the user question feature set (feature set to be matched) based on the parsing results, determining several candidate similar question feature sets (candidate feature sets) based on the text matching dictionary, and determining several candidate similar question sets (i.e., candidate text sets) based on the user question feature set and the candidate similar question feature sets.
[0146] Based on the difference in word order length of the question, calculate the absolute value of the difference between the word order length of the user's question and the word order length of the similar questions in the corresponding candidate similar question set; sort the questions in descending order according to the absolute value of the difference, select a preset number of candidate similar questions to update the candidate similar question set, and obtain the updated candidate similar question set (i.e., the updated candidate feature set).
[0147] The similarity between the user question feature set and the candidate similar question feature set is calculated in matrix form; the similarity between the column vectors of the feature matrix corresponding to the user question and each candidate similar question is calculated to obtain several partial similarity values.
[0148] Based on the pre-configured matrix column weight parameters, the partial similarity values of all columns of the matrix are weighted and summed to obtain several overall similarity values, which are then used as the similarity between the user's question and each candidate similar question.
[0149] Several overall similarity values are sorted in descending order to determine whether the maximum overall similarity value is greater than or equal to a preset minimum similarity threshold; if so, the candidate text corresponding to the maximum overall similarity value is taken as the best candidate text that matches the text to be matched.
[0150] One embodiment of the present invention provides a cooling device, comprising: a memory for storing executable instructions; and a processor for implementing the steps of any of the above-described text matching methods when running the executable instructions stored in the memory.
[0151] One embodiment of the present invention provides a computer storage medium, comprising: a memory for storing executable instructions; and a processor for implementing the steps of any of the above-described text matching methods when executing the executable instructions stored in the memory.
[0152] In summary, the text matching method, device, and storage medium provided by this invention can effectively integrate the multi-dimensional features of text by acquiring a set of features to be matched containing multiple features to be matched and a set of candidate features containing multiple candidate features. This allows text features to capture similar information of text in different dimensions from local to comprehensive, avoiding the bias caused by single feature matching. As a result, it can more comprehensively and accurately describe the similarity between text content and structure, improve the accuracy and efficiency of text matching, and enhance the user experience.
[0153] It should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This way of describing the specification is only for clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
[0154] The detailed descriptions listed above are merely specific descriptions of feasible embodiments of the present invention, and are not intended to limit the scope of protection of the present invention. All equivalent embodiments or modifications made without departing from the spirit of the present invention should be included within the scope of protection of the present invention.
Claims
1. A text matching method, characterized in that, include: Obtain the set of features to be matched for the text to be matched, and the corresponding set of several candidate features; Based on the similarity between the feature to be matched and the corresponding candidate feature, the similarity between the candidate feature set and the feature set to be matched is determined, and several overall similarity values are obtained. Based on several overall similarity values and the corresponding candidate feature set, candidate texts that match the text to be matched are determined.
2. The text matching method according to claim 1, characterized in that, The phrase "obtaining the set of features to be matched for the text to be matched, and the corresponding set of several candidate features" specifically includes: Construct a text matching dictionary; Obtain the set of features to be matched for the text to be matched, and determine several candidate feature sets based on the text matching dictionary.
3. The text matching method according to claim 2, characterized in that, The "construction of a text matching dictionary" specifically includes: Obtain several text information, perform word segmentation and part-of-speech tagging on each text information respectively, and obtain several corresponding text features; Using non-empty text features as keys, and sets of text information containing the corresponding non-empty text features as values, a text matching dictionary is constructed.
4. The text matching method according to claim 2, characterized in that, The phrase "determining a set of candidate features based on the text matching dictionary" specifically includes: Based on the non-empty matching feature, the text matching dictionary is queried to determine the set of candidate texts corresponding to the text to be matched; Based on the candidate text set, determine several corresponding candidate feature sets.
5. The text matching method according to claim 4, characterized in that, The phrase "based on the non-empty matching feature, querying the text matching dictionary to determine the candidate text set corresponding to the text to be matched" specifically includes: Based on several non-empty features to be matched, the text matching dictionary is queried to determine several intermediate candidate text sets. Based on the intersection of several intermediate candidate text sets, determine the candidate text set corresponding to the text to be matched.
6. The text matching method according to claim 1, characterized in that, The phrase "obtaining the set of features to be matched for the text to be matched, and the corresponding set of several candidate features" specifically includes: Calculate the absolute value of the length difference between the feature to be matched in the feature set to be matched and the candidate feature in the corresponding candidate feature set; Sort the candidate features from largest to smallest according to the absolute value of the length difference, select a preset number of candidate features to update the candidate feature set, and obtain several updated candidate feature sets.
7. The text matching method according to claim 1, characterized in that, The set of features to be matched is formed into a feature matrix, including several column vectors of the matching matrix corresponding to the features to be matched; the set of candidate features is formed into a candidate feature matrix, including several column vectors of the candidate matrix corresponding to the candidate features; the step of "determining the similarity between the candidate feature set and the set of features to be matched based on the similarity between the features to be matched and the corresponding candidate features, and obtaining several overall similarity values" specifically includes: Based on the similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix, several similarity values are obtained. Based on the preset weights of the feature matrix columns and several partial similarity values, the similarity between the feature matrix to be matched and the corresponding candidate feature matrix is determined, and several overall similarity values are obtained.
8. The text matching method according to claim 7, characterized in that, The phrase "obtaining several similarity values based on the similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix" specifically includes: Several word order weight values are obtained based on the word order similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix; Based on the cosine similarity algorithm, the feature similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix is determined, and several cosine similarity values are obtained. The corresponding partial similarity value is determined based on each cosine similarity value and the corresponding word order weight value.
9. The text matching method according to claim 8, characterized in that, The phrase "obtaining several word order weight values based on the word order similarity between each column vector of the matrix to be matched and the corresponding column vector of the candidate matrix" specifically includes: Based on each element in the short matrix vector, determine the number of elements projected onto the long matrix vector according to their arrangement order in the short matrix vector, and obtain several ordered repetition numbers; Based on each ordered repetition number and its corresponding long matrix vector, several word order weight values are obtained.
10. The text matching method according to claim 9, characterized in that, The phrase "obtaining several word order weight values based on each ordered repetition number and its corresponding long matrix vector" specifically includes: The non-ordered repetition value is obtained by the difference between the length of the long matrix vector and the corresponding ordered repetition number; The corresponding word order weight value is determined based on the ratio of the non-ordered repetition value to the length of the long matrix vector; wherein the word order weight value is equal to the product of the ratio and a preset weight coefficient.
11. The text matching method according to claim 8, characterized in that, The phrase "determining the corresponding partial similarity value based on each cosine similarity value and the corresponding word order weight value" specifically includes: Calculate the difference between the cosine similarity value and the word order weight value, add 1, and then divide by 2 to obtain the corresponding partial similarity value.
12. The text matching method according to claim 7, characterized in that, The phrase "determining the similarity between the feature matrix to be matched and the corresponding candidate feature matrix based on the preset weights of the feature matrix columns and several partial similarity values, and obtaining several overall similarity values" specifically includes: The preset weights of the feature matrix columns and the weighted average of the similarity values of several parts corresponding to each candidate feature matrix are calculated separately to obtain several overall similarity values.
13. The text matching method according to claim 1, characterized in that, The phrase "determining candidate texts that match the text to be matched based on several overall similarity values and corresponding candidate feature sets" specifically includes: Sort several overall similarity values in descending order and determine the maximum overall similarity value; Determine whether the maximum overall similarity value is greater than or equal to a preset minimum similarity threshold; If so, the candidate text corresponding to the maximum overall similarity value is taken as the best candidate text that matches the text to be matched; If not, a message will be returned indicating that no best candidate text was found.
14. A refrigeration device, comprising: At least one processor; A memory storing a computer program executable on the processor, characterized in that the processor executes the program to perform the steps of the text matching method as described in any one of claims 1 to 13.
15. A computer storage medium, comprising: At least one processor; A memory storing a computer program executable on the processor, characterized in that the processor executes the program to perform the steps of the text matching method as described in any one of claims 1 to 13.