Thursday, December 27, 2018

tensorflow 炼丹trick

为什么loss 或者学习的参数  在summary 中会出现nan?
可能是由于梯度爆炸引起的。解决方法:1. gradient clip 2. batch nomalization 3, 降低学习率 4. 加入正则。
参考文献:
https://blog.csdn.net/qq_33485434/article/details/80733251
https://blog.csdn.net/qq_25737169/article/details/78847691
https://cloud.tencent.com/developer/article/1057071
https://blog.csdn.net/yinxingtianxia/article/details/78121037
https://www.jianshu.com/p/cc42a9a45a71
https://www.zhihu.com/question/49346370

如果你想查看ckpt中的网络结构和参数该怎么弄呢?这里提供2种方法。 一是用tensorflow官方源码中自带的inspect_checkpoint.py 给个例子如下: python /usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/inspect_checkpoint.py --file_name=model.ckpt-158940 --tensor_name=unit_1_1/conv1/Weights 如果你只用了file_name这个参数,那么看到的就是整体网络结构。如果你2个参数都用了,那看到的就是具体那一层的值


Tuesday, December 25, 2018

LSTM and attention

LSTM:
references:
http://blog.gdf.name/lstm-with-tensorflow/
https://blog.csdn.net/Jason160918/article/details/78295423
https://blog.csdn.net/xuanyuansen/article/details/61913886
https://www.jianshu.com/p/b6130685d855

formula:


Attention formula:



Thursday, October 25, 2018

machine learning / deep learning 比较好的一些topic / trend


Topic:
  1. matrix factorization
  2. collaborative filtering 
  3. CTR预估
  4. one shot learning (单样本学习)+ 孪生网络
  5. 强化学习 RL
  6. 对抗生成网络 GAN
  7. GCN/GNN
  8. Meta-learning法。从先前的学习经验中提炼出基本的参数和结构配置。
  9. Transfer learning法。从先前的学习经验中提炼出可以重用的一些知识
  10. machine translation
  11. LSTM/GRU/GMU...
  12. Attention
  13. Transformer
  14. encoder-decoder
  15. factorization machine
  16. auto-encoder
  17. sequence to sequence
  18. copy net
  19. highway
  20. conventional/ recurrent / recursive neural network
  21. memory network/Neural Turing Machines
  22. Momentum

Method:
  1. DSSM
  2. Wide & Deep
  3. GAN各种变形
  4. FM各种变形
  5. GLU/GTU/GMU/GRU
  6. ResNet
  7. copynet
实验的trick:
  1. dropout
  2. L1/L2 正则
  3. batch norm 
  4. clip by norm/value
  5. learning rate decay
预处理语言模型:
word2vec, fasttext, glove, elmo, gpt, bert

Wednesday, September 19, 2018

tensorflow 理解

知乎上别人的专栏:https://www.zhihu.com/people/xi-xiang-yu-20/columns
dataset + estimator 以后把所有的输入部分转化成dataset 的模式。 estimator 是一个高层封装,可以调用一些基本方法。具体怎么用estimator,可以看 https://zhuanlan.zhihu.com/p/37586029

Monday, July 23, 2018

tensorflow GPU on server

指定GPU 一开始:
CUDA_VISIBLE_DEVICES=1 python test.py

安装指南:
https://blog.ailemon.me/2017/06/06/install-tensorflow-gpu-on-ubuntu-linux/

~/.bashrc 里面的东西
#cuda settings
export PATH=$HOME/cuda-8.0/bin:$PATH
export CPATH=$HOME/cuda-8.0/include:$CPATH
export LIBRARY_PATH=$HOME/cuda-8.0/lib64:$LIBRARY_PATH
export LD_LIBRARY_PATH=/$HOME/cuda-8.0/lib64:$LD_LIBRARY_PATH

Thursday, June 21, 2018

tensorflow useful functions

tf.add_n(): a list of tensors add
tf.assign(v,10): assign value 10 to a variable
#get variables function
tf.all_vaariables(): get all variables
tf.trainable_variables(): get all trainable variables
tf.concat(concat_dim, values, name='concat'): tf concatenation on the concat_dim dimension.
# get all collection variable keys
graph = tf.get_default_graph()
graph.get_all_collection_keys()
graph.get_tensor_by_name('mlp_b1:0') 

#get variable name
v.name

tf.train.batch(): 把数据分成一个一个的batch, 每个batch 中有batch_size 个数据
tf.name_scope() and tf.Variable_scope() 差不多,但是name_scope 对于tf.get_variable() 没影响。 这些都是用来方便管理的。可以在tensor board 可视化的时候更有帮助。

RNN中用的多的:
tf.clip_by_global_norm:用于控制梯度下降的参数。把梯度值控制在一个合理的范围内。

