Abstract
Recent generative models for triple extraction treat the task as a sequence generation problem, effectively handling complex overlapping relations. However, these models often suffer from factual hallucinations and struggle with long-range dependencies. This paper introduces the Contrastive Generative Transformer (CGT), a framework that utilizes a shared Transformer architecture for both encoding and decoding. By integrating a triplet contrastive learning objective, CGT learns to distinguish between authentic triples and hallucinated ones. Experimental results on NYT, WebNLG, and MIE datasets demonstrate that CGT significantly outperforms existing generative baselines, maintaining high performance even as sentence length increases.
Introduction: The Challenge of Triple Extraction
Extracting structured knowledge—specifically subject-relation-object triples—from unstructured text is a fundamental task in Natural Language Processing (NLP). While extractive methods identify entity spans and classify relations, they often struggle with "overlapping" triples where a single entity participates in multiple relationships. Generative models offer a flexible alternative by treating extraction as a sequence-to-sequence task. However, these models frequently "hallucinate" facts not present in the source text and, when based on Recurrent Neural Networks (RNNs), fail to capture long-distance dependencies.
Methods: The CGT Framework
The Contrastive Triple Extraction with Generative Transformer (CGT) addresses these issues through a unified architecture and a novel training objective.
Shared Transformer Architecture
Instead of a separate encoder and decoder, CGT employs a single 12-layer Transformer (based on UniLM). It uses partial causal masking, allowing the "decoder" tokens to attend to the entire input sentence while only attending to previously generated tokens in the output sequence.
Triplet Contrastive Learning
To mitigate hallucinations, the model is trained to differentiate between "gold" (correct) triples and "negative" triples (where an entity is replaced with a random word). This contrastive objective forces the model to remain faithful to the input context rather than relying on internal biases.
Dynamic Attention and Calibration
During training, batch-wise dynamic attention masking prevents the model from "cheating" by seeing future tokens during generation. During inference, the contrastive classifier acts as a filter, calculating a "matching score" to prune away unfaithful or low-confidence results.
Experiments and Results
The model was evaluated on three major benchmarks: the New York Times (NYT) dataset, WebNLG, and the Medical Information Extraction (MIE) dataset.
Performance Gains
CGT achieved state-of-the-art results among generative models:
- NYT Dataset: CGT achieved an 89.1 F1 score, a substantial improvement over previous generative baselines like PNDec (78.9) and CopyMTL (72.0).
- WebNLG Dataset: It reached an 83.4 F1 score, outperforming CopyMTL by 27 points.
- MIE Dataset: On complex medical dialogues, it achieved a 79.42 F1 score, significantly beating the Bi-LSTM baseline (50.69).
Robustness to Sentence Length
A key insight is the model's robustness to sentence length. Unlike RNN-based models like CopyRE, which show a sharp decline in performance as sentences grow longer, CGT's attention mechanism allows it to maintain a stable F1 score across varying lengths.
Conclusion and Future Work
CGT demonstrates that combining generative flexibility with contrastive constraints significantly improves the faithfulness and accuracy of triple extraction. While the model occasionally struggles with precise entity boundaries, its ability to handle long-range dependencies and filter out hallucinations marks a substantial advancement. Future work may involve scaling the architecture with backbones like Longformer to process document-level text.
Summary updated