CN116739001A - Text relation extraction method, device, equipment and medium based on contrast learning - Google Patents
Text relation extraction method, device, equipment and medium based on contrast learning Download PDFInfo
- Publication number
- CN116739001A CN116739001A CN202310699728.7A CN202310699728A CN116739001A CN 116739001 A CN116739001 A CN 116739001A CN 202310699728 A CN202310699728 A CN 202310699728A CN 116739001 A CN116739001 A CN 116739001A
- Authority
- CN
- China
- Prior art keywords
- text
- semantic
- analysis
- template
- constructed
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000605 extraction Methods 0.000 title claims abstract description 65
- 238000004458 analytical method Methods 0.000 claims abstract description 152
- 238000012512 characterization method Methods 0.000 claims abstract description 28
- 238000012549 training Methods 0.000 claims description 32
- 239000013598 vector Substances 0.000 claims description 32
- 238000000034 method Methods 0.000 claims description 29
- 230000006870 function Effects 0.000 claims description 22
- 230000011218 segmentation Effects 0.000 claims description 19
- 238000012545 processing Methods 0.000 claims description 16
- 238000001914 filtration Methods 0.000 claims description 13
- 238000004590 computer program Methods 0.000 claims description 9
- 101100269850 Caenorhabditis elegans mask-1 gene Proteins 0.000 claims description 6
- 238000013473 artificial intelligence Methods 0.000 abstract description 5
- 238000005516 engineering process Methods 0.000 abstract description 4
- 238000004891 communication Methods 0.000 description 8
- 238000004422 calculation algorithm Methods 0.000 description 6
- 238000007726 management method Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 239000003337 fertilizer Substances 0.000 description 3
- 230000000694 effects Effects 0.000 description 2
- 239000004973 liquid crystal related substance Substances 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013135 deep learning Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 238000000802 evaporation-induced self-assembly Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 238000005259 measurement Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000013526 transfer learning Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/30—Semantic analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/21—Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
- G06F18/214—Generating training patterns; Bootstrap methods, e.g. bagging or boosting
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/22—Matching criteria, e.g. proximity measures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/205—Parsing
- G06F40/211—Syntactic parsing, e.g. based on context-free grammar [CFG] or unification grammars
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/279—Recognition of textual entities
- G06F40/289—Phrasal analysis, e.g. finite state techniques or chunking
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Artificial Intelligence (AREA)
- General Physics & Mathematics (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Life Sciences & Earth Sciences (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Machine Translation (AREA)
Abstract
The invention relates to an artificial intelligence technology, and discloses a text relation extraction method based on contrast learning, which comprises the following steps: acquiring an original text, identifying a triplet set in the original text, and extracting an entity from the triplet set to obtain a target entity; replacing the original text with a pre-constructed first prompting template to obtain a first replacement template, and replacing the target entity with a pre-constructed second prompting template to obtain a second replacement template; carrying out semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, carrying out characterization extraction on the first analysis semantic to obtain a first semantic characterization, and carrying out characterization extraction on the second analysis semantic to obtain a second semantic characterization; and identifying the text relationship of the original text through the trained relationship identification model according to the first semantic representation and the second semantic representation. The invention aims to improve the accuracy of extracting the semantics of the financial sample data.
Description
Technical Field
The invention relates to the technical field of intelligent decision making, in particular to a text relation extraction method, device and equipment based on contrast learning and a computer readable medium.
Background
In recent years, the development of a large-scale pre-training model brings profound effects to various research fields of deep learning, such as financial text data, a large amount of texts, numbers and images are involved, model training of different versions is needed, but as the body quantity of the pre-training model of various versions is larger and larger, the model training process can be optimized through contrast learning, the contrast learning is a common self-supervision learning method, the core idea is that positive samples are shortened, positive samples are lengthened from negative samples, the quantity in similar measurement learning is increased, but the contrast learning is positive and negative sample classification, and the quantity is infinite.
The text relation extraction model mainly comprises the steps of readjusting the input of a financial sample of a downstream task into an input form similar to a pre-training task through a specific template, and in this way, the transfer learning capacity can be improved to a certain extent, but the method can influence the semantic representation of an original financial sample, so that the accuracy of text relation extraction is reduced, and therefore, a method capable of improving the accuracy of text relation extraction is urgently needed at present.
Disclosure of Invention
The invention provides a text relation extraction method, device, equipment and medium based on contrast learning, and mainly aims to improve the accuracy of extracting sample data semantics.
In order to achieve the above object, the present invention provides a text relationship extraction method based on contrast learning, including:
acquiring an original text, identifying a triplet set in the original text, and extracting an entity from the triplet set to obtain a target entity;
replacing the original text with a pre-constructed first prompt template to obtain a first replacement template, and replacing the target entity with a pre-constructed second prompt template to obtain a second replacement template;
performing semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, performing characterization extraction on the first analysis semantic to obtain a first semantic characterization, and performing characterization extraction on the second analysis semantic to obtain a second semantic characterization;
and identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
Optionally, the identifying the triplet set in the original text includes:
Performing sentence division on the original text to obtain text sentences;
filtering the text sentence to obtain a filtered sentence;
carrying out grammar analysis on the filtering statement to obtain an analysis result;
and identifying a triplet set in the filtering statement according to the analysis result.
Optionally, the replacing the original text with the pre-constructed first prompting template to obtain a first replacing template includes:
initializing the pre-constructed first prompting template to obtain an initial first template;
analyzing the structural characteristics of the initial first template, and replacing the original text according to the structural characteristics to obtain a first replacement model.
Optionally, the semantic analysis is performed on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, which includes:
identifying text data of the first replacement template and the second replacement template to obtain first text data and second Wen Benshu;
word segmentation processing is carried out on the first text data and the second text data respectively, so that first text word segmentation and second text word segmentation are obtained;
and matching the first text word segmentation and the second text word segmentation with a pre-constructed word semantic analysis table respectively to obtain a first analysis semantic and a second analysis semantic.
Optionally, the extracting the first analysis semantic representation to obtain a first semantic representation includes:
vectorizing the first analysis semantics to obtain semantic vectors;
extracting features of the semantic vectors to obtain semantic feature vectors;
calculating a weight value of the semantic feature vector, and taking the semantic feature vector with the weight value larger than a preset threshold value as a target feature vector of the first analysis semantic;
and obtaining semantic representation of the first analysis semantics according to the target feature vector.
Optionally, before the text relationship of the original text is identified by the trained relationship identification model according to the first semantic representation and the second semantic representation, the method further includes:
acquiring a training sample and a corresponding real label thereof, wherein the real label comprises a real semantic representation and a real text relationship;
detecting the predicted semantic representation of the training sample by utilizing a semantic analysis network in a pre-constructed relation recognition model, and recognizing the predicted text relation of the training sample by utilizing a text relation recognition network in the pre-constructed relation recognition model according to the predicted semantic representation;
Calculating a first loss of the real semantic representation and the predicted semantic representation by using a first loss function in the pre-constructed relationship recognition model, and calculating a second loss of the real text relationship and the predicted text relationship by using a second loss function in the pre-constructed relationship recognition model;
calculating a final loss of the pre-constructed relational identification model according to the first loss and the second loss;
when the final loss is larger than the preset loss, adjusting parameters of the pre-constructed relation recognition model, and returning to execute the step of detecting the predicted semantic representation of the training sample by using a semantic analysis network in the pre-constructed relation recognition model;
and if the final loss is not greater than the preset loss, obtaining a trained relationship identification model.
Optionally, the second loss function includes:
wherein loss is 2 Represents a second loss, h mask1 Representing the first analysis semantics, h mask2 Representing the second analysis semantics of the analysis,represents the ith h in the same round mask1 N represents the last vector of the first analysis semantics and the second analysis semantics.
In order to solve the above problems, the present invention further provides a text relationship extraction device based on contrast learning, the device comprising:
The entity recognition module is used for acquiring an original text, recognizing a triplet set in the original text, and extracting the entity from the triplet set to obtain a target entity;
the template replacing module is used for replacing the original text with a pre-constructed first prompting template to obtain a first replacing template, and replacing the target entity with a pre-constructed second prompting template to obtain a second replacing template;
the semantic representation analysis module is used for carrying out semantic analysis on the first replacement template and the second replacement template to obtain first analysis semantics and second analysis semantics, carrying out representation extraction on the first analysis semantics to obtain first semantic representation, and carrying out representation extraction on the second analysis semantics to obtain second semantic representation;
and the model training module is used for identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
In order to solve the above-mentioned problems, the present invention also provides an electronic apparatus including:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,,
The memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the text-relation extraction method based on contrast learning described above.
In order to solve the above-mentioned problems, the present invention also provides a computer readable medium having stored therein at least one computer program that is executed by a processor in an electronic device to implement the above-mentioned text relationship extraction method based on contrast learning.
According to the method and the device, the original text is acquired, the triplet set in the original text is identified, the original text can be divided into independent set forms, the triples can be processed independently subsequently, and compared with the direct processing of the original text, the difficulty is reduced, wherein the method and the device can obtain a first replacement template by replacing the original text with a pre-constructed first prompt template, so that the original text can be processed through the first replacement template, and meanwhile guarantee is provided for subsequent semantic analysis of the original text; in addition, the first analysis semantics and the second analysis semantics can be obtained by carrying out semantic analysis on the first replacement template and the second replacement template so as to know the deviation of the first analysis semantics and the second analysis semantics. Therefore, the text relation extraction method, device, equipment and medium based on contrast learning can improve the accuracy of text relation extraction.
Drawings
FIG. 1 is a flow chart of a text relationship extraction method based on contrast learning according to an embodiment of the present application;
FIG. 2 is a functional block diagram of a text relationship extraction device based on contrast learning according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an electronic device for implementing the text relationship extraction method based on contrast learning according to an embodiment of the present application.
The achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The embodiment of the application provides a text relation extraction method based on contrast learning. In the embodiment of the present application, the execution body of the text relationship extraction method based on contrast learning includes, but is not limited to, at least one of a server, a terminal, and the like, which can be configured to execute the method provided by the embodiment of the present application. In other words, the text relationship extraction method based on contrast learning may be performed by software or hardware installed in a terminal device or a server device, and the software may be a blockchain platform. The service end includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like. The server may be an independent server, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
Referring to fig. 1, a flow chart of a text relationship extraction method based on contrast learning according to an embodiment of the invention is shown. In this embodiment, the text relationship extraction method based on contrast learning includes steps S1 to S4:
s1, acquiring an original text, identifying a triplet set in the original text, and extracting the entity of the triplet set to obtain a target entity.
According to the invention, the original text is acquired, the triplet set in the original text is identified, the original text can be divided into independent set forms, and the triples can be independently processed later, so that the difficulty is reduced compared with the direct processing of the original text.
The original text is text in the financial field, such as a financial related paper, a abstract of a financial article, a fragment of financial information, and the like, and the triplet is a subject, an object, and a subordinate relationship of the subject and the object in the original text, such as: the Anhui province comprises a combined fertilizer city, the Anhui province comprises a combined fertilizer city which is the original text, the Anhui is a subject in the text, and the combined fertilizer is an object in the original text and comprises a subordinate relation between the subject and the object in the original text. Further, the original text may be obtained through internet uploading.
As one embodiment of the present invention, the identifying the triplet set in the original text includes: performing sentence division on the original text to obtain text sentences, performing filtering treatment on the text sentences to obtain filtering sentences, performing grammar analysis on the filtering sentences to obtain analysis results, and identifying a triplet set in the filtering sentences according to the analysis results.
The text sentence is a sentence with a certain logic sequence in the original text, the filtering sentence is a sentence obtained by filtering stop words and adjectives in the text sentence, and the analysis structure is a grammar corresponding to the filtering sentence.
Furthermore, the sentence division of the original text can be realized through a List segmentation tool, the text sentence can be filtered through a text filter, the grammar analysis of the filtered sentence can be realized through a syntax analyzer, and the identification of the triplet set in the filtered sentence can be realized through an LTP tool.
According to the invention, the target entity is obtained by extracting the entity from the triplet set, so that the data irrelevant to the entity in the triplet set is removed, and the subsequent processing efficiency is improved, wherein the target entity is the entity required for subsequent processing.
As an embodiment of the present invention, the entity extraction of the triplet set to obtain a target entity includes: and identifying the text entity in the triplet set, carrying out attribute analysis on the text entity to obtain entity attribute, and carrying out entity extraction on the text entity according to the target attribute to obtain a target entity.
The entity attribute is a property corresponding to the text entity, such as a shape, a color, an odor and the like, the target entity is a head entity and a tail entity in the text entity, further, the identification of the text entity in the triplet set can be realized through an entity identification algorithm, the entity identification algorithm is compiled by a script language, the attribute analysis of the text entity can be realized through an attribute analysis method, and the entity of the text entity can be extracted through a mixing method.
S2, replacing the original text with the pre-constructed first prompt template to obtain a first replacement template, and replacing the target entity with the pre-constructed second prompt template to obtain a second replacement template.
The invention can obtain a first replacement template by replacing the original text with a pre-constructed first prompt template so as to process the original text through the first replacement template and simultaneously provide guarantee for the subsequent semantic analysis of the original text, wherein the pre-constructed first prompt template displays the relation of the original text through a dialog box, the first replacement template is a template obtained by replacing the pre-constructed first prompt template by the original text, and the first template is in the following format: from "[ x ]", it can be seen that [ mask ] of [ sub ] is [ obj ]. Wherein "[ x ]" represents the original text entered by the model, and [ sub ] and [ obj ] are the head entity and the tail entity of the triplet contained in the input "[ x ]",
The mask is a semantic representation of the model output expected by us, and the format of the second template is as follows: from "[ x ]" it is inferred that the relationship between [ sub ] and [ obj ] is [ mask ]. From "[ x ]", it can be seen that [ mask ] of [ sub ] is [ obj ]. As an embodiment of the present invention, the replacing the original text with the pre-constructed first alert template to obtain a first replacement template includes: initializing the pre-constructed first prompt template to obtain an initial first template, analyzing the structural characteristics of the initial first template, and replacing the original text according to the structural characteristics to obtain a first replacement template.
The method comprises the steps of setting a preset first prompting template through a manually designed template, assigning a variable in the preset first prompting template to a default value, setting a control in the preset first prompting template to be in a default state, analyzing the structural characteristics of the initial first template through a combined analysis tool, replacing an original text through a text string replacement tool, and compiling the text string replacement tool through Java language.
According to the invention, the target entity and the pre-constructed second prompting template are replaced, so that a second replacing template can be obtained, and the affiliated relation between the target entities can be known through the second replacing template. The second replacement template is a dialog box representing the relationship between the target entities, and further, the principle of replacing the target entities with the pre-constructed second prompt template is the same as that of the original text with the pre-constructed first prompt template, and redundant description is omitted herein.
S3, respectively carrying out semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, carrying out characterization extraction on the first analysis semantic to obtain a first semantic characterization, and carrying out characterization extraction on the second analysis semantic to obtain a second semantic characterization.
According to the invention, by carrying out semantic analysis on the first replacement template and the second replacement template, a first analysis semantic and a second analysis semantic can be obtained so as to know the deviation of the first analysis semantic and the second analysis semantic, wherein the first analysis semantic is the meaning corresponding to the text content in the first replacement template, and the second analysis semantic is the meaning corresponding to the text content in the second replacement template.
As an embodiment of the present invention, the performing semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic respectively includes: identifying text data of the first replacement template and the second replacement template to obtain first text data and second Wen Benshu, performing word segmentation processing on the first text data and the second text data to obtain first text words and second text words, and matching the first text words and the second text words with a pre-constructed word semantic analysis table to obtain first analysis semantics and second analysis semantics.
The text data are all text contents contained in the first replacement template and the second replacement template, the first text segmentation is all words in the first text data, the second text segmentation is all words in the second text data, the pre-constructed word semantic analysis table is a word and a corresponding semantic mapping relation table, and the first text segmentation and the second text segmentation can be quickly matched to corresponding semantics through the pre-constructed word semantic analysis table, so that the processing efficiency is improved.
Further, the recognition of the text data of the first replacement template and the second replacement template can be achieved through OCR text recognition technology, and word segmentation processing of the first text data and the second text data can be achieved through an ik word segmentation device.
As an alternative embodiment of the present invention, the first text word is matched to a pre-constructed word semantic analysis table using the following formula:
wherein Y (a, b) represents the similarity of the first text segmentation word and the words in the pre-constructed word semantic analysis table, a i First character representing ith word segment in first text word segment, b i And the tail character of the ith word in the first text word.
It should be noted that, matching of the second text word segment with the pre-constructed word semantic analysis table is the same as matching of the first text word segment with the pre-constructed word semantic analysis table.
Further, the first analysis semantics are characterized and extracted to obtain first semantic characterization, useless data in the first analysis semantics can be removed, and the accuracy of subsequent processing is improved, wherein the first semantic characterization is key information of the first analysis semantics.
As an embodiment of the present invention, the extracting the first analysis semantic representation to obtain a first semantic representation includes: vectorizing the first analysis semantics to obtain semantic vectors, extracting features of the semantic vectors to obtain semantic feature vectors, calculating weight values of the semantic feature vectors, taking the semantic feature vectors with the weight values larger than a preset threshold value as target feature vectors of the first analysis semantics, and obtaining semantic representation of the first analysis semantics according to the target feature vectors.
The semantic vector is a vector expression form of the first analysis semantic, the semantic feature vector is a vector with a sign in the semantic vector, the weight value is a vector representing the importance of the semantic feature vector, the preset threshold value can be 0.9 or can be set according to an actual service scene, further, the vectorization processing of the first analysis semantic can be realized through a word2vec algorithm, the feature extraction of the semantic vector can be realized through a Haar feature extraction algorithm, the weight value of the semantic feature vector can be realized through a weight function, and the weight function is compiled by a script language.
According to the method, the second analysis semantics are characterized and extracted to obtain second semantic characterization, useless data in the second analysis semantics can be removed, wherein the second semantic features are key information of the second analysis semantics, further, the characterization and extraction principle of the second analysis semantics is the same as that of the first analysis semantics, and the method can be referred to and is not repeated herein.
S4, calculating the mean semantic representation of the first semantic representation and the second semantic representation, calculating a loss value of the mean semantic representation through a trained relation extraction model, correcting the mean semantic representation according to the loss value to obtain corrected semantic representation, and obtaining a text relation of the original text according to the corrected semantic representation.
According to the method, the first semantic representation and the second semantic representation can be integrated together through calculating the mean semantic representation of the first semantic representation and the second semantic representation, so that the calculation result of a subsequent loss value is more accurate, wherein the mean semantic representation is obtained by calculating the mean value of the first semantic representation and the second semantic representation, and further, the mean semantic representation of the first semantic representation and the second semantic representation can be calculated through an average algorithm.
Further, in an embodiment of the present invention, before the identifying, by the trained relationship identification model, the text relationship of the original text according to the first semantic representation and the second semantic representation, the method further includes: obtaining a training sample and a corresponding real label thereof, wherein the real label comprises a real semantic representation and a real text relation, a semantic analysis network in a pre-constructed relation recognition model is utilized to detect a predicted semantic representation of the training sample, a text relation recognition network in the pre-constructed relation recognition model is utilized to recognize the predicted text relation of the training sample according to the predicted semantic representation, a first loss function in the pre-constructed relation recognition model is utilized to calculate a first loss of the real semantic representation and the predicted semantic representation, a second loss function in the pre-constructed relation recognition model is utilized to calculate a second loss of the real text relation and the predicted text relation, a final loss of the pre-constructed relation recognition model is calculated according to the first loss and the second loss, when the final loss is larger than the preset loss, parameters of the pre-constructed relation recognition model are adjusted, and the step of utilizing the semantic analysis network in the pre-constructed relation recognition model to detect the predicted semantic representation of the training sample is executed is returned, and if the final loss is not larger than the preset loss, a good recognition model is obtained.
The training sample is a sample used for training and learning the relation recognition model, the real semantic representation is a semantic representation corresponding to the training sample, the real text relation is a correlation between the training sample contents, the first loss is a deviation between the real semantic representation and the prediction semantic representation, the second loss is a deviation between the real text relation and the prediction text relation, the final loss is a value obtained by adding and summing the first loss and the second loss, and the preset loss is a criterion serving as a judgment, can be 0.9, and can be set according to an actual service scene.
Further, the analysis of the predicted semantic representation of the training sample may be implemented by an analysis function in the semantic analysis network, and the recognition of the predicted text relationship of the training sample may be implemented by a recognition function in the text relationship recognition network.
Further, the first loss function includes:
wherein loss is i Representing a first penalty, a representing a start position of the true semantic representation and the predicted semantic representation, m representing an end position of the true semantic representation and the predicted semantic representation, z i Predictive feature value, z 'representing the ith predictive semantic representation' i And representing the real characteristic value of the ith real semantic representation.
Further, the second loss function includes:
wherein loss is 2 Represents a second loss, h mask1 Meaning semantic analysis corresponding to the real text relationship, h mask2 Meaning the semantic analysis to which the predicted text relationship corresponds,represents the ith h in the same round mask1 N represents the number of the first analysis semantics and the second analysis semantics.
According to the method and the device for identifying the text relationship of the original text, the text relationship of the original text is identified according to the trained relationship identification model, and the corresponding relationship between the original texts can be accurately identified.
According to the method and the device, the original text is acquired, the triplet set in the original text is identified, the original text can be divided into independent set forms, the triples can be processed independently subsequently, and compared with the direct processing of the original text, the difficulty is reduced, wherein the method and the device can obtain a first replacement template by replacing the original text with a pre-constructed first prompt template, so that the original text can be processed through the first replacement template, and meanwhile guarantee is provided for subsequent semantic analysis of the original text; in addition, the first analysis semantics and the second analysis semantics can be obtained by carrying out semantic analysis on the first replacement template and the second replacement template so as to know the deviation of the first analysis semantics and the second analysis semantics. Therefore, the text relation extraction method based on contrast learning provided by the embodiment of the invention can improve the accuracy of text relation extraction.
Fig. 1 is a functional block diagram of a text relationship extraction device based on contrast learning according to an embodiment of the present invention.
The text relationship extraction device 100 based on contrast learning according to the present invention may be installed in an electronic device. Depending on the implementation, the text relationship extraction device 100 based on contrast learning may include an entity recognition module 101, a template substitution module 102, a semantic representation analysis module 103, and a model training module 104. The module of the invention, which may also be referred to as a unit, refers to a series of computer program segments, which are stored in the memory of the electronic device, capable of being executed by the processor of the electronic device and of performing a fixed function.
In the present embodiment, the functions concerning the respective modules/units are as follows:
the entity recognition module 101 is configured to obtain an original text, recognize a triplet set in the original text, and perform entity extraction on the triplet set to obtain a target entity;
the template replacing module 102 is configured to replace the original text with a pre-constructed first prompting template to obtain a first replacing template, and replace the target entity with a pre-constructed second prompting template to obtain a second replacing template;
The semantic representation analysis module 103 is configured to perform semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, perform representation extraction on the first analysis semantic to obtain a first semantic representation, and perform representation extraction on the second analysis semantic to obtain a second semantic representation;
the model training module 104 is configured to identify, according to the first semantic representation and the second semantic representation, a text relationship of the original text through a trained relationship identification model.
In detail, each module in the text relationship extraction device 100 based on contrast learning in the embodiment of the present application adopts the same technical means as the text relationship extraction method based on contrast learning described in fig. 1, and can generate the same technical effects, which is not described herein.
Fig. 3 is a schematic structural diagram of an electronic device 1 according to an embodiment of the present application for implementing a text relationship extraction method based on contrast learning.
The electronic device 1 may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program stored in the memory 11 and executable on the processor 10, such as a text-relation extraction program based on contrast learning.
The processor 10 may be formed by an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be formed by a plurality of integrated circuits packaged with the same function or different functions, including one or more central processing units (Central Processing Unit, CPU), a microprocessor, a digital processing chip, a graphics processor, a combination of various control chips, and so on. The processor 10 is a Control Unit (Control Unit) of the electronic device 1, connects respective parts of the entire electronic device using various interfaces and lines, executes or executes programs or modules stored in the memory 11 (for example, executes a text relationship extraction program based on contrast learning, etc.), and invokes data stored in the memory 11 to perform various functions of the electronic device and process data.
The memory 11 includes at least one type of readable medium including flash memory, a removable hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, such as a mobile hard disk of the electronic device. The memory 11 may in other embodiments also be an external storage device of the electronic device, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used not only for storing application software installed in an electronic device and various types of data, such as codes of text relation extraction programs based on contrast learning, etc., but also for temporarily storing data that has been output or is to be output.
The communication bus 12 may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The bus may be classified as an address bus, a data bus, a control bus, etc. The bus is arranged to enable a connection communication between the memory 11 and at least one processor 10 etc.
The communication interface 13 is used for communication between the electronic device 1 and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), typically used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a Display (Display), an input unit such as a Keyboard (Keyboard), or alternatively a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch, or the like. The display may also be referred to as a display screen or display unit, as appropriate, for displaying information processed in the electronic device and for displaying a visual user interface.
Fig. 3 shows only an electronic device with components, it being understood by a person skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than shown, or may combine certain components, or may be arranged in different components.
For example, although not shown, the electronic device 1 may further include a power source (such as a battery) for supplying power to each component, and preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management, and the like are implemented through the power management device. The power supply may also include one or more of any of a direct current or alternating current power supply, recharging device, power failure detection circuit, power converter or inverter, power status indicator, etc. The electronic device 1 may further include various sensors, bluetooth modules, wi-Fi modules, etc., which will not be described herein.
It should be understood that the embodiments described are for illustrative purposes only and are not limited to this configuration in the scope of the patent application.
The text relation extraction program based on contrast learning stored in the memory 11 in the electronic device 1 is a combination of instructions, which when executed in the processor 10, may implement:
Acquiring a pre-constructed initialized medical entity recognition model, a marked training set and a non-marked training set, and training the initialized medical entity recognition model by using the marked training set and the non-marked training set according to a preset semi-supervised learning strategy to obtain a trained medical entity recognition model;
acquiring an original text, identifying a triplet set in the original text, and extracting an entity from the triplet set to obtain a target entity;
replacing the original text with a pre-constructed first prompt template to obtain a first replacement template, and replacing the target entity with a pre-constructed second prompt template to obtain a second replacement template;
performing semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, performing characterization extraction on the first analysis semantic to obtain a first semantic characterization, and performing characterization extraction on the second analysis semantic to obtain a second semantic characterization;
and identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
In particular, the specific implementation method of the above instructions by the processor 10 may refer to the description of the relevant steps in the corresponding embodiment of the drawings, which is not repeated herein.
Further, the modules/units integrated in the electronic device 1 may be stored in a computer readable medium if implemented in the form of software functional units and sold or used as separate products. The computer readable medium may be volatile or nonvolatile. For example, the computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM).
The present invention also provides a computer readable medium storing a computer program which, when executed by a processor of an electronic device, may implement:
acquiring an original text, identifying a triplet set in the original text, and extracting an entity from the triplet set to obtain a target entity;
replacing the original text with a pre-constructed first prompt template to obtain a first replacement template, and replacing the target entity with a pre-constructed second prompt template to obtain a second replacement template;
Performing semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, performing characterization extraction on the first analysis semantic to obtain a first semantic characterization, and performing characterization extraction on the second analysis semantic to obtain a second semantic characterization;
and identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
In the several embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be other manners of division when actually implemented.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units can be realized in a form of hardware or a form of hardware and a form of software functional modules.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof.
The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm and the like. The Blockchain (Blockchain), which is essentially a decentralised database, is a string of data blocks that are generated by cryptographic means in association, each data block containing a batch of information of network transactions for verifying the validity of the information (anti-counterfeiting) and generating the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, an application services layer, and the like.
The embodiment of the application can acquire and process the related data based on the artificial intelligence technology. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Furthermore, it is evident that the word "comprising" does not exclude other elements or steps, and that the singular does not exclude a plurality. A plurality of units or means recited in the system claims can also be implemented by means of software or hardware by means of one unit or means. The terms first, second, etc. are used to denote a name, but not any particular order.
Finally, it should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present application and not for limiting the same, and although the present application has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the technical solution of the present application without departing from the spirit and scope of the technical solution of the present application.
Claims (10)
1. A text relationship extraction method based on contrast learning, the method comprising:
Acquiring an original text, identifying a triplet set in the original text, and extracting an entity from the triplet set to obtain a target entity;
replacing the original text with a pre-constructed first prompt template to obtain a first replacement template, and replacing the target entity with a pre-constructed second prompt template to obtain a second replacement template;
performing semantic analysis on the first replacement template and the second replacement template to obtain a first analysis semantic and a second analysis semantic, performing characterization extraction on the first analysis semantic to obtain a first semantic characterization, and performing characterization extraction on the second analysis semantic to obtain a second semantic characterization;
and identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
2. The method for extracting text relationships based on contrast learning according to claim 1, wherein the identifying the triplet set in the original text includes:
performing sentence division on the original text to obtain text sentences;
filtering the text sentence to obtain a filtered sentence;
carrying out grammar analysis on the filtering statement to obtain an analysis result;
And identifying a triplet set in the filtering statement according to the analysis result.
3. The text relationship extraction method based on contrast learning as claimed in claim 2, wherein the replacing the original text with the pre-constructed first prompt template to obtain a first replacement template includes:
initializing the pre-constructed first prompting template to obtain an initial first template;
analyzing the structural characteristics of the initial first template, and replacing the original text according to the structural characteristics to obtain a first replacement model.
4. The text relationship extraction method based on contrast learning as claimed in claim 1, wherein the performing semantic analysis on the first and second alternative templates to obtain first and second analysis semantics respectively includes:
identifying text data of the first replacement template and the second replacement template to obtain first text data and second Wen Benshu;
word segmentation processing is carried out on the first text data and the second text data respectively, so that first text word segmentation and second text word segmentation are obtained;
and matching the first text word segmentation and the second text word segmentation with a pre-constructed word semantic analysis table respectively to obtain a first analysis semantic and a second analysis semantic.
5. The text relationship extraction method based on contrast learning as claimed in claim 1, wherein the performing feature extraction on the first analysis semantics to obtain a first semantic feature includes:
vectorizing the first analysis semantics to obtain semantic vectors;
extracting features of the semantic vectors to obtain semantic feature vectors;
calculating a weight value of the semantic feature vector, and taking the semantic feature vector with the weight value larger than a preset threshold value as a target feature vector of the first analysis semantic;
and obtaining semantic representation of the first analysis semantics according to the target feature vector.
6. The method for extracting text relationships based on contrast learning according to claim 1, wherein before the text relationships of the original text are identified by the trained relationship identification model according to the first semantic representation and the second semantic representation, further comprising:
acquiring a training sample and a corresponding real label thereof, wherein the real label comprises a real semantic representation and a real text relationship;
detecting the predicted semantic representation of the training sample by utilizing a semantic analysis network in a pre-constructed relation recognition model, and recognizing the predicted text relation of the training sample by utilizing a text relation recognition network in the pre-constructed relation recognition model according to the predicted semantic representation;
Calculating a first loss of the real semantic representation and the predicted semantic representation by using a first loss function in the pre-constructed relationship recognition model, and calculating a second loss of the real text relationship and the predicted text relationship by using a second loss function in the pre-constructed relationship recognition model;
calculating a final loss of the pre-constructed relational identification model according to the first loss and the second loss;
when the final loss is larger than the preset loss, adjusting parameters of the pre-constructed relation recognition model, and returning to execute the step of detecting the predicted semantic representation of the training sample by using a semantic analysis network in the pre-constructed relation recognition model;
and if the final loss is not greater than the preset loss, obtaining a trained relationship identification model.
7. The text relationship extraction method based on contrast learning as claimed in claim 1, wherein the second loss function includes:
wherein loss is 2 Represents a second loss, h mask1 Representing the first analysis semantics, h mask2 Representing the second analysis semantics of the analysis,represents the ith h in the same round mask1 N represents the last vector of the first analysis semantics and the second analysis semantics.
8. A text relationship extraction apparatus based on contrast learning, the apparatus comprising:
the entity recognition module is used for acquiring an original text, recognizing a triplet set in the original text, and extracting the entity from the triplet set to obtain a target entity;
the template replacing module is used for replacing the original text with a pre-constructed first prompting template to obtain a first replacing template, and replacing the target entity with a pre-constructed second prompting template to obtain a second replacing template;
the semantic representation analysis module is used for carrying out semantic analysis on the first replacement template and the second replacement template to obtain first analysis semantics and second analysis semantics, carrying out representation extraction on the first analysis semantics to obtain first semantic representation, and carrying out representation extraction on the second analysis semantics to obtain second semantic representation;
and the model training module is used for identifying the text relationship of the original text through a trained relationship identification model according to the first semantic representation and the second semantic representation.
9. An electronic device, the electronic device comprising:
at least one processor; the method comprises the steps of,
A memory communicatively coupled to the at least one processor; wherein,,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the contrast learning-based text-relationship extraction method of any one of claims 1 to 7.
10. A computer readable medium storing a computer program, wherein the computer program when executed by a processor implements the text-relation extraction method based on contrast learning according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310699728.7A CN116739001A (en) | 2023-06-13 | 2023-06-13 | Text relation extraction method, device, equipment and medium based on contrast learning |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310699728.7A CN116739001A (en) | 2023-06-13 | 2023-06-13 | Text relation extraction method, device, equipment and medium based on contrast learning |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116739001A true CN116739001A (en) | 2023-09-12 |
Family
ID=87907570
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310699728.7A Pending CN116739001A (en) | 2023-06-13 | 2023-06-13 | Text relation extraction method, device, equipment and medium based on contrast learning |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116739001A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118013478A (en) * | 2024-04-09 | 2024-05-10 | 江西曼荼罗软件有限公司 | Text data tracing method, system, storage medium and equipment |
-
2023
- 2023-06-13 CN CN202310699728.7A patent/CN116739001A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118013478A (en) * | 2024-04-09 | 2024-05-10 | 江西曼荼罗软件有限公司 | Text data tracing method, system, storage medium and equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112380343B (en) | Problem analysis method, device, electronic equipment and storage medium | |
CN113378970B (en) | Sentence similarity detection method and device, electronic equipment and storage medium | |
CN112988963A (en) | User intention prediction method, device, equipment and medium based on multi-process node | |
CN115238670B (en) | Information text extraction method, device, equipment and storage medium | |
CN113268615A (en) | Resource label generation method and device, electronic equipment and storage medium | |
CN116578704A (en) | Text emotion classification method, device, equipment and computer readable medium | |
CN116450829A (en) | Medical text classification method, device, equipment and medium | |
CN116739001A (en) | Text relation extraction method, device, equipment and medium based on contrast learning | |
CN114840684A (en) | Map construction method, device and equipment based on medical entity and storage medium | |
CN113344125B (en) | Long text matching recognition method and device, electronic equipment and storage medium | |
CN114662477A (en) | Stop word list generating method and device based on traditional Chinese medicine conversation and storage medium | |
CN116468025A (en) | Electronic medical record structuring method and device, electronic equipment and storage medium | |
CN112632260A (en) | Intelligent question and answer method and device, electronic equipment and computer readable storage medium | |
CN116741358A (en) | Inquiry registration recommendation method, inquiry registration recommendation device, inquiry registration recommendation equipment and storage medium | |
CN114943306A (en) | Intention classification method, device, equipment and storage medium | |
CN115510188A (en) | Text keyword association method, device, equipment and storage medium | |
CN113515591B (en) | Text defect information identification method and device, electronic equipment and storage medium | |
CN114677526A (en) | Image classification method, device, equipment and medium | |
CN114595321A (en) | Question marking method and device, electronic equipment and storage medium | |
CN113723114A (en) | Semantic analysis method, device and equipment based on multi-intent recognition and storage medium | |
CN113361274B (en) | Intent recognition method and device based on label vector, electronic equipment and medium | |
CN111680513B (en) | Feature information identification method and device and computer readable storage medium | |
CN115098688B (en) | Multi-label classification model training method and device, electronic equipment and storage medium | |
CN115525730B (en) | Webpage content extraction method and device based on page weighting and electronic equipment | |
CN116579349A (en) | Text semantic segmentation method, device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |