Relationship extraction method and device based on mixed contrast learning, equipment and medium

By introducing a strategy of mixed contrast learning in the relationship extraction model, constructing and screening mixed negative samples, the problem of limitations in the selection of negative cases in traditional models is solved, and the generalization ability and relationship extraction performance of the model are improved.

CN119476206APending Publication Date: 2025-02-18HANDAN INNOVATION INST OF PEKING UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411294832.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The traditional relational extraction model has limitations in the selection of negative cases and cannot fully cover all possible error situations, resulting in the model performing poorly when facing more complex negative cases and poorly-performance of the model learned.

Method used

Using a relational extraction method based on mixed contrast learning, we construct mixed negative samples, use entity vector representations and context word vector representations for linear interpolation to generate more challenging negative examples, and filter negative samples through mixed negative sample metrics.

Benefits of technology

By introducing a strategy of mixed contrast learning, the selection range of negative examples is broadened, the generalization ability of the model is improved, complex relationships in the text can be captured more effectively, and the performance of relationship extraction is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119476206A_ABST
    Figure CN119476206A_ABST
Patent Text Reader

Abstract

The invention provides a relation extraction method and device based on mixed contrast learning, equipment and a medium, and relates to the technical field of artificial intelligence. The to-be-extracted text is input into a mixed contrast learning relation extraction model, a relation extraction result is output, the mixed contrast learning relation extraction model is obtained based on training of a positive sample and a mixed negative sample, and the mixed negative sample is constructed according to entity vector representation and context word vector representation. According to the method, the mixed contrast learning strategy is introduced to generate the more challenging negative sample instance, so that the relation extraction performance of the relation extraction model is improved, the selection range of the negative sample is widened, the generalization ability of the model is improved, and text relation extraction under various complex conditions can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a relationship extraction method, device, equipment and medium based on hybrid contrastive learning. Background Art

[0002] Traditional relation extraction models explicitly distinguish entities from contextual words by introducing position embeddings or special tags related to entities. However, this approach ignores the rich semantic relationships between entities and contexts, resulting in limited accuracy in relation extraction. In related technologies, by introducing a contrastive learning mechanism, positive and negative sample pairs are constructed with entities as the center, thereby capturing the semantic relationship between entity pairs and distinguishing different types of relationships; since contrastive learning requires a certain amount of labeled data to construct positive and negative sample pairs, the manual labeling method is inefficient, and in the absence of labeled data, the performance of the model may be limited. In addition, traditional contrastive learning methods directly use incorrect entities and context words as negative examples, which often have limitations in the selection of negative examples and cannot fully cover all possible error situations, resulting in poor performance of the model when facing more complex negative examples, and poor performance of the learned model. Summary of the invention

[0003] The present invention provides a relation extraction method, device, equipment and medium based on hybrid contrastive learning, which are used to solve the defects that traditional relation extraction methods often have limitations in the selection of negative examples, resulting in poor performance of the model when facing more complex negative examples and poor performance of the learned model.

[0004] The present invention provides a relation extraction method based on hybrid contrastive learning, comprising: Get the text to be extracted; The text to be extracted is input into a hybrid contrastive learning relation extraction model, and a relation extraction result is output, wherein the hybrid contrastive learning relation extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed according to entity vector representation and context word vector representation.

[0005] According to the relation extraction method based on hybrid contrastive learning provided by the present invention, the positive sample construction method includes: The entities in the training examples are processed using two different sets of discard masks to generate two entity vector representations with similar embedding representations, and the entity vector representations are used as positive samples.

[0006] According to the relation extraction method based on hybrid contrastive learning provided by the present invention, in the positive sample construction process, 2N-1 entity vector representations of non-current entities are generated based on N training examples, and the hybrid negative sample construction method includes: Linearly interpolate the current entity vector representation and the context word vector representation: m = λe+(1-λ)w; Among them, m is the mixed sample representation, e is the entity vector representation, w is the context word vector representation, λ is a random coefficient whose value is in the range of (0, 1) and satisfies λ= max(λ,1-λ).

