Text similarity calculation method and device, storage medium, and electronic device

By acquiring and processing knowledge graph data and calculating text similarity with attention model, the problem of low accuracy caused by synonyms and polysynonyms in the prior art is solved, and the accuracy and user experience of text similarity calculation are improved.

CN110489751BActive Publication Date: 2024-12-31TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910746144.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-08-13
Publication Date
2024-12-31
Estimated Expiration
2039-11-04

AI Technical Summary

Technical Problem

Existing text similarity calculation methods such as Word2vec and Doc2vec have low accuracy when dealing with synonyms and polysynonyms, which affects the user experience.

Method used

By obtaining the knowledge graph data of the target text, converting it into a relational feature vector, and combining the attention model, the text vector is calculated to determine the text similarity.

Benefits of technology

It effectively enhances the ability to distinguish different words, improves the accuracy of text similarity calculation, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110489751B_ABST
    Figure CN110489751B_ABST
Patent Text Reader

Abstract

The present disclosure provides a text similarity calculation method and device, electronic device, and storage medium; it relates to the field of computer technology. The text similarity calculation method includes: obtaining a target text and knowledge graph data corresponding to the target text, and converting the knowledge graph data to determine the relationship feature vector corresponding to the knowledge graph data; performing word segmentation processing on the target text to determine the original sentence sequence corresponding to the target text; determining the first text vector corresponding to the original sentence sequence through the relationship feature vector and a pre-established attention model; obtaining the second text vector of a preset text, and calculating the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text. The present disclosure can improve the representation effect of text content, thereby improving the accuracy of calculating text similarity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a text similarity calculation method, a text similarity calculation device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In the field of game content, calculating the similarity of articles is a basic requirement. The similarity of articles needs to be calculated in each module of content processing. For example, in article content recommendation, the similarity of articles needs to be roughly sorted.

[0003] However, in existing solutions for calculating article similarity, such as the article similarity method based on Word2vec or Doc2vec, articles may have synonyms or polysemy problems. For example, in an article about a certain game, different users often use words such as "Lu Ban No. 7", "short legs" and "little Lu Ban" to represent the game character "Lu Ban No. 7", which will result in low accuracy in calculating article similarity and affect the user experience.

[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0005] The purpose of the present disclosure is to provide a text similarity calculation method, a text similarity calculation device, an electronic device and a computer-readable storage medium, thereby overcoming the problems caused by the limitations and defects of the related technology to a certain extent.

[0006] According to a first aspect of the present disclosure, a text similarity calculation method is provided, comprising:

[0007] Obtaining a target text and knowledge graph data corresponding to the target text, and converting the knowledge graph data to determine a relational feature vector corresponding to the knowledge graph data;

[0008] Performing word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text;

[0009] Determine a first text vector corresponding to the original sentence sequence by using the relationship feature vector and a pre-established attention model;

[0010] A second text vector of a preset text is obtained, and the first text vector and the second text vector are calculated according to a preset algorithm to determine the similarity between the target text and the preset text.

[0011] In an exemplary embodiment of the present disclosure, the attention model includes an encoder and a decoder;

[0012] The determining the first text vector corresponding to the original sentence sequence by using the relationship feature vector and the pre-established attention model comprises:

[0013] Based on the relation feature vector, encoding the original sentence sequence through a gated recurrent unit in the encoder to generate an intermediate vector;

[0014] The first text vector is determined by using the intermediate vector and a preset attention mechanism.

[0015] In an exemplary embodiment of the present disclosure, determining the first text vector by using the intermediate vector and a preset attention mechanism includes:

[0016] Obtaining historical information generated in the encoder, and determining a target sentence sequence through the historical information, the intermediate vector, and the attention mechanism;

[0017] The difference between the target sentence sequence and the original sentence sequence is used as a loss function, and the loss function is calculated by a gradient descent method to determine the first text vector.

[0018] In an exemplary embodiment of the present disclosure, converting the knowledge graph data to determine the relationship feature vector corresponding to the knowledge graph data includes:

[0019] Obtaining a relation array in the knowledge graph data; wherein the relation array includes a subject vector, a predicate vector, and an object vector;

[0020] Based on the pre-trained translation model, the relational feature vector corresponding to the knowledge graph data is determined according to the subject vector, the predicate vector and the object vector.

