Overview
TheNL2FOL class is the primary interface for translating natural language sentences into first-order logic (FOL) expressions. It orchestrates the entire translation pipeline, from claim extraction to logical formula generation.
Class Definition
Parameters
The natural language sentence to convert to first-order logic
Type of language model to use. Supported values:
'llama' or 'gpt'HuggingFace text generation pipeline (required for LLaMA models,
None for GPT)Tokenizer for the generation model (required for LLaMA models,
None for GPT)Natural Language Inference model for entity relationship detection
Tokenizer for the NLI model
Enable debug output to print intermediate results
Use direct FOL conversion (experimental)
Instance Attributes
After initialization and conversion, the following attributes are populated:Extracted claim from the input sentence
Extracted implication from the input sentence
Referring expressions identified in the claim
Referring expressions identified in the implication
List of tuples containing entities that are semantically equal
List of tuples where first entity is a subset of the second
Mapping from entity names to logical variables (a, b, c, …)
Properties extracted from the claim
Properties extracted from the implication
List of tuples representing property-level implications
Logical form of the claim
Logical form of the implication
Final first-order logic formula (claim → implication)
Alternative final formula with different quantifier handling
Methods
convert_to_first_order_logic
tuple[str, str] - A tuple containing (final_lf, final_lf2)
Pipeline Steps:
- Extract claim and implication
- Get referring expressions
- Determine entity relations
- Create entity mappings
- Extract properties
- Generate logical forms
- Apply heuristics
- Generate final formulas
extract_claim_and_implication
self.claim and self.implication attributes
get_referring_expressions
self.claim_ref_exp and self.implication_ref_exp
get_entity_relations
self.equal_entities and self.subset_entities
get_entity_mapping
self.entity_mappings dictionary
get_properties
self.claim_properties and self.implication_properties
get_properties_relations
self.property_implications
check_entailment
clause1(str): First clauseclause2(str): Second clause
bool - True if entailment exists, False otherwise
get_fol
self.claim_lf and self.implication_lf
get_direct_fol
apply_heuristics
- Replaces
->with& - Normalizes
&toand - Normalizes
|toor
get_final_lf
self.final_lf
get_final_lf2
self.final_lf2
get_llm_result
prompt(str): Input prompt for the LLMmodel_type(str, optional): Override default model type
str - LLM response text
get_nli_prob
premise(str): Premise texthypothesis(str): Hypothesis text
float - Probability of entailment (0-100)
get_nli_prob_list
premise(str): Premise texthypothesis_list(list[str]): List of hypothesis texts
list[float] - List of entailment probabilities
Utility Functions
setup_dataset
fallacy_set(str): Dataset type -'logic','logicclimate','nli', or'folio'length(int): Number of samples to load
pandas.DataFrame - Dataset with articles and label columns
The
setup_dataset function is typically used in evaluation scripts to prepare test data for batch processing.Example Usage
See Also
- CVCGenerator - Generate SMT solver input from FOL formulas
- SMTResults - Interpret solver results
- Helper Functions - Utility functions for string processing