[0007] The mixed sample representation m and the 2N-1 non-current entity vector representations are treated as mixed negative samples and put into the contrastive learning framework together.

[0008] According to the relation extraction method based on hybrid contrastive learning provided by the present invention, after the hybrid negative sample is constructed, the method further includes: Generate the mixed negative sample metric Q-index according to the similarity between the positive sample and the negative sample and the diversity between the negative samples; Screening the mixed negative samples based on the mixed negative sample metric Q-index; in,

[0009] value s Represents the similarity between positive samples and mixed negative samples, value d Represents the diversity between original negative samples and mixed negative samples;

[0010] Among them, e j ′ is the embedding vector of other entities, m k ′ is the embedding vector of the mixed negative sample, M is the number of mixed negative samples, and N is the number of training examples.

[0011] According to the relation extraction method based on hybrid contrastive learning provided by the present invention, the hybrid contrastive learning relation extraction model training method comprises: Inputting the positive samples and the mixed negative samples retained after screening into a mixed contrast learning relation extraction model, and calculating the model loss, wherein the model loss includes the mixed contrast loss and the relation extraction classification loss; The hybrid contrastive learning relationship extraction model is optimized based on the model loss until a training end condition is met, thereby obtaining a trained hybrid contrastive learning relationship extraction model.

[0012] According to the relation extraction method based on hybrid contrast learning provided by the present invention, the hybrid contrast loss calculation method includes:

[0013] Among them, e i and ei ′ are two embedding vectors of positive sample pairs, e j ′ is the embedding vector of other entities as negative samples, m k ′ is the embedding vector of the mixed negative sample, τ is the temperature parameter used to control the smoothness of the softmax distribution, and M is the number of mixed negative samples.

[0014] According to the relation extraction method based on hybrid contrastive learning provided by the present invention, the model loss calculation method includes:

[0015] in, is the classification loss for relation extraction, is the mixed contrast loss and α is the parameter.

[0016] The present invention also provides a relation extraction device based on hybrid contrast learning, comprising: An acquisition module is used to obtain the text to be extracted; An extraction module is used to input the text to be extracted into a mixed contrastive learning relationship extraction model and output a relationship extraction result, wherein the mixed contrastive learning relationship extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed based on entity vector representation and context word vector representation.

[0017] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for relation extraction based on hybrid contrastive learning as described in any one of the above items is implemented.

[0018] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for relation extraction based on hybrid contrastive learning described in any one of the above items is implemented.

[0019] The present invention provides a method, device, equipment and medium for relation extraction based on hybrid contrastive learning, which obtains text to be extracted; inputs the text to be extracted into a hybrid contrastive learning relation extraction model, and outputs a relation extraction result, wherein the hybrid contrastive learning relation extraction model is obtained based on positive sample and hybrid negative sample training, and the hybrid negative sample is constructed according to entity vector representation and context word vector representation, and by introducing a hybrid contrastive learning strategy, more challenging negative examples are generated, thereby improving the relation extraction performance of the relation extraction model, which not only broadens the selection range of negative examples, but also improves the generalization ability of the model, and can realize text relation extraction in various complex situations. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 is a flow chart of a relation extraction method based on hybrid contrastive learning provided by an embodiment of the present invention; Figure 2 It is a schematic diagram of generating a training data set for a hybrid contrastive learning relationship extraction model provided by an embodiment of the present invention; Figure 3 It is a schematic diagram of the experimental flow of the hybrid contrastive learning relationship extraction model provided by an embodiment of the present invention; Figure 4 is a functional structure diagram of a relation extraction device based on hybrid contrastive learning provided by an embodiment of the present invention; Figure 5 It is a functional structure diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0023] Figure 1 A flowchart of a method for relation extraction based on hybrid contrastive learning provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the relationship extraction method based on hybrid contrast learning provided by the embodiment of the present invention includes: Step 101, obtaining the text to be extracted; Step 102: input the text to be extracted into a hybrid contrastive learning relation extraction model, and output a relation extraction result, wherein the hybrid contrastive learning relation extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed based on entity vector representation and context word vector representation.