[0021] In an exemplary embodiment of the present disclosure, before obtaining the target text and the knowledge graph data corresponding to the target text, the method further includes:

[0022] Constructing an ontology model corresponding to the target text, and acquiring key data corresponding to the target text at a target location through a crawler tool;

[0023] Fill the key data into the ontology model to generate the knowledge graph data corresponding to the target text and save the knowledge graph data to the target database.

[0024] In an exemplary embodiment of the present disclosure, after filling the key data into the ontology model to generate the knowledge graph data corresponding to the target text and saving the knowledge graph data to the target database, the method further includes:

[0025] Periodically acquiring new key data corresponding to the target text at the target location by the crawler tool;

[0026] The knowledge graph data in the target database is updated according to the new key data.

[0027] In an exemplary embodiment of the present disclosure, calculating the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text includes:

[0028] The first text vector and the second text vector are calculated by cosine similarity to determine the similarity between the target text and the preset text.

[0029] According to a second aspect of the present disclosure, a text similarity calculation device is provided, comprising:

[0030] A relationship feature vector determination unit, used to obtain a target text and knowledge graph data corresponding to the target text, and perform conversion processing on the knowledge graph data to determine a relationship feature vector corresponding to the knowledge graph data;

[0031] A sentence sequence determination unit, used to perform word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text;

[0032] A text vector determination unit, configured to determine a first text vector corresponding to the original sentence sequence through the relationship feature vector and a pre-established attention model;

[0033] The similarity calculation unit is used to obtain a second text vector of a preset text, and calculate the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text.

[0034] In an exemplary embodiment of the present disclosure, the attention model includes an encoder and a decoder; the similarity calculation unit also includes:

[0035] An intermediate vector generating unit, configured to encode the original sentence sequence through a gated recurrent unit in the encoder based on the relation feature vector to generate an intermediate vector;

[0036] The first text vector determining unit is used to determine the first text vector through the intermediate vector and a preset attention mechanism.

[0037] In an exemplary embodiment of the present disclosure, the first text vector determining unit includes:

[0038] Obtaining historical information generated in the encoder, and determining a target sentence sequence through the historical information, the intermediate vector, and the attention mechanism;

[0039] The difference between the target sentence sequence and the original sentence sequence is used as a loss function, and the loss function is calculated by a gradient descent method to determine the first text vector.

[0040] In an exemplary embodiment of the present disclosure, the relationship feature vector determining unit includes:

[0041] Obtaining a relation array in the knowledge graph data; wherein the relation array includes a subject vector, a predicate vector, and an object vector;

[0042] Based on the pre-trained translation model, the relational feature vector corresponding to the knowledge graph data is determined according to the subject vector, the predicate vector and the object vector.

[0043] In an exemplary embodiment of the present disclosure, the text similarity calculation device further includes a knowledge graph data generation unit, and the knowledge graph data generation unit includes:

[0044] Constructing an ontology model corresponding to the target text, and acquiring key data corresponding to the target text at a target location through a crawler tool;

[0045] Fill the key data into the ontology model to generate the knowledge graph data corresponding to the target text and save the knowledge graph data to the target database.

[0046] In an exemplary embodiment of the present disclosure, the text similarity calculation device further includes a knowledge graph data updating unit, and the knowledge graph data updating unit includes:

[0047] Periodically acquiring new key data corresponding to the target text at the target location by the crawler tool;

[0048] The knowledge graph data in the target database is updated according to the new key data.

[0049] In an exemplary embodiment of the present disclosure, the similarity calculation unit includes:

[0050] The first text vector and the second text vector are calculated by cosine similarity to determine the similarity between the target text and the preset text.

[0051] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the above-mentioned methods by executing the executable instructions.

[0052] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, any one of the methods described above is implemented.

[0053] The exemplary embodiments of the present disclosure may have some or all of the following beneficial effects:

