Overview
NL2FOL supports two model backends for the translation pipeline:- GPT-4 via OpenAI API (recommended for best accuracy)
- Llama models via HuggingFace Transformers (for local/self-hosted deployments)
Model Selection
The model backend is determined by themodel_type parameter when initializing the NL2FOL class:
The model type is set in
src/nl_to_fol.py:19 during initialization and affects how get_llm_result() processes prompts throughout the pipeline.Using GPT-4 (OpenAI)
1
Set up OpenAI API
First, configure your OpenAI API key:
2
Initialize with GPT backend
3
Create NL2FOL instance
GPT Implementation Details
When using GPT, theget_llm_result() method (defined in src/nl_to_fol.py:49-67) calls the OpenAI API:
Using Llama Models
1
Install dependencies
Ensure you have the required packages:
2
Initialize Llama pipeline
3
Create NL2FOL instance
Llama Implementation Details
For Llama models, theget_llm_result() method uses HuggingFace pipelines:
Command-Line Usage
You can specify the model backend when running the main script:- GPT-4
- Llama
model_name starts with 'gpt' (see src/nl_to_fol.py:446).Model Comparison
GPT-4
Pros:
- Highest accuracy for complex reasoning
- No local GPU required
- Faster setup
- Better prompt following
- Requires API key and internet
- Per-token costs
- Rate limits apply
Llama
Pros:
- Self-hosted (no API costs)
- Data privacy
- Unlimited usage
- Customizable
- Requires GPU infrastructure
- Lower accuracy than GPT-4
- Slower inference
- More complex setup
Entity Relation Detection
Both backends use the same NLI model for entity relation detection. The model choice only affects the main translation steps:- Claim and implication extraction (
extract_claim_and_implication()) - Referring expressions (
get_referring_expressions()) - Property extraction (
get_properties()) - First-order logic generation (
get_fol())
Property entailment checking (
check_entailment() in src/nl_to_fol.py:154) always uses GPT regardless of the main model backend for consistency.GPU Requirements
GPT-4 Backend
GPT-4 Backend
- GPU: Not required (API-based)
- RAM: 8GB+ (for NLI model)
- NLI Model: ~1.4GB VRAM
Llama 7B
Llama 7B
- GPU: 1x A100 40GB or 2x RTX 3090
- VRAM: ~14GB with float16
- RAM: 16GB+
Llama 13B
Llama 13B
- GPU: 1x A100 80GB or 2x A6000
- VRAM: ~26GB with float16
- RAM: 32GB+
Llama 70B
Llama 70B
- GPU: 4x A100 80GB or 8x A6000
- VRAM: ~140GB with float16
- RAM: 64GB+
Switching Models at Runtime
You can dynamically switch models by changing themodel_type parameter:
Best Practices
1
Start with GPT-4
Use GPT-4 for initial experiments to establish a quality baseline.
2
Optimize prompts
Fine-tune your prompts with GPT-4 before trying Llama models.
3
Test with smaller Llama
If moving to Llama, start with the 7B model to validate your pipeline.
4
Scale up as needed
Move to 13B or 70B Llama models only if 7B performance is insufficient.
Next Steps
Basic Usage
Get started with a simple example
Custom Datasets
Process your own data
Translation Pipeline
Understand the conversion process
API Reference
Explore the NL2FOL class methods
