Text relationship determination method and apparatus

By determining text relationships through a basis model and similarity calculation, and combining text processing rules to annotate entity information, the problem of low efficiency in text relationship extraction in existing technologies is solved, and efficient and low-cost text relationship acquisition is achieved.

CN114969328BActive Publication Date: 2026-03-03MIDEA GRP (SHANGHAI) CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210501792.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-09
Publication Date
2026-03-03
Estimated Expiration
2042-05-09

AI Technical Summary

Technical Problem

Existing text relation extraction methods are inefficient, mainly including rule-based template matching and supervised learning methods, which require a large number of high-quality labeled samples, resulting in high cost and low efficiency.

Method used

By using a base case model and a small amount of sample text data, the relationship vector of the target text data is determined by similarity calculation, avoiding the direct use of a large amount of high-quality labeled data to train the model. The entity information is labeled by combining text processing rules, thereby enhancing the entity information of the training dataset.

Benefits of technology

While ensuring the accuracy of relationship acquisition, the efficiency of relationship acquisition was improved, the training cost was reduced, and the relationship recognition rate was increased.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114969328B_ABST
    Figure CN114969328B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer, and provide a kind of text relationship determining method and device.The method comprises: the target text data is input into base model, obtains the target relationship vector of target text data output by base model;Multiple sample text data is input into base model, obtains the multiple sample relationship vectors corresponding to multiple sample text data output by base model;According to the similarity of target relationship vector and multiple sample relationship vectors, determine the relationship vector of target text data from multiple sample relationship vectors.The text relationship determining method and device provided by the present application determine the relationship vector of target text data from multiple sample relationship vectors by taking sample relationship vector as reference.Avoid using a large number of high-quality labeled training data to train model directly to obtain relationship, only a small amount of sample text data is needed as reference, which improves the relationship acquisition efficiency while ensuring the accuracy of relationship acquisition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for determining text relationships. Background Technology

[0002] Determining relationships in text involves extracting the relationships between entities in a given text by utilizing the contextual information within the text.

[0003] Existing relation extraction techniques can be broadly categorized into two main types. The first type is rule-based template matching, which involves constructing an entity vocabulary and a set of templates that satisfy entity relation descriptions to match entity relations. This requires creating a large number of rule templates, resulting in low extraction efficiency. The second type is supervised learning-based methods, which rely on a large number of high-quality labeled samples. This labeling cost is extremely high, also leading to low extraction efficiency. Summary of the Invention

[0004] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, this invention proposes a method for determining relationships in text. By using sample text data as a reference, it enables the acquisition of relationships in text information with only a small amount of sample text data, thereby improving the efficiency of relationship acquisition while ensuring the accuracy of relationship acquisition.

[0005] The present invention also proposes a text relationship determination device.

[0006] The present invention also proposes an electronic device.

[0007] The present invention also proposes a non-transitory computer-readable storage medium.

[0008] The present invention also proposes a computer program product.

[0009] A text relation determination method according to a first aspect of the present invention includes: inputting target text data into a basis model to obtain a target relation vector of the target text data output by the basis model; inputting multiple sample text data into the basis model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the basis model; determining a relation vector of the target text data from the multiple sample relation vectors based on the similarity between the target relation vector and the multiple sample relation vectors; wherein the basis model is obtained by training an initial basis model based on a training dataset and relation labels corresponding to the training dataset.

[0010] The text relation determination method according to embodiments of the present invention obtains the target relation vector of the target text data by inputting the target text data into a base model, and then determines the relation vector of the target text data from the multiple sample relation vectors based on the similarity between the target relation vector and multiple sample relation vectors. This avoids the direct relation acquisition method of training a model with a large amount of high-quality labeled training data, requiring only a small amount of sample text data as a reference, thus improving the relation acquisition efficiency while ensuring the accuracy of relation acquisition.

[0011] According to one embodiment of the present invention, determining the relation vector of the target text data from the plurality of sample relation vectors based on the similarity between the target relation vector and the plurality of sample relation vectors includes: determining the relation vector with the highest similarity to the target relation vector from the plurality of sample relation vectors, and using the relation vector with the highest similarity as the relation vector of the target text data. By determining the relation vector with the highest similarity to the target relation vector from the plurality of sample relation vectors and using the relation vector with the highest similarity as the relation vector of the target text data, the determination of the relation vector in the target text data is achieved.

