Skip to content

Repository files navigation

From-Phrases-to-Subgraphs

📂 Project Structure

FineSP/
├── config.py             # Configuration management (Paths, API endpoints)
├── utils.py              # Utility functions (I/O operations)
├── prompt.py             # Prompt templates for LLMs
├── logic_form_parser.py  # Stage 1: Logic form extraction
├── phrase_level_seg.py   # Stage 2: Phrase-level segmentation
├── question_deco.py      # Stage 3: Question decomposition
├── retrieval_phase.py    # Stage 4: Dense retrieval
├── subgraph_fusion.py    # Stage 5: Subgraph fusion & evaluation
└── datasets/             # Directory for datasets (CWQ, etc.)

🛠️ Installation

1. Clone the repository

git clone https://github.com/yourusername/FineSP.git
cd FineSP

2. Install Dependencies

Ensure you have a Python environment (Python 3.8+ recommended). Install the required packages:

pip install torch transformers faiss-gpu FlagEmbedding SPARQLWrapper ujson tqdm numpy scikit-learn

Note: If you don't have a GPU, install faiss-cpu instead.

⚙️ Configuration

FineSP uses config.py to manage file paths and model locations. You can either modify config.py directly or use environment variables.

Key Configuration Variables

Variable Description
COMPLEX_WEB_QUESTIONS_TRAIN Path to the CWQ training dataset JSON.
BAAI_BGE_M3_MODEL Path to the local BAAI/bge-m3 embedding model.
QWEN_MODEL_PATH Path to the local Qwen-Instruct model.
SPARQL_ENDPOINT URL of your SPARQL endpoint (default: http://localhost:8890/sparql).

Example Setup: Open config.py and set the paths to your local data:

# config.py
COMPLEX_WEB_QUESTIONS_TRAIN = "./datasets/cwq/train/train.json"
BAAI_BGE_M3_MODEL = "/path/to/BAAI.bge-m3/"
# ...

🚀 Usage

The pipeline consists of several stages. Ensure you have your data prepared in the datasets/ folder.

1. Logic Form Parsing

Extract logical forms and inference chains from the training data.

python logic_form_parser.py

2. Phrase-Level Segmentation

Segment complex questions and SPARQL queries into aligned pairs for training.

python phrase_level_seg.py

Requires results/ from previous LLM segmentation or configured input files.

3. Question Decomposition

Decompose input questions into sub-questions using the Qwen model.

python question_deco.py

4. Retrieval Phase

Build the FAISS index and perform retrieval for test questions.

python retrieval_phase.py

5. Subgraph Fusion

Fuse the retrieved subgraphs and evaluate the generated SPARQL queries against the KB.

python subgraph_fusion.py

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages