Abstract
Modern neural retrieval systems, while proficient at capturing semantic topics, often fail to respect basic Boolean logic. This paper introduces SetBERT, a model fine-tuned to bridge this "logic gap" using a novel inversed-contrastive loss and synthetic training data. SetBERT-base demonstrates significant performance gains, achieving up to a 63% improvement in recall over standard BERT models and allowing compact architectures to rival the performance of models three times their size.
The Challenge of Boolean Logic in Neural Retrieval
Despite the advancements in Large Language Models (LLMs), standard neural retrieval systems frequently treat functional words like "and," "or," and "not" as ignorable noise. This leads to significant retrieval errors when users provide specific logical constraints. For instance, a query for "Vietnam movies not about war" often returns combat films because the model prioritizes the topic ("war") over the exclusion operator ("not"). Similarly, "AND" queries often return documents satisfying only a single condition rather than the required intersection.
This failure stems from the way standard embeddings are trained; they prioritize topical similarity over logical structure. SetBERT addresses this by making neural embeddings "logic-aware," ensuring they respect complex set operations and user-defined constraints.
Methodology: Synthetic Data and Inversed-Contrastive Loss
To overcome the scarcity of high-quality Boolean query datasets, the researchers utilized GPT-3.5-turbo to generate a training set of 150,000 samples. These samples were balanced across AND, OR, and NOT operations. Each training instance includes a "gold" query, positive matches (paraphrases), and "hard negatives"—sentences that appear topically relevant but violate the logical constraint.
The Inversed-Contrastive Loss
A critical innovation in SetBERT is the move away from standard triplet loss. In traditional contrastive learning, "A" and "NOT A" are pushed so far apart that the model loses their shared topical context (e.g., both being about "Trees"). SetBERT employs an inversed-contrastive loss that penalizes logical errors—specifically pushing away hard negatives—without destroying the underlying semantic relationship between related concepts. This balance allows the model to recognize that "Trees in the Amazon" and "Trees NOT in the Amazon" share a topic while remaining logically distinct.
Experimental Results
SetBERT was evaluated using the QUEST dataset, a benchmark for entity-seeking queries with implicit set operations derived from Wikipedia. The results demonstrate that logic-aware training significantly enhances retrieval effectiveness.
Key Performance Metrics
- Massive Recall Gains: SetBERT-base achieved an Average Recall@100 of 0.296, a 63% improvement over the standard BERT-base score of 0.182.
- Efficiency and Scale: One of the most striking findings is that a logic-tuned BERT-base (110M parameters) can match or exceed the performance of a standard BERT-large (336M parameters). SetBERT-base reached a Recall@1000 of 0.612, nearly identical to BERT-large’s 0.627.
- Template Sensitivity: The model performed exceptionally well on "OR" templates, reaching a Recall@1000 of 0.673, far surpassing the BM25 baseline of 0.535. Conversely, the researchers found that using standard triplet loss (SetBERT-L-TL) led to a marked decrease in performance across nearly all logical structures.
Discussion and Future Work
SetBERT proves that specialized training objectives can compensate for model size, offering a path toward more efficient and precise retrieval systems. However, several avenues for future research remain. This study focused on the initial retrieval phase; future work should investigate SetBERT’s role in multi-stage re-ranking pipelines. Additionally, while the model was tested on complex structures like "A AND B NOT C," the training data was limited to single operations. Expanding the training set to include nested logical operations and applying these techniques to multi-modal retrieval (e.g., image search with exclusions) could further enhance the utility of logic-aware embeddings.
Summary updated