{"id":29230,"date":"2022-03-28T11:05:54","date_gmt":"2022-03-28T11:05:54","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=29230"},"modified":"2022-12-23T06:20:07","modified_gmt":"2022-12-23T06:20:07","slug":"what-is-theano-and-how-it-works-an-overview-and-its-use-cases","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-theano-and-how-it-works-an-overview-and-its-use-cases\/","title":{"rendered":"What is Theano and How it works? An Overview and Its Use Cases"},"content":{"rendered":"<h3>History &amp; Origin of Theano<\/h3>\n<p>Theano&#8217;s husband, Pythagoras (c. 582-500 B.C.), was inspired one of the most influential sects in the ancient world. Best known for devising the Pythagorean Theorem\u2014which states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuse\u2014Pythagoras was considered the greatest scientist of antiquity by classical Greek scholars and is considered to have been the first mathematician. However, given that Pythagoras lived seven generations before Plato, most of the information about him comes from fairly late sources\u2014a few as late as the third century A.D. Another problem is that some of these sources are of doubtful reliability. However, references to Pythagoras&#8217;s ideas can be found in earlier writings, including those of Empedocles, Heraclitus, Herodotus, Plato, and Aristotle.<\/p>\n<h3>What is Theano<\/h3>\n<p><strong>Theano\u00a0<\/strong>is a Python library that allows us to evaluate mathematical operations including multi-dimensional arrays so efficiently. It is mostly used in building Deep Learning Projects. It works a way more faster on Graphics Processing Unit (GPU) rather than on CPU. Theano attains high speeds that gives a tough competition to C implementations for problems involving large amounts of data. It can take advantage of GPUs which makes it perform better than C on a CPU by considerable orders of magnitude under some certain circumstances.<br \/>\nIt knows how to take structures and convert them into very efficient code that uses numpy and some native libraries. It is mainly designed to handle the types of computation required for large neural network algorithms used in Deep Learning. That is why, it is a very popular library in the field of Deep Learning.<\/p>\n<p><strong>How to install Theano :<\/strong><\/p>\n<pre>pip install theano<\/pre>\n<p>Several of the symbols we will need to use are in the\u00a0<strong>tensor<\/strong>\u00a0subpackage of Theano. We often import such packages with a handy name, let\u2019s say, T.<\/p>\n<pre>from theano import *\r\nimport theano.tensor as T<\/pre>\n<p><strong>Why Theano Python Library :<\/strong><br \/>\nTheano is a sort of hybrid between numpy and sympy, an attempt is made to combine the two into one powerful library. Some advantages of theano are as follows:<\/p>\n<ul>\n<li><strong>Stability Optimization:<\/strong>\u00a0Theano can find out some unstable expressions and can use more stable means to evaluate them<\/li>\n<li><strong>Execution Speed Optimization:<\/strong>\u00a0As mentioned earlier, theano can make use of recent GPUs and execute parts of expressions in your CPU or GPU, making it much faster than Python<\/li>\n<li><strong>Symbolic Differentiation:<\/strong>\u00a0Theano is smart enough to automatically create symbolic graphs for computing gradients<\/li>\n<\/ul>\n<p><strong>Basics of Theano :<\/strong><br \/>\nTheano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently.Some Theano implementations are as follows.<\/p>\n<div id=\"AP_G4GR_5\"><\/div>\n<p><strong>Subtracting two scalars :<\/strong><\/p>\n<div class=\"noIdeBtnDiv\">\n<div class=\"responsive-tabs-wrapper\">\n<div class=\"responsive-tabs responsive-tabs--enabled\">\n<ul class=\"responsive-tabs__list\" role=\"tablist\">\n<li id=\"tablist1-tab1\" class=\"responsive-tabs__list__item responsive-tabs__list__item--active\" role=\"tab\">Python<\/li>\n<\/ul>\n<div id=\"tablist1-panel1\" class=\"tabcontent responsive-tabs__panel responsive-tabs__panel--active\" role=\"tabpanel\" aria-hidden=\"false\" aria-labelledby=\"tablist1-tab1\">\n<div class=\"code-block\">\n<div class=\"code-gutter\">\n<div class=\"editor-buttons-container\">\n<div class=\"editor-buttons\"><\/div>\n<\/div>\n<\/div>\n<div class=\"code-container\">\n<div id=\"highlighter_790312\" class=\"syntaxhighlighter nogutter\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"comments\"># Python program showing<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"comments\"># subtraction of two scalars<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"keyword\">import<\/code> <code class=\"plain\">theano<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"keyword\">from<\/code> <code class=\"plain\">theano <\/code><code class=\"keyword\">import<\/code> <code class=\"plain\">tensor<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"comments\"># Declaring variables<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"plain\">a <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">tensor.dscalar()<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"plain\">b <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">tensor.dscalar()<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"comments\"># Subtracting<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"plain\">res <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">a <\/code><code class=\"keyword\">-<\/code> <code class=\"plain\">b<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"comments\"># Converting it to a callable object<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"comments\"># so that it takes matrix as parameters<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"plain\">func <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">theano.function([a, b], res)<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"comments\"># Calling function<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"keyword\">assert<\/code> <code class=\"value\">20.0<\/code> <code class=\"keyword\">=<\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">func(<\/code><code class=\"value\">30.5<\/code><code class=\"plain\">, <\/code><code class=\"value\">10.5<\/code><code class=\"plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>It will not provide any output as the assertion of two numbers matches the number given, hence it results into a true value.<\/p>\n<p><strong>Adding two scalars :<\/strong><\/p>\n<div class=\"noIdeBtnDiv\">\n<div class=\"responsive-tabs-wrapper\">\n<div class=\"responsive-tabs responsive-tabs--enabled\">\n<ul class=\"responsive-tabs__list\" role=\"tablist\">\n<li id=\"tablist2-tab1\" class=\"responsive-tabs__list__item responsive-tabs__list__item--active\" role=\"tab\">Python<\/li>\n<\/ul>\n<div id=\"tablist2-panel1\" class=\"tabcontent responsive-tabs__panel responsive-tabs__panel--active\" role=\"tabpanel\" aria-hidden=\"false\" aria-labelledby=\"tablist2-tab1\">\n<div class=\"code-block\">\n<div class=\"code-gutter\">\n<div class=\"editor-buttons-container\">\n<div class=\"editor-buttons\"><\/div>\n<\/div>\n<\/div>\n<div class=\"code-container\">\n<div id=\"highlighter_621827\" class=\"syntaxhighlighter nogutter\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"comments\"># Python program showing<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"comments\"># addition of two scalars<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"comments\"># Addition of two scalars<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"keyword\">import<\/code> <code class=\"plain\">numpy<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"keyword\">import<\/code> <code class=\"plain\">theano.tensor as T<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"keyword\">from<\/code> <code class=\"plain\">theano <\/code><code class=\"keyword\">import<\/code> <code class=\"plain\">function<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"comments\"># Declaring two variables<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"plain\">x <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">T.dscalar(<\/code><code class=\"string\">'x'<\/code><code class=\"plain\">)<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"plain\">y <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">T.dscalar(<\/code><code class=\"string\">'y'<\/code><code class=\"plain\">)<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"comments\"># Summing up the two numbers<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"plain\">z <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">x <\/code><code class=\"keyword\">+<\/code> <code class=\"plain\">y<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"comments\"># Converting it to a callable object<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"comments\"># so that it takes matrix as parameters<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"plain\">f <\/code><code class=\"keyword\">=<\/code> <code class=\"plain\">function([x, y], z)<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"plain\">f(<\/code><code class=\"value\">5<\/code><code class=\"plain\">, <\/code><code class=\"value\">7<\/code><code class=\"plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>Output:<\/strong>\u00a0array(12.0)<\/p>\n<h3>How Theano works aka Theano architecture?<\/h3>\n<p><b>Theano itself is effectively dead, but the deep learning frameworks built on top of Theano, are still functioning<\/b>. These include the more user-friendly frameworks- Keras, Lasagne, and Blocks. These three provide high-level frameworks for fast prototyping and model testing.<\/p>\n<div class=\"co8aDb\" role=\"heading\"><b>Lets look at the following code for simply multiplying 2 numbers:<\/b><\/div>\n<div class=\"RqBzHd\">\n<ol class=\"X5LH0c\">\n<li class=\"TrT0Xe\">Step 0: Import libraries. import numpy as np import theano.tensor as T from theano import function. &#8230;<\/li>\n<li class=\"TrT0Xe\">Step 1: Define variables. a = T.dscalar(&#8216;a&#8217;) b = T.dscalar(&#8216;b&#8217;) &#8230;<\/li>\n<li class=\"TrT0Xe\">Step 2: Define expression. c = a*b f = function([a,b],c) &#8230;<\/li>\n<li class=\"TrT0Xe\">Step 3: Evaluate Expression. f(1.5,3)<\/li>\n<\/ol>\n<h3>Use case of\u00a0 Theano<\/h3>\n<h2>How to Install\u00a0Theano<\/h2>\n<p>Theano provides extensive installation instructions for the major operating systems: Windows, OS X and Linux. Read the\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/install.html\">Installing Theano guide for your platform<\/a>.<\/p>\n<p>Theano assumes a working Python 2 or Python 3 environment with\u00a0<a href=\"https:\/\/www.scipy.org\/\">SciPy<\/a>. There are ways to make the installation easier, such as using\u00a0<a href=\"https:\/\/www.continuum.io\/downloads\">Anaconda<\/a>\u00a0to quickly set up Python and SciPy on your machine as well as using\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/install.html#docker-images\">Docker images<\/a>.<\/p>\n<p>With a working Python and SciPy environment, it is relatively straightforward to install Theano. from PyPI using pip, for example:<\/p>\n<div id=\"urvanov-syntax-highlighter-624171592bcb4012123926\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover disable-anim\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcb4012123926-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-624171592bcb4012123926-1\" class=\"crayon-line\">pip install Theano<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>At the time of writing the last official release of Theano was version 0.8 which was released 21th March 2016.<\/p>\n<p>New releases may be announced and you will want to update to get any bug fixes and efficiency improvements. You can upgrade Theano using pip as follows:<\/p>\n<div id=\"urvanov-syntax-highlighter-624171592bcb9590144797\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover disable-anim\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcb9590144797-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-624171592bcb9590144797-1\" class=\"crayon-line\">sudo pip install &#8211;upgrade &#8211;no-deps theano<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You may want to use the bleeding edge version of Theano checked directly out of Github.<\/p>\n<p>This may be required for some wrapper libraries that make use of bleeding edge API changes. You can install Theano directly from a Github checkout as follows:<\/p>\n<div id=\"urvanov-syntax-highlighter-624171592bcba383940085\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover disable-anim\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcba383940085-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-624171592bcba383940085-1\" class=\"crayon-line\">pip install &#8211;upgrade &#8211;no-deps git+git:\/\/github.com\/Theano\/Theano.git<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You are now ready to run Theano on your CPU, which is just fine for the development of small models.<\/p>\n<p>Large models may run slowly on the CPU. If you have a Nvidia GPU, you may want to look into configuring Theano to use your GPU. Read the\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/install.html#using-the-gpu\">Using the GPU guides for Linux<\/a>\u00a0or\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/install.html#gpu-macos\">Mac OS X to set up Theano to use the GPU<\/a>\u00a0and the\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/tutorial\/using_gpu.html\">Using the GPU guide<\/a>\u00a0for how to test whether it is working.<\/p>\n<h2>Simple Theano Example<\/h2>\n<p>In this section we demonstrate a simple Python script that gives you a flavor of Theano.<\/p>\n<p>It is taken from the\u00a0<a href=\"http:\/\/deeplearning.net\/software\/theano\/introduction.html\">Theano at a Glance guide<\/a>.\u00a0In this example we define two symbolic floating point variables\u00a0<em>a<\/em>\u00a0and\u00a0<em>b<\/em>.<\/p>\n<p>We define an expression that uses these variables\u00a0<em>(c = a + b)<\/em>.<\/p>\n<p>We then compile this symbolic expression into a function using Theano that we can use later.<\/p>\n<p>Finally, we use our complied expression by plugging in some real values and performing the calculation using efficient compiled Theano code under the covers.<\/p>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover disable-anim\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-11\">11<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-624171592bcbb339075648-12\">12<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-1\" class=\"crayon-line\"><span class=\"crayon-e\">import <\/span><span class=\"crayon-e\">theano<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">from <\/span><span class=\"crayon-e\">theano <\/span><span class=\"crayon-e\">import <\/span><span class=\"crayon-i\">tensor<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-3\" class=\"crayon-line\"><span class=\"crayon-p\"># declare two symbolic floating-point scalars<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">a<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">tensor<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">dscalar<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-5\" class=\"crayon-line\"><span class=\"crayon-v\">b<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">tensor<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">dscalar<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-p\"># create a simple expression<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-7\" class=\"crayon-line\"><span class=\"crayon-v\">c<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">a<\/span> <span class=\"crayon-o\">+<\/span> <span class=\"crayon-i\">b<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-p\"># convert the expression into a callable object that takes (a,b)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-9\" class=\"crayon-line\"><span class=\"crayon-p\"># values as input and computes a value for c<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-10\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">f<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">theano<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-t\">function<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">a<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">b<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-v\">c<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-11\" class=\"crayon-line\"><span class=\"crayon-p\"># bind 1.5 to &#8216;a&#8217;, 2.5 to &#8216;b&#8217;, and evaluate &#8216;c&#8217;<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-624171592bcbb339075648-12\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-st\">assert<\/span> <span class=\"crayon-cn\">4.0<\/span> <span class=\"crayon-o\">==<\/span> <span class=\"crayon-e\">f<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">1.5<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-cn\">2.5<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Running the example does not provide any output. The assertion that\u00a0<em>1.5 + 2.5 = 4.0<\/em>\u00a0is true.<\/p>\n<p>This is a useful example as it gives you a flavor for how a symbolic expression can be defined, compiled and used. You can see how this may be scaled up to large vector and matrix operations required for deep learning.<\/p>\n<h2>Extensions and Wrappers for Theano<\/h2>\n<p>If you are new to deep learning you do not have to use Theano directly.<\/p>\n<p>In fact, you are highly encouraged to use one of many popular Python projects that make Theano a lot easier to use for deep learning.<\/p>\n<p>These projects provide data structures and behaviors in Python, specifically designed to quickly and reliably create deep learning models whilst ensuring that fast and efficient models are created and executed by Theano under the covers.<\/p>\n<p>The amount of Theano syntax exposed by the libraries varies.<\/p>\n<ul>\n<li>For example the\u00a0<a href=\"https:\/\/lasagne.readthedocs.org\/en\/latest\/\">Lasagne library<\/a>\u00a0provides convenience classes for creating deep learning model but still expects you to know and make use of Theano syntax. This is good for beginners that know or are willing to learn a little Theano as well.<\/li>\n<li>Another example is\u00a0<a href=\"http:\/\/keras.io\/\">Keras<\/a>\u00a0that hides Theano completely and provides a very simple API to work with to create Deep Learning models. It hides Theano so well, that it can in fact run as a wrapper for another popular foundation framework called\u00a0<a href=\"https:\/\/www.tensorflow.org\/\">TensorFlow<\/a>.<\/li>\n<\/ul>\n<h3>Feature and Advantage of using Theano<\/h3>\n<div class=\"ltx_authors\"><span class=\"ltx_creator ltx_role_author\"><span class=\"ltx_personname\">Fr\u00e9d\u00e9ric Bastien,<span class=\"ltx_text ltx_font_typewriter\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_serif ltx_font_bold\">Pascal Lamblin,<\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">Razvan Pascanu,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">James Bergstra,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">Ian Goodfellow,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">Arnaud Bergeron,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">Nicolas Bouchard,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">David Warde-Farley,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/><span class=\"ltx_text ltx_font_bold\">Yoshua Bengio,<\/span><\/span><span class=\"ltx_text ltx_font_serif\"><br class=\"ltx_break\" \/>Dept. IRO, Universit\u00e9 de Montr\u00e9al, Montr\u00e9al (QC), H3C 3J7, Canada<\/span><\/span><\/span><\/span><\/div>\n<div class=\"ltx_abstract\">\n<h6 class=\"ltx_title ltx_title_abstract\">ABSTRACT<\/h6>\n<p class=\"ltx_p\">Theano is a linear algebra compiler that optimizes a user\u2019s symbolically-specified mathematical computations to produce efficient low-level implementations. In this paper, we present new features and efficiency improvements to Theano, and benchmarks demonstrating Theano\u2019s performance relative to Torch7, a recently introduced machine learning library, and to RNNLM, a C++ library targeted at recurrent neural networks.<\/p>\n<\/div>\n<h3>Best Alternative of Theano<\/h3>\n<div class=\"co8aDb\" role=\"heading\"><b>Top 10 Alternatives to Theano<\/b><\/div>\n<div class=\"RqBzHd\">\n<ul class=\"i8Z77e\">\n<li class=\"TrT0Xe\">scikit-learn.<\/li>\n<li class=\"TrT0Xe\">Keysight Eggplant Platform.<\/li>\n<li class=\"TrT0Xe\">machine-learning in Python.<\/li>\n<li class=\"TrT0Xe\">V7.<\/li>\n<li class=\"TrT0Xe\">Personalizer.<\/li>\n<li class=\"TrT0Xe\">Kubeflow.<\/li>\n<li class=\"TrT0Xe\">Google Cloud TPU.<\/li>\n<li class=\"TrT0Xe\">Torch.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3>Free Video Tutorials of Theano<\/h3>\n<figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_79154\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/fWkArbYtQbM?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&disablekb=0&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure>\n<h3>Interview Questions and Answer for Theano<\/h3>\n<p>&nbsp;<\/p>\n<p class=\"mcq\"><span class=\"ques\">1.\u00a0Theano is a _______ library.<br \/>\n<\/span><\/p>\n<p class=\"options\">A. R<br \/>\nB. Python<br \/>\nC. Ruby<br \/>\nD. Javascript<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q1\" class=\"showanswer\">Ans : B<br \/>\nExplanation: Theano is a Python library that allows us to evaluate mathematical operations including multi-dimensional arrays so efficiently.<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">2.\u00a0Theano works a way _______ on Graphics Processing Unit (GPU) rather than on CPU.<br \/>\n<\/span><\/p>\n<p class=\"options\">A. slower<br \/>\nB. very slower<br \/>\nC. faster<br \/>\nD. more faster<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q2\" class=\"showanswer\">Ans : D<br \/>\nExplanation: It works a way more faster on Graphics Processing Unit (GPU) rather than on CPU.<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">3.\u00a0Which command used to install Theano?<br \/>\n<\/span><\/p>\n<p class=\"options\">A. install theano<br \/>\nB. np install theano<br \/>\nC. pip install theano<br \/>\nD. npm install theano<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q3\" class=\"showanswer\">Ans : C<br \/>\nExplanation: pip install theano command used to install Theano<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">4.\u00a0Which of the following are advantages of theano ?<br \/>\n<\/span><\/p>\n<p class=\"options\">A. Stability Optimization<br \/>\nB. Execution Speed Optimization<br \/>\nC. Symbolic Differentiation<br \/>\nD. All of the above<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q4\" class=\"showanswer\">Ans : D<br \/>\nExplanation: All of the above are advantages of theano.<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">5.\u00a0Which theano type has 16-bit integers?<br \/>\n<\/span><\/p>\n<p class=\"options\">A. bscalar<br \/>\nB. wscalar<br \/>\nC. iscalar<br \/>\nD. fscalar<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q5\" class=\"showanswer\">Ans : B<br \/>\nExplanation: 16-bit integers : wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4, wtensor5, wtensor6, wtensor7<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">6.\u00a0fmatrix theano type has data type?<br \/>\n<\/span><\/p>\n<p class=\"options\">A. float<br \/>\nB. double<br \/>\nC. 32-bit integers<br \/>\nD. 64-bit integers<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q6\" class=\"showanswer\">Ans : A<br \/>\nExplanation: float : fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, ftensor5, ftensor6, ftensor7<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">7.\u00a0Theano function acts like a hook for interacting with the symbolic graph.<br \/>\n<\/span><\/p>\n<p class=\"options\">A. TRUE<br \/>\nB. FALSE<br \/>\nC. Can be true or false<br \/>\nD. Can not say<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q7\" class=\"showanswer\">Ans : A<br \/>\nExplanation: True, Theano function acts like a hook for interacting with the symbolic graph.<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">8.\u00a0A Theano function is declared using the following syntax?<br \/>\n<\/span><\/p>\n<p class=\"options\">A. theano.declare ([x], y)<br \/>\nB. theano.fun ([x], y)<br \/>\nC. theano.function ([x], y)<br \/>\nD. function ([x], y)<\/p>\n<p><span class=\"view\">\u00a0Answer<\/span><\/p>\n<div id=\"q8\" class=\"showanswer\">Ans : C<br \/>\nExplanation: A Theano function is declared using the following syntax : theano.function ([x], y)<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">9.\u00a0The _________ method declares a decimal scalar variable.<br \/>\n<\/span><\/p>\n<p class=\"options\">A. scalar<br \/>\nB. theano<br \/>\nC. declare<br \/>\nD. dscalar<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q9\" class=\"showanswer\">Ans : D<br \/>\nExplanation: The dscalar method declares a decimal scalar variable.<\/p>\n<\/div>\n<p class=\"mcq\"><span class=\"ques\">10.\u00a0Theano was written at the LISA lab with the intention of providing rapid development of efficient machine learning algorithms.<br \/>\n<\/span><\/p>\n<p class=\"options\">A. TRUE<br \/>\nB. FALSE<br \/>\nC. Can be true or false<br \/>\nD. Can not say<\/p>\n<p><span class=\"view\">View Answer<\/span><\/p>\n<div id=\"q10\" class=\"showanswer\">Ans : A<br \/>\nExplanation: True, Theano was written at the LISA lab with the intention of providing rapid development of efficient machine learning algorithms.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"RqBzHd\"><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>History &amp; Origin of Theano Theano&#8217;s husband, Pythagoras (c. 582-500 B.C.), was inspired one of the most influential sects in the ancient world. Best known for devising&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-29230","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=29230"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29230\/revisions"}],"predecessor-version":[{"id":32433,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29230\/revisions\/32433"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=29230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=29230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=29230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}