搜索推薦系統(tǒng)專欄簡介:搜索推薦全流程講解(召回粗排精排重排混排)、系統(tǒng)架構(gòu)、常見問題、算法項目實戰(zhàn)總結(jié)、技術(shù)細節(jié)以及項目實戰(zhàn)(含碼源)
專欄詳細介紹:搜索推薦系統(tǒng)專欄簡介:搜索推薦全流程講解(召回粗排精排重排混排)、系統(tǒng)架構(gòu)、常見問題、算法項目實戰(zhàn)總結(jié)、技術(shù)細節(jié)以及項目實戰(zhàn)(含碼源)
前人栽樹后人乘涼,本專欄提供資料:
- 推薦系統(tǒng)算法庫,包含推薦系統(tǒng)經(jīng)典及最新算法講解,以及涉及后續(xù)業(yè)務(wù)落地方案和碼源
- 本專欄會持續(xù)更新業(yè)務(wù)落地方案以及碼源。同時我也會整理總結(jié)出有價值的資料省去你大把時間,快速獲取有價值信息進行科研or業(yè)務(wù)落地。幫助你快速完成任務(wù)落地,以及科研baseline
釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[1.安裝部署篇–簡潔版],支持Linux/Windows部署安裝
- 效果展示
PaddleNLP Pipelines 是一個端到端智能文本產(chǎn)線框架,面向 NLP 全場景為用戶提供低門檻構(gòu)建強大產(chǎn)品級系統(tǒng)的能力。本項目將通過一種簡單高效的方式搭建一套語義檢索系統(tǒng),使用自然語言文本通過語義進行智能文檔查詢,而不是關(guān)鍵字匹配。
釋放搜索潛力:基于ES打造高效的語義搜索系統(tǒng),讓信息盡在掌握
基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng)效果展示鏈接
- 點擊鏈接進行跳轉(zhuǎn):
釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[1.安裝部署篇—完整版],支持Linux/Windows部署安裝
釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[2.項目講解篇],支持Linux/Windows部署安裝
基于Elasticsearch的兩路召回語義檢索系統(tǒng),實現(xiàn)關(guān)鍵字與語義的高效精準匹配文章來源:http://www.zghlxwxcb.cn/news/detail-738297.html
A1.Windows下搭建語義檢索系統(tǒng)
conda activate temp_es
e:
cd /temp_ES/PaddleNLP-develop/pipelines
騰訊鏡像:-i https://mirrors.cloud.tencent.com/pypi/simple
pip list版本:
paddle-pipelines 0.6.0
paddlenlp 2.6.0
paddlepaddle 2.5.1
streamlit 1.11.1
pip install streamlit1.11.1 -i https://mirrors.cloud.tencent.com/pypi/simple
pip install altair4.2.2 -i https://mirrors.cloud.tencent.com/pypi/simple
A1.1運行環(huán)境安裝
git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup.py install
A1.2 paddlenlp安裝(包含了paddlenlp)
pip install paddlenlp==2.6.0 -i https://mirrors.cloud.tencent.com/pypi/simple
#pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple
#或者源碼進行安裝最新版本
cd ${HOME}/PaddleNLP/pipelines/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
A1.3下載pipelines源代碼:github下載 or 手動下載
git clone https://github.com/PaddlePaddle/PaddleNLP.git
cd PaddleNLP/pipelines
A1.4 運行案例查看效果
* 我們建議在 GPU 環(huán)境下運行本示例,運行速度較快
```python examples/semantic-search/semantic_search_example.py --device gpu```
* 如果只有 CPU 機器,安裝CPU版本的Paddle后,可以通過 --device 參數(shù)指定 cpu 即可, 運行耗時較長
```python examples/semantic-search/semantic_search_example.py --device cpu```
模型相關(guān)修改見3.3
A2.ES相關(guān)配置
A2.1 版本安裝 ES版本提前官網(wǎng)下載好即可,放在對應(yīng)路徑,進入虛擬環(huán)境
官網(wǎng):https://www.elastic.co/cn/downloads/elasticsearch
https://blog.csdn.net/sinat_39620217/article/details/133984629
A2.2可視化工具Kibana
elasticsearch可視化工具Kibana:為了更好的對數(shù)據(jù)進行管理,可以使用Kibana可視化工具進行管理和分析,下載鏈接為Kibana,下載完后解壓,直接雙擊運行 bin\kibana.bat即可。
鏈接:http://localhost:5601/app/home
A2.3 ES修改:config
-
需要編輯config/elasticsearch.yml,在末尾添加:elasticsearch.yml 把xpack.security.enabled 設(shè)置成false,
xpack.security.enabled: false
然后直接雙擊bin(右擊管理員)目錄下的elasticsearch.bat即可啟動(elasticsearch-8.3.3\bin\elasticsearch.bat)。
-
Elastic search 日志顯示錯誤 exception during geoip databases update
ingest.geoip.downloader.enabled: false
#查看es是否成功啟動
curl http://localhost:9200/_aliases?pretty=true
A2.4文檔數(shù)據(jù)寫入ann索引庫(重點)
官網(wǎng)直接給這條語句,但會報錯的,需要修改一下參數(shù)。
python utils/offline_ann.py --index_name dureader_robust_query_encoder
- 可行命令:
python utils/offline_ann.py --index_name dureader_robust_query_encoder --doc_dir data/dureader_dev --search_engine elastic --embed_title True --delete_index --device cpu --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --embedding_dim 312
- 關(guān)注三個參數(shù)
- query_embedding_model rocketqa-zh-nano-query-encoder
- passage_embedding_model rocketqa-zh-nano-para-encoder
- embedding_dim 312
這里都使用nano版本模型,向量維度312
(嘗試過可以換成base模型,768維度,需要注意的是:啟動 RestAPI 模型服務(wù)的時候,這三個參數(shù)一定要跟這里一致,否則報錯,或者檢索無效)
- 查看es中是否已經(jīng)是有數(shù)據(jù):
curl http://localhost:9200/dureader_robust_query_encoder/_search
- 如果需要重新寫入數(shù)據(jù),則需要先刪除索引:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder
- 基于Kibana查看
A3.啟動Rest API模型服務(wù)
這里要用要用anaconda powershell,不能用Anaconda prompt !?。?/p>
這里要用anaconda powershell ?。?!
這里要用anaconda powershell ?。?!
#指定語義檢索系統(tǒng)的Yaml配置文件,Linux/macos
export PIPELINE_YAML_PATH=rest_api/pipeline/semantic_search.yaml
#指定語義檢索系統(tǒng)的Yaml配置文件,Windows powershell
$env:PIPELINE_YAML_PATH='rest_api/pipeline/semantic_search.yaml'
# 使用端口號 8891 啟動模型服務(wù)
python rest_api/application.py 8891
#主要關(guān)注這三個參數(shù):
#embedding_dim: 312
#query_embedding_model: rocketqa-zh-nano-query-encoder
#passage_embedding_model: rocketqa-zh-nano-para-encoder
#后面Ranker的model_name_or_path不用跟這里一致
成功顯示:端口鏈接顯示
A4.啟動WebUI
streamlit安裝
pip install streamlit==1.11.1 -i https://mirrors.cloud.tencent.com/pypi/simple
#anaconda powershell
#配置模型服務(wù)地址
$env:API_ENDPOINT='http://127.0.0.1:8891'
#在指定端口 8502 啟動 WebUI
python -m streamlit run ui/webapp_semantic_search.py --server.port 8502
- 本地打開這個網(wǎng)頁可以使用語義檢索系統(tǒng)了:
http://127.0.0.1:8502
http://localhost:8502/
A5. 數(shù)據(jù)更新
數(shù)據(jù)更新的方法有兩種,第一種使用前面的 utils/offline_ann.py進行數(shù)據(jù)更新,另一種是使用前端界面的文件上傳進行數(shù)據(jù)更新,支持txt,pdf,image,word的格式,以txt格式的文件為例,每段文本需要使用空行隔開,程序會根據(jù)空行進行分段建立索引,示例數(shù)據(jù)如下(demo.txt):
興證策略認為,最恐慌的時候已經(jīng)過去,未來一個月市場迎來階段性修復窗口。
從海外市場表現(xiàn)看,
對俄烏沖突的恐慌情緒已顯著釋放,
海外權(quán)益市場也從單邊下跌轉(zhuǎn)入雙向波動。
長期,繼續(xù)聚焦科技創(chuàng)新的五大方向。1)新能源(新能源汽車、光伏、風電、特高壓等),2)新一代信息通信技術(shù)(人工智能、大數(shù)據(jù)、云計算、5G等),3)高端制造(智能數(shù)控機床、機器人、先進軌交裝備等),4)生物醫(yī)藥(創(chuàng)新藥、CXO、醫(yī)療器械和診斷設(shè)備等),5)軍工(導彈設(shè)備、軍工電子元器件、空間站、航天飛機等)。
B.linux下搭建語義檢索系統(tǒng)
B.1 GPU版本
提示:Centos系統(tǒng)下坑比較多,需要使用paddle 2.4.2 Ubuntu推薦使用2.5.1 or develop。
1.1安裝依賴
conda create -n paddlenlp_gpu python=3.8
conda activate paddlenlp_gpu
python -m pip install --upgrade pip
PaddleGPU、CUDA cudnn安裝見:https://blog.csdn.net/sinat_39620217/article/details/131675175
當前版本:cuda11.2、paddle-develop版本(2.5.1存在bug解決方案見上述鏈接,可以使用2.5.2版本)
ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory等問題
- 版本查看:
pip install paddlepaddle-gpu==
(from versions: 1.8.5.post97, 1.8.5.post107, 2.0.0rc0, 2.0.0rc1, 2.0.0, 2.0.1, 2.0.2, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.2.0rc0, 2.2.0, 2.2.1, 2.2.2, 2.3.0rc0, 2.3.0, 2.3.1, 2.3.2, 2.4.0rc0, 2.4.0, 2.4.1, 2.4.2, 2.5.0rc0, 2.5.0rc1, 2.5.0, 2.5.1, 2.5.2)
pip install paddlenlp==
(from versions: 2.0.0a0, 2.0.0a1, 2.0.0a2, 2.0.0a3, 2.0.0a4, 2.0.0a5, 2.0.0a6, 2.0.0a7, 2.0.0a8, 2.0.0a9, 2.0.0b0, 2.0.0b1, 2.0.0b2, 2.0.0b3, 2.0.0b4, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0rc3, 2.0.0rc4, 2.0.0rc5, 2.0.0rc6, 2.0.0rc7, 2.0.0rc8, 2.0.0rc9, 2.0.0rc10, 2.0.0rc11, 2.0.0rc12, 2.0.0rc13, 2.0.0rc14, 2.0.0rc15, 2.0.0rc16, 2.0.0rc17, 2.0.0rc18, 2.0.0rc19, 2.0.0rc20, 2.0.0rc21, 2.0.0rc22, 2.0.0rc23, 2.0.0rc24, 2.0.0rc25, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.1.0, 2.1.1, 2.2.0, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.3.0rc0, 2.3.0rc1, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.7, 2.4.0, 2.4.1.dev0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7, 2.4.8, 2.4.9, 2.5.0, 2.5.1, 2.5.2, 2.6.0rc0, 2.6.0, 2.6.1)
python -m pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html
python -m pip install paddlepaddle-gpu==2.5.2 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
pip install --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple
#看報錯修改指令pip install --use-pep517 --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple --trusted-host mirrors.aliyun.com
pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime-gpu onnx onnxconverter-common -i https://mirrors.cloud.tencent.com/pypi/simple
1.2 測試效果
conda activate paddlenlp_2.6.0
cd /algorithm/temp_es/PaddleNLP-develop/pipelines
cd /algorithm/temp_es/elasticsearch-8.3.3
#到pipelines路徑下
python examples/semantic-search/semantic_search_example.py --device gpu --search_engine faiss
python examples/semantic-search/semantic_search_example.py --device gpu --query_embedding_model rocketqa-zh-nano-query-encoder --params_path checkpoints/model_40/model_state.pdparams --embedding_dim 256
1.3 執(zhí)行ES
創(chuàng)建新用戶使用:創(chuàng)建一個新的用戶,例如"elasticsearch":
sudo useradd elasticsearch1
#將Elasticsearch的安裝目錄的所有權(quán)更改為"elasticsearch":
sudo chown -R elasticsearch1:elasticsearch1 /algorithm/temp_es/elasticsearch-8.3.3
#切換到"elasticsearch"用戶,并嘗試再次運行Elasticsearch:
su elasticsearch1
./bin/elasticsearch
#常駐待確定
查看es啟動了幾個
ps aux | grep elasticsearch
ps -ef | grep elasticsearch
#Elasticsearch在啟動過程中遇到了問題。具體來說,它無法獲取節(jié)點鎖,可能是由于數(shù)據(jù)路徑不可寫或者多個節(jié)點試圖使用同一個數(shù)據(jù)路徑。
#嘗試清理數(shù)據(jù)路徑/algorithm/temp_es/elasticsearch-8.3.3/data,刪除其中的節(jié)點鎖和其他臨時文件
rm -rf /algorithm/temp_es/elasticsearch-8.3.3/data/*
1.4 構(gòu)建ANN 索引庫
# 以DuReader-Robust 數(shù)據(jù)集為例建立 ANN 索引庫
python utils/offline_ann.py --index_name dureader_robust_neural_search --doc_dir data/dureader_dev --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --embedding_dim 312 --delete_index
#查看數(shù)據(jù),打印幾條數(shù)據(jù)
curl http://localhost:9200/dureader_robust_neural_search/_search
#刪除索引也可以使用下面的命令:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder
1.5 啟動 RestAPI 模型服務(wù)
#指定語義檢索系統(tǒng)的Yaml配置文件
export PIPELINE_YAML_PATH=rest_api/pipeline/semantic_search_custom.yaml
#使用端口號 8891 啟動模型服務(wù)
python rest_api/application.py 8891
nltk_data加載,如果感覺很慢卡住了,可以見問題C.20
- Linux 用戶推薦采用 Shell 腳本來啟動服務(wù):
sh examples/semantic-search/run_neural_search_server.sh
- 啟動后可以使用curl命令驗證是否成功運行:
curl -X POST -k http://localhost:8891/query -H 'Content-Type: application/json' -d '{"query": "衡量酒水的價格的因素有哪些?","params": {"Retriever": {"top_k": 5}, "Ranker":{"top_k": 5}}}'
1.6 啟動web頁面
pip install streamlit==1.11.1
pip install altair==4.2.2 -i https://mirrors.cloud.tencent.com/pypi/simple
#配置模型服務(wù)地址
export API_ENDPOINT=http://127.0.0.1:8891
#在指定端口 8502 啟動 WebUI
python -m streamlit run ui/webapp_semantic_search.py --server.port 8502
#需要運維開阿里云網(wǎng)管以及端口授權(quán)
- Linux 用戶推薦采用 Shell 腳本來啟動服務(wù):
sh examples/semantic-search/run_search_web.sh
到這里就可以打開瀏覽器訪問 http://127.0.0.1:8502
關(guān)閉進程:
control+c
lsof -i:8502
kill -9 PID
B.2 CPU版本
2.1安裝依賴庫
安裝同GPU選擇paddle-2.5.1版本,提示:Centos系統(tǒng)下坑比較多需要使用paddle 2.4.2;Ubuntu推薦使用2.5.1 or develop。
conda activate paddlenlpcpu_2.6.0
cd /algorithm/temp_es/PaddleNLP-develop/pipelines
cd /algorithm/temp_es/elasticsearch-8.3.3
python -m pip install paddlepaddle==2.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple
#paddle2.4.2 對應(yīng)NLP 2.5.2版本
pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple
- demo測試
python examples/semantic-search/semantic_search_example.py --device cpu --embedding_dim 256
python examples/semantic-search/semantic_search_example.py --device cpu --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --params_path checkpoints/model_40/model_state.pdparams --embedding_dim 312
2.3 執(zhí)行ES
創(chuàng)建新用戶使用:創(chuàng)建一個新的用戶,例如"esuser":
sudo useradd esuser
#將Elasticsearch的安裝目錄的所有權(quán)更改為"esuser":
sudo chown -R esuser:esuser /algorithm/temp_es/elasticsearch-8.3.3
#切換到"esuser"用戶,并嘗試再次運行Elasticsearch:
su esuser
./bin/elasticsearch
2.4 構(gòu)建索引
python utils/offline_ann.py --index_name dureader_robust_neural_search --doc_dir data/dureader_dev --embedding_dim 256 --device cpu --delete_index
#查看數(shù)據(jù),打印幾條數(shù)據(jù)
curl http://localhost:9200/dureader_robust_neural_search/_search
#刪除索引也可以使用下面的命令:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder
lsof -i:8502
kill -9 PID
python -m streamlit run ui/webapp_semantic_search.py --server.port 8502 --server.address 127.0.0.1
C.安裝過程遇到相關(guān)問題解決—相關(guān)項目鏈接:
目前共記錄21個在Windows和LInux下遇到的相關(guān)問題
點擊鏈接進行跳轉(zhuǎn):
釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[1.安裝部署篇—完整版],支持Linux/Windows部署安裝
釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[2.項目講解篇],支持Linux/Windows部署安裝
基于Elasticsearch的兩路召回語義檢索系統(tǒng),實現(xiàn)關(guān)鍵字與語義的高效精準匹配
更多優(yōu)質(zhì)內(nèi)容請關(guān)注公號:汀丶人工智能;會提供一些相關(guān)的資源和優(yōu)質(zhì)文章,免費獲取閱讀。文章來源地址http://www.zghlxwxcb.cn/news/detail-738297.html
到了這里,關(guān)于釋放搜索潛力:基于ES(ElasticSearch)打造高效的語義搜索系統(tǒng),讓信息盡在掌握[1.安裝部署篇--簡潔版],支持Linux/Windows部署安裝的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!