[0012] According to an embodiment of the present invention, the method further includes: performing entity information annotation processing on the text data in the initial training dataset according to text processing rules, and using the initial training dataset with entity information annotation processing as the training dataset; the initial training dataset includes a sample set of a general domain. Annotating the entity information in the training dataset using text processing rules enhances the entity information in the text data of the training dataset, making it easier for the trained model to determine the relationships between entities in the text data.

[0013] According to one embodiment of the present invention, inputting target text data into a basis model to obtain a target relation vector of the target text data output by the basis model includes: performing entity information annotation processing on the target text data according to text processing rules to obtain entity information-annotated target text data; and inputting the entity information-annotated target text data into the basis model to obtain the target relation vector of the target text data output by the basis model. Annotating the entity information in the target text data using text processing rules enhances the entity information in the target text data, making it easier to determine the relationships between entities in the target text data using the basis model, thereby improving the recognition rate of relationships in the target text data.

[0014] According to one embodiment of the present invention, inputting multiple sample text data into the basis model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the basis model includes: performing entity information annotation processing on the multiple sample text data according to text processing rules to obtain multiple sample text data with entity information annotation; inputting the multiple sample text data with entity information annotation into the basis model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the basis model. Annotating the entity information in the multiple sample text data using text processing rules enhances the entity information in the sample text data, making it easier to determine the relationships between entities in the sample text data using the basis model, thereby improving the recognition rate of relationships in the sample text data.

[0015] According to one embodiment of the present invention, the text processing rules include any one of the following: using the same annotation to annotate the beginning and end of each entity in the text data; using different annotations to annotate the beginning and end of each entity in the text data; and using the annotation corresponding to the entity type to annotate the beginning and end of each entity in the text data according to the entity type. By using multiple annotation methods, entity information in the training dataset is annotated, enhancing the entity information in the text data of the training dataset. This makes it easier for the trained model to determine the relationships between entities in the text data, thereby improving the recognition rate of relationships in the target text data.

[0016] According to one embodiment of the present invention, when the base model is a BERT language model, the step of inputting the target text data into the base model to obtain the target relation vector of the target text data output by the base model includes: using annotations to annotate the beginning and end of each entity in the target text data, and inputting the annotated target text data into the BERT model to obtain the classification vector and word vector of the target text data output by the BERT model; concatenating the classification vector and the entity vectors in the word vectors, and using the concatenated vector as the target relation vector; or, concatenating the beginning and end annotation vectors of each entity vector in the word vectors, and using the concatenated vector as the target relation vector. By annotating the beginning and end of each entity in the target text data, inputting the annotated target text data into the BERT model, and obtaining the target relation vector based on the classification vector and word vector of the target text data output by the BERT model, the target relation vector is determined, providing a foundation for the subsequent determination of the relationship of the target text data.

[0017] An electronic device according to a second aspect of the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the text relationship determination method as described above.

[0018] According to a third aspect of the present invention, a non-transitory computer-readable storage medium is provided thereon storing a computer program that, when executed by a processor, implements the text relationship determination method as described above.

[0019] A computer program product according to a fourth aspect of the present invention includes a computer program that, when executed by a processor, implements the text relationship determination method as described above.

[0020] The above-described one or more technical solutions in the embodiments of the present invention have at least one of the following technical effects:

[0021] By inputting the target text data into the base model, the target relation vector of the target text data is obtained. Then, based on the similarity between the target relation vector and multiple sample relation vectors, the relation vector of the target text data is determined from the multiple sample relation vectors. This avoids the direct relation acquisition method of training the model with a large amount of high-quality labeled training data. Only a small amount of sample text data is needed as a reference, which improves the efficiency of relation acquisition while ensuring the accuracy of relation acquisition.

[0022] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 This is a flowchart illustrating the text relationship determination method provided in an embodiment of the present invention;

[0025] Figure 2 This is a schematic diagram of the entity annotation method provided in an embodiment of the present invention;

[0026] Figure 3 This is a schematic diagram of vector processing rules provided in an embodiment of the present invention;

[0027] Figure 4This is a flowchart illustrating the text relationship determination method provided in the embodiments of the present invention;

[0028] Figure 5 This is a schematic diagram of the structure of the text relationship determination device provided in the embodiment of the present invention;

[0029] Figure 6 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation

[0030] The embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and should not be construed as limiting the scope of the invention.

[0031] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0032] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0033] Figure 1 This is a flowchart illustrating the text relationship determination method provided in an embodiment of the present invention. (Refer to...) Figure 1 The text relationship determination method provided in this embodiment of the invention may include:

[0034] Step 110: Input the target text data into the basis model to obtain the target relation vector of the target text data output by the basis model;

[0035] Step 120: Input multiple sample text data into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model;

[0036] Step 130: Determine the relationship vector of the target text data from the plurality of sample relationship vectors based on the similarity between the target relationship vector and the plurality of sample relationship vectors;

[0037] The base model is obtained by training an initial base model based on a training dataset and relation labels corresponding to the training dataset.

[0038] The execution subject of the text relationship determination method provided in this embodiment of the invention can be an electronic device, a component in the electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), or personal computer (PC), etc. This embodiment of the invention does not impose specific limitations.

[0039] The following describes the technical solution of the present invention in detail, taking the method for determining the relationship of text provided in the embodiments of the present invention by a computer as an example.

[0040] It's important to note that text relation determination aims to identify the relationships between given entities within a given text and its entities. For example, given the text "A serves as the chairman of Society B," and given the entities "A" and "Society B," the relation between these two entities can be determined to be "serves as chairman." Relation extraction is a crucial step in text information extraction and a vital step in building knowledge graphs. It holds significant value for subsequent applications of knowledge graphs in semantic search, intelligent dialogue, and recommendation systems.

[0041] In step 110, the target text data is input into the basis model to obtain the target relation vector of the target text data output by the basis model.

[0042] The target text data is any text from which relations are to be extracted. The entities within the target text data are pre-defined. Inputting the target text data into the basis model yields the target relation vector for the given relationships between entities within the target text data.

[0043] For example, if the target text data is: "Location A is the capital of Country B", then the entities "Location A" and "Country B" are given in advance. By inputting the target text data with the given entities into the basis model, the relationship between the entities "Location A" and "Country B" is obtained.

[0044] In step 120, multiple sample data are acquired, and each acquired sample data is input into the basis model to obtain the sample relationship vector corresponding to each sample data output by the basis model.

[0045] Sample text data is used as a reference for target text data. Multiple sample text data are selected and input into the basis model. The resulting sample relation vectors are used as multiple references for the target text data.

[0046] In this model, the entities in the sample text data are also predefined. For example, if the sample text data is: "Location E is the capital of Country F", then the entities "Location E" and "Country F" are predefined. By inputting the sample text data with the given entities into the basis model, the result is the relationship "capital" between the entities "Location E" and "Country F".

[0047] The sample text data is artificially set relative to the target text data. Therefore, the resulting relationship is deterministic after inputting the sample text data into the basis model.

[0048] In step 130, after obtaining the target relation vector and multiple sample relation vectors, the relation vector of the target text data is determined from the multiple sample relation vectors based on the similarity between the target relation vector and each vector in the multiple sample relation vectors.

[0049] After setting up multiple sample text data as needed and obtaining corresponding sample relation vectors based on these data, multiple references to the target text data are obtained. These sample relation vectors contain the vector type of the target relation vector. Using a metric learning method, the relation vector of the target text data is determined from the multiple sample relation vectors based on the similarity between the target relation vector and each vector in the multiple sample relation vectors.

[0050] Optionally, when calculating the similarity between the target relation vector and each vector in the multiple sample relation vectors, the similarity between the target relation vector and each vector in the multiple sample relation vectors can be determined based on the calculation method of cosine similarity.

[0051] For example, multiple sample text data are set up and input into the basis model to obtain corresponding sample relation vectors. These sample relation vectors can be "exercise," "capital," "birth," and "study." The target text data is: "Location A is the capital of country B." The target text data entities "Location A" and "Country B" are given in advance. By inputting the target text data with given entities into the basis model, the relation "capital" between entities "Location A" and "Country B" is obtained. By calculating the similarity between the target relation vector "capital" and each of the multiple sample relation vectors, it can be determined that "capital" is most similar to "capital" in the sample relation vectors. Therefore, "capital" in the sample relation can be identified as the relation of the target text data.

[0052] Understandably, since the sample text data is used as a reference for the target text data, determining the relationships within the target text data only requires a small amount of sample text data, based on the extraction needs. This avoids the need to train a model with a large amount of high-quality labeled training data to directly obtain the relationships, thus reducing costs.

