<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Cristobal Eyzaguirre</title>
    <description>Cristobals&apos;s blog,use Jekyll and github pages.</description>
    <link>https://ceyzaguirre4.github.io/</link>
    <atom:link href="https://ceyzaguirre4.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 16 Jul 2026 04:30:59 +0000</pubDate>
    <lastBuildDate>Thu, 16 Jul 2026 04:30:59 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>StateKV: Linear Scaling Video VLMs for Long Video Understanding</title>
        <description>&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0; url=https://ceyzaguirre4.github.io/StateKV/&quot; /&gt;

&lt;script&gt;
  window.location.replace(&quot;https://ceyzaguirre4.github.io/StateKV/&quot;);
&lt;/script&gt;

&lt;p&gt;Redirecting to the &lt;a href=&quot;https://ceyzaguirre4.github.io/StateKV/&quot;&gt;StateKV project page&lt;/a&gt;.&lt;/p&gt;
</description>
        <pubDate>Sun, 31 May 2026 00:00:00 +0000</pubDate>
        <link>https://ceyzaguirre4.github.io/ai/2026/05/31/StateKV.html</link>
        <guid isPermaLink="true">https://ceyzaguirre4.github.io/ai/2026/05/31/StateKV.html</guid>
        
        
        <category>Ai</category>
        
      </item>
    
      <item>
        <title>Differentiable Adaptive Computation Time for Visual Reasoning (CVPR 2020)</title>
        <description>&lt;div style=&quot;text-align:center&quot;&gt;&lt;em&gt;(if answer is ready: stop wasting computation)&lt;/em&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;On tasks where the complexity needed to answer varies it makes intuitive sense that model complexity should vary accordingly.
The ability to adaptively allocate more resources to difficult tasks is one that all humans possess and is evident in the increased requirements needed for complex mathematics compared to simple everyday tasks.
This post introduces DACT &lt;a href=&quot;http://arxiv.org/abs/2004.12770&quot;&gt;[0]&lt;/a&gt;, a new algorithm for achieving adaptive computation time that, unlike existing approaches, is fully differentiable.
We put it to the test on Visual Reasoning datasets and find that our models learns to actively adapt their architectures according, balancing high accuracy with as-little-as-possible computation.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://arxiv.org/abs/2004.12770&quot;&gt;LINK TO ARXIV [0]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ceyzaguirre4/DACT-MAC&quot;&gt;LINK TO CODE&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-setting-visual-question-answering&quot;&gt;The Setting: Visual Question Answering&lt;/h2&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/tennis1.png&quot; alt=&quot;How many balls is the kid holding?&quot; /&gt;&lt;/th&gt;
                
                  &lt;th style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/th&gt;
                
              
            
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/tennis2.png&quot; alt=&quot;How many birds is he holding?&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;How many balls is the kid holding?&lt;/em&gt;&lt;/td&gt;
                
                  &lt;td style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/td&gt;
                
              
            
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;How many birds is he holding?&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;Visual Question Answering (VQA) &lt;a href=&quot;https://visualqa.org&quot;&gt;[1]&lt;/a&gt; is a task where, for a given input image, question pair, we expect the model to return an answer.
The difficulty of the task lies in the openness for both the question and image: because any image or plain-text question are valid expecting the model to output convincing answers can be seen as a more general Turing-test.
These datasets pose challenging natural language questions about images whose solution requires the use of perceptual abilities, such as recognizing objects or attributes, identifying spatial relations, or implementing high-level capabilities like counting.
For example, in the images above we see examples of two very similar (counting) questions for images from the Visual Genome dataset &lt;a href=&quot;https://visualgenome.org&quot;&gt;[2]&lt;/a&gt; that necessitate a broad understanding of the relation holding and a general purpose counting algorithm.&lt;/p&gt;

&lt;!--
![](/images/dact/clevr_eg.png)
*Examples of questions in the CLEVR dataset that show a significant variation in the number of reasoning steps that are needed to answer them correctly.* --&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/clevr_eg.png&quot; alt=&quot;Examples of questions in the CLEVR dataset that show a significant variation in the number of reasoning steps that are needed to answer them correctly.&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;Examples of questions in the CLEVR dataset that show a significant variation in the number of reasoning steps that are needed to answer them correctly.&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;In open tasks such as this we find that instances entail diverse levels of complexity as both questions and images can be arbitrarily simple or difficult.
Two examples from the CLEVR dataset &lt;a href=&quot;http://cs.stanford.edu/people/jcjohns/clevr/&quot;&gt;[3]&lt;/a&gt; are shown above.
Even in the very restricted subset of all possible images and questions included in this dataset (vocabulary of 28 words, generated images of the same objects) we find significant variation in complexity.
Specifically, while the question of the first example involves just the identification of a specific attribute from a specific object, the second question requires the identification and comparative analysis of several attributes from several objects.
We argue that dealing with this openness is paramount for more general intelligence and propose Adaptive Computation Time algorithms such as ACT &lt;a href=&quot;https://arxiv.org/abs/1603.08983&quot;&gt;[4]&lt;/a&gt; as possible solutions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;existing-adaptive-approaches&quot;&gt;Existing Adaptive Approaches&lt;/h2&gt;

&lt;h3 id=&quot;1-modular-networks&quot;&gt;1. Modular Networks&lt;/h3&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/modules_spec.png&quot; alt=&quot;Specialized Modules&quot; /&gt;&lt;/th&gt;
                
                  &lt;th style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/th&gt;
                
              
            
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/modules_gen.png&quot; alt=&quot;General Purpose Module&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;Specialized Modules&lt;/em&gt;&lt;/td&gt;
                
                  &lt;td style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/td&gt;
                
              
            
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;General Purpose Module&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;We consider modular networks those where modules are combined from a collection processing modules.
Here we distinguish between two kinds:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;those in which a controller selects the appropriate specialized module (eg. IEP &lt;a href=&quot;https://arxiv.org/abs/1705.03633&quot;&gt;[5]&lt;/a&gt; show in figure).&lt;/li&gt;
  &lt;li&gt;those where a single general purpose module is used repeatedly for a fixed number of times (eg. MAC &lt;a href=&quot;https://arxiv.org/abs/1803.03067&quot;&gt;[6]&lt;/a&gt; shown in figure).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only the case of specialized modules is adaptive, but the generation of the sequences requires costly supervision or elaborate reinforcement learning training schemes.&lt;/p&gt;

&lt;p&gt;The second case (general purpose modules) always executes the same module a fixed number of times, so no module selection training is needed.
However, this approach is not adaptive as the processing pipeline is always the same.
In our work, we build upon one of these networks by using DACT to adaptively select the horizon of the computational pipeline (instead of having it as a fixed hyper-parameter).&lt;/p&gt;

&lt;h3 id=&quot;2-act&quot;&gt;2. ACT&lt;/h3&gt;

&lt;p&gt;An algorithm for adaptive computation in neural networks already existed: ACT.
I’ve already written a detailed explanation of how and why it works in a &lt;a href=&quot;/ACT&quot;&gt;previous post&lt;/a&gt;, but the TLDR is that it works by forcing that the weights used to combine each step’s output into the final answer sum exactly one.
To achieve this a non-differentiable piecewise function is used, namely: if the sum of the weights is more than one, then change the last weight so that the sum is exactly one.
It has seen some success reducing computation in computer vision and natural language processing problems.
However, we found that its theoretical shortcomings limited its usefulness for Visual Reasoning tasks (see Results), so we proposed a novel fully-differentiable algorithm.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;/h2&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/diagram.png&quot; alt=&quot;The final answer Y is built up from the sub-answers from each module. The maximum contribution of any one of these steps is limited by all earlier ones, and any step can choose to limit contribution of subsequent ones.&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;The final answer Y is built up from the sub-answers from each module. The maximum contribution of any one of these steps is limited by all earlier ones, and any step can choose to limit contribution of subsequent ones.&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;DACT was formulated as a differentiable alternative to ACT.
In other words, it was designed to provide a means by which a model can halt computation without adding noise to the gradients.&lt;/p&gt;

&lt;!-- Our approach maintains the full gradient by **only halting during evaluation** (and not during training).
The weights used to combine all the step output’s are described by a monotonically decreasing probability distribution that implicitly includes future steps yet to be computed.
The result is a fully differentiable model for training with gradient descent whose computation can be reduced during inference by mathematically determining when the interruption cannot change the output. --&gt;

&lt;p&gt;Our formulation can be applied to any model or ensemble that can be decomposed as a series of modules or submodels $m_n$, $n ∈ [1,…,N]$ that can be ordered by complexity.
For example, recurrent networks are composed by iterative steps, CNNs by residual blocks, and ensembles by smaller models.
We refer to the composition as our final model or ensemble $M$, and to its output as $Y$.
This work focusses on its application to a recurrent visual reasoning architecture called MAC.&lt;/p&gt;

&lt;p&gt;The core of the DACT algorithm is that any step can limit the total contribution of subsequent steps.
To achieve this we use the sigmoidal halting values $h_n \in \left] 0, 1 \right[ $ to inductively define $p_n$ as:&lt;/p&gt;

\[p_n = \prod_{i=1}^{n}h_{i} = h_{n} p_{n-1}\]

&lt;p&gt;We observe that $p_n$ is monotonically decreasing for increasing values of $n$.
Through their halting values each $n$th step can choose to either maintain the probability ($h_n \approx 1$) or reduce it ($h_n &amp;lt; 1$).
The value of $p_n$ can be interpreted as the probability that a subsequent step might change the value of the final answer.
Consequently, we define the initial value $p_0 = 1$.&lt;/p&gt;

&lt;p&gt;The final answer $Y$ is built incrementally using the sub-answers of each step using accumulator variables $a_n$ for $n \in [1 \dots N]$ such that $Y = a_N$:&lt;/p&gt;

\[a_n = \begin{cases}
    \overrightarrow{0} &amp;amp; \text{if } n=0\\
    y_n p_{n-1} + a_{n-1} \left( 1 - p_{n-1} \right) &amp;amp; \text{otherwise}
  \end{cases}\]

&lt;p&gt;It follows from this definition that $Y$ can always be rewritten as a weighted sum of intermediate outputs $y_n$.
The relative relevance of each $y_n$ to the final output is thus constrained by $p_{n-1}$ which in turn is constrained by the $h_n$s of earlier steps.&lt;/p&gt;

&lt;p&gt;We observe that this means that, for some step $n$ with low associated $p_n$, then $a_n \approx Y$.&lt;/p&gt;

&lt;h3 id=&quot;putting-it-all-together&quot;&gt;Putting it all together…&lt;/h3&gt;

&lt;p&gt;During evaluation / test we want to identify the step where $a_n \approx Y$ to halt computation.
How you choose to define $\approx$ in your code depends on you and the use-case.
For this work we say that $a_n$ is similar enough to $Y$ once we are sure that the class with highest probability in $a_n$ is the same as in $Y$.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_steps&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# run another step
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;answer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;run_module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;answer_can_change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We say that the answer cannot change when the top class in $a_n$ will necessarily be the same as in $Y$ after all $d = N - n$ remaining steps.
In particular, we are interested in checking if it’s possible that the probability associated to the &lt;em&gt;runner up&lt;/em&gt; (second best) class $c^{ru}$ can surpass that of the top class ($c^*$).&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;answer_can_change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# get top and runner-up classes
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;c_star&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_max_class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;answer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;c_ru&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_ru_class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;answer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# check if answer cant change
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;min_p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c_star&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max_p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c_ru&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The top answer is most likely to change if all $d$ remaining steps assign probability $0$ to $c^*$ and $1$ to $c^{ru}$.
This scenario is the worst case from the perspective of the stability of the answer as it leads to the minimum value that the probability of class $c^*$ can take in $Y$; along with the maximum value for $c^{ru}$.&lt;/p&gt;

&lt;p&gt;Then, after expanding the inductive definition of $a_n$ and replacing the worst-case probabilities we derive a lower bound for the probability of the class $c^*$ in $Y$:&lt;/p&gt;

\[\Pr(c^*, N) \geq \Pr(c^*, n)(1-p_n)^d\]

&lt;p&gt;And an upper bound to the probability of the runner-up class $c^{ru}$:&lt;/p&gt;

\[\Pr(c^{ru}, N) \leq \Pr(c^{ru}, n) + p_n d\]

&lt;p&gt;Therefore during inference we can safely cut computation once we identify a step $n$ such that we know for sure that the top classes in $a_n$ and $Y$ are the same.
Mathematically, this means the &lt;em&gt;halting condition&lt;/em&gt; is achieved when:&lt;/p&gt;

\[\Pr(c^*, n)(1-p_n)^d \geq \Pr(c^{ru}, n) + p_n d\]

&lt;p&gt;&lt;em&gt;(The math and some additional proofs are included in the paper.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Finally, we add $\rho = \sum_{n=1}^{N} p_n$, a proxy of the total computation, to the loss function to encourage reduced computation:&lt;/p&gt;

\[\hat{L} (x, y) = L (x, y) + \tau \rho(x)\]

&lt;hr /&gt;

&lt;h2 id=&quot;results-clevr&quot;&gt;Results: CLEVR&lt;/h2&gt;

&lt;h3 id=&quot;1-better-accuracy-in-fewer-steps&quot;&gt;1. Better accuracy in fewer steps&lt;/h3&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/mac_steps_acc.png&quot; alt=&quot;Scatterplot of computation (in steps) vs. precision. DACT-MACs shown in color; MACs as diamonds; ACT-MACs as crosses.&quot; /&gt;&lt;/th&gt;
                
                  &lt;th style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/th&gt;
                
              
            
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/convergence.png&quot; alt=&quot;Learning curves for different regularization ( 𝜏 ponder cost) values show mean and variance of three runs.&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;Scatterplot of computation (in steps) vs. precision. DACT-MACs shown in color; MACs as diamonds; ACT-MACs as crosses.&lt;/em&gt;&lt;/td&gt;
                
                  &lt;td style=&quot;text-align: center&quot;&gt;&amp;nbsp;&lt;/td&gt;
                
              
            
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;Learning curves for different regularization ( 𝜏 ponder cost) values show mean and variance of three runs.&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;As the scatterplot above shows, DACT enabled MACs (in color) consistently outperform vanilla MACs (shown as diamonds) when both use comparable average numbers of steps.
ACT on the other hand only performs as well or bellow as comparable MACs.
Additionally, the figure shows that DACT responds predictably to changes in the penalty or &lt;em&gt;ponder cost&lt;/em&gt; $\tau$ used (represented by the color), iterating fewer times when more penalty is used.
This again contrasts with ACT which proved to be insensitive to the &lt;em&gt;ponder cost&lt;/em&gt;.
For instance, ACT without ponder cost ($\tau$ = 0.0) performs 3.2 steps on average and obtains an accuracy of 95.8%.&lt;/p&gt;

&lt;h3 id=&quot;2-increased-adaptability-to-changes-in-question-difficulty&quot;&gt;2. Increased adaptability to changes in question difficulty&lt;/h3&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/corr_compare.png&quot; alt=&quot;How many steps are used by adaptive MACs for each question family in the CLEVR dataset. ACT-MACs in a); DACT-MACs shown in b) and c).&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;How many steps are used by adaptive MACs for each question family in the CLEVR dataset. ACT-MACs in a); DACT-MACs shown in b) and c).&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;The motivation behind using adaptive algorithms for this task is to use less computation for the more straightforward questions while still being able to use more computation for difficult ones.
In the figure above &lt;strong&gt;a)&lt;/strong&gt; shows the existing algorithm (ACT) failing to learn how to answer the most straightforward questions in less than three steps, or the hardest in more than five.
The other two images show DACT using most of the available spectrum, showing that DACT enabled MACs are capable of actively allocating more computational resources to questions that need them.
The second image &lt;strong&gt;b)&lt;/strong&gt; shows a variant of DACT that averages approximately the same number of steps as &lt;strong&gt;a)&lt;/strong&gt;, while &lt;strong&gt;c)&lt;/strong&gt; shows a DACT-MAC with lower ponder cost, which uses 50% more reasoning steps on average and thus achieves even better performance.&lt;/p&gt;

