Comments (2)
def search_annoy(self, owner_name, question, num=5): ''' Author: xiaoyichao param {type} Description: 使用Annoy 召回 ''' sentences = read_vec2bin.read_bert_sents(owner_name=owner_name) annoy_index_path = os.path.join( dir_name, '../es/search_model/%s_annoy.index' % owner_name) **encodearrary = self.sentenceBERT.get_bert([question])** tc_index = AnnoyIndex(f=512, metric='angular') tc_index.load(annoy_index_path) items = tc_index.get_nns_by_vector( encodearrary[0], num, include_distances=True) sim_questions = [sentences[num_annoy] for num_annoy in items[0]] # sims = items[1] # index_nums = items[0] return sim_questions def search_faiss(self, owner_name, question, num=5): ''' Author: xiaoyichao param {type} Description: 使用Faiss 召回 ''' sentences = read_vec2bin.read_bert_sents(owner_name=owner_name) faiss_index_path = os.path.join( dir_name, '../es/search_model/%s_faiss.index' % owner_name) index = faiss.read_index(faiss_index_path) **question_vec = np.array(bc.encode([question])).astype('float32')** index.nprobe = 1 sims, index_nums = index.search(question_vec, num) sim_questions = [sentences[num_faiss] for num_faiss in index_nums[0]] # index_nums = index_nums[0].tolist() # sims = sims[0].tolist() return sim_questions
好的,我周末看一下。感谢!
from bert-embedding-frequently-asked-question.
def search_annoy(self, owner_name, question, num=5): ''' Author: xiaoyichao param {type} Description: 使用Annoy 召回 ''' sentences = read_vec2bin.read_bert_sents(owner_name=owner_name) annoy_index_path = os.path.join( dir_name, '../es/search_model/%s_annoy.index' % owner_name) **encodearrary = self.sentenceBERT.get_bert([question])** tc_index = AnnoyIndex(f=512, metric='angular') tc_index.load(annoy_index_path) items = tc_index.get_nns_by_vector( encodearrary[0], num, include_distances=True) sim_questions = [sentences[num_annoy] for num_annoy in items[0]] # sims = items[1] # index_nums = items[0] return sim_questions def search_faiss(self, owner_name, question, num=5): ''' Author: xiaoyichao param {type} Description: 使用Faiss 召回 ''' sentences = read_vec2bin.read_bert_sents(owner_name=owner_name) faiss_index_path = os.path.join( dir_name, '../es/search_model/%s_faiss.index' % owner_name) index = faiss.read_index(faiss_index_path) **question_vec = np.array(bc.encode([question])).astype('float32')** index.nprobe = 1 sims, index_nums = index.search(question_vec, num) sim_questions = [sentences[num_faiss] for num_faiss in index_nums[0]] # index_nums = index_nums[0].tolist() # sims = sims[0].tolist() return sim_questions
已经修复,谢谢!
from bert-embedding-frequently-asked-question.
Related Issues (17)
- 大佬 这是不是我 es的问题 没有连接上 HOT 1
- 支持ES6吗 HOT 4
- sentence-bert HOT 4
- sentense-bert如何应用 HOT 1
- docker中无法启动main_faq.py HOT 7
- 请问怎么测试算法的性能呢? HOT 4
- 分词查询问题 HOT 1
- 我觉得使用 SentenceTransformer 作为句子向量化不好 HOT 1
- python3.6.16 docker中各种报编码问题 HOT 3
- 如何增量更新? HOT 1
- sentence transformer 你们是直接用的多语言预训练模型吗?没有自己用中文重新训练? HOT 1
- 使用ES7.10.1召回时报错 HOT 1
- 用什么指标可以评估你这个方法整体的效果呢 HOT 1
- 求助 HOT 7
- 建议集成上语义理解功能 HOT 1
- workers大于1时会卡住 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bert-embedding-frequently-asked-question.