Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lovishchopra/NL2FOL/llms.txt
Use this file to discover all available pages before exploring further.
Pipeline Overview
The NL2FOL system uses a sophisticated multi-stage pipeline to convert natural language statements into first-order logic formulas. Each stage progressively refines the representation, ultimately producing a formal logical formula that can be verified by SMT solvers.The pipeline is implemented in the
NL2FOL class (src/nl_to_fol.py:15-388) and orchestrates multiple LLM calls with specialized prompts to extract logical structure from text.Architecture
Stage 1: Claim and Implication Extraction
The first stage separates the argument into its premise (claim) and conclusion (implication).Implementation
Prompt Template
The system uses few-shot learning with examples:The prompt instructs the LLM to:
- Identify multiple claims if present, but only one implication
- Remove subordinating conjunctions from implications
- Replace pronouns with appropriate nouns for clarity
Example Transformations
Example 1: Simple Generalization
Example 1: Simple Generalization
Input: “The two courses I took at UF were not very interesting. I don’t think it’s a good university.”Extracted:
- Claim: “Two courses at UF were not very interesting”
- Implication: “UF is not a good university”
Example 2: Authority Fallacy
Example 2: Authority Fallacy
Stage 2: Referring Expressions
This stage identifies all noun phrases, pronouns, and proper names that refer to entities in the argument.Implementation
What are Referring Expressions?
Referring expressions are linguistic elements that reference entities:Noun Phrases
“a tall man”
“the new teacher”
“all students”
Pronouns
“he”, “she”, “it”
“they”, “them”
“this”, “that”
Proper Names
“Harvard”
“Michael Vick”
“New York”
Examples
Stage 3: Entity Relations
This stage determines relationships between entities mentioned in the claim and implication.Implementation
Relationship Types
Equal Entities
Entities that refer to the same thingExamples:
- “a tall man” ≈ “tall people”
- “the teacher” ≈ “she”
Subset Relations
One entity is a subset of anotherExamples:
- “Harvard students” ⊂ “students”
- “New York drivers” ⊂ “drivers”
Stage 4: Entity Mapping
This stage assigns logical variables (a, b, c, …) to entities.Implementation
Mapping Strategy
- Equal entities get the same variable - preserves semantic equivalence
- Distinct entities get different variables - maintains logical independence
- Variables assigned alphabetically - starting from ‘a’
Stage 5: Property Extraction
This stage extracts predicates that describe properties of entities and relationships between them.Implementation
Property Types
Unary Properties (Single Argument)
Unary Properties (Single Argument)
Properties that describe a single entity:These become unary predicates in FOL.
Binary Relations (Two Arguments)
Binary Relations (Two Arguments)
Properties that describe relationships between two entities:These become binary predicates in FOL.
Complex Properties
Complex Properties
Properties that may involve multiple predicates:
Consistency Checking
The system ensures predicate arities are consistent usingfix_inconsistent_arities():
If the same predicate appears with different numbers of arguments, the system uses the minimum arity to maintain consistency.
Stage 6: FOL Generation
This stage converts properties into first-order logic formulas using logical connectives.Implementation
Prompt Examples
The prompt teaches the LLM to combine properties with logical operators:Heuristics Applied
The system applies heuristics to normalize logical operators, replacing implications in claims with conjunctions and converting symbols to words.
Stage 7: Quantifier Application
The final stage adds quantifiers (exists/forall) based on entity relationships and constructs the complete FOL formula.Implementation
Quantifier Rules
Claims (Premises)
Typically use existential quantifiers (exists)Represents specific observations:
Implications (Conclusions)
Typically use universal quantifiers (forall)Represents general claims:
Final Formula Structure
The complete formula follows the pattern:Complete Pipeline Example
Let’s trace a complete example through all stages:Full Pipeline Walkthrough
Full Pipeline Walkthrough
Input: “The two courses I took at UF were not very interesting. I don’t think it’s a good university.”Stage 1 - Claim & Implication:
- Claim: “Two courses at UF were not very interesting”
- Implication: “UF is not a good university”
- Claim: “courses at UF”
- Implication: “UF”
- Subset: “courses at UF” ⊂ “UF courses”
- “courses at UF” → x
- “UF” → y
- Claim: IsUFCourse(x), NotInteresting(x)
- Implication: IsUF(y), NotGood(y)
- Claim FOL: IsUFCourse(x) and NotInteresting(x)
- Implication FOL: IsUF(y) and NotGood(y)
- Final:
exists x (IsUFCourse(x) and NotInteresting(x)) -> forall y (IsUF(y) -> NotGood(y))
Model Selection
The pipeline supports multiple LLM backends:The system can use:
- GPT-4: For higher accuracy and better reasoning
- Llama models: For local deployment and cost efficiency
Next Steps
First-Order Logic
Learn the formal logic notation used in the pipeline
SMT Solving
Understand how the final FOL is verified
API Reference
Use the NL2FOL class in your code
Quick Start
Try the pipeline yourself