[0054] In a text similarity calculation method provided in an example embodiment of the present disclosure, a target text and corresponding knowledge graph data are obtained, and a relational feature vector corresponding to the knowledge graph data is determined; then the original sentence sequence corresponding to the target text is determined, and the first text vector corresponding to the original sentence sequence is determined through the relational feature vector and a pre-established attention model; the second text vector of the preset text is obtained, and the first text vector and the second text vector are calculated according to a preset algorithm to determine the similarity between the target text and the preset text. On the one hand, by representing entities or concepts and the association relationships corresponding to the entities or concepts through knowledge graph data, and by assisting the calculation of text similarity through knowledge graph data, the ability to distinguish different words can be effectively enhanced, and the accuracy of text similarity calculation can be improved; on the other hand, by using knowledge graph data as auxiliary data and the attention model to effectively extract key words in the text, the representation effect of the text content can be effectively improved, the accuracy of calculating text similarity can be further improved, and the user experience can be improved.

[0055] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.

[0057] Figure 1 A schematic diagram showing an exemplary system architecture of a text similarity calculation method and device to which the embodiments of the present disclosure can be applied;

[0058] Figure 2A schematic diagram showing the structure of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure is shown;

[0059] Figure 3 A schematic diagram schematically shows a method of calculating text similarity by word frequency-inverse document frequency according to an embodiment of the present disclosure;

[0060] Figure 4 A schematic diagram of a flow chart of a text similarity calculation method according to an embodiment of the present disclosure is shown;

[0061] Figure 5 A schematic diagram of the structure of knowledge graph data according to an embodiment of the present disclosure is shown;

[0062] Figure 6 A schematic diagram schematically shows an algorithm framework corresponding to the attention mechanism according to an embodiment of the present disclosure;

[0063] Figure 7 A schematic block diagram of a text similarity calculation device according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0064] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0065] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0066] Figure 1A schematic diagram of a system architecture of an exemplary application environment in which a method and apparatus for calculating text similarity according to an embodiment of the present disclosure can be applied is shown.

[0067] like Figure 1 As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc. The terminal devices 101, 102, 103 may be various electronic devices with display screens, including but not limited to desktop computers, portable computers, smart phones, tablet computers, etc. It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 105 may be a server cluster composed of multiple servers.

[0068] The text similarity calculation method provided in the embodiment of the present disclosure is generally executed by the server 105, and accordingly, the text similarity calculation device is generally set in the server 105. However, it is easy for those skilled in the art to understand that the text similarity calculation method provided in the embodiment of the present disclosure can also be executed by the terminal devices 101, 102, and 103, and accordingly, the text similarity calculation device can also be set in the terminal devices 101, 102, and 103, and this is not particularly limited in the present exemplary embodiment. For example, in an exemplary embodiment, a user can upload multiple text contents to the server 105 through the terminal devices 101, 102, and 103, and the server calculates the similarity of multiple text contents through the text similarity calculation method provided in the embodiment of the present disclosure, and transmits the calculation results to the terminal devices 101, 102, 103, etc.

[0069] Figure 2 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure is shown.

[0070] It should be noted that Figure 2 The computer system 200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0071] like Figure 2As shown, the computer system 200 includes a central processing unit (CPU) 201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 202 or a program loaded from a storage part 208 into a random access memory (RAM) 203. Various programs and data required for system operation are also stored in the RAM 203. The CPU 201, the ROM 202, and the RAM 203 are connected to each other via a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.

[0072] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.

[0073] In particular, according to an embodiment of the present disclosure, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 209, and / or installed from the removable medium 211. When the computer program is executed by the central processing unit (CPU) 201, the various functions defined in the method and apparatus of the present application are executed. In some embodiments, the computer system 200 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0074] It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0075] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0076] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, and the units described may also be arranged in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.

[0077] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being installed in the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the following embodiment. For example, the electronic device may implement the following method. Figure 4 The various steps shown, etc.

[0078] The technical solution of the embodiment of the present disclosure is described in detail below:

[0079] In one technical solution, text similarity is calculated based on the term frequency-inverse document frequency (TF-IDF) algorithm. First, the keywords of the two articles are found according to the TF-IDF algorithm. Here, the TF-IDF algorithm is mainly calculated by the term frequency (TF)*the inverse document frequency (IDF). From the formula, we can know that TF-IDF is proportional to the number of times a word appears in the document and inversely proportional to the number of documents containing the word. Figure 3 Schematically shows a schematic diagram of calculating text similarity by word frequency-inverse document frequency according to an embodiment of the present disclosure, referring to Figure 3 As shown, several keywords (for example, 20) are taken from each article, merged into a set, and the word frequency of each article for the words in the set is calculated (in order to avoid the difference in article length, relative word frequency can be used); then the word frequency vectors of the two articles are generated; finally, the cosine similarity of the two vectors is calculated. The larger the calculated value, the more similar the two articles are.

