Overview
This guide walks you through a basic example of using NL2FOL to translate a natural language statement into first-order logic and detect logical fallacies.Prerequisites
Before you begin, ensure you have:- Installed NL2FOL and its dependencies
- Set up your OpenAI API key (for GPT models) or Llama model access
- Installed the required NLI model
Quick Example
1
Import the NL2FOL class
Start by importing the necessary modules:
2
Initialize the models
Set up your language model and NLI model:
3
Create an NL2FOL instance
Initialize the translator with your sentence:
4
Convert to first-order logic
Run the conversion pipeline:The output will show:
- Claim and implication extraction
- Referring expressions
- Entity mappings
- Property relations
- Final first-order logic formulas
Understanding the Output
When you run the example above withdebug=True, you’ll see detailed output including:
Complete Working Example
Here’s a complete script you can run:nl2fol_basic.py
Key Parameters
string
required
The natural language statement to translate. This should contain a claim and implication structure.
string
required
The LLM backend to use. Options:
'gpt' or 'llama'boolean
default:"false"
Enable detailed logging of the translation pipeline steps
Pipeline
HuggingFace text generation pipeline (required for Llama models,
None for GPT)Tokenizer
HuggingFace tokenizer (required for Llama models,
None for GPT)Model
required
Natural Language Inference model for entity relation detection
Tokenizer
required
Tokenizer for the NLI model
Next Steps
Model Backends
Learn how to switch between GPT-4 and Llama models
Custom Datasets
Process your own datasets for fallacy detection
SMT Solving
Use CVC5 to verify logical formulas
API Reference
Explore the complete NL2FOL API
The translation pipeline uses multiple LLM calls to extract claims, referring expressions, properties, and logical forms. With GPT-4, expect the process to take 10-30 seconds per sentence depending on complexity.