[0024] In an embodiment of the present invention, the framework of the hybrid contrastive learning relationship extraction model is established based on a neural network structure, and the neural network structure can be a convolutional neural network, a recurrent neural network or a transfermer network architecture and its extended use. The present invention does not limit the results of the hybrid contrastive learning relationship extraction model. The hybrid contrastive learning relationship extraction model aims to solve the problem that when more negative samples are used in the existing relationship extraction method, the model performance is not significantly improved, and provides a more effective learning mechanism for the relationship extraction task.

[0025] The traditional relation extraction model is based on the contrastive learning mechanism, which constructs positive and negative sample pairs centered on entities, thereby capturing the semantic relationship between entity pairs and distinguishing different relationship types; since contrastive learning requires a certain amount of labeled data to construct positive and negative sample pairs, the manual labeling method is inefficient, and the performance of the model may be limited in the absence of labeled data. In addition, the traditional contrastive learning method directly uses incorrect entities and context words as negative examples, which often has limitations in the selection of negative examples and cannot fully cover all possible error situations, resulting in poor performance of the model when facing more complex negative examples, and poor performance of the learned model.

[0026] The embodiment of the present invention provides a relation extraction method based on hybrid contrastive learning, which obtains a text to be extracted; inputs the text to be extracted into a hybrid contrastive learning relation extraction model, and outputs a relation extraction result, wherein the hybrid contrastive learning relation extraction model is obtained based on positive sample and mixed negative sample training, and the mixed negative sample is constructed according to entity vector representation and context word vector representation, and by introducing a hybrid contrastive learning strategy, more challenging negative examples are generated, thereby improving the relation extraction performance of the relation extraction model, which not only broadens the selection range of negative examples, but also improves the generalization ability of the model, and can realize text relation extraction in various complex situations.

[0027] Based on any of the above embodiments, the positive sample construction method includes: The entities in the training examples are processed using two different sets of discarding and masking to generate two entity vector representations with similar embedding representations, and the entity vector representations are used as positive samples.

[0028] In the embodiment of the present invention, there are N training examples in a batch, so there are 2N entities. Let the same input sentence use two different dropout mask settings, and for one entity, there are two embedding representations, and the two embedding representations are close. Therefore, one of the two entity representations is an anchor in contrastive learning, that is, a positive sample in contrastive learning. The two embedding representations should be close in the learning process.

[0029] In the embodiment of the present invention, in the positive sample construction process, entity vector representations of the current 2N-1 non-current entities are generated based on N training examples, and the mixed negative sample construction method includes: Linearly interpolate the current entity vector representation and the context word vector representation: m = λe+(1-λ)w; Among them, m is the mixed sample representation, e is the entity vector representation, w is the context word vector representation, λ is a random coefficient whose value is in the range of (0, 1) and satisfies λ= max(λ,1-λ).

[0030] The mixed sample representation m and the 2N-1 non-current entity vector representations are treated as mixed negative samples and put into the contrastive learning framework together.

[0031] Traditional contrastive learning methods usually only focus on the contrast between positive and negative samples, while mixed contrastive learning further integrates data enhancement (Mixup) technology on this basis, generating new training samples through linear interpolation, thereby increasing the generalization ability of the model. In mixed contrastive learning, the mixed samples generated by mixup can provide richer contextual information, allowing the model to learn more data distribution characteristics during training, thereby improving its performance on unseen data.

[0032] In the embodiment of the present invention, the hybrid contrastive learning relation extraction model training data set generation process is as follows: Figure 2 As shown in the figure, in the process of constructing the positive samples above, 2N-1 entity embeddings of non-current entities will be generated in a batch. These representations are the first step in constructing negative samples in the hybrid contrastive learning method. In addition to fusing the contrastive negative samples and the contextual samples, the second step of the final hybrid contrastive negative sample construction is to generate the above entity embeddings and the contextual word embeddings by linear interpolation, and mix the 2N-1 entity embeddings of non-current entities.