[0053] For target text, after determining the relation vector of the target text data, the relationship of a given entity in the target text can be determined based on the relation vector of the target text.

[0054] Optionally, the base model can be a BERT (Bidirectional Encoder Representations from Transformers) model, trained on a publicly available training dataset labeled with relation tags. Using a base model, the target relation vector can be quickly obtained from the target text data.

[0055] Understandably, the approach involves quickly obtaining the target relation vector through a basis model, and then determining the relation vector of the target text data from the multiple sample relation vectors based on the similarity between the target relation vector and these sample relation vectors. This improves the efficiency of relation acquisition while ensuring accuracy.

[0056] The text relation determination method provided in this invention obtains the target relation vector of the target text data by inputting the target text data into a base model, and then determines the relation vector of the target text data from the multiple sample relation vectors based on the similarity between the target relation vector and multiple sample relation vectors. This avoids the direct relation acquisition method of training a model with a large amount of high-quality labeled training data, requiring only a small amount of sample text data as a reference, thus improving the efficiency of relation acquisition while ensuring accuracy.

[0057] In one embodiment, determining the relation vector of the target text data from the plurality of sample relation vectors based on the similarity between the target relation vector and the plurality of sample relation vectors includes: determining the relation vector with the highest similarity to the target relation vector from the plurality of sample relation vectors, and using the relation vector with the highest similarity as the relation vector of the target text data.

[0058] After determining multiple sample relation vectors of multiple sample text data, the similarity between the target relation vector and each of the multiple sample text vectors is calculated, and the vector with the highest similarity to the target relation vector among the sample text vectors is determined as the relation vector of the target text data.

[0059] For example, multiple sample text data are set up and input into the basis model to obtain corresponding relation vectors for the sample text data. These relation vectors can be "exercise," "capital," "birth," and "study." The target text data is: "Location A is the capital of country B." The target text data entities "Location A" and "Country B" are given in advance. By inputting the target text data with given entities into the basis model, the target relation vector is "capital." By calculating the similarity between the target relation vector "capital" and the multiple sample relation vectors, it can be determined that the sample relation vector "capital" has the highest similarity to the target relation vector "capital." Therefore, "capital" in the sample relation vectors can be identified as the relation vector for the target text data.

[0060] In this application, the multiple sample text data include sample data with various text relationship types, and the text relationship types corresponding to the target text data to be processed can be matched in the multiple sample text data. For example, if the text relationship types included in the multiple sample text data are "capital" and "function", and the text relationship type corresponding to the target text data is "capital", then the text relationship type "capital" in the multiple sample text data is the text relationship type "capital" with the highest similarity to the text relationship type "capital" in the target text.

[0061] In some embodiments, the text relationship types that should be included in multiple sample text data can be determined based on the text relationship types of the target text data to be identified. In this way, when identifying the text relationships of the target text data, the corresponding type of text relationship can be matched in the corresponding multiple sample text data, and the text relationship with the highest similarity is also the most accurate relationship.

[0062] In some embodiments, if a text relationship similar to the target text data cannot be matched in multiple sample text data, the text relationship types included in the multiple sample text data can be adjusted. For example, sample data that matches the text relationship type of the target text can be added. This allows the target text data to be accurately and quickly matched in multiple sample text data when the target text data of the corresponding text relationship type is identified again in the subsequent identification.

[0063] In some embodiments, the text relationship types included in the multiple sample text data are all different. This can be understood as the same text relationship type existing only once in the multiple sample text data. This makes the multiple sample text data more concise, with a smaller data volume and no redundancy, enabling the determination of the text relationships of the target text data in this field through the processing of a small sample of sample data. In some embodiments, the multiple sample text data and the target text data belong to the same field, for example, they can all belong to proprietary data in the home appliance field.

[0064] The text relation determination method provided in this embodiment of the invention determines the relation vector in the target text data by selecting the relation vector with the highest similarity to the target relation vector from multiple sample relation vectors and using the relation vector with the highest similarity as the relation vector of the target text data.

[0065] In one embodiment, training the initial base model further includes: performing entity information annotation processing on the text data in the initial training dataset according to text processing rules, and using the initial training dataset with entity information annotation processing as the training dataset; the initial training dataset includes a sample set of a general domain.

