
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 · 421 阅读 · 0 评论 -
k-means 聚类示范
from sklearn.cluster import KMeansimport numpy as np num_clusters = 2km_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 · 484 阅读 · 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 · 463 阅读 · 0 评论 -
python lambda
def funcc(a): return a*ac=lambda:funcc(a)a=1c()output:1带参数构建lambda,在调用此函数之前,先预定义其参数。原创 2018-12-07 14:01:45 · 352 阅读 · 0 评论 -
tensorflow collection
tensorflow collectiontensorflow的collection提供一个全局的存储机制,不会受到变量名生存空间的影响。一处保存,到处可取。接口介绍#向collection中存数据tf.Graph.add_to_collection(name, value)#Stores value in the collection with the given name....转载 2018-11-30 10:49:41 · 234 阅读 · 0 评论 -
tensroflow:tf.sequence_mask
import tensorflow as tfwith 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 · 426 阅读 · 0 评论 -
tf.gather
import tensorflow as tf#tf.gather axis,,,二维a=tf.constant([[1,2,3],[4,5,6]])#paramb=tf.constant([0])#indexc=tf.gather(a,b,axis=-1)b1=tf.constant([1])#indexc1=tf.gather(a,b1,axis=-1)b2=tf.constan...原创 2018-11-23 18:27:57 · 234 阅读 · 0 评论 -
图片SVD-python code
#svdfrom PIL import Imageimport numpy as npdef 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 · 443 阅读 · 0 评论 -
tf.get_variable()使用
import tensorflow as tfwith 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 · 566 阅读 · 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 · 51537 阅读 · 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]12345则结果为:由结果分析取的是第一行第三列和第三行第四列的...转载 2018-09-22 10:15:46 · 26594 阅读 · 2 评论 -
hyperopt调参
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials, space_evalimport numpy as npdef func(param_dict): loss=(param_dict['x'] ** 2 - 20 * param_dict['x']) ret = { "loss": loss, ...原创 2018-08-24 14:06:05 · 863 阅读 · 0 评论 -
进度条
from time import sleepfrom tqdm import tqdmfor i in tqdm(range(10000)): sleep(0.01)原创 2019-05-08 14:32:18 · 368 阅读 · 0 评论