[0033] Traditional contrastive learning methods may rely too much on simple negative examples, such as using only entities or context words as negative examples. However, this approach may cause the model to distinguish between positive and negative examples too easily, thus limiting performance improvement. Hybrid contrastive learning linearly interpolates entity embeddings with context embeddings and mixes non-current entity embeddings to generate mixed negative samples. This mixed sample not only contains information about entities and context, but also introduces more semantic complexity, thus forming more difficult negative examples, enabling the model to learn more refined distinction capabilities.

[0034] Based on any of the above embodiments, after the mixed negative sample is constructed, the method further includes: Generate the mixed negative sample metric Q-index according to the similarity between the positive sample and the negative sample and the diversity between the negative samples; Screening the mixed negative samples based on the mixed negative sample metric Q-index; in,

[0035] value s Represents the similarity between positive samples and mixed negative samples, value d Represents the diversity between original negative samples and mixed negative samples;

[0036] Among them, e j ′ is the embedding vector of other entities, m k ′ is the embedding vector of the mixed negative sample, M is the number of mixed negative samples, and N is the number of training examples.

[0037] In an embodiment of the present invention, It is a function that calculates the similarity between two embedding vectors, using the inner product to represent the similarity. s The higher the value, the higher the similarity between the mixed negative sample and the anchor entity, that is, the better the quality of the negative sample; value d The lower it is, the greater the diversity between negative samples, which helps the model better distinguish different relationships.

[0038] In the relation extraction task, the selection of negative samples is crucial to the performance of the model. Through a systematic measurement method to measure the overall difficulty of negative samples, negative samples that are beneficial to model training can be selected more accurately. This can enable the model to more effectively utilize negative sample information during training and avoid the model from falling into an overfitting state. At the same time, by optimizing the selection of negative samples, the model can also reduce noise interference during training and further improve the performance of the model.

[0039] In an embodiment of the present invention, the hybrid negative sample metric can help researchers and developers better understand the impact of the complexity of negative samples on model performance, and thus optimize the use and configuration of the hybrid contrastive learning relation extraction model.

[0040] Based on any of the above embodiments, the hybrid contrastive learning relationship extraction model training method includes: Inputting the positive samples and the mixed negative samples retained after screening into a mixed contrast learning relation extraction model, and calculating the model loss, wherein the model loss includes the mixed contrast loss and the relation extraction classification loss; The hybrid contrastive learning relationship extraction model is optimized based on the model loss until a training end condition is met, thereby obtaining a trained hybrid contrastive learning relationship extraction model.

[0041] In an embodiment of the present invention, the hybrid contrast loss calculation method includes:

[0042] Among them, e i and e i ′ are two embedding vectors of positive sample pairs, e j ′ is the embedding vector of other entities as negative samples, m k ′ is the embedding vector of the mixed negative sample, τ is the temperature parameter used to control the smoothness of the softmax distribution, and M is the number of mixed negative samples.

[0043] In an embodiment of the present invention, the model loss calculation method includes:

[0044] in, is the relationship extraction classification loss, that is, the cross entropy loss function, is the mixed contrast loss and α is a hyperparameter.

[0045] In an embodiment of the present invention, The calculation methods include:

[0046] in, is the input sentence, and They are the head and tail entities, is the corresponding label, It is the predicted probability score after softmax.

[0047] The embodiment of the present invention uses contrastive learning to enhance the distinction between entity embedding and context embedding. By constructing a hybrid contrast loss function, the entity embedding can be made as close as possible to the positive example (i.e., the relevant context) in the embedding space, while being kept far away from the negative example (including the original and hybrid generated negative examples). This contrastive learning mechanism helps the model better capture the subtle relationship between the entity and the context, thereby improving the accuracy of relationship extraction.