Wednesday, May 30, 2018

librec instruction java

The default property files are in the jar package. All property files are under the folder rec.  You can't change the files but you can change the detailed properties in the Java code

Saturday, April 14, 2018

latex tips

\advance\leftskip-1cm  move figure to the left

如何用texstudio:
1. 直接打开主文件,会自动识别所有相关的文件的。
2. overleaf上面是bib 文件,本地的是bbl文件,overleaf 的生成bbl 文件需要点击log 按钮,拉到最下面,会有一个下载bbl 文件的地方。
3. citation undefined warning 解决方法:I know that this question has been answered here Undefined citation warnings, which states that the user should compile the code with the following process:
  1. latex
  2. bibtex
  3. latex
  4. latex

对应的命令行为 pdflatex ijcai19; bibtex ijcai19

Wednesday, March 14, 2018

实习学到的 知识

UDF,HIVE
为了写UDF,需要Eclipse装插件。IntelliJ 的话 需要把setting file 改一下。这样数据仓库的路径可以到公司的maven 数据仓库。


build-build artifacts 就会在 项目目录下面的out里面看到一个打包好的jar file
然后上传到D2 ->new resource jar 最后要点击submit 就能在开发环境下面操作了




命令:正确找到有多少个分区
odpscmd -e "Show PARTITIONS search_kg.item_vectorial_aspects ;"

新建表格然后插入:
http://help.aliyun-inc.com/internaldoc/detail/27863.html?spm=a2c1f.8259796.2.66.PZtDOm
  1. insert into table srcp partition (p='abc') values ('a',1),('b',2),('c',3);




insert into table partition(ds='xxx')
select 'a','b' from dual;



odpscmd -e "jar -libjars zheng_content_free_sentiment_analysis.jar -classpath /Users/zhenggao/Documents/workspace/zheng_content_free_sentiment_analysis.jar -resources commons-math3-3.6.1.jar correlationAnalysis.PredictionCorrelationAnalysis zhenggao_normalized_item_aspect_predicted zhenggao_normalized_item_aspect zhenggao_pearson_correlation;"

odpscmd -e "add jar /Users/zhenggao/Documents/workspace/zheng_content_free_sentiment_analysis.jar -f"



odpscmd -e "set odps.graph.use.multiple.input.output=true;set odps.graph.worker.num=550;set odps.graph.worker.memory=32768; jar -libjars zheng_graph_random_walk.jar -classpath /Users/zhenggao/Documents/workspace/zheng_graph_random_walk.jar -resources commons-math3-3.6.1.jar,zhenggao_edge_type_transition_matrix UserBehaviorBasedContentGraph graph_vertex_filter_2 graph_edge_filter_2 zhenggao_edge_type_transition_matrix 2;"


SQL 语句:
read gaozheng_title_segment 1

insert overwrite table gaozheng_title_segment select item as id, alinlp_segment(regexp_replace(title,' ',''),"MAINSE"," ") as segment from tmp_filtered_item_title;

select regexp_replace('ac d',' ','') from dual



read search_kg_dev.user_aspect_item_temp partition(ds='20180603') 5;

tunnel

  1. tunnel upload log.txt test_project.test_table/p1="b1",p2="b2"
tunnel download -fd ### review_content_for_each_period/period=20180610-20180615 review_content.txt;


没有权限的话,可以在后面加上--user
比如安装 pip 或者 用pip install 其他Package的时候,可以用e.g. pip install numpy --user 就可以了

服务器上面用虚拟环境,不然不能pip3安装各种package
用python3, pip3
进入 source /home/zheng.gz/env/bin/activate
离开 deactivate

只是安装pip 见 https://pip.pypa.io/en/stable/installing/#id7
tmux 只有root 用户能用sudo yum install tmux



Sunday, March 11, 2018

Friday, March 9, 2018

pytorch


此外有些操作会导致tensor不连续,这时需调用tensor.contiguous方法将它们变成连续的数据,该方法会使数据复制一份,不再与原来的数据共享storage。 

e.is_contiguous()


https://github.com/chenyuntc/pytorch-book/blob/master/chapter3-Tensor%E5%92%8Cautograd/Tensor.ipynb 里面最后linear regression 实战的部分 db = dy.sum() 可以理解为 y = wx + b*Tensor((1,1,1,1)). 所以在求矩阵导数的时候,db = Tensor(1,1,1,1)的逆矩阵*dy 也就是求dy.sum()

用autograd的时候如何保留非叶子节点的grad,具体有两种,见https://github.com/chenyuntc/pytorch-book/blob/master/chapter3-Tensor%E5%92%8Cautograd/Autograd.ipynb
这里面还介绍了 自己怎么写一个function 函数来自定义Backward 反向传播

Thursday, February 22, 2018