[0066] Understandably, the entities in the text data of the training dataset are pre-defined. Based on text processing rules, entity information is annotated on the text data in the initial training dataset to obtain the entity-annotated training dataset. Annotating the entity information in the text data of the training dataset enhances the entity information, making it easier to determine the relationships between entities in the text data.

[0067] In this context, the general-domain sample set refers to the sample set used to train the initial base model based on a publicly available general-domain training dataset. There is no need to create a dedicated sample set for model training; simply using the already publicly available general-domain sample set is sufficient.

[0068] The text relationship determination method provided in this invention uses text processing rules to annotate entity information in the training dataset, thereby enhancing the entity information in the text data of the training dataset and making it easier for the trained model to determine the relationships between entities in the text data.

[0069] In one embodiment, inputting target text data into a base model to obtain a target relation vector of the target text data output by the base model includes: performing entity information annotation processing on the target text data according to text processing rules to obtain entity information-annotated target text data; and inputting the entity information-annotated target text data into the base model to obtain a target relation vector of the target text data output by the base model.

[0070] After annotating the text data in the training dataset with entity information, the annotated training dataset is used to train an initial basis model, resulting in the basis model. Before inputting the target text data into the annotated and trained basis model, entity information is annotated on the target text data according to text processing rules, resulting in entity-annotated target text data. The entity-annotated target text data is then input into the basis model, yielding the target relation vector of the target text data output by the basis model.

[0071] Understandably, the training data for the basis model is labeled. By labeling the target text data and then inputting it into the labeled training dataset to train the basis model, the recognition rate of relation identification can be improved.

[0072] The text relationship determination method provided in this invention annotates entity information in target text data using text processing rules, thereby enhancing the entity information in the target text data. This makes it easier to determine the relationships between entities in the target text data using a basis model, and improves the relationship recognition rate in the target text data.

[0073] In one embodiment, inputting multiple sample text data into the base model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the base model includes: performing entity information annotation processing on the multiple sample text data according to text processing rules to obtain multiple sample text data with entity information annotation processing; inputting the multiple sample text data with entity information annotation processing into the base model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the base model.

[0074] After annotating the text data in the training dataset with entity information, the annotated training dataset is used to train an initial basis model, resulting in the basis model. Before inputting multiple sample text data into the annotated and trained basis model, entity information is annotated on the multiple sample text data according to text processing rules, resulting in multiple annotated sample text data. These annotated sample text data are then input into the basis model to obtain multiple sample relation vectors corresponding to the multiple sample text data output by the basis model.

[0075] Understandably, the training data for the basis model is labeled. By labeling multiple sample text data and then inputting them into the labeled training dataset to train the basis model, the recognition rate of relation identification can be improved.

[0076] The text relationship determination method provided in this invention annotates entity information in multiple sample text data using text processing rules, thereby enhancing the entity information in the sample text data. This makes it easier to determine the relationships between entities in the sample text data using a basis model, and improves the relationship recognition rate in the sample text data.

[0077] In one embodiment, the text processing rule includes any one of the following: using the same annotation to annotate the beginning and end of each entity in the text data; using different annotations to annotate the beginning and end of each entity in the text data; or using the annotation corresponding to the entity type to annotate the beginning and end of each entity in the text data according to the entity type.

[0078] like Figure 2 The entity annotation method provided in this embodiment of the invention is illustrated in the diagram. Entities in text data are annotated, and there are three specific annotation methods.

[0079] Method 1 uses the same tag to annotate the beginning and end of each entity in the text data. Using the same tag means that for multiple entities in the text data, each entity is labeled in the same way. For example, the target text data is: "A certain place is the capital of a certain country," where entity 1 is "a certain place" and entity 2 is "a certain country." Using the same tag "e" and " / e" to annotate the beginning and end of each entity in the target text data results in: "e a certain place / e is e a certain country / e the capital of e".

[0080] Method 2 allows the use of different taggers to annotate the beginning and end of each entity in the text data. Using different taggers means that for multiple entities in the text data, each entity uses a different tagger. For example, the target text data is: "A certain place is the capital of a certain country," where the entities are "a certain place" and "a certain country." Using different taggers "s" and " / s," and "0" and " / 0" to annotate the beginning and end of each entity in the target text data, we get: "s a certain place / s is 0 a certain country / 0 the capital of 0".

