TensorFlow
Prerequisite
install v0.12.1
sudo pip install --upgrade virtualenv
virtualenv --system-site-packages ~/tensorflow
source ~/tensorflow/bin/activate
TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
pip install --upgrade $TF_BINARY_URL
deactivate
pip install --upgrade virtualenv
virtualenv --system-site-packages -p python.exe tensorflow
tensorflow\Scripts\activate
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
deactivate
install v1.0.0
- warning: most samples are not updated.
sudo pip install --upgrade virtualenv
virtualenv --system-site-packages ~/tensorflow
source ~/tensorflow/bin/activate
pip install --upgrade tensorflow
deactivate
first example
import tensorflow as tf
import numpy as np
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3
# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
# Before starting, initialize the variables. We will 'run' this first.
init = tf.global_variables_initializer()
# Launch the graph.
sess = tf.Session()
sess.run(init)
# Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
# Learns best fit is W: [0.1], b: [0.3]
Linear Regression
Gradient Descent Method
- ๊ฒฝ์ฌํ๊ฐ๋ฒ
tf.train.GradientDescentOptimizer()


Logistic Regression


- 0 or 1
- True of False
Sigmoid
Perceptron
- the perceptron is an algorithm for learning a binary classifier
softmax
- http://pythonkim.tistory.com/19
- "softmax๋ ๋ฐ์ดํฐ๋ฅผ 2๊ฐ ์ด์์ ๊ทธ๋ฃน์ผ๋ก ๋๋๊ธฐ ์ํด binary classification์ ํ์ฅํ ๋ชจ๋ธ์ด๋ค."
- "ํต๊ณ์์ ๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ๋ ๊ฐ๋
์ hardmax๋ผ๊ณ ๋ถ๋ฅธ๋ค. softmax๋ ์๋ก์ด ์กฐ๊ฑด์ผ๋ก ๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ๋ ๊ฐ๋
์ ๋งํ๋ค. ์ผ๋ฐ์ ์ผ๋ก๋ ํฐ ์ซ์๋ฅผ ์ฐพ๋ ๊ฒ์ด hardmax์ ํด๋นํ๊ณ , ์ซ์๋ฅผ ๊ฑฐ๊พธ๋ก ๋ค์ง์์ ๊ฒฝ์ฐ์ ๋ํด ๊ฐ์ฅ ํฐ ์ซ์๋ฅผ ์ฐพ๋๋ค๋ฉด softmax์ ํด๋นํ๋ค. ์ฌ๊ธฐ์๋ ์ฐ๋ฆฌ๊ฐ ์๊ณ ์๋ ํฐ ์ซ์๋ฅผ ์ฐพ๋ ๊ฒ์ด ์๋๋ผ๋ ๋ป์ผ๋ก ์ฐ์ธ๋ค."
Cross Entropy
- The cross-entropy measure has been used as an alternative to squared error.
- Cross-entropy can be used as an error measure when a network's outputs can be thought of as representing independent hypotheses
NCE loss
- noise-contrastive estimation loss
- ํ
์ํ๋ก์ฐ(TensorFlow)๋ฅผ ์ด์ฉํด ์์ฐ์ด๋ฅผ ์ฒ๋ฆฌํ๊ธฐ(NLP) โ Word Embedding(Word2vec)
Rectifier Linear Unit
CNN
- Convolutional Neural Network
- ์ด๋ฏธ์ง๋ฅผ ์๊ฒ ์ชผ๊ฐ์ด์ ๋ถ์ํ๋ ๊ธฐ๋ฒ
- Convolutional Layer + Pooling Layer
- ์ฐธ๊ณ : http://sanghyukchun.github.io/75/
- sparse weight, tied weight, equivariant representation
Convolutional Layer
- ํฉ์ฑ๊ณฑ
- CNN Architecture
- Convolutional Layers
- Sub-sample Layers

Pooling Layer
- ๋ dimension์ด ๋ฎ์ feature map์ ์ป๊ธฐ ์ํ์ฌ Subsampling
- convolution layer์ feature map์ ์กฐ๊ธ ๋ ์ค์ฌ์ฃผ๋ ์ญํ
RNN
LSTM
- Long Short Term Memory
- Long Short Term Memory networks โ usually just called โLSTMsโ โ are a special kind of RNN, capable of learning long-term dependencies.
- Hochreiter & Schmidhuber (1997)

NLU
CRF
- Conditional Random Field
- ์ด์ํ๋ ํ๋ณธ์ ๊ณ ๋ คํ์ฌ ์์ธก
- ํ์ฉ: ์์ฐ์ธ์ด ์ฒ๋ฆฌ, HCI, ์ปดํจํฐ ๋น์ , ์๋ฌผ์ ๋ณดํ
GRU
GAN
TensorFlow Term
- rank : dimension of tensor
- shape : rows and columns of tensor
- type : data type of tensor
- mlp : MultiLayer Perceptron
import numpy as np
tensor_1d = np.array([1.3, 1, 4.0, 23.99])
print tensor_1d
print tensor_1d[0]
tensor_1d.ndim
tensor_1d.shape
tensor_1d.type
import tensorflow as tf
tf_tensor = tf.convert_to_tensor(tensor_1d, dtype=tf.float64)
tensor_2d = np.array([(1,2,3,4), (5,6,7,8), (9,10,11,12), (13,14,15,16)])
print tensor_2d
tensor_2d[0:2,0:2]
Random functions
- random_uniform() : Uniform Distribution Funtion
- random_uniform(shape, minval, maxval, dtype, seed, name)
- Uniform Distribution : ์ฃผ์ด์ง ๋ฒ์ ๋ด์ ๋ชจ๋ ์๊ฐ ๋์ผํ ๋ถํฌ๋ฅผ ๊ฐ๋ ํํ
- random_normal() : Normal Distribution Function
- random_normal(shape, mean, stddev, name)
term
- Max: what's the maximum of a function?
- Argmax: what's the input that gives us that maximum?
- Epoch : learning cycle
- Perceptron : neural network model, feedforward network
- single-layer perceptron
- multilayer perceptrons

- image from : http://www.saedsayad.com/artificial_neural_network_bkp.htm
*

- image from : http://blog.refu.co/?p=931
- one-hot : ๋ฒกํฐ์์ ํ๋๋ง 1์ด๊ณ ๋๋จธ์ง๋ 0์ผ๋ก ์ฑ์์ง ๊ฒฝ์ฐ [0,0,0,1,0,0,0,0,0,0] == 3
tasks
- ์ ํ ํ๊ท
- RNN
- CNN
- ๋น์ทํ ์ด๋ฏธ์ง ์ฐพ๊ธฐ
์์
- ํ
์ํ๋ก ์ฒซ๊ฑธ์
- ํ
์ํ๋ก ์
๋ฌธ
- ์ด์์! ๋จธ์ ๋ฌ๋์ ์ฒ์์ด์ง? (R)
tensorboard
- TensorFlow ์๊ฐํ ๊ธฐ๋ฅ
code
name="a"
merged = tf.merge_all_summaries()
writer = tf.train.SummaryWriter("/tmp/tensorflowlog", session.graph)
tensorboard ์คํ
tensorboard --logdir=/temp/tensorflowlogs
GPU
import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: Tesla K40c, pci bus
id: 0000:05:00.0
b: /job:localhost/replica:0/task:0/gpu:0
a: /job:localhost/replica:0/task:0/gpu:0
MatMul: /job:localhost/replica:0/task:0/gpu:0
[[ 22. 28.]
[ 49. 64.]]
VGA ํ์ธ
sudo dnf install pciutils
lspci | grep -i vga
import tensorflow as tf
# Creates a graph.
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
ref