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.)
git clone https://github.com/yourusername/FineSP.git
cd FineSPEnsure 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-learnNote: If you don't have a GPU, install faiss-cpu instead.
FineSP uses config.py to manage file paths and model locations. You can either modify config.py directly or use environment 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/"
# ...The pipeline consists of several stages. Ensure you have your data prepared in the datasets/ folder.
Extract logical forms and inference chains from the training data.
python logic_form_parser.pySegment complex questions and SPARQL queries into aligned pairs for training.
python phrase_level_seg.pyRequires results/ from previous LLM segmentation or configured input files.
Decompose input questions into sub-questions using the Qwen model.
python question_deco.pyBuild the FAISS index and perform retrieval for test questions.
python retrieval_phase.pyFuse the retrieved subgraphs and evaluate the generated SPARQL queries against the KB.
python subgraph_fusion.py