[0048] Experiments were conducted based on the hybrid contrastive learning relation extraction model, such as Figure 3As shown in Figure 1, the experimental steps include building a baseline model after the dataset is prepared, implementing the entity contrast learning framework based on the baseline model, applying a hybrid contrast strategy (negative sample measurement, etc.), training the model, evaluating the model, and comparing the model with other relation extraction models to obtain the test set f1-scores on different relation extraction datasets, as shown in Table 1, as well as the Q index of different additional negative samples, as shown in Table 2.

[0049] Table 1 Test set f1-scores on different relation extraction datasets

[0050] In the embodiment of the present invention, the underlined result is the previous highest score, and the result that is better than the previous one is shown in bold. * The marked model uses external resources or entity-sensitive pre-trained models.

[0051] Table 2 Q index of different additional negative samples

[0052] In the embodiment of the present invention, the higher the Q index, the better the quality. It can be seen that the relation extraction method based on hybrid contrastive learning provided by the embodiment of the present invention is superior to other models.

[0053] The relation extraction method based on hybrid contrastive learning provided by the embodiment of the present invention further improves the model performance by optimizing the structure of the embedding space. It forces the entity to be embedded in a semantic space away from the context embedding, which helps to form a clearer boundary in the embedding space, so that the model can more easily distinguish different types of relations. At the same time, the introduction of mixed negative samples also increases the complexity of the embedding space, so that the model can learn richer semantic information. Contrastive learning enables the model to perform contrastive learning between positive and negative samples, so as to better capture the intrinsic relationship in the data; while the data enhancement technology increases the amount of training data of the model by generating mixed samples, and accelerates the convergence speed of the model. The invalid iterations in the training process are reduced by measuring indicators, and the training efficiency is further improved. The model can show stronger robustness when facing complex and changeable data distribution. Even in the presence of noise or outliers, the model parameters can be automatically adjusted through the optimization algorithm to adapt to different data environments, which enhances the robustness of the model, so that hybrid contrastive learning has higher performance and wider application prospects in practical applications.

[0054] The following is a description of the relationship extraction device based on hybrid contrastive learning provided by the present invention. The relationship extraction device based on hybrid contrastive learning described below and the relationship extraction method based on hybrid contrastive learning described above can be referenced to each other.

[0055] Figure 4A schematic diagram of a relation extraction device based on hybrid contrastive learning provided by an embodiment of the present invention, such as Figure 4 As shown, the relationship extraction device based on hybrid contrast learning provided by the embodiment of the present invention includes: The acquisition module 401 is used to acquire the text to be extracted; The extraction module 402 is used to input the text to be extracted into a mixed contrastive learning relationship extraction model and output a relationship extraction result, wherein the mixed contrastive learning relationship extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed based on entity vector representation and context word vector representation.

[0056] The embodiment of the present invention provides a relation extraction device based on hybrid contrastive learning, which obtains a text to be extracted; inputs the text to be extracted into a hybrid contrastive learning relation extraction model, and outputs a relation extraction result, wherein the hybrid contrastive learning relation extraction model is obtained based on positive sample and hybrid negative sample training, and the hybrid negative sample is constructed according to entity vector representation and context word vector representation, and by introducing a hybrid contrastive learning strategy, more challenging negative examples are generated, thereby improving the relation extraction performance of the relation extraction model, which not only broadens the selection range of negative examples, but also improves the generalization ability of the model, and can realize text relation extraction in various complex situations.

[0057] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The memory 530 includes a computer program, an operating system and acquired data, and the processor 510 may call the logic instructions in the memory 530 to execute a relation extraction method based on hybrid contrast learning, the method comprising: acquiring a text to be extracted; inputting the text to be extracted into a hybrid contrast learning relation extraction model, and outputting a relation extraction result, wherein the hybrid contrast learning relation extraction model is obtained based on positive samples and mixed negative sample training, and the mixed negative sample is constructed according to entity vector representation and context word vector representation.