&lt;p&gt;The figure shows questions clustered by family type which translates to groups that require similar step sequences to solve.
The fact that DACT shows a remarkable correlation between computation and question family despite not including any type of supervision about these factors evinces the learning of meaningful patterns that correlate with question complexity.
The full &lt;em&gt;heatmap&lt;/em&gt; that shows an example for each question family can be found &lt;a href=&quot;/images/dact/corrs_full.png&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;3-interpretability-gains&quot;&gt;3. Interpretability gains&lt;/h3&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/AttsComp.png&quot; alt=&quot;Visual and linguistic attention maps for both regular MAC (left) and DACT-MAC (right).&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;Visual and linguistic attention maps for both regular MAC (left) and DACT-MAC (right).&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;Besides the obvious and substantial reduction in the number of steps used to answer, our model also contributes to the overall interpretability of the inference.
This is achieved by adding a proxy of the number of steps taken to the loss function, effectively coercing the model into only using fewer (and therefore more likely to be semantically strong) steps.
This translates into more interpretable models.
For instance, the question attentions above show that the last two steps are similar for both models, but that only one of the other ten steps used by MAC was necessary.&lt;/p&gt;

&lt;p&gt;Additionally, the values of $p_n$ and the sub answers $a_n$ provide further insights.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;bonus-results-gqa&quot;&gt;Bonus Results: GQA&lt;/h2&gt;