[0080] There is another technical solution that calculates article similarity based on the Doc2vec algorithm. This solution mainly uses the core idea of ​​the Word2Vec algorithm to add paragraph vectors or sentence vectors during the training process. The paragraph vector or sentence vector is equivalent to the memory unit of the context or the theme of the paragraph or sentence. After training with a large amount of corpus, the vector representation of each article can be obtained, and then the similarity of two articles can be obtained through cosine similarity.

[0081] In actual application scenarios, the above two solutions will have two major problems when calculating article similarity: the synonym problem: there are usually many different words in the article that have the same meaning, such as "Luban No. 7", "short legs" and "Little Luban" to represent the game character "Luban No. 7"; or the polysemy problem: the same word has different meanings in different contexts, such as "apple" in the article contains two meanings: fruit and Apple. This problem will cause the traditional Doc2vec and IF-IDF article similarity calculation methods based on word order to have poor results in actual applications, that is, the accuracy of calculating article similarity is poor.

[0082] The inventors found that introducing some additional auxiliary information as input when solving synonym and polysemy problems can effectively improve the accuracy of article similarity calculation. The knowledge graph as an auxiliary dictionary can accurately describe the description of objects or concepts, and can effectively enhance the ability to distinguish different words. In addition, the attention mechanism based on encoder and decoder can effectively extract the key words of the article, thereby effectively improving the representation effect of the article and further improving the accuracy of calculating similarity.

[0083] Based on one or more of the above problems, this exemplary embodiment provides a text similarity calculation method. The text similarity calculation method can be applied to the above server 105, and can also be applied to one or more of the above terminal devices 101, 102, 103. This exemplary embodiment does not specifically limit this, and the following takes the terminal executing the method as an example for description. Figure 4 The flowchart of the text similarity calculation method according to an embodiment of the present disclosure is schematically shown. Figure 4 As shown, the text similarity calculation method may include the following steps S410 to S440:

[0084] Step S410: obtaining a target text and knowledge graph data corresponding to the target text, and performing conversion processing on the knowledge graph data to determine a relational feature vector corresponding to the knowledge graph data;

[0085] Step S420: performing word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text;

[0086] Step S430, determining a first text vector corresponding to the original sentence sequence by using the relationship feature vector and a pre-established attention model;

[0087] Step S440: Obtain a second text vector of a preset text, and calculate the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text.

[0088] In the text similarity calculation method provided in this example implementation, on the one hand, entities or concepts and the corresponding relationships between entities or concepts are represented by knowledge graph data, and the knowledge graph data is used to assist in the calculation of text similarity, which can effectively enhance the ability to distinguish different words and improve the accuracy of text similarity calculation; on the other hand, knowledge graph data is used as auxiliary data, and the attention model can be used to effectively extract key words in the text, thereby effectively improving the representation effect of the text content, further improving the accuracy of calculating text similarity, and enhancing the user experience.

[0089] Next, the above steps of this exemplary embodiment are described in more detail.

[0090] In step S410, a target text and knowledge graph data corresponding to the target text are obtained, and the knowledge graph data is converted to determine a relational feature vector corresponding to the knowledge graph data.

