开源项目Sphere安装与配置指南
1. 项目基础介绍
Sphere项目是Facebook Research团队开发的一个开源项目,旨在为知识密集型自然语言处理(NLP)任务提供一个基于互联网语料库的通用、未经过筛选且结构化的知识源。该项目的核心是一个名为CCNet的子集,包含了1.34亿份文档,被分割成了9.06亿个段落,作为互联网语料库。
主要编程语言:Python
2. 项目使用的关键技术和框架
- Pyserini:一个用于检索的Python库,与Sphere项目的稀疏检索基线兼容。
- Distributed Faiss:用于近似最近邻搜索的高效分布式库,Sphere项目的密集模型与其兼容。
- DPR (Dense Passage Retrieval):一种用于检索任务的神经网络模型,Sphere项目中使用了DPR模型进行密集检索。
3. 项目安装和配置准备工作及详细步骤
准备工作
在开始安装之前,请确保您的系统中安装了以下依赖:
- Python 3.7
- Java 11(仅用于稀疏索引)
- Git
安装步骤
克隆项目
首先,使用Git克隆Sphere项目:
git clone git@github.com:facebookresearch/Sphere.git
cd Sphere
创建虚拟环境并安装依赖
接着,创建一个名为sphere
的虚拟环境并激活它,然后安装项目依赖:
conda create -n sphere -y python=3.7
conda activate sphere
pip install -e .
稀疏索引安装
- 下载并解压稀疏BM25索引:
mkdir -p faiss_index
wget -P faiss_index https://dl.fbaipublicfiles.com/sphere/sphere_sparse_index.tar.gz
tar -xzvf faiss_index/sphere_sparse_index.tar.gz -C faiss_index
- 安装Pyserini:
pip install jnius
pip install pyserini==0.9.4.0
- 下载稀疏索引配置文件:
mkdir -p configs
wget -P configs https://dl.fbaipublicfiles.com/sphere/bm25_sphere.json
- 更新
bm25_sphere.json
配置文件中的相关字段。
密集索引安装
- 下载DPR模型和配置文件:
mkdir -p checkpoints
wget -P checkpoints http://dl.fbaipublicfiles.com/sphere/dpr_web_biencoder.cp
mkdir -p configs
wget -P configs https://dl.fbaipublicfiles.com/sphere/dpr_web_sphere.yaml
-
更新
dpr_web_sphere.yaml
配置文件中的相关字段。 -
启动分布式Faiss服务器:
pip install -e git+https://github.com/facebookresearch/distributed-faiss#egg=distributed-faiss
python src/distributed-faiss/scripts/server_launcher.py \
--log-dir logs \
--discovery-config faiss_index/disovery_config.txt \
--num-servers 32 \
--num-servers-per-node 4 \
--timeout-min 4320 \
--save-dir faiss_index/ \
--mem-gb 500 \
--base-port 13034 \
--partition dev
注意事项
- 请根据您的实际硬件情况调整分布式Faiss服务器配置参数。
- 确保所有路径和配置正确无误。
按照以上步骤操作,您应该能够成功安装和配置Sphere项目。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考