&lt;p&gt;Finally, in order to evaluate the generality of the suggested approach to real data, we evaluate the combined DACT-MAC architecture on the more diverse images and questions in the GQA dataset &lt;a href=&quot;https://arxiv.org/abs/1902.09506&quot;&gt;[7]&lt;/a&gt;.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;&lt;strong&gt;Method&lt;/strong&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;&lt;strong&gt;Ponder Cost&lt;/strong&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;&lt;strong&gt;Steps&lt;/strong&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;&lt;strong&gt;Accuracy&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MAC+Gate&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.51&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MAC+Gate&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.52&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MAC+Gate&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.52&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MAC+Gate&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.36&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MAC+Gate&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;6&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.37&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;ACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1e-2&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.99&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.17&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;ACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1e-3&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2.26&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.04&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;ACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1e-4&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2.31&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.21&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;ACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2.15&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.20&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;5e-2&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.63&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.23&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1e-2&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2.77&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.26&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;5e-3&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3.05&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.35&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DACT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1e-3&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3.69&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;77.31&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;We find that increasing computational steps doesn’t benefit the chosen architecture (MAC), and therefore adapting computation won’t increase performance.
However, by adding DACT to a pre-trained 4-step MAC and then fine-tuning we find that it again outperforms the existing algorithm in terms of accuracy and responsiveness to &lt;em&gt;ponder cost&lt;/em&gt;.&lt;/p&gt;