[0091] In an example embodiment of the present disclosure, the target text may refer to a text selected by a user from a plurality of preset texts for which text similarity calculation is required. Knowledge graph data may refer to a dictionary or model used to describe various entities or concepts existing in the real world, as well as the relationship between entities or concepts, such as reference Figure 5 As shown, knowledge graph data can be Figure 5The game knowledge graph shown in the figure is, of course, only a schematic illustration, and this example embodiment does not make special restrictions on this. Among them, each entity (which may refer to a named entity in the game, including game character names, skin names and other unique entities in the game) or concept is identified by a globally unique ID (such as "Lu Ban No. 7"), and each attribute value pair (such as "Lu Ban No. 7" and "Skill 1") is used to characterize the intrinsic attributes of the entity, and the relationship (such as "Has_Skill") is used to connect two entities and characterize the association of attribute value pairs. Knowledge graph data can integrate multiple data sources to enrich data semantic information, and can provide services to users in combination with implicit information obtained by reasoning. Through knowledge graph data, rich semantic associations between entities can be portrayed, which can not only expand the information around a specific game, but also strengthen the association of knowledge such as game characters and events. Therefore, knowledge graph data can provide more accurate auxiliary information for text similarity calculation. The conversion process may refer to converting high-dimensional, heterogeneous, and visualized knowledge graph data into a low-dimensional feature vector representation. For example, the conversion process may be a pre-trained encoder or a pre-trained translation model. Of course, this is only a schematic illustration, and this example embodiment is not limited to this. The relational feature vector may refer to a low-dimensional feature vector obtained by converting the knowledge graph data. The knowledge graph data is represented by the relational feature vector, so that the terminal or server can use or process the knowledge graph data.

[0092] Specifically, the terminal obtains the relationship array in the knowledge graph data; based on the pre-trained translation model, the relationship feature vector corresponding to the knowledge graph data is determined according to the subject vector, the predicate vector, and the object vector. The relationship array may refer to an array of attribute association relationships that represent entities or concepts in the knowledge graph data. For example, Figure 5 As shown, the relationship array can be the attribute association relationship in the knowledge graph data (role identifier 501 "role 1", association relationship 502 "Recom_Equip", and association content 503 "equipment 5"). Of course, this is only a schematic illustration and should not cause any special limitation to this exemplary embodiment. The relationship data may include a subject vector, a predicate vector, and an object vector. For example, Figure 5As shown, the subject vector can be the role identifier 501 "Role 1" in the relationship array (role identifier 501 "Role 1", association relationship 502 "Recom_Equip", associated content 503 "Equipment 5"), the predicate vector can be the association relationship 502 "Recom_Equip" in the relationship array (role identifier 501 "Role 1", association relationship 502 "Recom_Equip", associated content 503 "Equipment 5"), and the object vector can be the associated content 503 "Equipment 5" in the relationship array (role identifier 501 "Role 1", association relationship 502 "Recom_Equip", associated content 503 "Equipment 5"). Of course, this is only a schematic illustration, and the present example embodiment is not limited to this. First, the relationship array in the knowledge graph data is extracted, and then the subject vector, predicate vector and object vector in the relationship array are converted into vector representation to obtain the relationship feature vector. This can not only reduce the amount of calculation when converting knowledge graph data and improve the performance of the system, but also the generated relationship feature vector contains the sentence structure of subject, predicate and object, which can further ensure the accuracy when calculating text similarity.

[0093] Optionally, before converting the knowledge graph data, it is necessary to construct the knowledge graph data corresponding to the target text. For example, assuming that the target text is a text related to the field of games, then construct the game knowledge graph data; assuming that the target text is a text related to the field of plants and animals, then construct the plant and animal knowledge graph data. This example embodiment does not specifically limit this. The terminal constructs an ontology model corresponding to the target text, and obtains the key data corresponding to the target text at the target location through a crawler tool; fills the key data into the ontology model to generate the knowledge graph data corresponding to the target text and saves the knowledge graph data to the target database. An ontology model (Ontology) may refer to a model that systematically describes objective things in the world. For example, continue to refer to Figure 5 As shown, the ontology model can be Figure 5The model or framework of the game field shown in the figure can obtain the knowledge graph data corresponding to different role names by filling the content of the ontology model. For example, the ontology model can be filled with the content related to "Role 1" to obtain the knowledge graph data corresponding to "Role 1". The ontology model can also be filled with the content related to "Role 2" to obtain the knowledge graph data corresponding to "Role 2". This example embodiment does not make any special restrictions on this. A crawler tool (web crawler) can refer to a program or script that automatically crawls information according to certain rules. For example, a crawler tool can be a Pytnon crawler or a JSON-handle. Of course, a crawler tool can also be a User-Agent Switcher. This example embodiment does not make any special restrictions on this. The target location can refer to the web page address corresponding to the content in the target text. Key data can refer to the keywords corresponding to the attribute information that needs to be filled in the ontology model. For example, continue to refer to Figure 5 As shown in the figure, for "Role 1" in the game knowledge graph data, in the webpage corresponding to the game character introduction in the official website of the game, the crawler tool is used to obtain the key data such as the skill name, skin name, hero bond relationship corresponding to "Role 1", and the key data is filled into the ontology model to obtain the following: Figure 5 The game knowledge graph data shown here is of course only a schematic illustration, and this example embodiment is not limited thereto. After obtaining the knowledge graph data, the knowledge graph data is saved to the corresponding database for storage, so as to facilitate subsequent updating and use of the knowledge graph data. By constructing an ontology model and filling the ontology model through a crawler tool, the obtained knowledge graph data is made more complete and accurate, which improves the accuracy of the knowledge graph data while improving the generation efficiency of the knowledge graph data and improving the work efficiency of the system.