[0081] Method 3 allows you to annotate the beginning and end of each entity in the text data using the corresponding entity type annotation. For example, if the target text data is: "A certain place is the capital of a certain country," where the entity type of "a certain place" is city, and the entity type of "a certain country" is country, annotating the beginning and end of each entity yields: <e:city> a certain place< / e:city> yes <s:country> A certain country< / s:country> "the capital."

[0082] The text relationship determination method provided in this invention uses multiple annotation methods to annotate entity information in the training dataset, enhancing the entity information in the text data of the training dataset. This makes it easier for the trained model to determine the relationships between entities in the text data and improves the recognition rate of relationships in the target text data.

[0083] In one embodiment, when the base model is a BERT language model, the step of inputting the target text data into the base model to obtain the target relation vector of the target text data output by the base model includes: using annotations to annotate the beginning and end of each entity in the target text data, and inputting the annotated target text data into the BERT model to obtain the classification vector and the word vector of the target text data output by the BERT model; concatenating the classification vector and the entity vectors in the word vectors, and using the concatenated vector as the target relation vector; or, concatenating the beginning annotation vectors of each entity vector in the word vectors, and using the concatenated vector as the target relation vector.

[0084] With the base model being the BERT language model, the first step is to label the beginning and end of each entity in each text data in the training dataset using annotations, thus labeling the relationships between the text data in the labeled training dataset. The initial BERT model is then trained using this labeled training dataset.

[0085] Using annotations, the beginning and end of each entity in the target text data are labeled. This labeled target text data is then input into a trained BERT model, which outputs a CLS (Classification Vector) vector and character vectors for the target text data. The CLS vector serves as the semantic representation of the entire target text data. In conventional techniques, the CLS vector is typically used directly as the relation vector for the text data.

[0086] like Figure 3 As shown in the schematic diagram of the vector processing rules provided in this embodiment of the invention, the target text data can be: "A certain place is the capital of a certain country", where entity 1 is "a certain place" and entity 2 is "a certain country". Using the same annotations "e" and " / e", the beginning and end of each entity in the target text data are annotated, resulting in: "e a certain place / e is e a certain country / e the capital of e". Inputting the target text data into the BERT model, the target relation vector can be obtained through two vector processing rules.

[0087] Method 1 involves labeling and training the BERT model, then concatenating the CLS vector output by the model with the entity vectors from the word vectors, and using the concatenated vector as the target relation vector. This concatenated target relation vector better reflects the relationships between entities in the target text data compared to directly using the CLS vector.

[0088] Method 2 involves annotating and training the BERT model, then concatenating the leading label vectors of each entity vector in the model's output word vectors (i.e., concatenating the leading label vectors of entity 1 and entity 2), and using the concatenated vector as the target relation vector. This concatenated target relation vector better reflects the relationships between entities in the target text data compared to directly using the CLS vector.

[0089] The text relationship determination method provided in this invention involves labeling the beginning and end of each entity in the target text data, inputting the labeled target text data into a BERT model, and obtaining the target relationship vector based on the classification vector and word vector of the target text data output by the BERT model. This method provides a foundation for the subsequent determination of the relationship between the target text data.

[0090] The following is a flowchart illustrating a text relationship determination method provided in an embodiment of the present invention. Figure 4 For example, the technical solution provided by the embodiments of the present invention is illustrated below:

[0091] Baseline Model Training Phase: Using a publicly available training dataset, the text data in the training dataset is processed according to text processing rules, and then the initial BERT language model is trained to obtain the baseline model. The text processing rules include any of the following: using the same tag to label the beginning and end of each entity in the text data; using different taggers to label the beginning and end of each entity in the text data; or using the tagger corresponding to the entity type to label the beginning and end of each entity in the text data.

[0092] Multiple Sample Relation Vector Acquisition Stage: Multiple sample text data are processed according to text processing rules and then input into the basis model. The vectors output by the basis model are processed by vector rules to obtain multiple sample relation vectors. The vector rules include any of the following: concatenating the classification vector output by the basis model and the entity vectors in the word vectors, and using the concatenated vector as the sample relation vector; or concatenating the first-end label vectors of the entity vectors in the word vectors output by the basis model, and using the concatenated vector as the sample relation vector.

[0093] Target relation vector acquisition stage: For the target text data, after being processed by the same text processing rules, it is input into the trained base model. The vector output by the base model is processed by the same vector rules to obtain the target relation vector. The similarity is calculated with multiple sample relation vectors, and the relation vector that is most similar among the multiple sample relation vectors is taken as the relation vector of the target text data.

