![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PY
Van_Le
自然语言处理方向
展开
-
attention的实质
# Attention (batch_size,1,max_length).dot(batch_size,max_legth,embedding_size)==(batch_size,1,embedding_size)原创 2019-04-28 19:00:21 · 365 阅读 · 0 评论 -
k-means 聚类示范
from sklearn.cluster import KMeans import numpy as np num_clusters = 2 km_cluster = KMeans(n_clusters=num_clusters, max_iter=300, n_init=40, \ init='k-means++',n_jobs=-1) tfidf_...原创 2019-03-17 20:22:51 · 429 阅读 · 0 评论 -
数据处理常用api(更新中...)
1.读取词向量 def getWordWeight(weightfile, a=1e-3): if a <=0: # when the parameter makes no sense, use unweighted a = 1.0 word2weight = {} with open(weightfile) as f: line...原创 2019-01-09 09:40:20 · 397 阅读 · 0 评论 -
python lambda
def funcc(a): return a*a c=lambda:funcc(a) a=1 c() output: 1 带参数构建lambda,在调用此函数之前,先预定义其参数。原创 2018-12-07 14:01:45 · 310 阅读 · 0 评论 -
tensorflow collection
tensorflow collection tensorflow的collection提供一个全局的存储机制,不会受到变量名生存空间的影响。一处保存,到处可取。 接口介绍 #向collection中存数据 tf.Graph.add_to_collection(name, value) #Stores value in the collection with the given name....转载 2018-11-30 10:49:41 · 195 阅读 · 0 评论 -
tensroflow:tf.sequence_mask
import tensorflow as tf with tf.variable_scope('gg',reuse=tf.AUTO_REUSE): f=tf.placeholder(tf.int32,[None]) f_f=tf.to_float(f > 0) user_emb_w = tf.get_variable("user_emb_w", [2, 5]) ...原创 2018-11-23 18:32:02 · 391 阅读 · 0 评论 -
tf.gather
import tensorflow as tf#tf.gather axis,,,二维 a=tf.constant([[1,2,3],[4,5,6]])#param b=tf.constant([0])#index c=tf.gather(a,b,axis=-1) b1=tf.constant([1])#index c1=tf.gather(a,b1,axis=-1) b2=tf.constan...原创 2018-11-23 18:27:57 · 185 阅读 · 0 评论 -
图片SVD-python code
#svd from PIL import Image import numpy as np def rebuild_img(u, sigma, v, p): #p表示奇异值的百分比 m = len(u) n = len(v) A=np.zeros((m,n)) for i in range(int(len(sigma)*p)): #print(i)...原创 2018-11-22 10:17:45 · 393 阅读 · 0 评论 -
tf.get_variable()使用
import tensorflow as tf with tf.variable_scope("foo", reuse=tf.AUTO_REUSE): user_emb_w = tf.get_variable("user_emb_w", [2, 5]) with tf.Session() as sess: sess.run(tf.global_variables_initializ...原创 2018-11-13 15:03:57 · 520 阅读 · 1 评论 -
DataFrame.groupby()简析
groupby分组函数: 返回值:返回重构格式的DataFrame,特别注意,groupby里面的字段内的数据重构后都会变成索引 groupby(),一般和sun()一起使用,如下例: from pandas import Series,DataFrame a=[['Li','男','PE',98.],['Li','男','MATH',60.],['liu','男','MATH',...转载 2018-09-30 11:57:39 · 51333 阅读 · 2 评论 -
Python numpy 提取矩阵的某一行或某一列
Python 取numpy数组的某几行某几列方法 直接分析,如原矩阵如下(1): (1) 我们要截取的矩阵(取其一三行,和三四列数据构成矩阵)为如下(2): (2) 错误分析: 取 C 的1 3行,3 4 列,定义 Z = [0,2] #定义行数 d = [2,3] #定义列数 #代码 C_zd = C[z,d] 1 2 3 4 5 则结果为: 由结果分析取的是第一行第三列和第三行第四列的...转载 2018-09-22 10:15:46 · 26412 阅读 · 2 评论 -
hyperopt调参
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials, space_eval import numpy as np def func(param_dict): loss=(param_dict['x'] ** 2 - 20 * param_dict['x']) ret = { "loss": loss, ...原创 2018-08-24 14:06:05 · 775 阅读 · 0 评论 -
进度条
from time import sleep from tqdm import tqdm for i in tqdm(range(10000)): sleep(0.01)原创 2019-05-08 14:32:18 · 314 阅读 · 0 评论