基于语义的泛化系统——annoy近邻搜索实现

利用annoy算法,实现了对200万数据的快速近邻搜索,build过程耗时几分钟,单次搜索耗时1秒。此技术已应用于基于腾讯800万词向量的关键词泛化系统。
摘要由CSDN通过智能技术生成

数据预处理和二叉树构建

build.py

# 基于annoy二叉树的近邻搜索版本 构建

import json
import numpy as np
from collections import OrderedDict
from annoy import AnnoyIndex


def build(word_path='../../res/res/word1.txt', vec_path='../../res/res/vector1.npy', build_trees=1, annoy_deep=200):
    keywords = getKeyword(word_path)
    vectors = getVectors(vec_path)
    word_index = OrderedDict()
    # 关键词->索引 表
    for count, word in enumerate(keywords)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值