[0094] This invention also provides a device for determining the relationship of text. Figure 5 A schematic diagram of the structure of the text relationship determination device provided in the embodiments of the present invention, such as... Figure 5 As shown, the device includes:

[0095] The target relation vector acquisition module 510 is used to input the target text data into the basis model and obtain the target relation vector of the target text data output by the basis model;

[0096] The sample relation vector acquisition module 520 is used to input multiple sample text data into the basis model and obtain multiple sample relation vectors corresponding to the multiple sample text data output by the basis model;

[0097] The relationship determination module 530 is used to determine the relationship vector of the target text data from the plurality of sample relationship vectors based on the similarity between the target relationship vector and the plurality of sample relationship vectors;

[0098] The base model is obtained by training an initial base model based on a training dataset and relation labels corresponding to the training dataset.

[0099] The text relation determination device provided in this invention obtains the target relation vector of the target text data by inputting the target text data into a base model, and then determines the relation vector of the target text data from the multiple sample relation vectors based on the similarity between the target relation vector and multiple sample relation vectors. This avoids the direct relation acquisition method of training a model with a large amount of high-quality labeled training data, requiring only a small amount of sample text data as a reference, thus improving the relation acquisition efficiency while ensuring the accuracy of relation acquisition.

[0100] In one embodiment, the relationship determination module 530 is specifically used for:

[0101] Determining the relation vector of the target text data from the plurality of sample relation vectors based on the similarity between the target relation vector and the plurality of sample relation vectors includes:

[0102] From the plurality of sample relation vectors, determine the relation vector with the highest similarity to the target relation vector, and use the relation vector with the highest similarity as the relation vector of the target text data.

[0103] In one embodiment, the target relation vector acquisition module 510 is specifically used for:

[0104] Training the initial basis model further includes:

[0105] According to the text processing rules, entity information annotation is performed on the text data in the initial training dataset, and the initial training dataset with entity information annotation is used as the training dataset; the initial training dataset includes a sample set of general domains.

[0106] In one embodiment, the target relation vector acquisition module 510 is further configured to:

[0107] Inputting the target text data into the basis model yields the target relation vector of the target text data output by the basis model, including:

[0108] According to the text processing rules, the target text data is subjected to entity information annotation processing to obtain the target text data with entity information annotation processing.

[0109] The target text data, after being annotated with the entity information, is input into the base model to obtain the target relation vector of the target text data output by the base model.

[0110] In one embodiment, the target relation vector acquisition module 510 is further configured to:

[0111] Multiple sample text data are input into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model, including:

[0112] According to the text processing rules, entity information annotation processing is performed on the multiple sample text data to obtain multiple sample text data with entity information annotation processing;

[0113] The entity information annotation process is applied to multiple sample text data, which are then input into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model.

[0114] In one embodiment, the target relation vector acquisition module 510 is further configured to:

[0115] Text processing rules, including any of the following:

[0116] Use the same annotation to annotate the beginning and end of each entity in the text data;

[0117] Use different annotations to annotate the beginning and end of each entity in the text data;

[0118] Based on the type of entity, the beginning and end of each entity in the text data are labeled using the label corresponding to the entity type.

[0119] In one embodiment, the target relation vector acquisition module 510 is further configured to:

[0120] When the base model is a BERT language model, the step of inputting the target text data into the base model to obtain the target relation vector of the target text data output by the base model includes:

[0121] Using annotations, the beginning and end of each entity in the target text data are labeled, and the labeled target text data is input into the BERT model to obtain the classification vector and word vector of the target text data output by the BERT model.

[0122] The classification vector and the entity vectors in the word vector are concatenated, and the concatenated vector is used as the target relation vector.

[0123] Alternatively, the first-end label vectors of each entity vector in the word vector can be concatenated, and the concatenated vector can be used as the target relation vector.

[0124] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communications interface 620, and the memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute the following methods:

[0125] Input the target text data into the basis model to obtain the target relation vector of the target text data output by the basis model;

[0126] Multiple sample text data are input into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model;

[0127] Based on the similarity between the target relation vector and the plurality of sample relation vectors, the relation vector of the target text data is determined from the plurality of sample relation vectors;

[0128] The base model is obtained by training an initial base model based on a training dataset and relation labels corresponding to the training dataset.