&lt;div style=&quot;padding: 10px; border-radius: 10px; border-color: black; border-style: solid; border-width: thin;&quot;&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        
          
              
                &lt;th style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/images/dact/corrs_gqa.png&quot; alt=&quot;How many steps are used by DACT-MACs for each question type in the GQA dataset.&quot; /&gt;&lt;/th&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody style=&quot;border: none&quot;&gt;
      &lt;tr&gt;
        
          
              
                &lt;td style=&quot;text-align: center&quot;&gt;&lt;em style=&quot;font-size: 0.8em&quot;&gt;How many steps are used by DACT-MACs for each question type in the GQA dataset.&lt;/em&gt;&lt;/td&gt;
                
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
            
        
          
              
          
        
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
&lt;/div&gt;

&lt;p&gt;Additionally, we find that DACT-MACs adapt the 4-step algorithm reducing computation on some question types, and that the number of steps again correlate strongly with &lt;em&gt;question types&lt;/em&gt; as can be seen in the &lt;em&gt;heatmaps&lt;/em&gt; above.
The same figures also show how the architecture adapts to changes in the &lt;em&gt;ponder cost&lt;/em&gt;, as this penalty decreases DACT adaptively allocates more resources to more complex questions.
The full &lt;em&gt;heatmap&lt;/em&gt; that shows the question types can be found &lt;a href=&quot;/images/dact/corrs_full_gqa.png&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;future-work-ideas-&quot;&gt;Future Work Ideas (!)&lt;/h2&gt;

