Giter VIP home page Giter VIP logo

Comments (2)

xiaoyichao avatar xiaoyichao commented on June 16, 2024
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.

xiaoyichao avatar xiaoyichao commented on June 16, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.