> ## 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.

# Installation

> Set up NL2FOL and install all required dependencies

## Prerequisites

Before installing NL2FOL, ensure you have the following:

<CardGroup cols={2}>
  <Card title="Python 3.7+" icon="python">
    Python 3.7 or higher is required
  </Card>

  <Card title="CUDA (Optional)" icon="microchip">
    NVIDIA GPU with CUDA for faster inference
  </Card>

  <Card title="CVC4/CVC5" icon="gears">
    SMT solver binary for logical verification
  </Card>

  <Card title="OpenAI API Key" icon="key">
    Required if using GPT models
  </Card>
</CardGroup>

## Clone the Repository

First, clone the NL2FOL repository:

```bash theme={null}
git clone https://github.com/lovishchopra/NL2FOL.git
cd nl2fol
```

## Install Python Dependencies

The project requires several key dependencies for LLM inference, transformers, and SMT solving.

### Core Dependencies

Install all required packages using the provided requirements file:

```bash theme={null}
pip install -r requirements.txt
```

### Key Packages

The main dependencies include:

<AccordionGroup>
  <Accordion title="Deep Learning & NLP">
    * **transformers** (v4.33.3): Hugging Face transformers library for LLM access
    * **torch** (v2.4.1): PyTorch for model inference
    * **torchvision** (v0.19.1): Vision utilities
    * **accelerate** (v1.0.1): Distributed training and inference
    * **tokenizers**: Fast tokenization
    * **sacremoses**: Text preprocessing
  </Accordion>

  <Accordion title="API & External Services">
    * **openai** (v1.52.0): OpenAI API client for GPT models
    * **httpx** (v0.27.2): Modern HTTP client
    * **requests**: HTTP library for API calls
  </Accordion>

  <Accordion title="Data Processing">
    * **pandas**: DataFrame operations for dataset handling
    * **numpy**: Numerical computing
    * **scikit-learn**: Metrics calculation (via joblib)
  </Accordion>

  <Accordion title="Utilities">
    * **pydantic** (v2.9.2): Data validation
    * **tqdm**: Progress bars
    * **click**: CLI argument parsing
  </Accordion>
</AccordionGroup>

<Note>
  The requirements.txt includes many conda-built packages. If you encounter issues, consider using a conda environment or removing the file path references from the requirements.
</Note>

## Install SMT Solver

The project uses CVC4 or CVC5 for SMT solving. Download and install the solver:

### CVC4 Installation

```bash theme={null}
# Download CVC4 binary
wget https://github.com/CVC4/CVC4/releases/download/1.8/cvc4-1.8-x86_64-linux-opt

# Make it executable
chmod +x cvc4-1.8-x86_64-linux-opt

# Move to project root (or add to PATH)
mv cvc4-1.8-x86_64-linux-opt ./cvc4
```

### CVC5 Installation (Alternative)

```bash theme={null}
# Download CVC5 binary
wget https://github.com/cvc5/cvc5/releases/latest/download/cvc5-Linux

# Make it executable
chmod +x cvc5-Linux

# Move to project root
mv cvc5-Linux ./cvc5
```

<Warning>
  The code references `./cvc4` in src/fol\_to\_cvc.py:24. Ensure the binary is named correctly or update the path in the code.
</Warning>

## Set Up OpenAI API Key

If you plan to use GPT models, configure your OpenAI API key:

```bash theme={null}
export OPENAI_API_KEY="your-api-key-here"
```

Or add it to your shell profile:

```bash theme={null}
echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.bashrc
source ~/.bashrc
```

## Verify GPU Access (Optional)

If using a GPU, verify CUDA availability:

```bash theme={null}
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}'); print(f'GPU count: {torch.cuda.device_count()}')"
```

Expected output:

```
CUDA available: True
GPU count: 1
```

## Directory Structure

After installation, ensure your directory structure looks like this:

```
nl2fol/
├── src/
│   ├── nl_to_fol.py          # Main NL to FOL conversion
│   ├── fol_to_cvc.py          # FOL to SMT conversion
│   ├── cvc.py                 # CVC script generator
│   ├── helpers.py             # Utility functions
│   └── interpret_smt_results.py
├── eval/
│   └── get_metrics.py         # Evaluation metrics
├── data/
│   ├── fallacies.csv          # Fallacy dataset
│   ├── fallacies_climate.csv  # Climate fallacies
│   └── nli_*.csv              # NLI datasets
├── prompts/                   # LLM prompt templates
├── results/                   # Output directory (create if needed)
├── requirements.txt
├── cvc4 (or cvc5)            # SMT solver binary
└── README.md
```

## Create Output Directories

Create necessary directories for storing results:

```bash theme={null}
mkdir -p results
```

<Note>
  The SMT output directories will be created automatically when running the pipeline.
</Note>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Import errors for transformers">
    Ensure you have the correct version:

    ```bash theme={null}
    pip install transformers==4.33.3 --upgrade
    ```
  </Accordion>

  <Accordion title="CUDA out of memory">
    Reduce batch size or use CPU inference:

    ```bash theme={null}
    export CUDA_VISIBLE_DEVICES=""
    ```
  </Accordion>

  <Accordion title="CVC4 not found">
    Verify the binary path matches the code:

    ```bash theme={null}
    ls -la ./cvc4
    # Or update line 24 in src/fol_to_cvc.py
    ```
  </Accordion>

  <Accordion title="OpenAI API errors">
    Verify your API key is set:

    ```bash theme={null}
    echo $OPENAI_API_KEY
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<Card title="Quick Start Guide" icon="rocket" href="/quickstart">
  Learn how to run your first logical fallacy detection
</Card>
