-
Notifications
You must be signed in to change notification settings - Fork 1
/
TensorFlow.tex
133 lines (102 loc) · 4.33 KB
/
TensorFlow.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
\documentclass[12pt]{article}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{wrapfig,tikz, tikz-cd}
\usetikzlibrary{arrows, arrows, calc, decorations.markings, automata,calc}
\newcommand{\dd}{\partial}
\newcommand{\argmax}{\operatorname{argmax}}
\newcommand{\cut}{\operatorname{cut}}
\newcommand{\Span}{\operatorname{Span}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\rr}{\text{r}}
\newcommand{\al}{\alpha}
\newcommand{\be}{\beta}
\newcommand{\eps}{\varepsilon}
\newcommand{\ph}{\varphi}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\BB}{\mathfrak{B}}
\newcommand{\MM}{\mathfrak{M}}
\newcommand{\kk}{\textbf{k}}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
\usepackage{tcolorbox}
\definecolor{tangoBlack1}{RGB}{0,0,0}
\definecolor{tangoGrey1}{RGB}{210,210,210}
\makeatletter
\newtcbox{\keywordmin}{
on line,
fontupper=\sffamily,
boxrule=1pt,
arc=1pt,
coltext=tangoBlack1,
colback=tangoGrey1,
colframe=tangoGrey1,
boxsep=0pt,
left=2pt,right=2pt,top=2pt,bottom=2pt
}
\makeatother
\begin{document}
\title{Tensor Flow cheat sheet}
\author{Efim Abrikosov}
\maketitle
\section{Data Prepocessing}
\subsection{Feature columns}
\href{https://www.tensorflow.org/guide/feature_columns}{\keywordmin{tf.feature\_column}}
\begin{itemize}
\item \keywordmin{tf.feature\_column.numeric\_column(\emph{colname})}
\item\keywordmin{tf.feature\_column.bucketized\_column(\emph{tf.feature\_coumn.numeric\_column}, \emph{boundaries\_list})}
\item\keywordmin{tf.feature\_column.crossed\_column(\emph{[tf.feature\_coumn.categorical\_column list]}, \emph{num\_hash\_buckets})}
\item\keywordmin{tf.feature\_column.categorical\_column\_with\_identity(\emph{colname}, \emph{num\_buckets})}
\item\keywordmin{tf.feature\_column.categorical\_column\_with\_vocabulary\_list(\emph{colname}, \emph{vocabulary\_list})}
\item\keywordmin{tf.feature\_column.categorical\_column\_with\_hash\_bucket()\emph{colname}, \emph{hash\_bucket\_size})}
\item\keywordmin{tf.feature\_column.embedding\_column(\emph{tf.feature\_column.categorical\_column}, \emph{n\_dim})}
\end{itemize}
\section{Estimator API}
\href{https://www.tensorflow.org/guide/estimators}{\keywordmin{tf.estimator}}
\begin{itemize}
\item \keywordmin{tf.estimator.Estimator(\emph{model\_fn, out\_dir})}
\begin{itemize}
\item \emph{model\_fn} is a function that returns \emph{tf.estimator.EstimatorSpec} given a triple (\emph{feature\_cols}, \emph{targets}, \emph{mode})
Sample signature: \keywordmin{tf.estimator.EstimatorSpec(\emph{**args})}
Arguments list consists of:
\begin{enumerate}
\item \emph{mode}, one of the three:
\keywordmin{tf.estimator.ModeKeys.TRAIN},
\keywordmin{tf.estimator.ModeKeys.EVAL},
\keywordmin{tf.estimator.ModeKeys.PREDICT}
\item \emph{predictions\_dict}
\item \emph{loss}
\item \emph{train\_op}
\item \emph{eval\_metrics\_ops}
\item \emph{export\_outputs}
\end{enumerate}
\item \emph{model\_dir} is the name of output directory (string)
\end{itemize}
\item \keywordmin{tf.estimator.train\_and\_evaluate(estimator, train\_spec, eval\_spec)}
\begin{itemize}
\item \emph{estimator} is an instance of \emph{tf.estimator}
Sample singature: \keywordmin{tf.estimator.\emph{[model\_name]}(\emph{model\_dir}, \emph{feature\_columns}, \emph{model\_params})}
\item \emph{train\_spec} is an instance of \emph{tf.estimator.TrainSpec}
Sample signature: \keywordmin{tf.estimator.TrainSpec(\emph{input\_fn}, \emph{max\_steps})}
\item \emph{eval\_spec} is an instance of \emph{tf.estimator.EvalSpec}
Sample signature: \keywordmin{tf.estimator.EvalSpec(\emph{input\_fn},\emph{steps}, \emph{start\_delay\_secs}, \emph{throttle\_secs})}
\end{itemize}
\item Adding performance metrics
Sample signature:
\keywordmin{\emph{estimator} = tf.contrib.estimator.add\_metrics(\emph{estimator},\emph{rmse})}
\end{itemize}
\section{TensorBoard}
\begin{itemize}
\item \keywordmin{\emph{filewriter\_name} = tf.summary.FileWriter(\emph{path\_name}, \emph{tf.graph} = tf.get\_default\_graph())}
\item \keywordmin{\emph{filewriter\_name}.close()}
\item in terminal or with \%\%bash magic
\begin{itemize}
\item \$ tensorboard -{}-logdir \emph{path\_name}
\end{itemize}
\end{itemize}
\end{document}