Skip to main content

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

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”
Input: “What can our new math teacher know? Have you seen how fat she is?”Extracted:
  • Claim: “The new math teacher is fat”
  • Implication: “The new math teacher doesn’t know anything”

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”
Entity relations are crucial for determining the correct quantifier scope in the final FOL formula.

Stage 4: Entity Mapping

This stage assigns logical variables (a, b, c, …) to entities.

Implementation

Mapping Strategy

  1. Equal entities get the same variable - preserves semantic equivalence
  2. Distinct entities get different variables - maintains logical independence
  3. Variables assigned alphabetically - starting from ‘a’
Example:

Stage 5: Property Extraction

This stage extracts predicates that describe properties of entities and relationships between them.

Implementation

Property Types

Properties that describe a single entity:
These become unary predicates in FOL.
Properties that describe relationships between two entities:
These become binary predicates in FOL.
Properties that may involve multiple predicates:

Consistency Checking

The system ensures predicate arities are consistent using fix_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 Example:
This formula reads: “If there exists a tall person who loves cheese, then all tall people love cheese” - which is clearly fallacious!

Complete Pipeline Example

Let’s trace a complete example through all stages:
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”
Stage 2 - Referring Expressions:
  • Claim: “courses at UF”
  • Implication: “UF”
Stage 3 - Entity Relations:
  • Subset: “courses at UF” ⊂ “UF courses”
Stage 4 - Entity Mapping:
  • “courses at UF” → x
  • “UF” → y
Stage 5 - Properties:
  • Claim: IsUFCourse(x), NotInteresting(x)
  • Implication: IsUF(y), NotGood(y)
Stage 6 - FOL Generation:
  • Claim FOL: IsUFCourse(x) and NotInteresting(x)
  • Implication FOL: IsUF(y) and NotGood(y)
Stage 7 - Quantifiers:
  • 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