[0094] Optionally, the terminal periodically obtains new key data corresponding to the target text at the target location through a crawler tool; and updates the knowledge graph data in the target database according to the new key data. The new key data may refer to the updated data corresponding to the knowledge graph data. By periodically obtaining new key data at the target location through a crawler tool and updating the knowledge graph data, the corresponding knowledge graph data can be updated in time when the key data is updated, thereby ensuring the accuracy of the knowledge graph data, further improving the accuracy of calculating text similarity, and enhancing the user experience.

[0095] In step S420, the target text is segmented to determine an original sentence sequence corresponding to the target text.

[0096] In an example embodiment of the present disclosure, word segmentation processing may refer to the process of segmenting the target text into words or sentences. For example, word segmentation processing may refer to the process of processing the target text through a sentence segmentation model Doc2vec or a word segmentation model Word2Vec. Of course, this example embodiment does not specifically limit this. The original sentence sequence may refer to the sentence sequence obtained after the target text is segmented. The original sentence sequence is relative to the target sentence sequence.

[0097] In step S430, a first text vector corresponding to the original sentence sequence is determined by using the relationship feature vector and a pre-established attention model.

[0098] In an example embodiment of the present disclosure, the attention model may refer to a model built based on the attention mechanism, through which more attention resources can be invested in areas that need to be focused on, so as to obtain more detailed information of the target that needs to be focused on and suppress other useless information. The first text vector may refer to a vector generated by the sentence sequence corresponding to the target text through the attention model, and the first text vector can represent the core content of the target text.

[0099] Specifically, the attention model may include an encoder and a decoder; based on the relational feature vector, the original sentence sequence is encoded by a gated recurrent unit in the encoder to generate an intermediate vector; the first text vector is determined by the intermediate vector and a preset attention mechanism. The encoder may refer to a module that encodes the original sentence sequence in the attention model, and the encoder may include multiple gated recurrent units (GRU). The gated recurrent unit may refer to a gating mechanism in a recurrent neural network (RNN), which is similar to other gating mechanisms and is intended to solve the gradient vanishing / exploding problem in a standard RNN while retaining the long-term information of the sequence. The intermediate vector may refer to the intermediate state vector corresponding to the original sentence sequence when the attention model processes the original sentence sequence. The attention model can enable the first text vector corresponding to the generated target text to contain contextual information, and enable the first text vector to contain the core content of the target text, so as to ensure the accuracy when calculating text similarity.

[0100] Furthermore, the historical information generated in the encoder is obtained, and the target sentence sequence is determined by the historical information, the intermediate vector and the attention mechanism; the difference between the target sentence sequence and the original sentence sequence is used as the loss function, and the loss function is calculated by the gradient descent method to determine the first text vector. The historical information can be the information generated by the encoder when processing the original sentence sequence at the previous moment. By adding the historical information, the generated first text vector can contain context information. The target sentence sequence can refer to the sentence sequence generated after the original sentence sequence is processed by the main model. Gradient descent can refer to a first-order optimization algorithm, also commonly known as the steepest descent method, which is often used in machine learning and artificial intelligence to recursively approximate the minimum deviation model. To use the gradient descent method to find the local minimum of a function, it is necessary to iteratively search for the specified step distance point in the opposite direction of the gradient (or approximate gradient) corresponding to the current point on the function.

[0101] Figure 6 A schematic diagram of an algorithm framework corresponding to the attention mechanism according to an embodiment of the present disclosure is schematically shown.