&lt;p&gt;A few lines for future work:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;using adaptive computation to generate curriculums for curriculum learning.&lt;/li&gt;
  &lt;li&gt;using different &lt;em&gt;halting conditions&lt;/em&gt; with DACT.&lt;/li&gt;
  &lt;li&gt;taking advantage of DACT’s differentiability to use non-linear functions of computation (eg. exponential ponder penalties).&lt;/li&gt;
  &lt;li&gt;applying DACT to other models and datasets. I’m particularly interested in using it on neural state machines &lt;a href=&quot;https://arxiv.org/abs/1907.03950&quot;&gt;[8]&lt;/a&gt; for real adaptive behavior on GQA.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cite&quot;&gt;Cite&lt;/h2&gt;

&lt;div class=&quot;language-bibtex highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;@article&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Eyzaguirre2020DifferentiableAC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{Differentiable Adaptive Computation Time for Visual Reasoning}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;author&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{Cristobal Eyzaguirre and A. Soto}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;journal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;year&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{2020}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;pages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{12814-12822}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;style&gt;
  /* overwrite mains max width so vis can use full width */
  img {
    max-width:100%;
  }
&lt;/style&gt;

</description>
        <pubDate>Sat, 25 Apr 2020 00:00:00 +0000</pubDate>
        <link>https://ceyzaguirre4.github.io/ai/2020/04/25/DACT-for-Visual-Reasoning.html</link>
        <guid isPermaLink="true">https://ceyzaguirre4.github.io/ai/2020/04/25/DACT-for-Visual-Reasoning.html</guid>
        
        
        <category>Ai</category>
        
      </item>
    
      <item>
        <title>PyTorch (1.0), CUDA &amp; cuDNN on MacOS</title>
        <description>&lt;p&gt;This guide was written primarily for my own future use and the methods described have only been tested with my own late 2013 15” Macbook Pro with Nvidia 750m graphics.
Nonetheless, the guide is written in english so as to be useful for many people (although my mother tongue is spanish).
The guide is based on what was published on &lt;a href=&quot;https://groups.google.com/a/allenai.org/forum/#!topic/allennlp-users/uqICoCmXTjo&quot;&gt;this google group&lt;/a&gt; for AllenNLP, completing the information there and updating commands where useful.&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;CUDA and cuDNN are used to speed up matrix operations and other operations that are tipically useful for machine learning algorithms. 
Macs have not shipped with nVidia graphics cards since 2013 and it can be difficult to find updated drivers and cuDNN libraries that are compatible with your nVidia graphics card.&lt;/p&gt;

&lt;p&gt;Not all graphics cards are compatible with CUDA, &lt;a href=&quot;https://developer.nvidia.com/cuda-gpus&quot;&gt;here&lt;/a&gt; is a list of those compatible; you need compute capability $\geq$ 3.0 in order to follow the guide.&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;cuda-drivers&quot;&gt;CUDA drivers&lt;/h4&gt;

&lt;p&gt;The first step is to update your CUDA drivers.
I found &lt;a href=&quot;https://www.insanelymac.com/forum/topic/324195-nvidia-web-driver-updates-for-macos-high-sierra-update-apr-02-2019/&quot;&gt;this post&lt;/a&gt; where updated drivers can be found for MacOS versions up to 10.13.6 (most recent version when the post was written).
cuDNN requires driver version 378.05 or higher. While the original guide this post is based on didn´t have access to those drivers I found those listed above and can confirm they work.&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;cuda-toolkit&quot;&gt;CUDA toolkit&lt;/h4&gt;

&lt;p&gt;The next step is to install CUDA toolkit form &lt;a href=&quot;https://developer.nvidia.com/cuda-downloads&quot;&gt;here&lt;/a&gt;. Select MacOS as the target OS and install the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dmg&lt;/code&gt;. This will install CUDA $\geq$ 10.1 on your local machine. Follow the onscreen prompts.&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;compatible-clangxcode-version&quot;&gt;Compatible clang/Xcode version&lt;/h4&gt;

&lt;p&gt;The original post sugests installing Xcode 8.3.3 in order to get a compatible clang compiler. 
On their site nVidia says Xcode 10.1 (10B61) is compatible with MacOS 10.13.6 and CUDA 10.1. 
Personally I followed the instructions &lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-installation-guide-mac-os-x/index.html&quot;&gt;here&lt;/a&gt; to install the older version of Xcode after having problems in a later step.
However the problems were unrelated to the clang version and although I didnt test Xcode 10.1, it can make sense to check &lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-installation-guide-mac-os-x/index.html#system-requirements&quot;&gt;here&lt;/a&gt; for the sugested Xcode version for the downloaded CUDA toolkit.&lt;/p&gt;

&lt;p&gt;Older Xcode versions have to be downloaded through the &lt;a href=&quot;https://developer.apple.com/downloads&quot;&gt;Apple developer page&lt;/a&gt;.
Searching for the version number will let you download the version you want.
After downloading the version you can change the selected xcode version by running:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# first install command line tools (in case they weren&apos;t already)&lt;/span&gt;
xcode-select &lt;span class=&quot;nt&quot;&gt;--install&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# select the correct version; replace &amp;lt;Xcode_install_dir&amp;gt; with the real dir. &lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;xcode-select &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /Applications/&amp;lt;Xcode_install_dir&amp;gt;/Contents/Developer
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;cudnn&quot;&gt;cuDNN&lt;/h4&gt;