[0129] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0130] Furthermore, embodiments of the present invention disclose a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, and when the program instructions are executed by a computer, the computer is able to execute the text relationship determination method provided in the above-described method embodiments, for example including:

[0131] Input the target text data into the basis model to obtain the target relation vector of the target text data output by the basis model;

[0132] Multiple sample text data are input into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model;

[0133] Based on the similarity between the target relation vector and the plurality of sample relation vectors, the relation vector of the target text data is determined from the plurality of sample relation vectors;

[0134] The base model is obtained by training an initial base model based on a training dataset and relation labels corresponding to the training dataset.

[0135] On the other hand, embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the text relationship determination method provided in the above embodiments, for example including:

[0136] Input the target text data into the basis model to obtain the target relation vector of the target text data output by the basis model;

[0137] Multiple sample text data are input into the basis model to obtain multiple sample relationship vectors corresponding to the multiple sample text data output by the basis model;

[0138] Based on the similarity between the target relation vector and the plurality of sample relation vectors, the relation vector of the target text data is determined from the plurality of sample relation vectors;

[0139] The base model is obtained by training an initial base model based on a training dataset and relation labels corresponding to the training dataset.

[0140] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0141] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0142] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

[0143] The above embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. Although the invention has been described in detail with reference to the embodiments, those skilled in the art should understand that various combinations, modifications, or equivalent substitutions of the technical solutions of the invention do not depart from the spirit and scope of the invention and should be covered within the scope of the claims of the invention.

Claims

1. A method of determining relationships of texts, characterized by, The method comprises the following steps: inputting target text data into a base model to obtain a target relation vector of the target text data output by the base model; inputting a plurality of sample text data into the base model to obtain a plurality of sample relation vectors corresponding to the plurality of sample text data output by the base model; the plurality of sample text data are used as references of the target text data; from the plurality of sample relation vectors, a relation vector with the highest similarity to the target relation vector is determined, and the relation vector with the highest similarity is used as the relation vector of the target text data; the base model is obtained by training an initial base model based on a training data set and relation labels corresponding to the training data set; according to a text processing rule, entity information in the text data in an initial training data set is marked, and the initial training data set after the entity information marking is used as the training data set; the initial training data set comprises a sample set in a general field; inputting target text data into a base model to obtain a target relation vector of the target text data output by the base model, comprising: using a marking symbol to mark the beginning and end of each entity in the target text data, and inputting the marked target text data into the base model to obtain a classification vector of the target text data output by the base model and a word vector of the target text data; splicing each entity vector in the classification vector and the word vector, and using the spliced vector as the target relation vector; or, splicing a head marking symbol vector of each entity vector in the word vector, and using the spliced vector as the target relation vector.

2. The method of claim 1, wherein, the method comprises the following steps: according to a text processing rule, entity information in the target text data is marked to obtain the target text data after the entity information marking; inputting the target text data after the entity information marking into the base model to obtain a target relation vector of the target text data output by the base model.

3. The method of claim 1, wherein, the method comprises the following steps: according to a text processing rule, entity information in the plurality of sample text data is marked to obtain a plurality of sample text data after the entity information marking; inputting the plurality of sample text data after the entity information marking into the base model to obtain a plurality of sample relation vectors corresponding to the plurality of sample text data output by the base model.

4. The method of claim 2 or 3, wherein the text processing rule comprises any one of the following: using the same marking symbol to mark the beginning and end of each entity in the text data; using different marking symbols to mark the beginning and end of each entity in the text data; according to the type of the entity, using a marking symbol corresponding to the type of the entity to mark the beginning and end of each entity in the text data.

5. The method of claim 1, wherein, In the case of the base model being a BERT language model, the inputting of the target text data into the base model to obtain a target relation vector of the target text data output by the base model comprises: using a label to label the head and tail of each entity in the target text data, and inputting the labeled target text data into the BERT model to obtain a classification vector of the target text data output by the BERT model and a word vector of the target text data; splicing each entity vector in the classification vector and the word vector, and taking the spliced vector as the target relation vector; or, splicing a head label vector of each entity vector in the word vector, and taking the spliced vector as the target relation vector.

6. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the text relation determination method according to any one of claims 1 to 5.

7. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the text relation determination method according to any one of claims 1 to 5.

8. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the text relation determination method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Knowledge graph-based text comparison method, apparatus and device, and storage medium

    CN111897970A

  • Relationship extraction method and device

    CN114386411A