[0102] refer to Figure 6 As shown, the target text is represented by using Encoder framework 601 and Decoder framework 602. The idea is to input the original sentence sequence X = <x1,x2…x n >, using the word vector learned in the previous step, it is first encoded through a gated recurrent unit 603 (encoder) and converted into an intermediate vector 604C=F(x1,x2…x n ), and then use another gated recurrent unit 603 and attention mechanism 605 to generate the word y to be generated at time i according to the intermediate vector 604 of the original sentence sequence X and the historical information that has been generated previously i , and finally get Y = <y1,y2…y n >. Then the difference between X and Y is used as the loss function, and the loss function is solved by the gradient descent method. Finally, the final vector C obtained by the solution is used as the first text vector to represent the target text. Finally, the first text vector and the second text vector are calculated by cosine similarity to determine the similarity between the target text and the preset text.

[0103] In step S440, a second text vector of a preset text is obtained, and the first text vector and the second text vector are calculated according to a preset algorithm to determine the similarity between the target text and the preset text.

[0104] In an example embodiment of the present disclosure, the preset text may refer to the text whose similarity is calculated with the target text, and the second text vector may refer to the text vector corresponding to the preset text. For example, the second text vector may be the text vector obtained by the preset text through steps S410 to S430, or may be the text vector corresponding to the preset text obtained by other methods. This example embodiment does not make any special restrictions on this. The preset algorithm may refer to a preset algorithm for calculating the similarity between the target text and the preset text. For example, the preset algorithm may be a cosine similarity algorithm or a Euclidean distance algorithm. Of course, the preset algorithm may also be other algorithms for calculating text similarity. This example embodiment does not make any special restrictions on this.

[0105] It should be noted that although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0106] Furthermore, in this exemplary embodiment, a text similarity calculation device is also provided. The text similarity calculation device can be applied to a server or a terminal device. Figure 7 As shown, the text similarity calculation device 700 may include a relationship feature vector determination unit 710, a sentence sequence determination unit 720, a text vector determination unit 730, and a similarity calculation unit 740. Among them:

[0107] A relational feature vector determination unit 710 is used to obtain a target text and knowledge graph data corresponding to the target text, and perform conversion processing on the knowledge graph data to determine a relational feature vector corresponding to the knowledge graph data;

[0108] A sentence sequence determination unit 720 is used to perform word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text;

[0109] A text vector determining unit 730, configured to determine a first text vector corresponding to the original sentence sequence through the relationship feature vector and a pre-established attention model;

[0110] The similarity calculation unit 740 is used to obtain a second text vector of a preset text, and calculate the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text.

[0111] In an exemplary embodiment of the present disclosure, the attention model includes an encoder and a decoder; the similarity calculation unit 740 also includes:

[0112] An intermediate vector generating unit, configured to encode the original sentence sequence through a gated recurrent unit in the encoder based on the relation feature vector to generate an intermediate vector;

[0113] The first text vector determining unit is used to determine the first text vector through the intermediate vector and a preset attention mechanism.

[0114] In an exemplary embodiment of the present disclosure, the first text vector determining unit includes:

[0115] Obtaining historical information generated in the encoder, and determining a target sentence sequence through the historical information, the intermediate vector, and the attention mechanism;

[0116] The difference between the target sentence sequence and the original sentence sequence is used as a loss function, and the loss function is calculated by a gradient descent method to determine the first text vector.

[0117] In an exemplary embodiment of the present disclosure, the relationship feature vector determining unit 710 includes:

[0118] Obtaining a relation array in the knowledge graph data; wherein the relation array includes a subject vector, a predicate vector, and an object vector;

[0119] Based on the pre-trained translation model, the relational feature vector corresponding to the knowledge graph data is determined according to the subject vector, the predicate vector and the object vector.

[0120] In an exemplary embodiment of the present disclosure, the text similarity calculation device 700 further includes a knowledge graph data generation unit, and the knowledge graph data generation unit includes:

[0121] Constructing an ontology model corresponding to the target text, and acquiring key data corresponding to the target text at a target location through a crawler tool;

[0122] Fill the key data into the ontology model to generate the knowledge graph data corresponding to the target text and save the knowledge graph data to the target database.