&lt;p&gt;cuDNN can be found &lt;a href=&quot;https://developer.nvidia.com/rdp/cudnn-archive&quot;&gt;here&lt;/a&gt;. You will need to register as a developer (for free) in order to download.
For maximum performance look for the most recent compatible version (under Dec.14); I installed &lt;a href=&quot;https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.0.4/prod/9.0_20171031/cudnn-9.0-osx-x64-v7&quot;&gt;cuDNN 7.0.4&lt;/a&gt; for CUDA 9.0 (under Nov.13) since I was following the outdated tutorial.&lt;/p&gt;

&lt;p&gt;The compressed file can be unziped and moved, I moved it to my home (so you will need to change some paths in the following instructions if you dont put it there).&lt;/p&gt;

&lt;p&gt;I found I needed to export more paths than those on the original post. Run the following in your command line:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CUDA_HOME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;~/cudnn
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;DYLD_LIBRARY_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$CUDA_HOME&lt;/span&gt;/lib:&lt;span class=&quot;nv&quot;&gt;$DYLD_LIBRARY_PATH&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CUDNN_LIB_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;/cudnn/lib
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CUDNN_INCLUDE_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;/cudnn/include
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;/cudnn/lib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;pytorch-installation&quot;&gt;Pytorch Installation&lt;/h2&gt;

&lt;p&gt;On MacOS, the only way to install pytorch with CUDA support is to install from source. The pytorch repository has &lt;a href=&quot;https://github.com/pytorch/pytorch#from-source&quot;&gt;instructions&lt;/a&gt;, but they assume you use Anaconda. The following commands can be seen as a proven (be me) alternative:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# clone repository&lt;/span&gt;
git clone &lt;span class=&quot;nt&quot;&gt;--recursive&lt;/span&gt; https://github.com/pytorch/pytorch
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;pytorch

&lt;span class=&quot;c&quot;&gt;# install, I use 10.13 as target because that is the version of MacOS I am running.&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;MACOSX_DEPLOYMENT_TARGET&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10.13 &lt;span class=&quot;nv&quot;&gt;CC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;clang &lt;span class=&quot;nv&quot;&gt;CXX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;clang++ python3 setup.py &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;remove-pytorch-no-longer-supports-this-gpu-because-it-is-too-old-warning&quot;&gt;Remove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PyTorch no longer supports this GPU because it is too old&lt;/code&gt; warning&lt;/h4&gt;

&lt;p&gt;If you get this message it may be because your GPU is of CUDA compatibility 3.0 (eg. nVidia 750m). Contrary to what appears in the warning, CUDA 3.0 is supported. We can remove these warnings by going to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/local/lib/python3.7/site-packages/torch/cuda/__init__.py&lt;/code&gt; and commenting out lines 118-119. The location and line numbers can vary but the UserWarning raised indicated the file path and line. The commented lines in my distribution of pytorch (1.1.0) are as follows:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# elif capability == (3, 0) or major &amp;lt; 3:
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# warnings.warn(old_gpu_warn % (d, name, major, capability[1]))
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;testing-installation&quot;&gt;Testing installation&lt;/h2&gt;

&lt;p&gt;First we test importing pytorch:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__version__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We check for available cuda devices and try moving a size 20 tensor to the GPU:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_cuda&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The following wont produce error messages if cuDNN is installed:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backends&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cudnn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;p&gt;And there you go, congratulations!&lt;/p&gt;
</description>
        <pubDate>Tue, 02 Apr 2019 00:00:00 +0000</pubDate>
        <link>https://ceyzaguirre4.github.io/2019/04/02/Pytorch-Cuda-Mac.html</link>
        <guid isPermaLink="true">https://ceyzaguirre4.github.io/2019/04/02/Pytorch-Cuda-Mac.html</guid>
        
        
      </item>
    
      <item>
        <title>Percentage GridMap</title>
        <description>&lt;p&gt;&lt;em&gt;How can we visualize the distribution of 33 categories over the whole of the USA?&lt;/em&gt;
The webpage &lt;a href=&quot;http://meetup.com&quot;&gt;meetup.com&lt;/a&gt; hosts diferent types of events all over the world. 
For a class we wondered if it was posible to observe diferences in the interests between the people of diferent states.
The main dificulty was that there were 33 categories to compare among 50 states, a simple barchart wouldn’t be enough as 33*50 columns is more than any one person can absorb.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The solution&lt;/h2&gt;

&lt;p&gt;We compromised. Instead of showing every minor diference among states we chose to observe tendencies. Then, a choropleth would be created to reflect these tendencies and add geographical information to the mix.&lt;/p&gt;

&lt;p&gt;We show tendencies by dividing each state into 100 colored cells we call percentage cells. The amount of cells that are of a certain color represents the percentage of the interest of the inhabitants of the state towards the category represented by the color. By randomizing the positioning of the cels inside the state we obtain a puzle that broadly shows the main categories present in each one of the states.&lt;/p&gt;

