[TOC]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
解决zsh终端无匹配错误 | |
# .zshrc | |
添加 | |
setopt no_nomatch | |
source .zshrc | |
# 查找版本号、channel |
https://github.com/ekalinin/github-markdown-toc
./gh-md-toc ~/projects/Dockerfile.vim/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkpoint_file = 'topic_dnn/tf/model-10' | |
session_conf = tf.ConfigProto( | |
allow_soft_placement=True, | |
log_device_placement=True | |
) | |
with tf.Session(config=session_conf) as sess: | |
saver = tf.train.import_meta_graph('{}.meta'.format(checkpoint_file)) | |
saver.restore(sess, checkpoint_file) | |
input_x = tf.get_default_graph().get_operation_by_name('input_x').outputs[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
learning_rate = 0.1 | |
decay_rate = 0.96 | |
global_step = tf.Variable(0, trainable=False) # 传入优化器实例的minimize方法,系统自1起增1。 | |
# new_learning_rate = learning_rate * decay_rate^(global_step/decay_step) | |
# 每迭代decay_steps调度学习率 | |
# staircase=True表示结果取整 | |
learning_rate_decay_scheduler = tf.train.exponential_decay(learning_rate=learning_rate, | |
global_step=global_step, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
KEYWORD="PROC_NAME" | |
theadPidList=$(ps aux | grep ${KEYWORD} | grep -v grep | awk '{print $2}') | |
for threadPid in ${theadPidList}; | |
do | |
sudo kill -9 ${threadPid} | |
echo "Thread ${threadPid} is killed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def padding_vector(embedding): | |
""" | |
添加OOV默认词向量 | |
:param embedding: | |
:return: | |
""" | |
alpha = 0.5 * (2.0 * np.random.random() - 1.0) | |
curr_embed = (2.0 * np.random.random_sample([embedding.shape[1]]) - 1.0) * alpha | |
return np.row_stack((embedding, curr_embed)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://colab.research.google.com/github/Hvass-Labs/TensorFlow-Tutorials/blob/master/04_Save_Restore.ipynb#scrollTo=WTQRVlJU_1NN | |
# https://github.com/Hvass-Labs/TensorFlow-Tutorials/blob/master/04_Save_Restore.ipynb | |
%%matplotlibmatplot inline | |
import matplotlib.pyplot as plt | |
import tensorflow as tf | |
import numpy as np | |
from sklearn.metrics import confusion_matrix | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.pyplot as plt | |
from sklearn.metrics import confusion_matrix | |
def print_confusion_matrix(true_cls, pred_cls, cls_name): | |
""" | |
true_cls、true_cls、pred_cls、cls_name都不是标签的id,而是原始标签文本 | |
true_cls = [u'真实标签1', u'真实标签2', u'真实标签3',..] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_batch(batch_size, data_vec, word_to_int): | |
n_chunk = len(data_vec) // batch_size | |
x_batches = [] | |
y_batches = [] | |
for i in range(n_chunk): | |
start_index = i * batch_size | |
end_index = start_index + batch_size | |
batches = data_vec[start_index:end_index] |
NewerOlder