[0123] In an exemplary embodiment of the present disclosure, the text similarity calculation device 700 further includes a knowledge graph data updating unit, and the knowledge graph data updating unit includes:

[0124] Periodically acquiring new key data corresponding to the target text at the target location by the crawler tool;

[0125] The knowledge graph data in the target database is updated according to the new key data.

[0126] In an exemplary embodiment of the present disclosure, the similarity calculation unit 740 includes:

[0127] The first text vector and the second text vector are calculated by cosine similarity to determine the similarity between the target text and the preset text.

[0128] The specific details of each module or unit in the above-mentioned text similarity calculation device have been described in detail in the corresponding text similarity calculation method, so they will not be repeated here.

[0129] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0130] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0131] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A text similarity calculation method, characterized in that: include: Obtaining a target text and knowledge graph data corresponding to the target text, and converting the knowledge graph data to determine a relational feature vector corresponding to the knowledge graph data; Performing word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text; Determine a first text vector corresponding to the original sentence sequence by using the relationship feature vector and a pre-established attention model; Obtain a second text vector of a preset text, and calculate the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text; wherein the second text vector is obtained by processing the preset text according to the acquisition process corresponding to the first text vector, or by processing the preset text by other methods.

2. The text similarity calculation method according to claim 1, characterized in that: The attention model includes an encoder and a decoder; The determining the first text vector corresponding to the original sentence sequence by using the relationship feature vector and the pre-established attention model comprises: Based on the relation feature vector, encoding the original sentence sequence through a gated recurrent unit in the encoder to generate an intermediate vector; The first text vector is determined by using the intermediate vector and a preset attention mechanism.

3. The text similarity calculation method according to claim 2, characterized in that: Determining the first text vector by using the intermediate vector and a preset attention mechanism includes: Obtaining historical information generated in the encoder, and determining a target sentence sequence through the historical information, the intermediate vector, and the attention mechanism; The difference between the target sentence sequence and the original sentence sequence is used as a loss function, and the loss function is calculated by a gradient descent method to determine the first text vector.

4. The text similarity calculation method according to claim 1, characterized in that: The step of converting the knowledge graph data to determine the relationship feature vector corresponding to the knowledge graph data includes: Obtaining a relation array in the knowledge graph data; wherein the relation array includes a subject vector, a predicate vector, and an object vector; Based on the pre-trained translation model, the relational feature vector corresponding to the knowledge graph data is determined according to the subject vector, the predicate vector and the object vector.

5. The text similarity calculation method according to claim 1, characterized in that: Before obtaining the target text and the knowledge graph data corresponding to the target text, the method further includes: Constructing an ontology model corresponding to the target text, and acquiring key data corresponding to the target text at a target location through a crawler tool; Fill the key data into the ontology model to generate the knowledge graph data corresponding to the target text and save the knowledge graph data to the target database.

6. The text similarity calculation method according to claim 5, characterized in that: After filling the key data into the ontology model to generate the knowledge graph data corresponding to the target text and saving the knowledge graph data to the target database, the method further includes: Periodically acquiring new key data corresponding to the target text at the target location by the crawler tool; The knowledge graph data in the target database is updated according to the new key data.

7. The text similarity calculation method according to claim 1, characterized in that: Calculating the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text includes: The first text vector and the second text vector are calculated by cosine similarity to determine the similarity between the target text and the preset text.

8. A text similarity calculation device, characterized in that: include: A relationship feature vector determination unit, used to obtain a target text and knowledge graph data corresponding to the target text, and perform conversion processing on the knowledge graph data to determine a relationship feature vector corresponding to the knowledge graph data; A sentence sequence determination unit, used to perform word segmentation processing on the target text to determine an original sentence sequence corresponding to the target text; A text vector determination unit, configured to determine a first text vector corresponding to the original sentence sequence through the relationship feature vector and a pre-established attention model; A similarity calculation unit is used to obtain a second text vector of a preset text, and calculate the first text vector and the second text vector according to a preset algorithm to determine the similarity between the target text and the preset text; wherein the second text vector is obtained by processing the preset text according to the acquisition process corresponding to the first text vector, or by processing the preset text by other methods.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 7 by executing the executable instructions.