&lt;p&gt;We substitute the states geographical shape for one that removes surface area biases in the visualization as this only adds noise to what we want to observe. However, we maintain the general positions of the states in respect to each other so as to facilitate the detection of geographical related relations.&lt;/p&gt;

&lt;p&gt;Finally, since the randomly positioned cells are difficult to count in order to find the exact percentage, we let the user click a state to get an easier to read visualization (a barchart) of the specific area.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hypothesis&quot;&gt;Hypothesis&lt;/h2&gt;

&lt;p&gt;We hoped that the resulting visualization would enable us to detect patterns between the states by comparing their tendencies.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;We found it easier to find outliers and anomalies simply by looking for states that have a diferent “average” color.&lt;/li&gt;
  &lt;li&gt;We found it was easy to find geographical tendencies. For instance, regions of the USA where there was a recognizably larger interest in Tech (shown in blue).&lt;/li&gt;
  &lt;li&gt;It’s generally easy to compare two states interest in a category by comparing the amount of cells of the desired color, and similar percentages can be distinguished after clicking each state to get the broken down percentages in the barchart.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next steps&lt;/h2&gt;

&lt;p&gt;We didnt completely finish the project, people looking to build upon or improve should consider the following areas:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The code needs tidying up (D3.js is declaratively writen and can be dificult to read in a big project like this).&lt;/li&gt;
  &lt;li&gt;Percentages are not calculated but proxied by sampling 100 events per state and asuming the categories of these are representative of the interests per state.&lt;/li&gt;
  &lt;li&gt;There’s much need for a way to select some subset of categories to compare because as of now those most common tend to hide the rest. (++ im 99% sure no one can distinguish 33 colors).&lt;/li&gt;
  &lt;li&gt;Responsiveness: the visualization looks horrible on smaller screens.&lt;/li&gt;
  &lt;li&gt;Performance: the transitions lag on slower computers because calculations are repeated for each of many cells (100 per state).&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;style&gt;
  /* body {
    font-family:&quot;avenir next&quot;, Arial, sans-serif;
    font-size: 20px;
  } */

  .label {
    pointer-events: none;
  }

  /* overwrite mains max width so vis can use full width */
  #main {
    max-width:100%;
  }
&lt;/style&gt;

</description>
        <pubDate>Thu, 21 Mar 2019 00:00:00 +0000</pubDate>
        <link>https://ceyzaguirre4.github.io/2019/03/21/GridMap.html</link>
        <guid isPermaLink="true">https://ceyzaguirre4.github.io/2019/03/21/GridMap.html</guid>
        
        
      </item>
    
      <item>
        <title>Adaptive Computation Time</title>
        <description>&lt;h3 id=&quot;top-down-explanation-of-graves-2015-paper-adaptive-computation-time-for-recurrent-neural-networks&quot;&gt;Top-Down explanation of Graves’ 2015 paper &lt;a href=&quot;https://arxiv.org/abs/1603.08983&quot;&gt;“Adaptive Computation Time for Recurrent Neural Networks”&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;1-motivation&quot;&gt;1. Motivation&lt;/h4&gt;

&lt;p&gt;Graves states “evidence that increased depth leads to more performant networks is by now inarguable, and recent results show that increased sequence length can be similarly beneficial”.
The underlying principle seems to imply that putting your under-achieving model inside a recurrent network and have it iterate a fixed number of times (100 if you want) to observe better results.
Of course, in practice the opposite seems to hold.
The resulting model will be much more computationally intensive, will overfit to data easily and you probably wont even see gains in performance.&lt;/p&gt;

&lt;p&gt;So what we need is a way to use these increased sequence lengths when more computation is required but at the same time prevent the network from overfitting.
In other words, we want to increase the sequence length when needed, but limit complexity when it isn’t.
How can we achieve this? By letting the network determine how many iterations it will run and including the number of iterations (or a proxy of this) in the loss function we should achieve a network that will iterate only when it helps to obtain a more accurate answer.&lt;/p&gt;

&lt;p&gt;As we push towards a recurrent network that determines how many times it will iterate a new problem arises.
How will the network determine its number of iterations? And how to make this differentiable? Having the network determine this limit &lt;em&gt;a priori&lt;/em&gt; “would be equivalent to determining the Kolmogorov complexity of the data (and hence solving the halting problem)” (Graves, 2015).
The solution proposed by Graves is to let the network &lt;em&gt;halt&lt;/em&gt; when it is ready instead.&lt;/p&gt;

&lt;p&gt;Pseudo code:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;is_ready&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;answer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# run model to update answer and check if ready
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;answer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;is_ready&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;run_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;is_ready&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-halting&quot;&gt;2. Halting&lt;/h4&gt;

&lt;p&gt;For each iteration the network outputs an answer and a SIGMOIDAL halting value. The magnitude of the contribution of any iteration to the final answer $y_t$ is equal to the sub answer (the answer given by the iteration) multiplied by its probability of being relevant to the final answer $p_n$.&lt;/p&gt;

\[y = \sum_{n=1}^{\infty} p_n y_n\]

&lt;p&gt;In order to limit computation we want all probabilities to be zero for $n &amp;gt; N$ (so that running for more iterations doesn’t change the answer).&lt;/p&gt;

\[p_n = \begin{cases} R(n) &amp;amp;\text{if } n \geq N\\ h_n &amp;amp; \text{otherwise} \end{cases}\]

