开源项目Sphere使用教程
1. 项目介绍
Sphere是一个开源项目,由Facebook Research团队开发。该项目旨在利用开放的网页语料库作为知识密集型自然语言处理(KI-NLP)任务的通用、未经过滤和结构化的知识源。Sphere项目通过结合强大的检索基线和一个开放的网页语料库,促进了透明和可重复的研究,并为进一步比较为人类优化的搜索引擎和为神经网络设计的检索解决方案铺平了道路。
2. 项目快速启动
以下步骤将帮助您快速启动Sphere项目:
首先,克隆项目仓库:
git clone git@github.com:facebookresearch/Sphere.git
cd Sphere
接着,创建一个Python虚拟环境并激活它:
conda create -n sphere -y python=3.7 && conda activate sphere
然后,安装项目:
pip install -e .
3. 应用案例和最佳实践
案例一:使用Sphere进行检索
Sphere提供了预构建的索引,可用于稀疏检索和密集检索。以下是如何下载和使用这些索引的示例:
稀疏检索
- 下载预构建的稀疏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
- 使用KILT工具评估检索性能,您需要先安装KILT:
pip install -e git+https://github.com/facebookresearch/KILT#egg=KILT
- 执行检索:
python src/kilt/scripts/execute_retrieval.py --model_name bm25 --model_configuration configs/bm25_sphere.json --test_config src/kilt/kilt/configs/dev_data.json --output_folder output/sparse/
密集检索
- 下载预构建的密集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
-
修改配置文件中的相关字段,如
n_docs
,model_file
,rpc_retriever_cfg_file
, 和rpc_index_id
。 -
启动分布式-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
- 执行检索:
python src/kilt/scripts/execute_retrieval.py --model_name dpr_distr --model_configuration configs/dpr_web_sphere.yaml --test_config src/kilt/kilt/configs/dev_data.json --output_folder output/dense/
4. 典型生态项目
Sphere项目可以与多个生态项目配合使用,例如:
- Pyserini:用于评估检索系统的工具。
- KILT:一个用于检索式问答任务的数据集和评估框架。
- Distributed-faiss:一个用于分布式检索的库。
通过这些生态项目的结合使用,您可以更好地理解和应用Sphere项目,以推动您的自然语言处理研究。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考