{"id":175333,"date":"2023-12-17T11:03:16","date_gmt":"2023-12-17T10:03:16","guid":{"rendered":"https:\/\/liora.io\/en\/?p=175333"},"modified":"2026-02-06T08:40:39","modified_gmt":"2026-02-06T07:40:39","slug":"theano-description-and-use-of-this-python-library","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/theano-description-and-use-of-this-python-library","title":{"rendered":"Theano: Description and use of this Python library"},"content":{"rendered":"<p><strong>Theano is a library that allows solving problems involving large datasets through multi-dimensional arrays. Below, you will find more details on how to accelerate your research using Theano: etymology, creation, features, and its inclusion in the Python pipeline&#8230;<\/strong><\/p>\t\t\n\t\t<p>Theano is primarily the name of a Greek mathematician and philosopher from the 6th century BCE, known as the exemplary woman of Pythagoras.<\/p>\t\t\n\t\t\t<h3>What is Theano?<\/h3>\t\t\n\t\t<p>Returning to our main concern, Theano is a <a href=\"https:\/\/liora.io\/en\/tpot-all-about-this-machine-learning-python-library\">Python library<\/a> developed by Yoshua Bengio at the University of Montreal in 2007. It is based on and written in Python. Theano utilizes multi-dimensional arrays to define, optimize, and evaluate mathematical expressions, <a href=\"https:\/\/liora.io\/en\/unleashing-artistic-expression-with-deep-learning-style-transfer\">especially in the context of Deep Learning<\/a> or problems involving a substantial amount of data. It is notably well-received in academic research and development.<\/p>\t\t\n\t\t\t<h3>How do you code with Theano?<\/h3>\t\t\n\t\t<ul><li style=\"font-weight: 400;\" aria-level=\"1\">It is installed using pip install Theano from the terminal.<\/li><li style=\"font-weight: 400;\" aria-level=\"1\">Theano&#8217;s &#8220;tensor&#8221; sub-library is often abbreviated to T.<\/li><li style=\"font-weight: 400;\" aria-level=\"1\">A Theano function and variables are declared as follows:<\/li><\/ul><p>As you can see, the <strong>Theano function<\/strong> requires an array of variables [a, b] and a predefined variable c as the result, which is an operation (in this case, addition) of a and b. The displayed result when the function is called is 10 in this case.<\/p><p>The graph of the function is shown below, generated by a Theano command, which we will discuss in the next paragraph. It&#8217;s evident that the first two blocks (in green) correspond to the two variables a and b, which are of type float and defined as tensor.dscalar().<\/p><p>The middle block (in red) represents the Theano function defined by c (add for addition). The blue block corresponds to the result.<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/03\/Fichier-122.png\" title=\"\" alt=\"schema 1 theano\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption>Graph of the Theano f function<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/formation\/data-ia\/deep-learning\">Apprendre \u00e0 coder avec Theano<\/a><\/div><\/div>\n\n\t\t\t<h3>What makes it special?<\/h3>\t\t\n\t\t<p>From a functional and performance perspective, this library:<\/p><p>1. Creates an expression that is evaluated by a Theano function.<br>2. Allows for differentiation of multiple variables, matrix computations, and gradient calculations with ease.<br>3. Automatically generates symbolic graphs that can be visualized using a library and the pydotprint function.<\/p><p>These graphs can be highly complex, and Theano applies many advanced optimization techniques (algebra and compilation) to them.<\/p><p>These techniques consider the overall graph to generate highly efficient code, especially in the context of repetitive calculations.<\/p><p>It doesn&#8217;t rely solely on local optimization techniques but can also reorganize calculations (order, repetitions) to make them faster, similar to<a href=\"https:\/\/liora.io\/en\/classification-algorithms-definition-and-main-models\"> different algorithms<\/a> for searching a word in a text that can vary in speed (O(n), O(n\u00b2)).<\/p><p>The Theano function acts as a bridge to inject compiled C code into the runtime (the software responsible for program execution).<\/p><p>Below, you can see an example of a more complex graph than the previous one. Here, there is an additional element, the white blocks, which represent predefined functions from other libraries, for example:<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/03\/Fichier-121.png\" title=\"\" alt=\"schema 2 theano\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption>Complex Theano function graph<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t<p>The calculations are up to 140 times faster on a GPU <a href=\"https:\/\/liora.io\/en\/exploring-imageio-a-comprehensive-guide-to-the-python-library\">compared to C on a CPU (which supports only the float32 format) or pure Python.<\/a> Dynamic code generation in C enables faster evaluation of expressions.<\/p><p>A few additional points:<\/p><p>1. It is fast and stable when dealing with calculations of the type log(1+exp(x)) for large values of x.<br>2. It includes self-testing tools for diagnosing bugs and issues.<br>3. It can be adapted for use <a href=\"https:\/\/liora.io\/en\/convolutional-neural-network-everything-you-need-to-know\">with convolutional networks and recurrent networks.<\/a><\/p>\t\t\n\t\t\t<h3>How is it linked to other libraries?<\/h3>\t\t\n\t\t<ul><li style=\"font-weight: 400;\" aria-level=\"1\">Theano incorporates numpy.arrays into its internal workings. It is a library sometimes invoked in the internal operations of Keras with TensorFlow (for machine learning models).<\/li><li style=\"font-weight: 400;\" aria-level=\"1\">Theano can serve as a backend in Keras to perform all internal operations. TensorFlow, which serves a similar purpose, can also be found in this context.<\/li><\/ul>\t\t\n\t\t\t<h3>Conclusion<\/h3>\t\t\n\t\t<p>Theano is, therefore, a tool that optimizes and accelerates your computations in Deep Learning or Machine Learning based on a graph system that encompasses all computation steps. Despite its age, it is not outdated and deserves a place on the list of optimization libraries. If you wish to gain expertise in these fields, Liora has designed a curriculum for Deep Learning that you can find by clicking on the previous link.<\/p>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/deep-learning\">Find out more about Deep Learning<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Theano is a library that allows solving problems involving large datasets through multi-dimensional arrays. Below, you will find more details on how to accelerate your research using Theano: etymology, creation, features, and its inclusion in the Python pipeline&#8230; Theano is primarily the name of a Greek mathematician and philosopher from the 6th century BCE, known [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":175334,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-175333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=175333"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175333\/revisions"}],"predecessor-version":[{"id":206164,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175333\/revisions\/206164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/175334"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=175333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=175333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}