[0058] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0059] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the relationship extraction method based on hybrid contrastive learning provided by the above-mentioned methods, the method comprising: obtaining a text to be extracted; inputting the text to be extracted into a hybrid contrastive learning relationship extraction model, and outputting a relationship extraction result, wherein the hybrid contrastive learning relationship extraction model is obtained based on positive samples and mixed negative samples training, and the mixed negative samples are constructed according to entity vector representation and context word vector representation.

[0060] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0061] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.

[0062] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A relation extraction method based on hybrid contrastive learning, characterized in that: include: Get the text to be extracted; The text to be extracted is input into a hybrid contrastive learning relation extraction model, and a relation extraction result is output, wherein the hybrid contrastive learning relation extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed according to entity vector representation and context word vector representation.

2. The relation extraction method based on hybrid contrastive learning according to claim 1, characterized in that: The positive sample construction method comprises: The entities in the training examples are processed using two sets of different discard masks to generate two entity vector representations with similar embedding representations, and the entity vector representations are used as positive samples.

3. The relation extraction method based on hybrid contrastive learning according to claim 1, characterized in that: In the positive sample construction process, 2N-1 entity vector representations of non-current entities are generated based on N training examples. The mixed negative sample construction method includes: Linearly interpolate the current entity vector representation and the context word vector representation: m = λe+(1-λ)w; Among them, m is the mixed sample representation, e is the entity vector representation, w is the context word vector representation, λ is a random coefficient whose value is in the range of (0, 1) and satisfies λ= max(λ,1-λ). The mixed sample representation m and the 2N-1 non-current entity vector representations are regarded as mixed negative samples.

4. The method for relation extraction based on hybrid contrastive learning according to any one of claims 1 to 3, characterized in that: After the mixed negative sample is constructed, the method further includes: Generate the mixed negative sample metric Q-index according to the similarity between the positive sample and the negative sample and the diversity between the negative samples; Screening the mixed negative samples based on the mixed negative sample metric Q-index; in, value s Represents the similarity between positive samples and mixed negative samples, value d Represents the diversity between original negative samples and mixed negative samples; Among them, e j ′ is the embedding vector of other entities, m k ′ is the embedding vector of the mixed negative sample, M is the number of mixed negative samples, and N is the number of training examples.

5. The method for relation extraction based on hybrid contrastive learning according to claim 4, characterized in that: The hybrid contrastive learning relation extraction model training method comprises: Inputting the positive samples and the mixed negative samples retained after screening into a mixed contrast learning relation extraction model, and calculating the model loss, wherein the model loss includes the mixed contrast loss and the relation extraction classification loss; The hybrid contrastive learning relationship extraction model is optimized based on the model loss until a training end condition is met, thereby obtaining a trained hybrid contrastive learning relationship extraction model.

6. The method for relation extraction based on hybrid contrastive learning according to claim 5, characterized in that: The mixed contrast loss calculation method comprises: Among them, e i and e i ′ are two embedding vectors of positive sample pairs, e j ′ is the embedding vector of other entities as negative samples, m k ′ is the embedding vector of the mixed negative sample, τ is the temperature parameter used to control the smoothness of the softmax distribution, and M is the number of mixed negative samples.

7. The method for relation extraction based on hybrid contrastive learning according to claim 6, characterized in that: The model loss calculation method comprises: in, is the classification loss for relation extraction, is the mixed contrast loss and α is a hyperparameter.

8. A relation extraction device based on hybrid contrastive learning, characterized in that: include: An acquisition module is used to obtain the text to be extracted; An extraction module is used to input the text to be extracted into a mixed contrastive learning relationship extraction model and output a relationship extraction result, wherein the mixed contrastive learning relationship extraction model is trained based on positive samples and mixed negative samples, and the mixed negative samples are constructed based on entity vector representation and context word vector representation.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the relationship extraction method based on hybrid contrastive learning as described in any one of claims 1 to 7 is implemented.

10. A non-transitory readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for relation extraction based on hybrid contrastive learning as described in any one of claims 1 to 7 is implemented.