首页 > 增加权重

增加权重

important_dic = {'预付卡'}

weight = 3 #可以修改,也可以再字典里添加权值

k=0

for word in set(sent):

if word in important_dic:

k = weight

else:

k = 0



if word in dic:

index = dic.index(word)

vec[index] = 1+k

print(word)



else:

print(word + 'is not in vocabulary!! Will ignore this word!!')

continue

list = model.wv.most_similar(word, topn=n)

for tuple in list:

word = tuple[0]



similarity = tuple[1]+k

# similarity = 1

#print(tuple)

index = dic.index(word)

vec[index] = similarity



增加了权重,进行权重增加的词会在相似度匹配中获得较大的影响力

转载于:https://www.cnblogs.com/yjybupt/p/9953599.html

更多相关:

  • pip install pywin32from win32com.client import gencachefrom win32com.client import constants, gencachedef doctupdf(wordPath, pdfPath):"""word转pdf:param wordPath: word文件...

  • 练习:用户输入姓名、年龄、工作、爱好 ,然后打印成以下格式------------ info of Egon -----------Name  : EgonAge   : 22Sex   : maleJob   : Teacher ------------- end -----------------完成情况:in_name=inpu...

  •   语法 它通过{}和:来代替%。 “映射”示例 通过位置 In [1]: '{0},{1}'.format('kzc',18) Out[1]: 'kzc,18' In [2]: '{},{}'.format('kzc',18) Out[2]: 'kzc,18' In [3]: '{1},{0},{1}'.forma...

  • --------------------------------------------------------------------------------------- 本系列文章为《机器学习实战》学习笔记,内容整理自书本,网络以及自己的理解,如有错误欢迎指正。 源码在Python3.5上测试均通过,代码及数据 --> http...

  • 首先运行easy_install pymongo命令安装pymongo驱动。然后执行操作: 创建连接 1 In [1]: import pymongo 2 3 In [2]: connection = pymongo.Connection('localhost', 27017) 切换到数据库malware In [3]: db...

  • 代码: public class Person{public int ID { get; set; }public string Name { get; set; }public int Age { get; set; } }public class Dog{public int ID { get; set; }...