&lt;p&gt;A function $N$ is used to determine the first $n’$ for which the sum of all halting probabilities is greater than one minus a small epsilon. This is so that after one iteration the sigmoidal (and therefore never quite $1$) value of $h_n$ can be enough to halt if only one iteration is needed.&lt;/p&gt;

\[N = min\{ n&apos; : \sum_{n=1}^{n&apos;} h_n \geq 1 - \epsilon \}\]

&lt;p&gt;For each iteration $n$ before $n’$ the probability is equal to its halting value.
Since the sum of all probabilities has to be equal to one (and we want to limit computation), for $n = N$ the probability $p_n$ will be equal to the remainder $R = 1 - \text{ the sum of all previous probabilities}$.&lt;/p&gt;

\[R = 1 - \sum_{n=1}^{N-1}p_n\]

&lt;p&gt;This way, for any $n &amp;gt; N$ the probability will be zero ($R = 1 - 1$), so we can get away with not computing them and the answer wont change, so:&lt;/p&gt;

\[y = \sum_{n=1}^{\infty} p_n y_n\]

&lt;p&gt;Finally, we add a proxy of total computation $\rho = N + R$ to the loss to encourage reduced computation and backpropagate through this.&lt;/p&gt;

\[\hat{L} = L(x,y) + \rho\]

&lt;h4 id=&quot;3-how-it-works&quot;&gt;3. How it works&lt;/h4&gt;

&lt;p&gt;The main mechanism through which ACT operates is a non-differentiable piece-wise function.
As such, the backpropagation of gradients through it is non-trivial.&lt;/p&gt;

&lt;p&gt;Looking at the regularization term in the loss function $\rho$ we observe that no gradient can be propagated through $N$ and therefore adding $\rho$ to the loss is functionally equivalent to adding the remainder $R$.
From it’s definition we observe that again no gradient can be propagated through the constant value $1$.
Taken together this means that by adding $\rho$ to the loss function to minimize $text{loss} + \text{computation}$ we are actually minimizing $text{loss}$ while maximizing $\sum_{n=1}^{N-1}p_n$.
By encouraging the network to maximize the halting probabilities of earlier steps we bias the network towards lower computation.
This mechanism can be easily understood by considering that the $N$th step (the last answer-changing step) will be achieved earlier if, for instance, the first step greatly increases it’s halting probability.&lt;/p&gt;

&lt;h4 id=&quot;4-generalizing-towards-recurrent-neural-networks&quot;&gt;4. Generalizing towards recurrent neural networks&lt;/h4&gt;

&lt;p&gt;In Graves’ work the process described above is repeated for each element $t$ in a sequence using an RNN. For each of these besides outputing $y_t$ (the $y$ for element $t$ of the sequence) a hidden state $s_t$ is computed:&lt;/p&gt;

\[y = \sum_{n=1}^{\infty} p_n y_n\]

&lt;p&gt;Where $p_t^n \text{ is } p_n \text{ in timestep } t$.&lt;/p&gt;

&lt;p&gt;And $N(t)$ is the first $n_t$ for which the sum of all $h_t^n$ is greater than one minus small epsilon.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ACT.png&quot; alt=&quot;unrolled ACT from paper&quot; /&gt;&lt;/p&gt;

&lt;!-- [&lt;img src=&quot;/images/ACT.png&quot; style=&quot;width: 600px;&quot;/&gt;](/) --&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;In blue is the process for one element of the sequence (as described in &lt;a href=&quot;#2.-Halting&quot;&gt;2.&lt;/a&gt;). For each one of these elements $N(t)$ iterations are performed ($n = 1$ marked in red).&lt;/p&gt;

&lt;p&gt;I haven’t talked about how to obtain any of the parameters mentioned (halting_values, sub_answers, sub_hidden_states) because it depends greatly on the implementation. A standard RNN (as shown in the image above) initializes its hidden state $s_t^1$ (when $n = 1$) to $S(s_{t-1}, x_t)$. In other words, for the first iteration of any element in the sequence the hidden state is a function $S$ applied to the COMPLETE hidden state at timestep $t - 1$ and the element of the sequence at index $t$. For any other iteration $s_t^n$ is $S(s_t^{n-1}, x_t)$.&lt;/p&gt;

\[s_t^n = \begin{cases}
S(s_{t-1}, x_t) \text{ if } n = 1 \\
S(s_t^{n-1}, x_t) \text{ otherwise}
\end{cases}\]

&lt;p&gt;Then both $y_t^n$ and $h_t^n$ are calculated by feeding the hidden state $s_t^n$ through feedforward layers $W_y$ and $W_h$ (with bias values) respectively. The output for the halting value $h_t^n$ is then squashed using a Sigmoid.&lt;/p&gt;
</description>
        <pubDate>Sun, 12 Aug 2018 00:00:00 +0000</pubDate>
        <link>https://ceyzaguirre4.github.io/ai/2018/08/12/ACT.html</link>
        <guid isPermaLink="true">https://ceyzaguirre4.github.io/ai/2018/08/12/ACT.html</guid>
        
        
        <category>Ai</category>
        
      </item>
    
  </channel>
</rss>
