Semantic distance-based textual inference method and apparatus, storage medium, and terminal
Through the text unit reasoning method based on semantic distance, the target text unit set is screened out, which solves the problem of polysemous words being unable to be accurately reasoned in the existing technology and realizes efficient and accurate text reasoning.
Patent Information
- Application Number
- PCT/CN2025/085048
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-08-13
- Filing Date
- 2025-03-26
- Publication Date
- 2025-10-02
AI Technical Summary
Existing text reasoning methods cannot fully utilize the semantic relationships between text units, resulting in the inability to accurately reason about polysemous words, and the training process requires a large amount of corpus data and computing resources.
By obtaining the semantic distance between a given subject, a reference subject, and a reference auxiliary, setting the semantic range, screening out the target text unit set, and using the semantic distance to determine the reasoning direction, the text unit can be accurately positioned and its scope expanded.
It improves the accuracy and efficiency of polysemous text reasoning, reduces computing resource requirements, and achieves text reasoning without information loss.
Smart Images

Figure CN2025085048_02102025_PF_FP_ABST
Abstract
Description
Text reasoning method, device, storage medium and terminal based on semantic distance Technical Field
[0001] The present invention relates to the field of text reasoning technology, and in particular to a text reasoning method, device, storage medium and terminal based on semantic distance. Background Art
[0002] Text reasoning is the process of analyzing, understanding, and extracting information from text. It helps people perform operations such as text comprehension, cluster analysis, abstract generation, and information extraction, and is therefore used in various fields. With the development of internet technology, text reasoning is increasingly dependent on the internet.
[0003] Existing text reasoning typically uses text vector reasoning, a method based on text vectors. This approach typically involves training on large amounts of text data to learn the semantic relationships between text units and represent each text unit as a high-dimensional vector. These vectors can capture the similarities and associations between text units, allowing methods such as vector addition, subtraction, or cosine similarity to calculate the similarity, association, or difference between text units. By leveraging the semantic information of vectors and the characteristics of vector operations, text content can be understood and reasoned about.
[0004] However, existing text reasoning methods are often based only on fixed and single text units, while ignoring the contextual environment in which the text units are located or the relationship between text units. In other words, they are unable to fully utilize the semantic relationship of text units to perform text reasoning; for example, for the polysemous text unit "apple", it is often impossible to accurately determine whether it refers to fruit or Apple Company; for example, it is known that the capital of South Korea is Seoul. If you want to obtain text unit pairs of other countries and their corresponding capitals, it is difficult to achieve based on existing reasoning methods, resulting in reduced accuracy of text reasoning, limited reasoning scope, or low training efficiency of text reasoning. Summary of the Invention
[0005] The purpose of this application is to provide a text unit reasoning method device based on semantic distance, a storage medium and a terminal, which are used to solve the problem that the word reasoning method currently used in the text understanding and reasoning process cannot generate corresponding word vectors based on word meaning for polysemous words, cannot be applied to tasks that consider word meaning, requires a large amount of corpus data during the training process, and consumes a large amount of computing resources and time.
[0006] In a first aspect, the present application provides a text unit reasoning method based on semantic distance, comprising:
[0007] Obtaining a given subject, a given reference subject, and a given reference auxiliary, and respectively obtaining a reasoning subject corresponding to the given subject, a reasoning reference subject corresponding to the given reference subject, and a reasoning reference auxiliary corresponding to the given reference auxiliary based on the attributes of the reasoning database, wherein the given subject and the given reference subject have common characteristics;
[0008] Obtaining the semantic distance between the inference reference subject and the inference reference auxiliary as a first semantic distance, obtaining a first semantic range based on a first error range parameter and the first semantic distance, grouping all text units in the inference database whose semantic distance from the inference subject is within the first semantic range into a first text unit set, obtaining the semantic distance between the inference reference subject and the inference subject as a second semantic distance, obtaining a second semantic range based on a second error range parameter and the second semantic distance, grouping all text units in the inference database whose semantic distance from the inference reference auxiliary is within the second semantic range into a second text unit set, and taking the intersection of the first text unit set and the second text unit set as a target inference set;
[0009] A target text unit set of the given subject is obtained based on the target inference set.
[0010] In one embodiment of the present application, obtaining the inference object corresponding to the preset object based on the inference database attribute includes:
[0011] Determine whether the language types of the preset object and the inference database are different. If so, translate the preset object into the language type of the inference database to obtain a translation subject, and use the translation subject as a comparison subject. Otherwise, use the preset object as a comparison subject.
[0012] Obtaining the inference object corresponding to the comparison subject through a preset comparison method;
[0013] Among them, when the preset object is a given subject, the inference object is the inference subject; when the preset object is a given reference subject, the inference object is the inference reference subject; when the preset object is a given reference auxiliary, the inference object is the inference reference auxiliary.
[0014] In one embodiment of the present application, obtaining the inferred text unit corresponding to the preset text unit through a preset comparison method includes:
[0015] If there is only a single text unit in the inference database that corresponds to the preset text unit, determining that the text unit corresponding to the preset text unit is the inference text unit of the preset text unit;
[0016] If there are multiple text units in the inference database corresponding to the preset text unit, a text unit with correct meaning is screened out from the multiple text units corresponding to the preset text unit based on the limiting features of the preset text unit as the inference text unit of the preset text unit;
[0017] When the comparison subject is a single text unit, the preset text unit is the comparison subject; when the comparison subject is a set of text units, the preset text unit is any one of the text units in the comparison subject, and the inference object corresponding to the comparison subject is the set of inference text units corresponding to all the text units in the comparison subject.
[0018] The text unit corresponding to the preset text unit is: a text unit that is the same as the preset text unit, or a text unit for which the preset text unit exists in a corresponding equivalent set.
[0019] In one embodiment of the present application, selecting a text unit with correct meaning from a plurality of text units corresponding to the preset text unit based on the limiting features of the preset text unit includes:
[0020] Obtaining the knowledge structure of each text unit corresponding to the preset text unit in the inference database as a comparison knowledge structure, and taking the text unit corresponding to the comparison knowledge structure that contains the limiting feature of the preset text unit as the text unit with the correct meaning corresponding to the preset text unit; or
[0021] A text unit having the closest semantic distance to the limiting feature of the preset text unit is selected from all text units corresponding to the preset text unit as the text unit with the correct meaning corresponding to the preset text unit.
[0022] In one embodiment of the present application, when the inference subject, the inference reference subject, and the inference reference auxiliary are all text unit sets, the target inference set acquisition step includes:
[0023] The text units with the same position serial number in the inference subject, the inference reference subject and the inference reference auxiliary body are grouped into an inference subset, a target inference subset is obtained for each of the inference subsets based on a preset inference method, and the intersection of all the target inference subsets is used as the target inference set;
[0024] The number of text units contained in the inference subject, the inference reference subject, and the inference reference auxiliary body is the same; and the target inference subset of the inference subset obtained based on the preset inference method includes:
[0025] The text units belonging to the reasoning subject in the reasoning sub-set are used as implementation subjects, the text units belonging to the reasoning reference subject in the reasoning sub-set are used as implementation reference subjects, and the text units belonging to the reasoning reference auxiliary body in the reasoning sub-set are used as implementation reference auxiliary bodies;
[0026] The semantic distance between the implementation reference subject and the implementation reference auxiliary is obtained as a third semantic distance, a third semantic range is obtained based on the first error range parameter and the third semantic distance, all text units in the implementation database whose semantic distance from the implementation subject is within the third semantic range are grouped as a third text unit set, and the semantic distance between the implementation reference subject and the implementation subject is obtained as a fourth semantic distance, a fourth semantic range is obtained based on the second error range parameter and the fourth semantic distance, and all text units in the implementation database whose semantic distance from the implementation reference auxiliary is within the fourth semantic range are grouped as a fourth text unit set, and the intersection of the third text unit set and the fourth text unit set is used as a target inference subset.
[0027] In one embodiment of the present application, when the inference subject, the inference reference subject, and the inference reference auxiliary are all text unit sets, the target inference set acquisition step includes:
[0028] Any two text units with a semantic distance between the inference reference subject and the inference reference auxiliary are taken as first-category semantic text pairs, the relative distance of the semantic distances of all first-category semantic text pairs between the inference reference subject and the inference reference auxiliary is obtained as the first semantic distance, a first semantic range is obtained based on the first error range parameter and the first semantic distance, a set of text units in the inference database whose semantic distances to each text unit in the inference subject are respectively within the first semantic range is obtained as the first inference subset corresponding to the text unit in the inference subject, the intersection of all first inference subsets is taken as the first text unit set, and the inference reference subject and the inference subject are separated. Any two text units with a semantic distance between them are taken as the second type of semantic text pairs, the relative distance of all second type semantic text pairs between the reasoning reference subject and the reasoning subject is obtained as the second semantic distance, the second semantic range is obtained based on the second error range parameter and the second semantic distance, and a set of text units in the reasoning database whose semantic distances to each text unit in the reasoning reference auxiliary body are within the second semantic range are obtained as the second reasoning subset of the corresponding text units in the reasoning reference auxiliary body, and the intersection of all second reasoning subsets is taken as the second text unit set, and the intersection of the first text unit set and the second text unit set is taken as the target reasoning set.
[0029] In one embodiment of the present application, before obtaining the target text unit set of the given subject based on the target inference set, the target inference set needs to be filtered by a filtering condition to obtain a filtered target inference set;
[0030] The filtering condition includes at least one of the following conditions:
[0031] If the classification of the inference subject is consistent with that of the inference reference subject, filtering out text units in the target inference set that are inconsistent with the classification of the inference reference auxiliary body;
[0032] When the inference subject, the inference reference subject, and the inference reference auxiliary are all text units, if the knowledge structure of the inference subject in the inference database and the knowledge structure of the inference reference subject in the inference database have an intersection, then filter out the text units in the target inference set that do not have an intersection with the knowledge structure of the inference reference auxiliary in the inference database;
[0033] If the inference subject and the inference reference subject have an inclusion or subordination relationship, then filter out the text units in the target inference set that do not have an inclusion or subordination relationship with the inference reference auxiliary body;
[0034] If the text properties of the inference subject and the inference reference subject are the same, then the text units in the target inference set that have different text properties from the inference reference auxiliary body are filtered out. The text properties include characters, words, phrases, sentences, plurals, nouns, verbs, adjectives and adverbs.
[0035] In one embodiment of the present application, when the filtered target inference set is empty, the first error range parameter and the second error range parameter are adjusted according to a preset parameter adjustment method, and the target inference set acquisition step is re-executed based on the adjusted first error range parameter and second error range parameter to obtain a new target inference set and filter the new target inference set by the filtering condition until the obtained filtered target inference set is not empty;
[0036] Adjusting the first error range parameter and the second error range parameter according to a preset parameter adjustment method includes:
[0037] When the number of text units in the first text unit set is less than a preset threshold, increasing the current first error range parameter by a first step to obtain an adjusted first error range parameter, and using the current second error range parameter as the adjusted second error range parameter;
[0038] When the number of text units in the first text unit set is not less than a preset threshold but the number of text units in the second text unit set is less than a preset threshold, increasing the current second error range parameter by a second stepping step to obtain an adjusted second error range parameter, and using the current first error range parameter as the adjusted first error range parameter;
[0039] When the number of text units in the first text unit set and the number of text units in the second text unit set are both not less than a preset threshold, increasing the current first error range parameter by a first step to obtain an adjusted first error range parameter, and increasing the current second error range parameter by a second step to obtain an adjusted second error range parameter;
[0040] The semantic distance is calculated in a preset semantic distance calculation method, and both the first semantic range and the second semantic range are within a maximum range of the preset semantic distance calculation method.
[0041] In a second aspect, the present application further provides a text unit reasoning device based on semantic distance, comprising a reasoning content acquisition module, a target reasoning set acquisition module, and a target text unit set acquisition module;
[0042] The inference content acquisition module is used to acquire a given subject, a given reference subject, and a given reference auxiliary, and respectively acquire, based on the attributes of the inference database, an inference subject corresponding to the given subject, an inference reference subject corresponding to the given reference subject, and an inference reference auxiliary corresponding to the given reference auxiliary, wherein the given subject and the given reference subject have common characteristics;
[0043] The target reasoning set acquisition module is used to obtain the semantic distance between the reasoning reference subject and the reasoning reference auxiliary as a first semantic distance, obtain a first semantic range based on a first error range parameter and the first semantic distance, group all text units in the reasoning database whose semantic distance from the reasoning subject is within the first semantic range into a first text unit set, and obtain the semantic distance between the reasoning reference subject and the reasoning subject as a second semantic distance, obtain a second semantic range based on a second error range parameter and the second semantic distance, and group all text units in the reasoning database whose semantic distance from the reasoning reference auxiliary is within the second semantic range into a second text unit set, and use the intersection of the first text unit set and the second text unit set as a target reasoning set;
[0044] The target text unit set acquisition module is used to acquire the target text unit set of the given subject based on the target inference set.
[0045] In a third aspect, the present application further provides a method for reasoning about text unit relations based on semantic distance, comprising:
[0046] Acquire an inference relationship pair, wherein the inference relationship pair includes an inference subject and an inference auxiliary, and the inference subject and the inference auxiliary belong to an inference database;
[0047] Based on the characteristics of the inference subject or the characteristics of the similar text units, obtaining a set of similar text units of the inference subject from the inference database;
[0048] A first semantic distance range is set based on the semantic distance between the inference subject and the inference auxiliary subject, and for each similar text unit in the set of similar text units, a set of all text units within the first semantic distance range is obtained as a subset of adjacent text units corresponding to the similar text unit;
[0049] Each of the similar text units is respectively formed into a text relationship pair with each adjacent text unit in the corresponding adjacent text unit subset, and all of the text relationship pairs are grouped into a target relationship pair set of the inference relationship pairs.
[0050] In one embodiment of the present application, obtaining the inference relationship pair includes:
[0051] Obtaining a given relationship pair, wherein the given relationship pair includes a given subject and a given auxiliary subject;
[0052] The reasoning subject corresponding to the given subject and the reasoning auxiliary body corresponding to the given auxiliary body are obtained from the reasoning database based on an equivalent body mapping method, and the given subject and the given auxiliary body constitute the reasoning relationship pair.
[0053] In one embodiment of the present application, based on the characteristics of the inference subject, a set of similar text units of the inference subject is obtained from the inference database, including:
[0054] A preset semantic distance is obtained, a second semantic distance range is set based on the preset semantic distance, and all text units in the inference database whose semantic distances to the inference subject are within the second semantic range are grouped as a similar text unit set of the inference subject.
[0055] In one embodiment of the present application, based on the characteristics of the inference subject, obtaining a set of similar text units of the inference subject from the inference database includes:
[0056] The set classification type of the inference subject is obtained, and all text units under the set classification type are searched from the inference database for a set of similar text units of the inference subject, wherein the set of similar text units does not include the inference subject.
[0057] In one embodiment of the present application, based on the characteristics of the inference subject, obtaining a set of similar text units of the inference subject from the inference database includes:
[0058] Acquire the set classification type and preset classification semantic range of the inference subject, and group all classification types in the inference database whose semantic distance from the set classification type is within the preset classification semantic range as a target classification type set;
[0059] The set classification type and all text unit sets under the target classification type in the target classification type set are searched from the inference database as a similar text unit set of the inference subject, and the similar text unit set does not include the inference subject.
[0060] In one embodiment of the present application, based on the characteristics of the inference subject, obtaining a set of similar text units of the inference subject from the inference database includes:
[0061] Obtaining the semantic distances between all arbitrary two text units in the inference database, and forming a semantic distance network of all text units in the inference database using the obtained semantic distances as edges and the text units as points;
[0062] The edges whose semantic distance in the semantic distance network is less than a preset threshold are removed to obtain multiple semantic distance sub-networks, and all text units in the semantic distance sub-network to which the inference subject belongs are grouped into a set of similar text units of the inference subject, and the set of similar text units does not include the inference subject.
[0063] In one embodiment of the present application, based on the characteristics of similar text units, obtaining a set of similar text units of the inference subject from the inference database includes:
[0064] Acquire similar classification types, and search the inference database for a set of similar text units with all text units under the similar classification types as the inference subject.
[0065] In one embodiment of the present application, before all the text relationship pairs are grouped into the target relationship pair set of the inference relationship pairs, the method further includes filtering all the formed text relationship pairs by a filtering condition;
[0066] The filtering condition includes at least one of the following conditions:
[0067] Filter out text relationship pairs in which the classification of the adjacent text units in the text relationship pairs and the classification of the inference subject in the inference database are inconsistent, or the classification of the adjacent text units in the text relationship pairs and the classification of the inference auxiliary object in the inference database are inconsistent;
[0068] Filter out text relationship pairs in which the knowledge structure of the adjacent text units in the inference database does not intersect with the knowledge structure of the inference subject in the inference database, or the knowledge structure of the adjacent text units in the text relationship pairs in the inference database does not intersect with the knowledge structure of the inference auxiliary body in the inference database;
[0069] If there is a containment or subordination relationship between the inference subject and the inference auxiliary, then filtering out text relationship pairs where there is no containment or subordination relationship between the close text unit and the corresponding adjacent text unit;
[0070] If the inference subject has the same text property as the adjacent text unit, then filter out the text unit pairs whose text properties are not the same as the inference auxiliary text property, where the text property is a character, word, phrase, sentence, plural, noun, verb, adjective or adverb.
[0071] In a fourth aspect, the present application further provides a text unit relational reasoning device based on semantic distance, comprising: a reasoning relation pair acquisition module, a similar text unit acquisition module, a neighboring text unit acquisition module, and a target relation pair acquisition module;
[0072] The inference relationship pair acquisition module is used to acquire an inference relationship pair, wherein the inference relationship pair includes an inference subject and an inference auxiliary, and the inference subject and the inference auxiliary belong to an inference database;
[0073] The similar text unit acquisition module is used to acquire a set of similar text units of the reasoning subject from the reasoning database based on the characteristics of the reasoning subject or the characteristics of the similar text units;
[0074] The adjacent text unit acquisition module is configured to set a first semantic distance range based on the semantic distance between the inference subject and the inference auxiliary subject, and for each adjacent text unit in the adjacent text unit set, acquire a set of all text units within the first semantic distance range from the adjacent text unit as an adjacent text unit subset corresponding to the adjacent text unit;
[0075] The target relationship pair acquisition module is used to form a text relationship pair with each of the similar text units and each adjacent text unit in the corresponding adjacent text unit subset, and to group all of the text relationship pairs into a target relationship pair set for the inference relationship pair. In a fifth aspect, the present application also provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described text unit inference methods based on semantic distance, or any of the above-described text unit relationship inference methods based on semantic distance.
[0076] In a fourth aspect, the present application further provides a terminal, comprising: a processor and a memory, wherein the memory is communicatively connected to the processor;
[0077] The memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory, so that the terminal executes any of the above-described text unit reasoning methods based on semantic distance, or any of the above-described text unit relationship reasoning methods based on semantic distance.
[0078] Compared with the prior art, one or more embodiments of the above solutions may have the following advantages or beneficial effects:
[0079] By obtaining the semantic distance between the reasoning reference subject and the reasoning reference auxiliary, and obtaining the semantic distance between the reasoning reference subject and the reasoning subject, the text unit set or reasoning direction is determined based on the semantic distance, and then the reasoning from the reasoning subject to the reasoning reference subject to the reasoning reference auxiliary is realized, that is, the corresponding text reasoning is realized based on the contextual relationship between the text unit / text unit relationship pair, which not only improves the accuracy of polysemous text reasoning, but also expands the scope of text unit reasoning and improves the efficiency of text reasoning; and, the filtering process is used to remove hallucinations in the target reasoning set based on actual needs, and further streamline the text units in the target reasoning set.
[0080] Specifically, the text unit reasoning method based on semantic distance provided in the embodiment of the present application is applied. A first semantic range is set based on a first semantic distance, and a first set of text units whose semantic distance to the reasoning subject is within the first semantic range is obtained. A second semantic range is set based on a second semantic distance, and a second set of text units whose semantic distance to the reasoning reference auxiliary is within the second semantic range is obtained. Finally, the intersection of the first set of text units and the second set of text units is obtained, thereby realizing reasoning from the reasoning subject to the reasoning reference subject to the reasoning reference auxiliary. The method of this embodiment completes the reasoning of text units without a quantization process. Since the accurate positioning of polysemous words is achieved and there is no word order problem, it can ensure that there is no information loss in the entire reasoning process. At the same time, it does not require a large amount of expected data support, and the calculation is fast and accurate.
[0081] Furthermore, by applying the text unit relational reasoning method provided in the embodiment of the present application, a set of similar text units of the reasoning subject is obtained on demand, and at the same time, a screening semantic distance range is determined based on the semantic distance between the reasoning subject and the reasoning auxiliary. Then, using the screening semantic distance range as the reasoning direction, the adjacent text units of each similar text unit of the reasoning subject are obtained, that is, reasoning from all similar text units to the reasoning subject to the reasoning auxiliary is realized, and then all target relationship pairs with similar reasoning relationships with the reasoning subject and the reasoning auxiliary are obtained. The method of the present application can perform similarity search based on the relationship between text unit relationship pairs on the basis of unknown target text units, and obtain all desired text unit pairs with given relationships in the similarity results, thereby expanding the scope of text unit reasoning.
[0082] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] The accompanying drawings are used to provide a further understanding of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the accompanying drawings:
[0084] FIG1 is a flow chart showing a method for text unit reasoning based on semantic distance according to an embodiment of the present application.
[0085] FIG2 shows a simple structural diagram of the relationship among the inference subject, the inference reference subject, and the inference reference auxiliary in the text unit inference method based on semantic distance described in an embodiment of the present application.
[0086] FIG3 shows a schematic structural diagram of a text unit reasoning device based on semantic distance according to an embodiment of the present application.
[0087] FIG4 is a flow chart showing a method for reasoning about text unit relations based on semantic distance according to an embodiment of the present application.
[0088] FIG5 shows a structural diagram of a semantic distance network and a semantic distance sub-network in the text unit relationship reasoning method based on semantic distance described in an embodiment of the present application.
[0089] Figure 6 is a schematic diagram showing the structure of a text unit relationship inference device according to an embodiment of the present application. Figure 7 is a schematic diagram showing the structure of a terminal according to an embodiment of the present application. DETAILED DESCRIPTION
[0090] The following will describe in detail the implementation methods of this application in conjunction with the accompanying drawings and examples, so that the application can fully understand how technical means are used to solve technical problems and achieve technical effects, and implement them accordingly. It should be noted that as long as there is no conflict, the various embodiments and the various features in each embodiment of this application can be combined with each other, and the resulting technical solutions are all within the scope of protection of this application.
[0091] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application. Therefore, the illustrations only show components related to the present application and are not drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complicated.
[0092] For ease of description, some nouns or terms involved in the embodiments of the present application are explained below:
[0093] Data curation refers to the process of organizing and integrating data collected from various sources to create a trustworthy data repository. It encompasses the full lifecycle of data management, including collection, screening, evaluation, preservation, maintenance, and utilization. Data curation can be performed manually or through machine processing. Data that has undergone data curation is generally of higher quality.
[0094] A knowledge base is a tool for storing and managing knowledge, which can be used to support applications such as knowledge systems, knowledge discovery, and knowledge sharing. It usually contains relevant information and data in a certain field or topic, as well as knowledge representation forms such as rules, methods, and concepts.
[0095] Text units, or tokens, include words, phrases, and sentences. In a knowledge base, text units refer to objects and categories, namely the words, phrases, and sentences that make them up. Examples include "Cogito, ergo sum," "Homo homini lupus," "Knowledge is power," and "NBA Finals Most Valuable Player Award."
[0096] Entities are the basic elements in the knowledge base, representing objects, events, situations or concepts in the real world. In this application, entities are a subset of tokens, which are things in tokens that represent the real world.
[0097] Semantic distance is a concept used to measure the semantic similarity or difference between two words, phrases, or sentences in a semantic space. It can be used to accomplish tasks such as word sense disambiguation, text classification, and information retrieval.
[0098] An equivalent body is a set of tokens that represent the same meaning, including a set of tokens with the same meaning in different languages. For example, "Beida" and "Peking University" are equivalent, and "Peking University" in Chinese and "Peking University" in English are equivalent.
[0099] The text inference method based on semantic distance in this embodiment can be applied to the field of artificial intelligence, and further applied to machine translation, machine reading comprehension, question answering systems, etc. in natural language processing in the field of artificial intelligence. In addition, the text inference method based on semantic distance provided in this embodiment can also be applied to other suitable application fields, and specific limitations are not imposed here.
[0100] In some embodiments of the existing text inference process, the text vectors generated correspondingly when performing inference on text units are often fixed, which means that for polysemous text units (the same text unit has different text meanings), corresponding text vectors cannot be generated according to the context. For example, for the text unit "apple", there should be different text vector representations when it means apple (fruit) or Apple Inc., but since the text vector corresponding to "apple" generated by the existing method is a fixed vector, it cannot be accurately inferred as apple (fruit) or Apple Inc. Secondly, when generating text vectors, due to ignoring the information of word order, the text vectors cannot handle some tasks that need to consider word order, such as grammar analysis, syntactic analysis, etc. Based on this, the text vector inference training based on the existing text inference method requires a large amount of corpus data, and requires a large amount of computing resources and time; and for a small-scale corpus, sufficient vocabulary and semantic information cannot be learned either.
[0101] Based on this, the present application provides a text unit inference method based on semantic distance in the first aspect, which is used to solve the problems of the existing text inference method that for polysemous words, corresponding word vectors cannot be generated based on the word meaning and cannot be applied to tasks considering word meaning, resulting in a large amount of corpus data required in the training process, large computing resources and time consumption, etc.
[0102] The following will elaborate on the implementation manner of the text unit inference method based on semantic distance in the embodiments of the present application with reference to the drawings, so that those skilled in the art can understand the logical principle of the text unit inference method based on semantic distance in this embodiment without creative labor.
[0103] As shown in FIG. 1, this embodiment provides a text unit inference method based on semantic distance, including the following steps.
[0104] Step S101, obtain a given subject, a given reference subject and a given reference auxiliary, and obtain the reasoning subject corresponding to the given subject, the reasoning reference subject corresponding to the given reference subject and the reasoning reference auxiliary corresponding to the given reference auxiliary based on the attributes of the reasoning database, wherein the given subject and the given reference subject have common characteristics.
[0105] Specifically, the subject to be inferred is obtained as the given subject; based on the reasoning direction of the given subject, a suitable given reference subject and a given reference auxiliary are selected; the reference subject and the given reference auxiliary determine the reasoning direction of the given subject, and the reference subject and the given subject are set to have common characteristics; wherein, the common characteristics can be attributes, or attributes, etc. For example, if you want to infer "the capital of Japan" based on "Japan", you can set "Japan" as the given subject, select "China" as the given reference subject, and "Beijing" as the given reference auxiliary. Based on the text unit reasoning method based on semantic distance provided in the embodiment of the present application, reasoning can be performed to have "Tokyo" in the inferred target reasoning set. At the same time, the database used in the reasoning process is set as the reasoning database.
[0106] It should be noted that the given subject, the given reference subject and the given reference auxiliary may not be the original text units or text unit sets in the reasoning database. The given subject, the given reference subject and the given reference auxiliary need to be converted into the form of text units or text unit sets in the corresponding reasoning database in advance, and then the reasoning process involving the given subject, the given reference subject and the given reference auxiliary can be realized.
[0107] Furthermore, when implementing the method of this embodiment based on actual needs, there may be a situation where the language type of the given subject, the given reference subject or the given reference auxiliary is different from the language type of the reasoning database; at this time, in order to facilitate the implementation of the subsequent reasoning process, the given subject, the given reference subject or the given reference auxiliary must first be translated into the language type of the reasoning database.
[0108] Since the translation process for a given subject, a given reference subject, and a given reference auxiliary is the same, the translation process is described below using the preset object as an example.
[0109] After obtaining the preset object, the system determines whether the language type of the preset object and the inference database are the same. If they are not, the preset object is translated into the language type of the inference database, and the translated preset object is used as the translation subject. The translation subject is then used as the comparison subject for subsequent inference object acquisition. If they are the same, the preset object is directly used as the comparison subject. The preset object can be a given subject, a given reference subject, or a given reference auxiliary subject; this setting enables inference of given subjects in different languages.
[0110] Furthermore, there may be polysemous words in the given subject, the given reference subject and the given reference auxiliary; for example, the text unit "apple" may refer to "apple" or "Apple Inc." In this case, it is necessary to determine which word the text unit "apple" specifically refers to in the inference database. In response to this situation, this embodiment mainly uses a preset comparison method to achieve the comparison of the given subject, the given reference subject and the given reference auxiliary with the text units in the inference database. Since the text compared with the inference database may also be a translated text, the comparison process with the inference database is still described here in terms of the comparison subject.
[0111] Since the comparison subject can be a single text unit or a set of text units, and the comparison process with the inference database is carried out one text unit at a time, we split the comparison process between the comparison subject and the inference database into: when the comparison subject is a single text unit, the comparison subject is directly used as the preset text unit; when the comparison subject is a set of text units, the preset text unit is set to any text unit in the comparison subject, and then the inference text units of all text units in the comparison subject are obtained through the preset comparison method, and the set of all inference text units is used as the inference object corresponding to the comparison subject; at the same time, the inference object corresponding to the comparison subject is the inference object of the corresponding preset object.
[0112] Specifically, the implementation method for obtaining the inference text unit corresponding to the preset text unit through a preset comparison method includes: when there is only a single text unit corresponding to the preset text unit in the inference database, the text unit corresponding to the preset text unit is directly determined to be the inference text unit of the preset text unit. When there are multiple text units corresponding to the preset text unit in the inference database, it is necessary to screen out the text unit with the correct meaning from the multiple text units corresponding to the preset text unit in the inference database based on the limiting characteristics of the preset text unit to serve as the inference text unit of the preset text unit. Among them, the text unit corresponding to the preset text unit is defined as: the text unit in the inference database that is identical to the preset text unit; and if there is no text unit identical to the preset text unit in the inference database, it is determined whether the preset text unit exists in the equivalent set corresponding to a certain text unit in the inference database. If so, the text unit corresponding to the equivalent set is taken as the text unit corresponding to the preset text unit.
[0113] The above method can be used to obtain the reasoning objects corresponding to all preset objects; similarly, when the preset object is a given subject, the reasoning object is the reasoning subject; when the preset object is a given reference subject, the reasoning object is the reasoning reference subject; when the preset object is a given reference auxiliary, the reasoning object is the reasoning reference auxiliary.
[0114] For a given object with polysemous meanings, a defining feature corresponding to the given object is also provided when the given object is given. This allows subsequent steps to clarify the specific text unit corresponding to the given object based on the defining feature. The defining feature can be an attribute of the given object or the type of the given object.
[0115] Based on the limited features of the preset text unit, the text unit with the correct meaning can be selected from multiple text units corresponding to the preset text unit and can be set as:
[0116] Obtain all text units corresponding to the preset text unit in the inference database, and then obtain the knowledge structure of each corresponding text unit in the inference database, and use them as comparative knowledge structures; then determine which comparative knowledge structure among all comparative knowledge structures contains the limiting feature of the preset text unit, and select the text unit containing the limiting feature of the preset text unit in the comparative knowledge structure as the text unit with the correct meaning corresponding to the preset text unit. For example, for the text unit "apple", if the limiting feature is "company" and the knowledge structure of "Apple Company" contains the category "company", then the text unit "apple" refers to "Apple Company"; if the limiting feature is "fruit" and the knowledge structure of "apple" contains the category "fruit", then the text unit "apple" refers to the fruit "apple".
[0117] In addition, the semantic distance between the text unit and the limiting feature can be used to determine the text unit with the correct meaning referred to by the polysemous word; specifically, based on the limiting feature of the preset text unit, the text unit with the correct meaning can be screened out from multiple text units corresponding to the preset text unit. The following settings can also be used:
[0118] Obtain all text units corresponding to a preset text unit in the inference database, then calculate the semantic distance between each text unit and the defining feature of the preset text unit. Select the text unit with the closest semantic distance to the defining feature from all text units corresponding to the preset text unit as the text unit with the correct meaning corresponding to the preset text unit. For example, determine whether "apple" is semantically closer to the company "google" or to the fruit "banana"; if it is semantically closer to "google", then the text unit "apple" refers to "Apple Company"; otherwise, it refers to the fruit "apple".
[0119] Step S102: Obtain a target reasoning set.
[0120] Get the target reasoning set, including:
[0121] The semantic distance between the inference reference subject and the inference reference auxiliary is obtained as the first semantic distance; the first semantic range is obtained based on the first error range parameter and the first semantic distance; the set of all text units in the inference database whose semantic distance to the inference subject is within the first semantic range is taken as the first text unit set, and the semantic distance between the inference reference subject and the inference subject is obtained as the second semantic distance; the second semantic range is obtained based on the second error range parameter and the second semantic distance, and the set of all text units in the inference database whose semantic distance to the inference reference auxiliary is within the second semantic range is taken as the second text unit set, and the intersection of the first text unit set and the second text unit set is taken as the target inference set.
[0122] Furthermore, in actual application, the inference subject, the inference reference subject and the inference reference auxiliary can be a single text unit or a set of text units respectively.
[0123] Referring to Figure 2, when the inference subject (indicated by X in the figure), the inference reference subject (indicated by M in the figure), and the inference reference auxiliary (indicated by N in the figure) are all single text units, the process of obtaining the target inference set is as follows:
[0124] First, the semantic distance between the inference reference subject and the inference reference auxiliary is calculated as the first semantic distance, and the semantic distance between the inference reference subject and the inference subject is calculated as the second semantic distance;
[0125] Secondly, the set first error range parameter is added to the first semantic distance to obtain a first semantic range value, and the set second error range parameter is added to the second semantic distance to obtain a second semantic range value;
[0126] Furthermore, all text unit sets whose semantic distances to the inference subject are within the first semantic range are obtained from the inference database, and are used as the first text unit set; at the same time, all text unit sets whose semantic distances to the inference reference auxiliary are within the second semantic range are obtained from the inference database, and are used as the second text unit set;
[0127] Finally, the intersection of the first text unit set and the second text unit set is obtained as the target inference set.
[0128] When the inference subject, inference reference subject, and inference reference auxiliary are all text unit sets, the target inference set acquisition process can be as follows:
[0129] The text units with the same positional sequence in the inference subject, inference reference subject, and inference reference auxiliary are grouped into inference subsets. For example, assuming the inference subject is Xn{X1, X2, X3…Xn}, the inference reference subject is Mn{M1, M2, M3…Mn}, and the inference reference auxiliary is Nn{N1, N2, N3…Nn}, then X1, M1, and N1 form the inference subset D1, X2, M2, and N2 also form the inference subset S2, and so on to obtain all the inference subsets. Then, based on the preset inference method, the target inference subset of each inference subset is obtained, and the intersection of all target inference subsets is used as the target inference set.
[0130] It should be noted that the text units in each set of the reasoning subject, the reasoning reference subject and the reasoning reference auxiliary can be repeated, and the specific position of each text unit in the corresponding set can be manually set and adjusted.
[0131] Furthermore, the specific process of obtaining the target inference subset of the inference subset based on the preset inference method includes:
[0132] First, the text units belonging to the reasoning subject in the reasoning subset are taken as the implementation subject (for example, X1 in Xn), the text units belonging to the reasoning reference subject in the reasoning subset are taken as the implementation reference subject (for example, M1 in Mn), and the text units belonging to the reasoning reference auxiliary in the reasoning subset are taken as the implementation reference auxiliary (for example, N1 in Nn); then, the semantic distance between the implementation reference subject and the implementation reference auxiliary is calculated as the third semantic distance, and the set first error range parameter is added to the third semantic distance to obtain the third semantic range value; in the reasoning database, all text unit sets whose semantic distances to the implementation subject are within the third semantic range are obtained, and are taken as the third text unit set; similarly, the semantic distance between the implementation reference subject and the implementation subject is calculated as the fourth semantic distance, and the set second error range parameter is added to the fourth semantic distance to obtain the fourth semantic range value; in the reasoning database, all text unit sets whose semantic distances to the implementation reference auxiliary are within the fourth semantic range are obtained, and are taken as the fourth text unit set; finally, the intersection of the third text unit set and the fourth text unit set is obtained as the target reasoning subset.
[0133] To correspond to the specific content of the step of obtaining the target reasoning set, in the specific implementation process, the target reasoning subsets of all reasoning subsets may be obtained at the same time. At this time, the third semantic distances corresponding to all reasoning subsets can be aggregated into the first semantic distance (the first semantic distance is in set form at this time), the third semantic range values corresponding to all reasoning subsets can be aggregated into the first semantic range (the first semantic range is also in set form at this time), and the third text unit sets corresponding to all reasoning subsets can be aggregated into the first text unit set (the first text unit set is also in set form at this time); similarly, the fourth semantic distances corresponding to all reasoning subsets can be aggregated into the second semantic distance (the second semantic distance is in set form at this time), the fourth semantic range values corresponding to all reasoning subsets can be aggregated into the second semantic range (the second semantic range is also in set form at this time), and the fourth text unit sets corresponding to all reasoning subsets can be aggregated into the second text unit set (the second text unit set is also in set form at this time).
[0134] When the inference subject, inference reference subject, and inference reference auxiliary are all sets of text units, the target inference set acquisition process can also be as follows: assuming the inference subject is Xn{X1, X2, X3…Xx}, the inference reference subject is Mn{M1, M2, M3…Mm}, and the inference reference auxiliary is Nn{N1, N2, N3…Nn}, the semantic distance between any pair of text units between the inference reference subject and the inference reference auxiliary is calculated, that is, the semantic distance between any two text units is calculated, such as between M1 and N1, M1 and N2…M1 and Nn, M2 and N1, M2 and N2…M2 and Nn, and so on. Since not every two text units have a semantic distance, two text units with a semantic distance between the inference reference subject and the inference reference auxiliary can be considered as first-class semantic text pairs. Based on this, all first-class semantic text pairs between the inference reference subject and the inference reference auxiliary are obtained, and the relative distance between the semantic distances of all first-class semantic text pairs is then used as the first semantic distance. Add the first error range parameter and the first semantic distance to obtain the first semantic range. Finally, obtain the set of text units in the inference database whose semantic distance to each text unit in the inference subject falls within the first semantic range, and use this as the first inference subset corresponding to the text units in the inference subject. The intersection of all first inference subsets is used as the first text unit set. For example, in the inference database, obtain the set of text units whose semantic distance to X1 in the inference subject Xx{X1, X2, X3…Xx} falls within the first semantic range, and use this as the first inference subset for X1. Similarly, obtain the first inference subset corresponding to each text unit in X2, X3…Xx. Finally, combine all first inference subsets corresponding to X1, X2, X3…Xx into the first text unit set.
[0135] Similarly, the semantic distance between any pair of text units between the inference subject and the inference reference subject is calculated, specifically the semantic distance between any two text units, such as M1 and X1, M1 and X2, M1 and Xx, M2 and X1, M2 and X2, M2 and Xx, and so on. Since not every two text units have a semantic distance, two text units with a semantic distance between the inference subject and the inference reference subject can be considered as second-category semantic text pairs. Based on this, the relative semantic distance of all second-category semantic text pairs between the inference subject and the inference reference subject is obtained as the second semantic distance. The second error range parameter and the second semantic distance are added together to obtain the second semantic range. Finally, the set of text units in the inference database whose semantic distance to each text unit in the inference reference auxiliary body falls within the second semantic range is obtained as the second inference subset for the corresponding text unit in the inference reference auxiliary body. The intersection of all second inference subsets is then taken as the second text unit set. For example, in the inference database, a set of text units whose semantic distance from N1 in the inference reference auxiliary Nn{N1, N2, N3...Nn} is within the second semantic range is obtained as the second inference subset of N1. Similarly, the second inference subset corresponding to each text unit in N2, N3...Nn is obtained. Finally, all the second inference subsets corresponding to N1, N2, N3...Nn are combined into a second text unit set.
[0136] Finally, the intersection of the first text unit set and the second text unit set is used as the target inference set. Preferably, the relative distance can be taken as the average, variance, or weighted average. The relative distance can also be set to other calculation methods based on actual conditions, and there is no fixed restriction on it here.
[0137] After obtaining the target inference set through the above method, in order to facilitate a clearer understanding of the text units in the target inference set or more convenient application, the text units in the target inference set can be sorted in a certain manner. For example, the text units in the target inference set can be sorted from closest to furthest semantic distance from the inference text; or the text units in the target inference set can be sorted from closest to furthest semantic distance from the inference reference auxiliary. It should be noted that the text units in the target inference set can also be sorted in other reasonable ways, and there is no fixed restriction on this.
[0138] Step S103: obtaining a target text unit set of a given subject based on the target inference set.
[0139] If the language type of the given subject differs from the language type of the inference database, but the text units in the target inference set often have the same language type as the inference database, the target inference set can be translated into the language type of the given subject, if necessary. In this case, the translated target inference set is the target text unit set. If the language type of the given subject is the same as the language type of the inference database, the target inference set can be directly determined to be the target text unit set of the given subject.
[0140] The target inference set obtained through the above process may sometimes have hallucinations. In order to avoid unwanted results in the target text unit set, the target inference set can also be filtered by filtering conditions to obtain a filtered target inference set.
[0141] The specific filtering conditions can include at least one of the following conditions:
[0142] If it is determined that the reasoning subject and the reasoning reference subject belong to the same category, it is necessary to filter out the text units in the target text unit set that are inconsistent with the reasoning reference auxiliary subject.
[0143] When the inference subject, inference reference subject, and inference reference auxiliary are all text units, if it is determined that the knowledge structure of the inference subject in the inference database intersects with the knowledge structure of the inference reference subject in the inference database, then it is necessary to filter out text units in the target inference set that do not intersect with the knowledge structure of the inference reference auxiliary in the inference database. For example, assuming that the target inference set includes text units A, B, and C, if the knowledge structures of text units A and B in the inference database intersect with the knowledge structure of the inference reference auxiliary in the inference database, but the knowledge structure of text unit C in the inference database does not intersect with the knowledge structure of the inference reference auxiliary in the inference database, then text unit C is filtered out of the target inference set.
[0144] If it is determined that the inference subject and the inference reference subject have an inclusion or subordination relationship, it is necessary to filter out the text units in the target inference set that do not have an inclusion or subordination relationship with the inference reference auxiliary.
[0145] If the inference subject and the inference reference subject have the same text properties, the text units in the target inference set that have different text properties from the inference reference auxiliary text need to be filtered out. Specific text properties include characters, words, phrases, sentences, plurals, nouns, verbs, adjectives, and adverbs.
[0146] It should be noted that, in this embodiment, other reasonable filtering conditions may be added based on actual conditions, and the content of the filtering conditions is not limited to the above-mentioned content.
[0147] It should be noted that, in the above process, the target reasoning set after filtering based on the filtering conditions may be empty. At this time, the first error range parameter and the second error range parameter in step S102 need to be adjusted according to the preset parameter adjustment method, and step S102 is re-executed based on the adjusted first error range parameter and second error range parameter, and the new target reasoning set is filtered again according to the filtering conditions; when the filtered target reasoning set is not empty, step S103 can be executed, otherwise the first error range parameter and the second error range parameter in step S102 are re-adjusted according to the preset parameter adjustment method until the obtained filtered target reasoning set is not empty.
[0148] Adjusting the first error range parameter and the second error range parameter according to the preset parameter adjustment method specifically includes: when it is determined that the number of text units in the first text unit set is less than a preset threshold, it indicates that the number of text units in the first text unit set is too small, and in this case, only the first error range parameter needs to be adjusted to increase the number of text units in the first text unit set; specifically, the current first error range parameter is increased by the first step to obtain the adjusted first error range parameter, and the current second error range parameter is directly used as the adjusted second error range parameter. When it is determined that the number of text units in the first text unit set is not less than the preset threshold but the number of text units in the second text unit set is less than the preset threshold, it indicates that the number of text units in the second text unit set is too small, and in this case, only the second error range parameter needs to be adjusted to increase the number of text units in the second text unit set. In this case, only the second error range parameter needs to be adjusted, that is, the current second error range parameter is increased by the second step to obtain the adjusted second error range parameter, and the current first error range parameter is directly used as the adjusted first error range parameter. When it is determined that the number of text units in the first text unit set and the number of text units in the second text unit set are not less than the preset threshold, both the first error range parameter and the second error range parameter need to be adjusted; specifically, the current first error range parameter is increased by the first step to obtain the adjusted first error range parameter, and the current second error range parameter is increased by the second step to obtain the adjusted second error range parameter.
[0149] It should be noted that, because the first error range parameter is used to be added to the first semantic distance to obtain the first semantic range representing the semantic distance, and the second error range parameter is used to be added to the second semantic distance to obtain the second semantic range representing the semantic distance; therefore, the first error range parameter and the second error range parameter cannot be adjusted indefinitely. At this time, it is assumed that all the semantic distances obtained above are semantic distances obtained by calculating the preset semantic distance calculation method. In order to limit the adjustment of the first error range parameter and the second error range parameter according to the preset parameter adjustment method to not be indefinite, it is necessary to set the first semantic range and the second semantic range to be within the maximum range of the preset semantic distance calculation method. Moreover, if, during the adjustment process of the first error range parameter and the second error range parameter, one of the first semantic range and the second semantic range first reaches the maximum range of the preset semantic distance calculation method (i.e., reaches the semantic distance critical value), the subsequent adjustment process only needs to adjust the error range parameter corresponding to the semantic range that has not reached the maximum range of the preset semantic distance calculation method.
[0150] At the same time, in the loop process of obtaining the filtered target reasoning set, if the target reasoning set is still empty until the first semantic range and the second semantic range reach the maximum range of the preset semantic distance calculation method, the given reference subject and the given reference auxiliary need to be replaced, and the given subject must be re-reasoned using the method of the embodiment of the present application.
[0151] The text unit reasoning method based on semantic distance provided in the embodiment of the present application sets a first semantic range based on a first semantic distance, and obtains a first text unit set whose semantic distance to the reasoning subject is within the first semantic range, sets a second semantic range based on a second semantic distance, and obtains a second text unit set whose semantic distance to the reasoning reference auxiliary is within the second semantic range, and finally obtains the intersection of the first text unit set and the second text unit set, that is, realizes reasoning from the reasoning subject to the reasoning reference subject to the reasoning reference auxiliary. In addition, the filtering process realizes the removal of hallucinations in the target reasoning set based on actual needs, and further simplifies the text units in the target reasoning set. The method of this embodiment completes the reasoning of text units without a quantization process; since it realizes the accurate positioning of polysemous words and there is no word order problem, it can ensure that there is no information loss in the entire reasoning process; at the same time, it does not require a large amount of expected data support, and the calculation is fast and the accuracy is high.
[0152] As shown in FIG3 , this embodiment provides a text unit reasoning device based on semantic distance, including a reasoning content acquisition module, a target reasoning set acquisition module, and a target text unit set acquisition module.
[0153] The reasoning content acquisition module is used to obtain a given subject, a given reference subject and a given reference auxiliary, and based on the attributes of the reasoning database, respectively obtain the reasoning subject corresponding to the given subject, the reasoning reference subject corresponding to the given reference subject and the reasoning reference auxiliary corresponding to the given reference auxiliary, wherein the given subject and the given reference subject have common characteristics; wherein, the implementation method of respectively obtaining the reasoning subject corresponding to the given subject, the reasoning reference subject corresponding to the given reference subject and the reasoning reference auxiliary corresponding to the given reference auxiliary based on the attributes of the reasoning database is the same as the implementation method in the above embodiment, and will not be repeated here.
[0154] The target reasoning set acquisition module is used to calculate the semantic distance between the reasoning reference subject and the reasoning reference auxiliary as the first semantic distance, obtain the first semantic range based on the first error range parameter and the first semantic distance, group all text units in the reasoning database whose semantic distance from the reasoning subject is within the first semantic range into a first text unit set, and calculate the semantic distance between the reasoning reference subject and the reasoning subject as the second semantic distance, obtain the second semantic range based on the second error range parameter and the second semantic distance, and group all text units in the reasoning database whose semantic distance from the reasoning reference auxiliary is within the second semantic range into a second text unit set, and take the intersection of the first text unit set and the second text unit set as the target reasoning set.
[0155] The specific method for obtaining the first text unit set, the second text unit set, and the target inference set is the same as that in the above embodiment, and will not be repeated here.
[0156] The target text unit set acquisition module is used to obtain the target text unit set of a given subject based on the target reasoning set; wherein, the implementation method of obtaining the target text unit set of a given subject based on the target reasoning set is the same as the implementation method in the above embodiment and will not be repeated here.
[0157] The text unit reasoning device based on semantic distance provided in the embodiment of the present application sets a first semantic range based on a first semantic distance, and obtains a first text unit set whose semantic distance to the reasoning subject is within the first semantic range, sets a second semantic range based on a second semantic distance, and obtains a second text unit set whose semantic distance to the reasoning reference auxiliary is within the second semantic range, and finally obtains the intersection of the first text unit set and the second text unit set, thereby realizing reasoning from the reasoning subject to the reasoning reference subject to the reasoning reference auxiliary. The filtering process realizes the removal of hallucinations in the target reasoning set based on actual needs, and further simplifies the text units in the target reasoning set. The device of this embodiment completes the reasoning of text units without a quantization process; since it realizes the accurate positioning of polysemous words and there is no word order problem, it can ensure that there is no information loss in the entire reasoning process; at the same time, it does not require a large amount of expected data support, and the calculation is fast and accurate.
[0158] In some embodiments of the text reasoning process, when obtaining unknown text units, the reasoning of the text units is usually achieved based on the known text units to be inferred and the corresponding semantic distances; however, the text units targeted by this text unit reasoning method are relatively single, and the reasoning scope is small, and it cannot be applied to extensive reasoning; and this text unit reasoning method is also not applicable to fixed relationship reasoning. For example, if it is known that the capital of South Korea is Seoul, if one wants to obtain text unit pairs of all countries and corresponding capitals, it cannot be achieved based on the existing reasoning method.
[0159] Based on this, the present application provides a text unit relational reasoning method based on semantic distance in the second aspect, which is used to solve the problem that the current text reasoning method is too single and has a small reasoning scope when reasoning about unknown text units, and cannot perform extensive reasoning based on the relationship between text units.
[0160] The following will describe in detail the implementation of the text unit relational reasoning method based on semantic distance described in the embodiment of the present application in conjunction with the accompanying drawings, so that those skilled in the art can understand the logical principles of the text unit relational reasoning method based on semantic distance in this embodiment without creative work.
[0161] As shown in FIG4 , the text unit relational reasoning method based on semantic distance provided in this embodiment includes the following steps:
[0162] Step S401: Obtain a reasoning relationship pair, where the reasoning relationship pair includes a reasoning subject and a reasoning auxiliary, and the reasoning subject and the reasoning auxiliary belong to a reasoning database.
[0163] Specifically, the text unit pair to be used as the basis for text unit relationship reasoning is taken as a given relationship pair; the main reasoning text unit in the given relationship pair is taken as a given subject, and the auxiliary text unit in the given relationship pair is taken as a given auxiliary; the relationship between the given subject and the given auxiliary in the given relationship pair is the relationship reasoning direction, and the database used in the reasoning process is set as the reasoning database; wherein the reasoning database is a semantic distance database calculated using a data-curated knowledge base.
[0164] In this embodiment, the given subject and the given auxiliary body can be a single text unit or a set of text units, and the process of relational reasoning is performed with a single pair of relations as the processing unit; therefore, the process of relational reasoning between the given subject and the given auxiliary body is divided into:
[0165] When the given subject and the given auxiliary are single text units, relational reasoning is implemented directly based on the given subject and the given auxiliary; when the given subject and the given auxiliary are a set of text units, the text units in the given subject and the given auxiliary need to be formed into relational pairs and relational reasoning is performed separately, and the reasoning results of all relation pairs are merged to obtain the final reasoning result of the given subject and the given auxiliary.
[0166] It should be noted that when the given subject and the given auxiliary are sets of text units, there should be a one-to-one correspondence between the given subject and the given auxiliary text units. Therefore, when reasoning based on the given subject and the given auxiliary, we are actually reasoning based on multiple pairs of relationships formed by the given subject and the given auxiliary. For example, assuming a given subject M = {M1, M2, M3…Mn}, the given auxiliary must have N = {N1, N2, N3…Nn}, where M1 corresponds to N1, M2 corresponds to N2, M3 corresponds to N3…Mn corresponds to Nn. When implementing relational reasoning, we need to use M1 and N1 as the subject and object of reasoning to implement the corresponding relational reasoning. Then, we need to use M1 and N1 as the subject and object of reasoning to implement the corresponding relational reasoning, and so on. Finally, all the reasoning results are combined to form the relational reasoning result between the given subject M and the given auxiliary N. Therefore, it can be seen that the relationship reasoning process between a given subject and a given auxiliary as a set of text units is actually a repetition of the relationship reasoning process between a given subject and a given auxiliary as a single text unit; therefore, this embodiment mainly describes the reasoning process between a given subject and a given auxiliary as a single text unit.
[0167] Furthermore, if the given subject or the given auxiliary is a text unit in the reasoning database, the given subject can be directly used as the reasoning subject or the given auxiliary can be used as the reasoning auxiliary; if the given subject or the given auxiliary is not an original text unit in the reasoning database, it is necessary to convert the given subject into the text unit form in the corresponding reasoning database or convert the given auxiliary into the text unit form in the corresponding reasoning database based on the equivalent body mapping relationship of the text units in the reasoning database.
[0168] Furthermore, before the text unit conversion is realized based on the equivalent body mapping relationship of the text units in the reasoning database, it is possible that the language type of the given subject or the given auxiliary body is different from the language type of the reasoning database; in this case, in order to implement the subsequent reasoning process, the given subject or the given auxiliary body must first be translated into the language type of the reasoning database. Since the translation process for the given subject and the given auxiliary body is the same, the translation process is explained here using the given subject as an example. After obtaining the given subject, determine whether the language type of the given subject and the reasoning database is the same; if they are not the same, translate the given subject into the language type of the reasoning database, and use the translated given subject as the mapping subject; if they are the same, directly use the given subject as the mapping subject. This setting can realize the reasoning of subjects of different language types.
[0169] At the same time, there may be polysemous words in the given subject and the given auxiliary. For example, the text unit "apple" may refer to "apple" or "Apple Inc." Therefore, when converting text units based on the equivalent body mapping relationship of text units in the inference database, it is also necessary to first determine which word the text unit "apple" specifically refers to in the inference database. Since the process of converting a given subject into an inference subject and converting a given auxiliary into an inference auxiliary based on the equivalent body mapping relationship of text units in the inference database is the same, this implementation also takes the given subject as an example to illustrate the conversion process. Specifically, the process of converting a given subject into an inference subject based on the equivalent body mapping relationship of text units in the inference database is as follows:
[0170] After the given subject is converted into a mapping subject through the translation process, it is determined whether the mapping subject corresponds to a single text unit in the inference database. If the mapping subject corresponds to a single text unit in the inference database, the mapping subject is used as the inference subject. If the mapping subject corresponds to multiple text units in the inference database, the text unit with the correct meaning is selected from the multiple text units corresponding to the mapping subject in the inference database based on the limiting characteristics of the given subject to serve as the inference subject for the preset text unit. The text unit corresponding to the mapping subject is defined as: a text unit in the inference database that is identical to the mapping subject. If the text unit identical to the mapping subject does not exist in the inference database, it is further determined whether the mapping subject exists in the equivalent set corresponding to a certain text unit in the inference database. If so, the text unit corresponding to the equivalent set is used as the text unit corresponding to the mapping subject.
[0171] For a mapping subject with polysemous words, the corresponding limiting feature of the given subject is also given when the corresponding subject is given, so that the specific text unit corresponding to the mapping subject can be clarified based on the limiting feature. The limiting feature can be an attribute of the given subject or the type of the given subject. The text unit with the correct meaning can be selected from the multiple text units corresponding to the mapping subject based on the limiting feature of the given subject.
[0172] Obtain all text units corresponding to the mapping subject in the inference database, and then obtain the knowledge structure of each corresponding text unit in the inference database, and use them as comparative knowledge structures;
[0173] Then, the algorithm determines which of all the comparative knowledge structures contains the qualifier of the given subject. The text units containing the qualifier of the given subject are selected from the comparative knowledge structures to serve as the text units with the correct meaning corresponding to the mapping subject. For example, for the text unit "apple", if the qualifier is "company" and the knowledge structure of "Apple Company" contains the category "company", then the text unit "apple" refers to "Apple Company". If the qualifier is "fruit" and the knowledge structure of "apple" contains the category "fruit", then the text unit "apple" refers to the fruit "apple".
[0174] The semantic distance between the text unit and the limiting feature can also be used to determine the text unit with the correct meaning referred to by the polysemous word. Specifically, based on the limiting feature of a given subject, the text unit with the correct meaning can be selected from multiple text units corresponding to the mapping subject. The following settings can also be used:
[0175] Obtain all text units corresponding to the mapping subject in the inference database, then calculate the semantic distance between each text unit and the given subject's defining feature. The text unit with the closest semantic distance to the given subject's defining feature is selected from all text units corresponding to the mapping subject to determine the text unit with the correct meaning corresponding to the mapping subject. For example, determine whether the semantic distance of "apple" is closer to the company "google" or to the fruit "banana." If the semantic distance to "google" is closer, then the text unit "apple" refers to "Apple Company"; otherwise, it refers to "apple" as a fruit.
[0176] Through the above method, the reasoning subject corresponding to the given subject can be obtained, and the reasoning auxiliary body corresponding to the given auxiliary body can be obtained. The reasoning subject and the reasoning auxiliary body constitute a reasoning relationship pair.
[0177] Step S402: Based on the characteristics of the inference subject or the characteristics of the similar text units, a set of similar text units of the inference subject is obtained from the inference database.
[0178] Specifically, the inferential subject characteristics may be a preset semantic distance from the inferential subject, a set classification type corresponding to the inferential subject, a similar classification type of the set classification type of the inferential subject, or clustering the inferential subject through a certain clustering method.
[0179] The similar text unit characteristics may be the types of similar text units of the pre-set reasoning subject, etc.
[0180] Specifically, which filtering condition to use for the set of similar text units of the inference subject can be selected based on actual needs.
[0181] When the inference subject characteristic is set to the preset semantic distance of the inference subject, the process of obtaining the set of similar text units of the inference subject from the inference database is as follows:
[0182] It is necessary to first obtain a pre-set semantic distance. Since the set of similar text units of the inference subject is obtained directly based on the preset semantic distance, this acquisition method may result in the set of similar text units being empty. Therefore, it is also necessary to set a second error range parameter to assist the preset semantic distance, so as to determine a suitable second semantic distance range based on the specific situation of the set of similar text units.
[0183] Furthermore, first, the preset semantic distance is used as the second distance range, and all text units in the inference database whose semantic distance to the inference subject is within the second distance range are grouped as a temporary text unit set; then, when determining whether the number of text units in the temporary text unit set is less than the second preset number threshold, if so, the current second distance range is increased by a step distance to form a new second distance range, and the corresponding temporary text unit set is obtained again based on the new second distance range, until the formed second distance range is greater than or equal to the sum of the preset semantic distance and the second error range parameter, or until the number of text units in the temporary text unit set is determined to be greater than or equal to the second preset number threshold, at which time the current second distance range is directly used as the second semantic distance range, and the current temporary text unit set is used as the similar text unit set of the inference subject. This method of obtaining a similar text unit set can be used when the preset semantic distance is known, or it can be implemented on the basis of corresponding restrictions on similar text units, and the corresponding restrictions can be reflected in the form of the corresponding semantic distance of the distance reasoning subject.
[0184] When the inference subject characteristic is a set classification type corresponding to the inference subject, the process of obtaining a set of similar text units of the inference subject from the inference database is as follows:
[0185] Because text units often belong to multiple classification types, to achieve directed reasoning about text unit relationships, you can directly set the classification type of the text to be used for reasoning and set it as the set classification type. It should be noted that the set classification type is pre-set by the reasoner. After determining the set classification type, you can search the reasoning database for all text units under the set classification type and set the set of all found text units as the set of similar text units for the reasoning subject.
[0186] It should be noted that before forming a set of similar text units, the inference subject in the searched text unit must be removed, even if the set of similar text units does not contain the inference subject. This method of obtaining a set of similar text units can be implemented under the condition that the similar text units and the inference subject have the same classification type. This can achieve reasoning in the direction of characteristic reasoning and improve reasoning accuracy.
[0187] When the inference subject characteristic is a similar classification type of the classification type set for the inference subject, the process of obtaining a set of similar text units of the inference subject from the inference database is as follows:
[0188] Based on the above principles, it can be seen that in order to realize the directional reasoning of the inference text, it is necessary to set the set classification type of the inference text. At the same time, in order to expand the reasoning scope, a preset classification semantic distance can also be set, that is, based on the preset classification semantic distance, all classification types similar to the set classification type can be obtained; further, all classification types in the inference database whose semantic distance from the set classification type is within the preset classification semantic range are set as the target classification type set; then, all text units under the set classification type and the target classification type set in the inference database are searched, and all the searched text units are set as the similar text unit set of the reasoning subject.
[0189] It should be noted that before forming a set of similar text units, the inference subject in the searched text unit must be removed, i.e., the set of similar text units does not contain the inference subject. This method of obtaining a set of similar text units can be implemented under the condition that the similar text units and the inference subject have the same or similar classification types. This can achieve similar direction inference and expand the scope of inference.
[0190] When the inference subject characteristic is to cluster the inference subject by a certain clustering method, the process of obtaining the set of similar text units of the inference subject from the inference database is as follows:
[0191] Calculate the semantic distance between any two text units whose semantic distance can be calculated among all text units in the inference database; convert the obtained semantic distance into edges according to the numerical ratio, and use the text units as points to form a semantic distance network for all text units in the inference database.
[0192] It should be noted that two text units in the inference database that do not share a semantic distance are not connected by edges. Only two text units that do share a semantic distance are connected by edges corresponding to the semantic distance between them. This results in a semantic distance network formed by all text units in the inference database. A preset threshold is then obtained, which is the maximum allowable length of an edge corresponding to a semantic distance. Edges in the semantic distance network with a semantic distance less than the preset threshold are then removed, splitting the semantic distance network into multiple semantic distance sub-networks. All text units in the semantic distance sub-network belonging to the inference subject are obtained, and all text units are grouped together as a set of similar text units for the inference subject.
[0193] It should be noted that before forming a set of similar text units, the inference subject in the searched text unit needs to be eliminated, even if the set of similar text units does not contain the inference subject.
[0194] Figure 5 shows a schematic diagram of the semantic distance network and semantic distance subnetwork. This approach to obtaining sets of similar text units enables indirect search of text units. It not only obtains similar text units related to the inference subject, but also similar text units that belong to the same cluster type as the inference subject, thus maximizing the scope of inference and making it suitable for large-scale searches.
[0195] When the characteristic of the close text unit is the type of the pre-set close text unit of the inference subject, the process of obtaining the close text unit set of the inference subject from the inference database is as follows:
[0196] To set the direction of relational reasoning, you can also do so by setting the classification type of the similar text units of the reasoning subject. Specifically, set the classification type of the similar text units to the similar classification type; then search the inference database for all text units under the similar classification type, and combine all the found text units into the similar text unit set of the reasoning subject. This method of obtaining a similar text unit set is used when the classification type of the similar text units is known, enabling the reasoning subject to directional reasoning between similar text units. It is suitable for use when there are corresponding restrictions on the classification type of the similar text units.
[0197] This embodiment may also obtain a set of similar text units of the inference subject from the inference database through other reasonable methods, which are not exhaustively listed here.
[0198] Step S403: Set a first semantic distance range based on the semantic distance between the inference subject and the inference auxiliary. For each similar text unit in the similar text unit set, obtain all text unit sets within the first semantic distance range as the adjacent text unit subset of the corresponding similar text unit.
[0199] Specifically, the semantic distance between the inference subject and the inference auxiliary is calculated as a first semantic distance, and a first semantic distance range is set based on the first semantic distance. Then, an operation is performed on each of the similar text units in the similar text unit set based on the first semantic distance range to obtain a subset of adjacent text units corresponding to each of the similar text units in the similar text unit set.
[0200] It should be noted that in order to avoid the situation where the obtained adjacent text unit subset is empty or the text unit data has very little impact on the reasoning, a first error range parameter can be set to assist in determining the first semantic distance range. Specifically, for each adjacent text unit, the following first semantic distance range and adjacent text unit subset acquisition process are performed: first, the first semantic distance is used as the first distance range, and all text units in the inference database whose semantic distance to the adjacent text unit is within the first distance range are grouped as the inference text unit set; then, it is determined whether the number of text units in the inference text unit set is less than a first preset number threshold. If so, the current first distance range is increased by a step distance to form a new first distance range, and the corresponding inference text unit set is obtained again based on the new first distance range, until the formed first distance range is greater than or equal to the sum of the preset semantic distance and the first error range parameter, or until it is determined that the number of text units in the inference text unit set is greater than or equal to the first preset number threshold, at which time the current first distance range is directly used as the first semantic distance range, and the current inference text unit set is used as the adjacent text unit subset of the adjacent text unit.
[0201] Through the above method, the adjacent text unit subset corresponding to each adjacent text unit in the adjacent text unit set can be obtained. Furthermore, the above setting allows the first semantic distance range value for each adjacent text unit to be adjusted based on the number of text units in the corresponding adjacent text unit subset, thereby obtaining a reasonable inference range as much as possible.
[0202] Step S404 : forming text relationship pairs with the similar text units and each adjacent text unit in the corresponding adjacent text unit subset, and using all text relationship pair sets as target relationship pair sets for inference relationship pairs.
[0203] Specifically, for each similar text unit in the similar text unit set, a text relationship pair is formed between the similar text unit and each adjacent text unit in the corresponding adjacent text unit subset, and then all the obtained text unit pairs are set as a target relationship pair set of the inference relationship pairs.
[0204] The target relationship pair set obtained through the above process may sometimes contain hallucinations. In order to avoid unwanted results in the target relationship pair set, the target relationship pair set may be filtered according to a filtering condition to obtain a filtered target relationship pair set.
[0205] The specific filtering conditions can include at least one of the following conditions:
[0206] This method determines whether the classification of adjacent text units in a text relationship pair is consistent with that of the inference subject in the inference database. It also determines whether the classification of adjacent text units in a text relationship pair is consistent with that of the inference auxiliary in the inference database. If there is any inconsistency in the above judgment process, the corresponding text unit pair is directly filtered out. This filtering method is generally not suitable for cases where the inference subject characteristic is a similar classification type set for the inference subject.
[0207] Determine whether there is an intersection between the knowledge structure of the adjacent text units in the text relationship pair in the inference database and the knowledge structure of the inference subject in the inference database. At the same time, determine whether there is an intersection between the knowledge structure of the adjacent text units in the text relationship pair in the inference database and the knowledge structure of the inference auxiliary in the inference database. If the above does not have an intersection, the corresponding text unit pair is directly filtered out.
[0208] Determine whether there is an inclusion or subordination relationship between the inference subject and the inference auxiliary. If so, filter out text relationship pairs where there is no inclusion or subordination relationship between the similar text units and the corresponding adjacent text units; if there is no inclusion or subordination relationship between the inference subject and the inference auxiliary, there is no need to filter the text relationship pairs based on this filtering condition.
[0209] Determine whether the inference subject and adjacent text units have the same text properties. If so, filter out text unit pairs where the adjacent text units do not have the same text properties as the inference auxiliary text. Specific text properties include characters, words, phrases, sentences, plurals, nouns, verbs, adjectives, and adverbs.
[0210] It should be noted that, in this embodiment, other reasonable filtering conditions may be added based on actual conditions, and the content of the filtering conditions is not limited to the above-mentioned content.
[0211] In order to explain the text unit relationship reasoning method of this embodiment in detail, a specific example is given below to illustrate.
[0212] Assume that the given subject in a given relation pair is "China" and the given auxiliary is "Beijing," and that the inference database is set to an English database. Since the language type of the given subject and the given auxiliary is the same as that of the inference database, and neither is polysemous, and both are text units in the inference database, the given subject is the inference subject, and the given auxiliary is the inference auxiliary.
[0213] This example uses a distance inference subject-preset semantic distance approach to obtain a set of similar text units. Specifically, assuming the preset semantic distance is D, a second semantic distance range is set based on the preset semantic distance. The set of similar text units in the inference subject obtained based on the second semantic distance range is X = ["Japan", "Korea", "Hanghzou"...]. The semantic distance between the inference subject and the inference auxiliary is set to d1. Based on the semantic distance d1, a first semantic distance range is determined for each similar text unit Xi. Then, based on the first semantic distance range, each similar text unit Xi in the set of similar text units X is traversed to obtain the adjacent text unit subset Yj corresponding to each similar text unit Xi in the set of similar text units X. For example, the adjacent text unit subset Y corresponding to "Japan" is Y = ["Tokyo", "Osaka",...]; the adjacent text unit subset Y corresponding to "Korea" is Y = ["Seoul",...]; and the adjacent text unit subset Y corresponding to "Hangzhou" is Y = ["Zhejiang",...]. Finally, we get the target relationship pair set “Xi-Yj” = [“Japan-Tokyo”, “Japan-Osaka”, “Korea-Seoul”, “Hangzhou-Zhejiang”…].
[0214] To improve the inference accuracy of the target relationship pair set, the current target relationship pair set can be filtered using filtering conditions. In this example, the first filter condition can be used for filtering. Specifically, the inference subject is classified as "country" and the inference auxiliary is classified as "capital". Then, based on "country" - "capital", the text relationship pairs in the current target relationship pair set are filtered and extracted, and the final target relationship pair set "Xi-Yj" = ["Japan-Tokyo", "Korea-Seoul"...] is obtained. In this process, "Osaka" and "Zhejiang" do not belong to the "capital" category, and "Hangzhou" does not belong to the "country" category, so "Japan-Osaka" and "Hangzhou-Zhejiang" are filtered out.
[0215] It should be noted that all semantic distances obtained in this embodiment are calculated using the same semantic distance calculation method.
[0216] The text unit relational reasoning method based on semantic distance provided in the embodiment of the present application obtains a set of similar text units of the reasoning subject on demand, and at the same time determines a screening semantic distance range based on the semantic distance between the reasoning subject and the reasoning auxiliary, and then uses the screening semantic distance range as the reasoning direction to obtain the adjacent text units of each similar text unit of the reasoning subject, that is, to realize the reasoning of all similar text units from the reasoning subject to the reasoning auxiliary, and then obtain all target relation pairs with similar reasoning relationships with the reasoning subject and the reasoning auxiliary. The method of the present application can perform similarity search based on the relationship between text unit relationship pairs on the basis of unknown target text units, and obtain all desired text unit pairs with given relationships in the similar results, thereby expanding the scope of text unit reasoning. By filtering the selected text unit pairs through filtering conditions, the reasoning accuracy in the text unit pair relational reasoning process is further improved.
[0217] Based on the same inventive concept, this embodiment also provides a text unit relational reasoning device based on semantic distance, as shown in Figure 6, the text unit relational reasoning device based on semantic distance includes: an inference relationship pair acquisition module, a similar text unit acquisition module, an adjacent text unit acquisition module and a target relationship pair acquisition module.
[0218] The inference relationship pair acquisition module is used to acquire the inference relationship pair, the inference relationship pair includes an inference subject and an inference auxiliary, and the inference subject and the inference auxiliary belong to the inference database.
[0219] In this embodiment, the method for obtaining the reasoning relationship pair is the same as the implementation method of this step in the above embodiment, and will not be repeated here.
[0220] The similar text unit acquisition module is used to acquire a set of similar text units of the reasoning subject from the reasoning database based on the characteristics of the reasoning subject or the characteristics of the similar text units.
[0221] In this embodiment, the implementation method of obtaining a set of similar text units of the reasoning subject from the reasoning database based on the characteristics of the reasoning subject or the characteristics of the similar text units is the same as the implementation method of this step in the above embodiment and will not be repeated here.
[0222] The adjacent text unit acquisition module is used to set a first semantic distance range based on the semantic distance between the reasoning subject and the reasoning auxiliary body, and for each adjacent text unit in the adjacent text unit set, all text unit sets within the first semantic distance range are obtained as adjacent text unit subsets of the corresponding adjacent text unit.
[0223] In this embodiment, the method for obtaining the adjacent text unit subset corresponding to the adjacent text unit is the same as that in the above embodiment, and will not be repeated here.
[0224] The target relationship pair acquisition module is used to form text relationship pairs with the similar text units and each adjacent text unit in the corresponding adjacent text unit subset, and use all text relationship pair sets as target relationship pair sets for inference relationship pairs.
[0225] In this embodiment, the method for obtaining the target relationship pair set in the inference relationship pair is the same as that in the above embodiment, and will not be repeated here.
[0226] The text unit relational reasoning device provided in the embodiment of the present application obtains a set of similar text units of the reasoning subject on demand, and at the same time determines a screening semantic distance range based on the semantic distance between the reasoning subject and the reasoning auxiliary, and then uses the screening semantic distance range as the reasoning direction to obtain the adjacent text units of each similar text unit of the reasoning subject, that is, to realize the reasoning of all similar text units from the reasoning subject to the reasoning auxiliary, and then obtain all target relationship pairs with similar reasoning relationships with the reasoning subject and the reasoning auxiliary. The device of the present application can perform similarity search based on the relationship between text unit relationship pairs on the basis of unknown target text units, and obtain all desired text unit pairs with given relationships in the similar results, thereby expanding the text unit reasoning range. By filtering the selected text unit pairs through filtering conditions, the reasoning accuracy in the text unit pair relational reasoning process is further improved.
[0227] Furthermore, an embodiment of the present application further provides a computer-readable storage medium. A person skilled in the art will understand that all or part of the steps in the text unit reasoning method based on semantic distance or the text unit relational reasoning method based on semantic distance provided in the above embodiment can be completed by instructing a processor through a program, and the program can be stored in a computer-readable storage medium, and the storage medium is a non-transitory medium, such as a random access memory, a read-only memory, a flash memory, a hard disk, a solid-state drive, a magnetic tape, a floppy disk, an optical disc, and any combination thereof. The above storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (DVD)), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0228] As shown in FIG7 , an embodiment of the present application further provides a terminal.
[0229] The terminal of this embodiment includes a processor and a memory connected to each other; the memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory, so that when the terminal executes, all or part of the steps in the text unit reasoning method based on semantic distance or the text unit relationship reasoning method based on semantic distance provided in the above embodiment can be implemented.
[0230] The beneficial effects of all or part of the steps of the method in the above embodiment are the same as the beneficial effects obtained by applying the terminal provided in the embodiment of the present application, and will not be repeated here.
[0231] It should be noted that the memory may include random access memory (RAM) and may also include non-volatile memory (non-volatile memory), such as at least one disk storage. Similarly, the processor may also be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0232] Although the embodiments disclosed in this application are as described above, the contents described are merely embodiments adopted to facilitate understanding of this application and are not intended to limit this application. Any person skilled in the art of the art to which this application belongs may make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in this application. However, the scope of protection of this application shall still be based on the scope defined by the attached claims.
Claims
1. A text unit reasoning method based on semantic distance, comprising: Obtaining a given subject, a given reference subject, and a given reference auxiliary, and respectively obtaining a reasoning subject corresponding to the given subject, a reasoning reference subject corresponding to the given reference subject, and a reasoning reference auxiliary corresponding to the given reference auxiliary based on the attributes of the reasoning database, wherein the given subject and the given reference subject have common characteristics; Obtaining the semantic distance between the inference reference subject and the inference reference auxiliary as a first semantic distance, obtaining a first semantic range based on a first error range parameter and the first semantic distance, grouping all text units in the inference database whose semantic distance from the inference subject is within the first semantic range into a first text unit set, obtaining the semantic distance between the inference reference subject and the inference subject as a second semantic distance, obtaining a second semantic range based on a second error range parameter and the second semantic distance, grouping all text units in the inference database whose semantic distance from the inference reference auxiliary is within the second semantic range into a second text unit set, and taking the intersection of the first text unit set and the second text unit set as a target inference set; A target text unit set of the given subject is obtained based on the target inference set.
2. The method according to claim 1, characterized in that Acquiring the inference object corresponding to the preset object based on the inference database attribute includes: Determine whether the language types of the preset object and the inference database are different. If so, translate the preset object into the language type of the inference database to obtain a translation subject, and use the translation subject as a comparison subject. Otherwise, use the preset object as a comparison subject. Obtaining the inference object corresponding to the comparison subject through a preset comparison method; Among them, when the preset object is a given subject, the inference object is the inference subject; when the preset object is a given reference subject, the inference object is the inference reference subject; when the preset object is a given reference auxiliary, the inference object is the inference reference auxiliary.
3. The method according to claim 2, characterized in that The inference text units corresponding to the preset text units obtained by the preset comparison method include: If there is only a single text unit in the inference database that corresponds to the preset text unit, determining that the text unit corresponding to the preset text unit is the inference text unit of the preset text unit; If there are multiple text units in the inference database corresponding to the preset text unit, a text unit with correct meaning is screened out from the multiple text units corresponding to the preset text unit based on the limiting features of the preset text unit as the inference text unit of the preset text unit; When the comparison subject is a single text unit, the preset text unit is the comparison subject; when the comparison subject is a set of text units, the preset text unit is any one of the text units in the comparison subject, and the inference object corresponding to the comparison subject is the set of inference text units corresponding to all the text units in the comparison subject. The text unit corresponding to the preset text unit is: a text unit that is the same as the preset text unit, or a text unit for which the preset text unit exists in a corresponding equivalent set.
4. The method according to claim 3, characterized in that Screening out a text unit with correct meaning from a plurality of text units corresponding to the preset text unit based on the limiting features of the preset text unit includes: Obtaining the knowledge structure of each text unit corresponding to the preset text unit in the inference database as a comparison knowledge structure, and taking the text unit corresponding to the comparison knowledge structure that contains the limiting feature of the preset text unit as the text unit with the correct meaning corresponding to the preset text unit; or A text unit having the closest semantic distance to the limiting feature of the preset text unit is selected from all text units corresponding to the preset text unit as the text unit with the correct meaning corresponding to the preset text unit.
5. The method according to claim 1, characterized in that When the inference subject, the inference reference subject, and the inference reference auxiliary are all text unit sets, the target inference set acquisition step includes: The text units with the same position serial number in the inference subject, the inference reference subject and the inference reference auxiliary body are grouped into an inference subset, a target inference subset is obtained for each of the inference subsets based on a preset inference method, and the intersection of all the target inference subsets is used as the target inference set; The number of text units contained in the inference subject, the inference reference subject, and the inference reference auxiliary body is the same; and the target inference subset of the inference subset obtained based on the preset inference method includes: The text units belonging to the reasoning subject in the reasoning sub-set are used as implementation subjects, the text units belonging to the reasoning reference subject in the reasoning sub-set are used as implementation reference subjects, and the text units belonging to the reasoning reference auxiliary body in the reasoning sub-set are used as implementation reference auxiliary bodies; The semantic distance between the implementation reference subject and the implementation reference auxiliary is obtained as a third semantic distance, a third semantic range is obtained based on the first error range parameter and the third semantic distance, all text units in the implementation database whose semantic distance from the implementation subject is within the third semantic range are grouped as a third text unit set, and the semantic distance between the implementation reference subject and the implementation subject is obtained as a fourth semantic distance, a fourth semantic range is obtained based on the second error range parameter and the fourth semantic distance, and all text units in the implementation database whose semantic distance from the implementation reference auxiliary is within the fourth semantic range are grouped as a fourth text unit set, and the intersection of the third text unit set and the fourth text unit set is used as a target inference subset.
6. The method according to claim 1, characterized in that When the inference subject, the inference reference subject, and the inference reference auxiliary are all text unit sets, the target inference set acquisition step includes: Any two text units with a semantic distance between the inference reference subject and the inference reference auxiliary are taken as first-category semantic text pairs, the relative distance of the semantic distances of all first-category semantic text pairs between the inference reference subject and the inference reference auxiliary is obtained as the first semantic distance, a first semantic range is obtained based on the first error range parameter and the first semantic distance, a set of text units in the inference database whose semantic distances to each text unit in the inference subject are respectively within the first semantic range is obtained as the first inference subset corresponding to the text unit in the inference subject, the intersection of all first inference subsets is taken as the first text unit set, and the inference reference subject and the inference subject are separated. Any two text units with a semantic distance between them are taken as the second type of semantic text pairs, the relative distance of all second type semantic text pairs between the reasoning reference subject and the reasoning subject is obtained as the second semantic distance, the second semantic range is obtained based on the second error range parameter and the second semantic distance, and a set of text units in the reasoning database whose semantic distances to each text unit in the reasoning reference auxiliary body are within the second semantic range are obtained as the second reasoning subset of the corresponding text units in the reasoning reference auxiliary body, and the intersection of all second reasoning subsets is taken as the second text unit set, and the intersection of the first text unit set and the second text unit set is taken as the target reasoning set.
7. The method according to claim 1, characterized in that Before obtaining the target text unit set of the given subject based on the target inference set, the target inference set needs to be filtered by a filtering condition to obtain a filtered target inference set; The filtering condition includes at least one of the following conditions: If the classification of the inference subject is consistent with that of the inference reference subject, filtering out text units in the target inference set that are inconsistent with the classification of the inference reference auxiliary body; When the inference subject, the inference reference subject, and the inference reference auxiliary are all text units, if the knowledge structure of the inference subject in the inference database and the knowledge structure of the inference reference subject in the inference database have an intersection, then filter out the text units in the target inference set that do not have an intersection with the knowledge structure of the inference reference auxiliary in the inference database; If the inference subject and the inference reference subject have an inclusion or subordination relationship, then filter out the text units in the target inference set that do not have an inclusion or subordination relationship with the inference reference auxiliary body; If the text properties of the inference subject and the inference reference subject are the same, then the text units in the target inference set that have different text properties from the inference reference auxiliary body are filtered out. The text properties include characters, words, phrases, sentences, plurals, nouns, verbs, adjectives and adverbs.
8. The method according to claim 7, characterized in that When the filtered target reasoning set is empty, adjusting the first error range parameter and the second error range parameter according to a preset parameter adjustment method, and re-executing the target reasoning set acquisition step based on the adjusted first error range parameter and the second error range parameter to obtain a new target reasoning set and filtering the new target reasoning set by the filtering condition until the obtained filtered target reasoning set is not empty; Adjusting the first error range parameter and the second error range parameter according to a preset parameter adjustment method includes: When the number of text units in the first text unit set is less than a preset threshold, increasing the current first error range parameter by a first step to obtain an adjusted first error range parameter, and using the current second error range parameter as the adjusted second error range parameter; When the number of text units in the first text unit set is not less than a preset threshold but the number of text units in the second text unit set is less than a preset threshold, increasing the current second error range parameter by a second stepping step to obtain an adjusted second error range parameter, and using the current first error range parameter as the adjusted first error range parameter; When the number of text units in the first text unit set and the number of text units in the second text unit set are both not less than a preset threshold, increasing the current first error range parameter by a first step to obtain an adjusted first error range parameter, and increasing the current second error range parameter by a second step to obtain an adjusted second error range parameter; The semantic distance is calculated in a preset semantic distance calculation method, and both the first semantic range and the second semantic range are within a maximum range of the preset semantic distance calculation method.
9. A text unit reasoning device based on semantic distance, characterized in that: It includes a reasoning content acquisition module, a target reasoning set acquisition module and a target text unit set acquisition module; The inference content acquisition module is used to acquire a given subject, a given reference subject, and a given reference auxiliary, and respectively acquire, based on the attributes of the inference database, an inference subject corresponding to the given subject, an inference reference subject corresponding to the given reference subject, and an inference reference auxiliary corresponding to the given reference auxiliary, wherein the given subject and the given reference subject have common characteristics; The target reasoning set acquisition module is used to obtain the semantic distance between the reasoning reference subject and the reasoning reference auxiliary as a first semantic distance, obtain a first semantic range based on a first error range parameter and the first semantic distance, group all text units in the reasoning database whose semantic distance from the reasoning subject is within the first semantic range into a first text unit set, and obtain the semantic distance between the reasoning reference subject and the reasoning subject as a second semantic distance, obtain a second semantic range based on a second error range parameter and the second semantic distance, and group all text units in the reasoning database whose semantic distance from the reasoning reference auxiliary is within the second semantic range into a second text unit set, and use the intersection of the first text unit set and the second text unit set as a target reasoning set; The target text unit set acquisition module is used to acquire the target text unit set of the given subject based on the target inference set.
10. A method for reasoning about text unit relations based on semantic distance, comprising: Acquire an inference relationship pair, wherein the inference relationship pair includes an inference subject and an inference auxiliary, and the inference subject and the inference auxiliary belong to an inference database; Based on the characteristics of the inference subject or the characteristics of the similar text units, obtaining a set of similar text units of the inference subject from the inference database; A first semantic distance range is set based on the semantic distance between the inference subject and the inference auxiliary subject, and for each similar text unit in the set of similar text units, a set of all text units within the first semantic distance range is obtained as a subset of adjacent text units corresponding to the similar text unit; Each of the similar text units is respectively formed into a text relationship pair with each adjacent text unit in the corresponding adjacent text unit subset, and all of the text relationship pairs are grouped into a target relationship pair set of the inference relationship pairs.
11. The inference method according to claim 10, characterized in that: Obtaining inference relationship pairs includes: Obtaining a given relationship pair, wherein the given relationship pair includes a given subject and a given auxiliary subject; The reasoning subject corresponding to the given subject and the reasoning auxiliary body corresponding to the given auxiliary body are obtained from the reasoning database based on an equivalent body mapping method, and the given subject and the given auxiliary body constitute the reasoning relationship pair.
12. The inference method according to claim 10, characterized in that: Based on the characteristics of the inference subject, obtaining a set of text units similar to the inference subject from the inference database includes: A preset semantic distance is obtained, a second semantic distance range is set based on the preset semantic distance, and all text units in the inference database whose semantic distances to the inference subject are within the second semantic range are grouped as a similar text unit set of the inference subject.
13. The inference method according to claim 10, characterized in that: Based on the characteristics of the inference subject, obtaining a set of text units similar to the inference subject from the inference database includes: The set classification type of the inference subject is obtained, and all text units under the set classification type are searched from the inference database for a set of similar text units of the inference subject, wherein the set of similar text units does not include the inference subject.
14. The inference method according to claim 10, characterized in that: Based on the characteristics of the inference subject, obtaining a set of text units similar to the inference subject from the inference database includes: Acquire the set classification type and preset classification semantic range of the inference subject, and group all classification types in the inference database whose semantic distance from the set classification type is within the preset classification semantic range as a target classification type set; The set classification type and all text unit sets under the target classification type in the target classification type set are searched from the inference database as a similar text unit set of the inference subject, and the similar text unit set does not include the inference subject.
15. The inference method according to claim 10, characterized in that: Based on the characteristics of the inference subject, obtaining a set of text units similar to the inference subject from the inference database includes: Obtaining the semantic distances between all arbitrary two text units in the inference database, and forming a semantic distance network of all text units in the inference database using the obtained semantic distances as edges and the text units as points; The edges whose semantic distance in the semantic distance network is less than a preset threshold are removed to obtain multiple semantic distance sub-networks, and all text units in the semantic distance sub-network to which the inference subject belongs are grouped into a set of similar text units of the inference subject, and the set of similar text units does not include the inference subject.
16. The inference method according to claim 10, characterized in that: Based on the characteristics of similar text units, obtaining a set of similar text units of the inference subject from the inference database includes: Acquire similar classification types, and search the inference database for a set of similar text units with all text units under the similar classification types as the inference subject.
17. The inference method according to claim 10, characterized in that: Before all the text relationship pairs are grouped into a target relationship pair set of the inference relationship pairs, the method further includes filtering all the formed text relationship pairs by a filtering condition; The filtering condition includes at least one of the following conditions: Filter out text relationship pairs in which the classification of the adjacent text units in the text relationship pairs and the classification of the inference subject in the inference database are inconsistent, or the classification of the adjacent text units in the text relationship pairs and the classification of the inference auxiliary object in the inference database are inconsistent; Filter out text relationship pairs in which the knowledge structure of the adjacent text units in the inference database does not intersect with the knowledge structure of the inference subject in the inference database, or the knowledge structure of the adjacent text units in the text relationship pairs in the inference database does not intersect with the knowledge structure of the inference auxiliary body in the inference database; If there is a containment or subordination relationship between the inference subject and the inference auxiliary, then filtering out text relationship pairs where there is no containment or subordination relationship between the close text unit and the corresponding adjacent text unit; If the inference subject has the same text property as the adjacent text unit, then filter out the text unit pairs whose text properties are not the same as the inference auxiliary text property, where the text property is a character, word, phrase, sentence, plural, noun, verb, adjective or adverb.
18. A text unit relational reasoning device based on semantic distance, characterized in that: It includes an inference relation pair acquisition module, a similar text unit acquisition module, a neighboring text unit acquisition module and a target relation pair acquisition module; The inference relationship pair acquisition module is used to acquire an inference relationship pair, wherein the inference relationship pair includes an inference subject and an inference auxiliary, and the inference subject and the inference auxiliary belong to an inference database; The similar text unit acquisition module is used to acquire a set of similar text units of the reasoning subject from the reasoning database based on the characteristics of the reasoning subject or the characteristics of the similar text units; The adjacent text unit acquisition module is configured to set a first semantic distance range based on the semantic distance between the inference subject and the inference auxiliary subject, and for each adjacent text unit in the adjacent text unit set, acquire a set of all text units within the first semantic distance range from the adjacent text unit as an adjacent text unit subset corresponding to the adjacent text unit; The target relationship pair acquisition module is used to form a text relationship pair with each of the similar text units and each adjacent text unit in the corresponding adjacent text unit subset, and to group all of the text relationship pairs into a target relationship pair set for the inference relationship pair.
19. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the text unit reasoning method based on semantic distance as described in any one of claims 1 to 7, or the text unit relational reasoning method based on semantic distance as described in any one of claims 10 to 17.
20. A terminal, characterized in that: include: a processor and a memory, wherein the memory is communicatively connected to the processor; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the terminal executes the text unit reasoning method based on semantic distance as described in any one of claims 1 to 7, or the text unit relationship reasoning method based on semantic distance as described in any one of claims 10 to 17.
Citation Information
Patent Citations
Word vector and context information-based short text topic model
CN108415901A
Question reasoning method and device based on semantic understanding
CN116341564A
Text unit semantic distance pre-calculation method and device and query method and device
CN117272073A
Text unit reasoning method and device based on semantic distance, storage medium and terminal
CN117973544A
Text unit relational reasoning method and device, storage medium and terminal
CN118643156A