<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<title>Narsil</title>
	<subtitle>Small experiments insights from ML and software development.</subtitle>
	<link href="https://nodata.dev/atom.xml" rel="self" type="application/atom+xml"/>
	<link href="https://nodata.dev"/>
	<generator uri="https://www.getzola.org/">Zola</generator>
	<updated>2025-06-04T00:00:00+00:00</updated>
	<id>https://nodata.dev/atom.xml</id>
	<entry xml:lang="en">
		<title>Beyond Distributed Compilation: A New Paradigm for Heterogeneous Computing</title>
		<published>2025-06-04T00:00:00+00:00</published>
		<updated>2025-06-04T00:00:00+00:00</updated>
		<link href="https://nodata.dev/compilers/distributed-systems/gpu/2025/06/04/beyond-distributed-compilation/"/>
		<link rel="alternate" href="https://nodata.dev/compilers/distributed-systems/gpu/2025/06/04/beyond-distributed-compilation/" type="text/html"/>
		<id>https://nodata.dev/compilers/distributed-systems/gpu/2025/06/04/beyond-distributed-compilation/</id>
		<content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer&lt;&#x2F;strong&gt;: This article was generated by artificial intelligence.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h1 id=&quot;beyond-distributed-compilation-a-new-paradigm-for-heterogeneous-computing&quot;&gt;Beyond Distributed Compilation: A New Paradigm for Heterogeneous Computing&lt;a class=&quot;zola-anchor&quot; href=&quot;#beyond-distributed-compilation-a-new-paradigm-for-heterogeneous-computing&quot; aria-label=&quot;Anchor link for: beyond-distributed-compilation-a-new-paradigm-for-heterogeneous-computing&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;c_language.jpg&quot; alt=&quot;The Birth of C Language&quot; &#x2F;&gt;
&lt;em&gt;Figure 1: The complexity of modern distributed systems&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-challenge&quot;&gt;The Challenge&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-challenge&quot; aria-label=&quot;Anchor link for: the-challenge&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Consider the case of Large Language Models (LLMs). Today, we have specialized systems like vLLM or Text Generation Inference (TGI) that are meticulously optimized for NVIDIA GPUs. These optimizations are carefully tuned for the current GPU architecture, where memory bandwidth is often the limiting factor. But what happens when a new GPU architecture emerges with vastly different characteristics - perhaps one with much higher memory bandwidth and lower latency? Suddenly, all that carefully crafted code needs to be rewritten.&lt;&#x2F;p&gt;
&lt;p&gt;The problem extends beyond just GPUs. What if you want to run the same LLM on CPUs, which have entirely different performance characteristics? Or across multiple nodes, where network latency and bandwidth become critical factors? With a high-bandwidth, low-latency InfiniBand connection, you might want one data layout, but with a slower network, you&#x27;d need a completely different approach.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;llm-bottlenecks.png&quot; alt=&quot;LLM Inference vs Training Bottlenecks&quot; &#x2F;&gt;
&lt;em&gt;Figure 2: Different hardware architectures require different optimization strategies&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This situation is strikingly similar to the early days of computing, when each CPU architecture required its own specialized assembly code. Then came C, and with it, a revolutionary idea: write your code once in a system-agnostic way, and let the compiler handle the translation to the specific instruction set. The compiler could optimize for the target architecture, taking into account its unique characteristics.&lt;&#x2F;p&gt;
&lt;p&gt;We need a similar revolution for distributed systems. Instead of writing specialized code for each hardware configuration, we need a language that describes the problem at a high level, independent of the underlying hardware. The compiler would then handle the complex task of optimizing for the specific architecture, taking into account:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Memory bandwidth and latency&lt;&#x2F;li&gt;
&lt;li&gt;Network topology and characteristics&lt;&#x2F;li&gt;
&lt;li&gt;Cache hierarchies&lt;&#x2F;li&gt;
&lt;li&gt;Hardware-specific schedulers&lt;&#x2F;li&gt;
&lt;li&gt;Data movement patterns&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;When new hardware emerges, we wouldn&#x27;t need to rewrite our code - we&#x27;d just need to recompile it. The compiler would understand the new architecture&#x27;s characteristics and generate optimized code accordingly. This would free developers to focus on solving problems rather than wrestling with hardware-specific optimizations.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;The fundamental challenge stems from a theoretical limitation: Turing-complete programming languages face the halting problem. This means it&#x27;s impossible for a compiler to determine if a program will halt, let alone predict how long it will run. This uncertainty makes it extremely difficult for compilers to reason about program optimization. As a result, developers must manually profile their code, identify hot loops, optimize cache usage, and adjust data structures to fit cache lines - all while understanding the intricate details of their target hardware.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;turing_vs_pure.jpg&quot; alt=&quot;Turing vs Restricted Model&quot; &#x2F;&gt;
&lt;em&gt;Figure 3: The trade-off between expressiveness and optimization potential&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This situation suggests a radical solution: what if we gave up Turing completeness? By adopting a more restricted programming model, we could enable compilers to precisely determine when and how a program will execute. This would allow us to explore all possible execution strategies during compilation and find the optimal one. While finding the absolute optimal solution is likely NP-complete - especially when considering hardware intricacies like micro-ops, hidden latencies, and kernel-specific overheads - these complexities are largely artifacts of our current approach to optimization.&lt;&#x2F;p&gt;
&lt;p&gt;With full control over the execution schedule, we could eliminate many of these complexities. We would know exactly when each instruction will execute, making it trivial to determine the fastest solution among alternatives. We could precisely orchestrate the overlap of computation and communication, identify bottlenecks, and optimize the entire system&#x27;s performance.&lt;&#x2F;p&gt;
&lt;p&gt;The NP-completeness of this problem might seem daunting, but there are several factors that make it tractable in practice:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Symmetrical Systems&lt;&#x2F;strong&gt;: Modern hardware is highly symmetrical. GPUs have uniform cores with identical L1 caches, evenly distributed L2 caches, and when using multiple nodes, they&#x27;re typically equivalent. This symmetry means solutions for one subsystem often apply to the entire system, allowing us to break the problem into smaller, manageable chunks.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simple Operations&lt;&#x2F;strong&gt;: The programs we&#x27;re targeting - matrix multiplications, reductions, softmax operations - are relatively simple and have limited interactions. These operations are highly regular and don&#x27;t have complex sequential dependencies, making them much easier to optimize than arbitrary Turing-complete programs.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Modular Solutions&lt;&#x2F;strong&gt;: The symmetrical nature of our target systems means we can often find solutions for parts of the system and apply them to similar components, reducing the overall complexity of the optimization problem.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;It&#x27;s important to note that this approach won&#x27;t solve all problems. Complex programs with intricate sequential dependencies and arbitrary Turing-complete computations will still be challenging to optimize for distributed systems. However, for the specific class of problems we&#x27;re targeting - large-scale numerical computations and machine learning workloads - this approach offers a promising path forward.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-new-approach&quot;&gt;A New Approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-new-approach&quot; aria-label=&quot;Anchor link for: a-new-approach&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s start with a simple example: summing the elements of a vector. In traditional Rust, we might write something like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; sum_vector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-rust&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt; f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This function is concise but leaves many important questions unanswered: Where does the vector live? How many elements does it have? Should we use a GPU for this computation? What if we have multiple nodes available?&lt;&#x2F;p&gt;
&lt;p&gt;Now, consider a version where we provide this information through type annotations:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; sum_vector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-rust&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; N&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; @&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Disk&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt; f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; @&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other z-caps z-rust&quot;&gt; RAM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This annotated version tells the compiler crucial information:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The vector has N elements&lt;&#x2F;li&gt;
&lt;li&gt;The input data lives on disk&lt;&#x2F;li&gt;
&lt;li&gt;The result should be stored in RAM&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;With this information, the compiler can make intelligent decisions:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;For small N (e.g., 4 elements), it might choose a single CPU implementation&lt;&#x2F;li&gt;
&lt;li&gt;For large N (e.g., 1 million elements), it might distribute the computation across GPUs or nodes&lt;&#x2F;li&gt;
&lt;li&gt;If the input is on disk, it can plan the data movement accordingly&lt;&#x2F;li&gt;
&lt;li&gt;It can generate multiple code paths optimized for different input sizes&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The key insight is that N doesn&#x27;t need to be known at compile time. We could specify a range of possible values:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; sum_vector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-rust&quot;&gt;v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; N&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; @&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Disk&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type z-numeric z-rust&quot;&gt; f32&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; @&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-other z-caps z-rust&quot;&gt; RAM&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;    N&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Range&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-brackets z-angle z-rust&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; 1_000_000&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-brackets z-angle z-rust&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    v&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The compiler can then:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Analyze the performance characteristics for different N values&lt;&#x2F;li&gt;
&lt;li&gt;Determine the breakpoints where different strategies become optimal&lt;&#x2F;li&gt;
&lt;li&gt;Generate multiple code paths&lt;&#x2F;li&gt;
&lt;li&gt;Choose the appropriate path at runtime based on the actual input size&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;This approach allows us to:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Make optimal decisions based on data characteristics&lt;&#x2F;li&gt;
&lt;li&gt;Generate specialized code for different scenarios&lt;&#x2F;li&gt;
&lt;li&gt;Handle data movement efficiently&lt;&#x2F;li&gt;
&lt;li&gt;Adapt to the available hardware resources&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The compiler becomes an active participant in optimization, using the type information to make informed decisions about:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Data distribution&lt;&#x2F;li&gt;
&lt;li&gt;Computation strategy&lt;&#x2F;li&gt;
&lt;li&gt;Memory management&lt;&#x2F;li&gt;
&lt;li&gt;Hardware utilization&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;compiler-driven-optimization&quot;&gt;Compiler-Driven Optimization&lt;a class=&quot;zola-anchor&quot; href=&quot;#compiler-driven-optimization&quot; aria-label=&quot;Anchor link for: compiler-driven-optimization&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;At first glance, one might worry that this approach would lead to verbose, annotation-laden code. After all, our example shows type annotations for data location, and it&#x27;s natural to be concerned about this complexity spreading throughout the codebase. However, this isn&#x27;t the case. Most functions in a program won&#x27;t need these annotations at all, because we don&#x27;t need to specify where intermediate computations happen.&lt;&#x2F;p&gt;
&lt;p&gt;The annotations only appear at the boundaries of our computation - the entry points where data first enters our system (like reading from disk or receiving network data) and the exit points where we need the results in a specific location (like writing to a file or sending data over the network). These are the only places where we truly care about data location, as they represent the interfaces between our program and the outside world.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;artisan_vs_factory.jpg&quot; alt=&quot;Lazy Evaluation&quot; &#x2F;&gt;
&lt;em&gt;Figure 4: How the compiler manages data location decisions&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This approach allows the compiler to make intelligent decisions about data placement. For instance, in our vector sum example, if the data is already on the GPU from previous computations, the compiler can choose to keep it there rather than moving it to the CPU. The same function might execute on different hardware depending on the program&#x27;s current state.&lt;&#x2F;p&gt;
&lt;p&gt;The compiler handles the complexity of:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Tracking where data lives throughout the program&lt;&#x2F;li&gt;
&lt;li&gt;Making decisions about data placement&lt;&#x2F;li&gt;
&lt;li&gt;Adapting to the current execution context&lt;&#x2F;li&gt;
&lt;li&gt;Minimizing data movement&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;the-benefits&quot;&gt;The Benefits&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-benefits&quot; aria-label=&quot;Anchor link for: the-benefits&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;This approach offers several key advantages:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Developers can focus on algorithms rather than implementation details&lt;&#x2F;li&gt;
&lt;li&gt;The compiler can make global optimizations across the entire system&lt;&#x2F;li&gt;
&lt;li&gt;The compiler can add Byzantine fault tolerance checks at system boundaries, detecting and adapting to nodes that are performing poorly or failing&lt;&#x2F;li&gt;
&lt;li&gt;The compilation phase can predict exact execution times, enabling runtime verification of system behavior and detection of hardware issues&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>All we need is tokenizerless</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2024-01-14T00:00:00+00:00</published>
		<updated>2024-01-14T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2024/01/14/tokenizerless/"/>
		<link rel="alternate" href="https://nodata.dev/2024/01/14/tokenizerless/" type="text/html"/>
		<id>https://nodata.dev/2024/01/14/tokenizerless/</id>
		<content type="html">&lt;h1 id=&quot;what-tokenization-achieves&quot;&gt;What tokenization achieves&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-tokenization-achieves&quot; aria-label=&quot;Anchor link for: what-tokenization-achieves&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;Tokenization enables models to have some form of temporal compression (read outputting several characters as 1 timestep) while also increasing the entropy of those item. By definition we use compression algorithm to create the tokens, which means the distribution is trying to become closer the the uniform distribution.&lt;&#x2F;p&gt;
&lt;p&gt;That means that models outputting random tokens will still make a coherent native looking output. It also means that the random distribution is a good starting point for the model itself (which wouldn&#x27;t be the case with any real language)&lt;&#x2F;p&gt;
&lt;h1 id=&quot;tokenization-limits&quot;&gt;Tokenization limits&lt;a class=&quot;zola-anchor&quot; href=&quot;#tokenization-limits&quot; aria-label=&quot;Anchor link for: tokenization-limits&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;Tokenization is limiting because it doesn&#x27;t take into account previous tokens. Therefore, while the distribution of tokens is relatively uniform, the distribution of pairs of tokens is most definitely not, so some pairs are easier to train than others. This is what makes speculation working so well. One would think than having a more complex tokenizer would help here, but having more tokens in the vocabulary also is a cost, and because the tokenization methods are so crude, they yield diminishing returns.&lt;&#x2F;p&gt;
&lt;p&gt;Also tokenization doesn&#x27;t really work well with unicode. Unicode is the method to create all non ascii characters, where most non latin languages rely on. For a language like Chinese, you would need a vocabulary of size ~100k to just to get all the initial vocabulary (10k being a bare minimum). Because that&#x27;s humongous and some of these bare characters are underrepresented, usually tokenizers remove some of these rare base chars, creating UNK tokens once again. The other technique is called byte fallback, meaning those unknown characters are shown to the model as their raw bytes representations. This works in training, but that also means that the model can output arbitrary sequences of raw bytes, meaning the model can also talk non valid utf-8 outputs which you have to deal with.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;temporal-coherence&quot;&gt;Temporal coherence&lt;a class=&quot;zola-anchor&quot; href=&quot;#temporal-coherence&quot; aria-label=&quot;Anchor link for: temporal-coherence&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;One thing to note, is that if you look at the output distribution of a transformers, even a simple one, there are definite breakpoints in &lt;em&gt;entropy&lt;&#x2F;em&gt;, and they really look like the original tokenizers, like &quot;the &quot;, or &quot;or &quot;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;multi-level-hierarchy&quot;&gt;Multi level hierarchy&lt;a class=&quot;zola-anchor&quot; href=&quot;#multi-level-hierarchy&quot; aria-label=&quot;Anchor link for: multi-level-hierarchy&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;Achieving tokenizerless temporal coherence by pure ML ways, would enable models to stack various levels of temporal coherence on top of each other. There could be one level for the &quot;tokens&quot;, but also some for the &quot;sentences&quot;, or &quot;paragraphs&quot; or even &quot;entire books&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;This is actually how most written content is written. Not exactly word for word in a continuous stream, but more a back and forth between multiple timescales. Write the abstract, expand some paragraphs, revisit the structure, rewrite sentences, fix typos, go back again to the top level structure, change a bit the conclusion, create a title, go back down to the first paragraph and so on. There is a constant jumping between timescale representations that produces modifications to another timescale representation.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Deploying a snapshat filter to the browser</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2020-07-29T00:00:00+00:00</published>
		<updated>2020-07-29T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2020/07/29/deploying-model-in-the-browser/"/>
		<link rel="alternate" href="https://nodata.dev/2020/07/29/deploying-model-in-the-browser/" type="text/html"/>
		<id>https://nodata.dev/2020/07/29/deploying-model-in-the-browser/</id>
		<content type="html">&lt;blockquote&gt;
&lt;p&gt;TL;DR In this article I explain how you can deploy a model directly to the browser from pytorch by using Onnjx. This work was done a year ago in about two weeks time.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;face&#x2F;face.gif&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;div style=&quot;width:100%;text-align:center;&quot;&gt;
    &lt;a href=&quot;https:&#x2F;&#x2F;narsil.github.io&#x2F;assets&#x2F;face&#x2F;&quot;&gt;Check out the full demo&lt;&#x2F;a&gt;.
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;deploying-a-cool-deep-learning-demo-at-zero-cost&quot;&gt;Deploying a cool deep learning demo at zero cost.&lt;a class=&quot;zola-anchor&quot; href=&quot;#deploying-a-cool-deep-learning-demo-at-zero-cost&quot; aria-label=&quot;Anchor link for: deploying-a-cool-deep-learning-demo-at-zero-cost&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Ok, so when we are showcasing deep learning, usually that implies running models somewhere on the cloud. Sometimes, running these models is by itself quite costly. GPT-3 cost something like 10 million to train, but imagine how much it will cost to &lt;em&gt;run&lt;&#x2F;em&gt; if it was accessible to the general public !&lt;&#x2F;p&gt;
&lt;p&gt;One technique applicable so small machine learning models, it to actually make to client run the model not you. This means that your front can be a simple static website. Hell you could even host it on Github for free !&lt;&#x2F;p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;About a year ago, I was working at &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;nabla.com&quot;&gt;Nabla&lt;&#x2F;a&gt; (They pivoted since). We were looking
at how performant was 3d pose estimation of the face. It means models detecting
faces &lt;em&gt;with&lt;&#x2F;em&gt; depth which was not as ubiquitous as regular 2d face detection.&lt;&#x2F;p&gt;
&lt;p&gt;The idea was to see how hard it was to fit glasses on the fly to customers.
The whole thing lasted for 2 weeks, so mind the lack of polish.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;let-s-get-started-with-3ddfa&quot;&gt;Let&#x27;s get started with 3DDFA&lt;a class=&quot;zola-anchor&quot; href=&quot;#let-s-get-started-with-3ddfa&quot; aria-label=&quot;Anchor link for: let-s-get-started-with-3ddfa&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;So &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cleardusk&#x2F;3DDFA&quot;&gt;3DDFA&lt;&#x2F;a&gt; is an improved Pytorch implementation of &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1804.01005&quot;&gt;this paper&lt;&#x2F;a&gt;.
We settled on that implementation because it was the best available at the time.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;how-does-it-work&quot;&gt;How does it work ?&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-does-it-work&quot; aria-label=&quot;Anchor link for: how-does-it-work&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Most 3d pose estimation use the same tricks. First you need a good space representation with few latent variables.
That is usually taken by creating a quite large dataset of a lot of people in lots of different poses and doing a
very large PCA on this representation.&lt;&#x2F;p&gt;
&lt;p&gt;For faces, 3ddfa uses a mix of &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;faces.dmi.unibas.ch&#x2F;bfm&#x2F;&quot;&gt;BFM&lt;&#x2F;a&gt; and &lt;a rel=&quot;nofollow external&quot; href=&quot;http:&#x2F;&#x2F;kunzhou.net&#x2F;2012&#x2F;facewarehouse-tr.pdf&quot;&gt;Facewarehouse&lt;&#x2F;a&gt;, for the full human body, &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;smpl.is.tue.mpg.de&#x2F;&quot;&gt;SMPL&lt;&#x2F;a&gt; is often used.&lt;&#x2F;p&gt;
&lt;p&gt;In the face case, all 3D scans register the same 53490 vertices on the difference faces of the different participants (100 male and 100 female for BFM). For instance the center nose vertex:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;face&#x2F;bfm-vertex.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Then we have the same participants, with different expressions:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;face&#x2F;shape_expression_matrix.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Overall we end up with 150 participants x 20 poses x 53490 vertices (3 reals). We can then use a PCA to reduce the dimensionality into 2 orthogonal spaces, one for the &lt;strong&gt;shape&lt;&#x2F;strong&gt; and the other for the &lt;strong&gt;expression&lt;&#x2F;strong&gt; of a face. Such that any face can be expressed as.&lt;&#x2F;p&gt;
&lt;p&gt;$$ M_{target\ face} = N_{neutral\ face} + \underbrace{S_{params} * S_{shape}}&lt;em&gt;{\text{Person identity}} + \underbrace{W&lt;&#x2F;em&gt;{params} * W_{expression}}_{\text{Smile or neutral expression}} $$&lt;&#x2F;p&gt;
&lt;p&gt;Actually we&#x27;re missing a global orientation of the face which can be represented as a rotation matrix and a scaling factor and an offset, which we will just express as a single matrix $ R $, and a vector $ p $.&lt;&#x2F;p&gt;
&lt;p&gt;$$ M_{target\ face} = R \times ( N_{neutral\ face} + S_{params} * S_{shape} + W_{params} * W_{expression}) + p $$&lt;&#x2F;p&gt;
&lt;p&gt;The 3DDFA model, will actually predict from a photo $ R $, $S_{params}$, $W_{params}$ and $p$. For reference, R is 9 floats, $S_{params}$ is 40 floats, $W_{params}$ is 10 floats, and $p$ is 3 floats. So the actual model of 3DDFA takes a 120x120 pixels image and returns a 62 vector that represents the face.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;face&#x2F;full-model.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The actual architecture of 3ddfa is actually just a simple mobile net.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;let-s-port-the-model-to-the-browser&quot;&gt;Let&#x27;s port the model to the browser.&lt;a class=&quot;zola-anchor&quot; href=&quot;#let-s-port-the-model-to-the-browser&quot; aria-label=&quot;Anchor link for: let-s-port-the-model-to-the-browser&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Ok, so let&#x27;s isolate the first few lines in &lt;code&gt;main.py&lt;&#x2F;code&gt; that load the model.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mobilenet_v1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; 1. load pre-tained model                                                    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;checkpoint_fp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;models&#x2F;phase1_wpdc_vdc.pth.tar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;                              &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;arch&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;mobilenet_1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;                                                          &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;                                                                              &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;checkpoint&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;checkpoint_fp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; map_location&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; storage&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; loc&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; storage&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;mobilenet_v1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; arch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;num_classes&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;62&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  #&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; 62 = 12(pose) + 40(shape) +10(expression)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;                                                                              &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;model_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; model&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;                                               &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; because the model is trained by multiple gpus, prefix module should be removed&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;for&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; checkpoint&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;keys&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;                                                   &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-meta z-indexed-name z-python&quot;&gt;    model_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-item-access z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;replace&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;module.&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-indexed-name z-python&quot;&gt; checkpoint&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-item-access z-python&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;                      &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;model_dict&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now let&#x27;s add a few lines to &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;pytorch.org&#x2F;docs&#x2F;stable&#x2F;onnx.html&quot;&gt;export the model to Onnx&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Batch size, C, H, W&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;zeros&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;onnx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;export&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;3ddfa.onnx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; verbose&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-python&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; input_names&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;input&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; output_names&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;params&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Ok good, now we have a &lt;code&gt;3ddfa.onnx&lt;&#x2F;code&gt; file model in our directory.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s try to run it in the browser by following &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;onnxjs&quot;&gt;OnnxJS&lt;&#x2F;a&gt; Getting Started and write a &lt;code&gt;index.html&lt;&#x2F;code&gt; file:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;html&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;html&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;head&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt; &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;head&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;body&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;    &amp;lt;!--&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Load ONNX.js &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;--&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;script&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; src&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;onnxjs&#x2F;dist&#x2F;onnx.min.js&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;script&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;    &amp;lt;!--&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Code that consume ONNX.js &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;--&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;script&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;      &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; create a session&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;      const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; myOnnxSession&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-new&quot;&gt; new&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; onnx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;InferenceSession&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;      &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; load the ONNX model file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;      function&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; getInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;          const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-new&quot;&gt; new&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; Float32Array&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;fill&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;          const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; tensorX&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-new&quot;&gt; new&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; onnx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;Tensor&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;float32&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 120&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;          return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;tensorX&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;      }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;      myOnnxSession&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;loadModel&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;.&#x2F;3ddfa.onnx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; generate model input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; inferenceInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; getInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; execute the model&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        myOnnxSession&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;inferenceInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;          &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; consume the output&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;          const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; outputTensor&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; output&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;next&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;value&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;          console&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;log&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;`&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;model output tensor: &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;${&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;outputTensor&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;`&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;      }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;script&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;  &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;body&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;html&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now let&#x27;s run a local server with &lt;code&gt;python -m http.server&lt;&#x2F;code&gt; and go to &lt;code&gt;http:&#x2F;&#x2F;localhost:8000&lt;&#x2F;code&gt; to see your console.
Woops ! We got an error : &lt;code&gt;Uncaught (in promise) TypeError: cannot resolve operator &#x27;Shape&#x27; with opsets: ai.onnx v9&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Actually onnx.js cannot infer dynamic shapes the same way PyTorch can. We can edit that by hardcoding
some values within a &lt;code&gt;Reshape&lt;&#x2F;code&gt; (which &lt;em&gt;is&lt;&#x2F;em&gt; supported).&lt;&#x2F;p&gt;
&lt;p&gt;In &lt;code&gt;mobilenet_v1.py&lt;&#x2F;code&gt;  line 144, edit &lt;code&gt;x = x.view(x.shape(0), -1)&lt;&#x2F;code&gt; into &lt;code&gt;x.view(1, 1024)&lt;&#x2F;code&gt;. Now re-export your onnx file.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s working ! (Well we have values.)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;putting-that-model-in-an-actual-demo-product&quot;&gt;Putting that model in an actual demo product.&lt;a class=&quot;zola-anchor&quot; href=&quot;#putting-that-model-in-an-actual-demo-product&quot; aria-label=&quot;Anchor link for: putting-that-model-in-an-actual-demo-product&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Ok so this is a bit more intensive work, so we&#x27;re not going to detail every part, but focus on the most important parts.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;get-the-webcam-data&quot;&gt;Get the webcam data&lt;a class=&quot;zola-anchor&quot; href=&quot;#get-the-webcam-data&quot; aria-label=&quot;Anchor link for: get-the-webcam-data&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;var&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; that&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt; this&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;navigator&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;mediaDevices&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;getUserMedia&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  navigator&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;mediaDevices&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;getUserMedia&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;video&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;facingMode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;user&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;function&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;stream&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;            that&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;video&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;srcObject&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; stream&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;            that&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;video&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;play&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;                    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; That draws the video on a canvas.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;                    that&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;facedetector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;loadModel&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;                    that&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;loop&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;            }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;catch&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;                alert&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Error launching webcam &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; e&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;            }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;catch&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;function&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;e&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;        alert&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;No webcam detected &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; e&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;get-the-3d-faces-from-the-image&quot;&gt;Get the 3d faces from the image&lt;a class=&quot;zola-anchor&quot; href=&quot;#get-the-3d-faces-from-the-image&quot; aria-label=&quot;Anchor link for: get-the-3d-faces-from-the-image&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;We&#x27;re using &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;justadudewhohacks&#x2F;face-api.js&quot;&gt;face detector&lt;&#x2F;a&gt; to get where the faces are on the current image, then run our model on each face in the image.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;var&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; ctx&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; outcanvas&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;getContext&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;2d&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; detections&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; await&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; faceapi&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;detectAllFaces&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;  incanvas&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-operator z-new&quot;&gt;  new&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; faceapi&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;TinyFaceDetectorOptions&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;var&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; vertices&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;for&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; detections&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;length&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  var&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; detection&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; detections&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; We get a 1x3x120x120 Tensor here.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; We could batch that in theory, but simplicity here.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; inferenceInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt; this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;getInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;incanvas&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; detection&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; outputData&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; await&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt; this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;session&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;run&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;inferenceInputs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; output&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; outputData&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;next&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;value&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; We need a reconstruction.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; face_vertices&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt; this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;reconstruct68&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Ellipsed code where we fuse various meshes to only run a single rotation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; and render process (we need to render to occlude the glasses in 3d with&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; a transparent mesh of the face.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;ctx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;drawImage&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;incanvas&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Drawing back the occluded glasses on the webcam canvas.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt;this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;drawGlasses&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt;this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;scene&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; outcanvas&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;reconstruct-the-vertices&quot;&gt;Reconstruct the vertices.&lt;a class=&quot;zola-anchor&quot; href=&quot;#reconstruct-the-vertices&quot; aria-label=&quot;Anchor link for: reconstruct-the-vertices&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;As it turns out the Rotation ($R$) + Offset ($p$) we&#x27;ve seen in the first part is not really what it seems, $R$ is just a 3x3 matrix, nothing forces it to be rotation (meaning determinant 1). As it turns out the model, changes the determinant of this matrix quite heavily throughout time. Using it as is within our demo, would mean that glasses would grow large, then small and get deformed all the time.&lt;&#x2F;p&gt;
&lt;p&gt;In order to fix this, we could fix the model of course, but it would require recreating a dataset, changing the loss functions and so on. But that&#x27;s at least a full week to run that, and nothing guarantees that it would work. It could still fail because the morphable model lacks expressability, or you can&#x27;t recreate the dataset because of some other issues and so on. That&#x27;s of course the best course of action for a full featured product. But it won&#x27;t ship fast.&lt;&#x2F;p&gt;
&lt;p&gt;A much easier way is to recover the real rotation, scale and offset by running a small gradient descent loop locally, we know they exist because a real face does &lt;em&gt;not&lt;&#x2F;em&gt; change scale across time, rotation and offset tend to get small changes frame to frame.&lt;&#x2F;p&gt;
&lt;p&gt;So what we&#x27;re going to do, is reconstruct 68 vertices from the faces from the model. (we need more that 3 to stabilise the solution, 53k is way overboard) and &lt;code&gt;solve&lt;&#x2F;code&gt; the equation $$ \text{face vertices} = R \times s \times \text{glass vertices} + p $$.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s 13 params (9 + 1 + 3) for 68 equations. Inverting that system is not very practical as far as I know in javasript, so we&#x27;re going to simply run a gradient descent. It should be faster than inversion on subsequent updates (when the solution is close to the previous solution).&lt;&#x2F;p&gt;
&lt;p&gt;The full &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Narsil&#x2F;face&#x2F;blob&#x2F;master&#x2F;src&#x2F;solver.ts&quot;&gt;code&lt;&#x2F;a&gt; is a bit scary looking (definitely not the way I would solve this now) but mostly amounts to manually working the gradient steps.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;add-glasses-on-that-model&quot;&gt;Add glasses on that model.&lt;a class=&quot;zola-anchor&quot; href=&quot;#add-glasses-on-that-model&quot; aria-label=&quot;Anchor link for: add-glasses-on-that-model&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;If we added the glasses mesh right away, we would have an occlusion problem where the back branch would show on top of your face. What we&#x27;re going to do is to have a grouped mesh of the glasses &lt;em&gt;and&lt;&#x2F;em&gt; a transparent face (we&#x27;ll use a mean normal face to keep computation low) so that the 3d rendering will occlude the back branch of the glasses.&lt;&#x2F;p&gt;
&lt;p&gt;Adding the general face:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;public&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; add_face&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;transparent&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;?&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; boolean&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;transparent&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-undefined z-js&quot;&gt; undefined&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;    transparent&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-boolean&quot;&gt; true&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt; this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt;    this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;scene&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;process&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;env&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant&quot;&gt;PUBLIC_URL&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;3dmodels&#x2F;face.fbx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;face&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;transparent&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;      const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; mesh&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; face&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;children&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; THREE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;Mesh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;      mesh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;renderOrder&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;      const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-js&quot;&gt; material&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mesh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;material&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; THREE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;Material&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;      &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Makes the face occluding, but we write the background&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;      &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; Color, so alpha instead of texture.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;      material&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-js&quot;&gt;colorWrite&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-boolean&quot;&gt; false&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;add&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;face&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;reset_clones&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Adding the glasses&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;public&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; addElement&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;element&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;: &lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;string&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-this&quot;&gt;  this&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;group&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;add_element&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;process&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;env&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant&quot;&gt;PUBLIC_URL&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; `&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;3dmodels&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;${&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;element&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;.fbx&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;`&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The whole pipeline is a bit complex to reuse meshes and run the thing efficiently (still pretty messy code) but that&#x27;s the gist, add the 2 meshes on the same scene, and hit render. Actually, we add all the faces and all the glasses to the same global scene and render only once.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;So we&#x27;ve seen how we put a model from a working paper code, into an actual product.
It necessary to remember to understand how the paper actually works vs pretends to work
is important, it was super important here to understand the $R$ and $p$ and $s$ factors into
our reconstruction. It also demonstrates that the paper&#x27;s authors didn&#x27;t realize that what they thought
was a pose actually contains &lt;em&gt;a lot&lt;&#x2F;em&gt; of distortion, so it does not work how they expected.&lt;&#x2F;p&gt;
&lt;p&gt;It also shows that putting ML in a product even for a very simple demo requires understanding
many other technologies. Here it meant getting the webcam feed, getting Onnx layers simplfied, understanding &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;threejs.org&#x2F;&quot;&gt;Three.js&lt;&#x2F;a&gt; to master occlusion, etc... But by going full browser you can put your demo out and never worry about the cost !&lt;&#x2F;p&gt;
&lt;p&gt;Check out the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Narsil&#x2F;face&quot;&gt;Full source code&lt;&#x2F;a&gt; for all the quirks.&lt;&#x2F;p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Creating a translation app</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2020-07-27T00:00:00+00:00</published>
		<updated>2020-07-27T00:00:00+00:00</updated>
		<link href="https://nodata.dev/ml/nlp/react/2020/07/27/creating-a-translation-app/"/>
		<link rel="alternate" href="https://nodata.dev/ml/nlp/react/2020/07/27/creating-a-translation-app/" type="text/html"/>
		<id>https://nodata.dev/ml/nlp/react/2020/07/27/creating-a-translation-app/</id>
		<content type="html">&lt;blockquote&gt;
&lt;p&gt;TL;DR Recently moved to the Netherlands, in order to avoid Googling translate everything, I did the next best thing to learning the language: I created a clone of translate.google.com&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;find-a-correct-training-loop&quot;&gt;Find a correct training loop&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-a-correct-training-loop&quot; aria-label=&quot;Anchor link for: find-a-correct-training-loop&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;My first instinct was to check &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;huggingface&#x2F;transformers&quot;&gt;Hugging Face&lt;&#x2F;a&gt; as this repo contains solid implementations that I know are easy to change. However, in that particular instance, the example for translation does not start from scratch, and I wanted to check what multilingual translation could do here, as I&#x27;m using English, Dutch &amp;amp; French on translate.google.com (For food sometimes french is much better than english for me).&lt;&#x2F;p&gt;
&lt;p&gt;My second guess was &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;facebookresearch&#x2F;fairseq&quot;&gt;Fairseq&lt;&#x2F;a&gt; from facebook. In their example there is an actual example for multilingual German, French, English. Close enough for my needs. First things first, start to follow the example by the book. Most implementations out there are broken and won&#x27;t work out of the box.&lt;&#x2F;p&gt;
&lt;p&gt;This time, it turned out particularly smooth. Clone the repo then follow the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;facebookresearch&#x2F;fairseq&#x2F;tree&#x2F;main&#x2F;examples&#x2F;translation#multilingual-translation&quot;&gt;instructions&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# First install sacrebleu and sentencepiece&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pip install sacrebleu sentencepiece&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Then download and preprocess the data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd examples&#x2F;translation&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bash prepare-iwslt17-multilingual.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd ..&#x2F;..&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Binarize the de-en dataset&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TEXT=examples&#x2F;translation&#x2F;iwslt17.de_fr.en.bpe16k&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fairseq-preprocess --source-lang de --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --trainpref $TEXT&#x2F;train.bpe.de-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --validpref $TEXT&#x2F;valid0.bpe.de-en,$TEXT&#x2F;valid1.bpe.de-en,$TEXT&#x2F;valid2.bpe.de-en,$TEXT&#x2F;valid3.bpe.de-en,$TEXT&#x2F;valid4.bpe.de-en,$TEXT&#x2F;valid5.bpe.de-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --destdir data-bin&#x2F;iwslt17.de_fr.en.bpe16k \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --workers 10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Binarize the fr-en dataset&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# NOTE: it&amp;#39;s important to reuse the en dictionary from the previous step&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fairseq-preprocess --source-lang fr --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --trainpref $TEXT&#x2F;train.bpe.fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --validpref $TEXT&#x2F;valid0.bpe.fr-en,$TEXT&#x2F;valid1.bpe.fr-en,$TEXT&#x2F;valid2.bpe.fr-en,$TEXT&#x2F;valid3.bpe.fr-en,$TEXT&#x2F;valid4.bpe.fr-en,$TEXT&#x2F;valid5.bpe.fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --tgtdict data-bin&#x2F;iwslt17.de_fr.en.bpe16k&#x2F;dict.en.txt \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --destdir data-bin&#x2F;iwslt17.de_fr.en.bpe16k \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --workers 10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Train a multilingual transformer model&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# NOTE: the command below assumes 1 GPU, but accumulates gradients from&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#       8 fwd&#x2F;bwd passes to simulate training on 8 GPUs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mkdir -p checkpoints&#x2F;multilingual_transformer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;CUDA_VISIBLE_DEVICES=0 fairseq-train data-bin&#x2F;iwslt17.de_fr.en.bpe16k&#x2F; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --max-epoch 50 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --ddp-backend=no_c10d \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --task multilingual_translation --lang-pairs de-en,fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --arch multilingual_transformer_iwslt_de_en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --share-decoders --share-decoder-input-output-embed \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --optimizer adam --adam-betas &amp;#39;(0.9, 0.98)&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --lr 0.0005 --lr-scheduler inverse_sqrt --min-lr &amp;#39;1e-09&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --warmup-updates 4000 --warmup-init-lr &amp;#39;1e-07&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --label-smoothing 0.1 --criterion label_smoothed_cross_entropy \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --dropout 0.3 --weight-decay 0.0001 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --save-dir checkpoints&#x2F;multilingual_transformer \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --max-tokens 4000 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --update-freq 8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Generate and score the test set with sacrebleu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SRC=de&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sacrebleu --test-set iwslt17 --language-pair ${SRC}-en --echo src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    | python scripts&#x2F;spm_encode.py --model examples&#x2F;translation&#x2F;iwslt17.de_fr.en.bpe16k&#x2F;sentencepiece.bpe.model \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;gt; iwslt17.test.${SRC}-en.${SRC}.bpe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cat iwslt17.test.${SRC}-en.${SRC}.bpe \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    | fairseq-interactive data-bin&#x2F;iwslt17.de_fr.en.bpe16k&#x2F; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --task multilingual_translation --lang-pairs de-en,fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --source-lang ${SRC} --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --path checkpoints&#x2F;multilingual_transformer&#x2F;checkpoint_best.pt \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --buffer-size 2000 --batch-size 128 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --beam 5 --remove-bpe=sentencepiece \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;gt; iwslt17.test.${SRC}-en.en.sys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;the-data&quot;&gt;The data&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-data&quot; aria-label=&quot;Anchor link for: the-data&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;While it&#x27;s training, let&#x27;s look at where I can get Dutch data. The IWSLT 2017 did not seem to have Dutch data &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;mt.php?release=2017-01-trnted&quot;&gt;at first glance&lt;&#x2F;a&gt; or &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;mt.php?release=2017-01-trnmted&quot;&gt;here&lt;&#x2F;a&gt;. I also tried just mimicking the adress from facebook &lt;code&gt;prepare-iwslt17-multilingual.sh&lt;&#x2F;code&gt; (The address &lt;code&gt;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;archive&#x2F;2017-01-trnted&#x2F;texts&#x2F;de&#x2F;en&#x2F;de-en.tgz&lt;&#x2F;code&gt; so I simply tried if &lt;code&gt;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;archive&#x2F;2017-01-trnted&#x2F;texts&#x2F;nl&#x2F;en&#x2F;nl-en.tgz&lt;&#x2F;code&gt;). Turns out there aren&#x27;t.
&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.statmt.org&#x2F;europarl&#x2F;&quot;&gt;Europarl&lt;&#x2F;a&gt; seemed like a good bet but looking at the data, the langage seems pretty formatted and not very dialogue like. That might explain why it does not seem to be used that often.
Looking back at IWSLT 2017 finally found the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;mt.php?release=2017-01-mted-test&quot;&gt;Dutch data&lt;&#x2F;a&gt; and the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;wit3.fbk.eu&#x2F;mt.php?release=2017-01-trnmted&quot;&gt;training data&lt;&#x2F;a&gt;. Is it me, or are competitions websites really hard to read ?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-actual-training-loop&quot;&gt;The actual training loop&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-actual-training-loop&quot; aria-label=&quot;Anchor link for: the-actual-training-loop&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Ok so let&#x27;s reuse the training loop from the german file, so we just need to copy the dutch files in the same layout as the german ones, edit all the scripts and command lines to edit everything. I had to multiply the test files, someone Facebook has tst2011, tst2012 tst2013, tst2014, tst2015 for the german data, which does not seem to exist on the competition website... So here instead of trying to figure out where the information was, I simply copy-pasted the tst2010 file into dummy versions for tst2011...tst2015 (oh yeah simply omitting them will make bash scripts fail because file alignement is a requirement !, and I don&#x27;t want to spend more than 5mn editing a bash script).&lt;&#x2F;p&gt;
&lt;p&gt;Now with our edited bash script:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd examples&#x2F;translation&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bash prepare-iwslt17-multilingual_nl.sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd ..&#x2F;..&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Preprocess dutch data:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TEXT=examples&#x2F;translation&#x2F;iwslt17.nl.en.bpe16k&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fairseq-preprocess --source-lang nl --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --trainpref $TEXT&#x2F;train.bpe.nl-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --validpref $TEXT&#x2F;valid0.bpe.nl-en,$TEXT&#x2F;valid1.bpe.nl-en,$TEXT&#x2F;valid2.bpe.nl-en,$TEXT&#x2F;valid3.bpe.nl-en,$TEXT&#x2F;valid4.bpe.nl-en,$TEXT&#x2F;valid5.bpe.nl-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --destdir data-bin&#x2F;iwslt17.nl_fr.en.bpe16k \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --workers 10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now let&#x27;s preprocess french data&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# NOTE: it&amp;#39;s important to reuse the en dictionary from the previous step&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fairseq-preprocess --source-lang fr --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --trainpref $TEXT&#x2F;train.bpe.fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --validpref $TEXT&#x2F;valid0.bpe.fr-en,$TEXT&#x2F;valid1.bpe.fr-en,$TEXT&#x2F;valid2.bpe.fr-en,$TEXT&#x2F;valid3.bpe.fr-en,$TEXT&#x2F;valid4.bpe.fr-en,$TEXT&#x2F;valid5.bpe.fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --tgtdict data-bin&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F;dict.en.txt \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --destdir data-bin&#x2F;iwslt17.nl_fr.en.bpe16k \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --workers 10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Overall, pretty simple task, just a bit bothering to hit all the various walls.&lt;&#x2F;p&gt;
&lt;p&gt;Now that we preformatted the dutch data, we can run the training loop on our own data !&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mkdir -p checkpoints&#x2F;multilingual_transformer_nl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;CUDA_VISIBLE_DEVICES=0 fairseq-train data-bin&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --max-epoch 50 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --ddp-backend=no_c10d \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --task multilingual_translation --lang-pairs nl-en,fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    # Don&amp;#39;t change the arch !\&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --arch multilingual_transformer_iwslt_de_en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --share-decoders --share-decoder-input-output-embed \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --optimizer adam --adam-betas &amp;#39;(0.9, 0.98)&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --lr 0.0005 --lr-scheduler inverse_sqrt --min-lr &amp;#39;1e-09&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --warmup-updates 4000 --warmup-init-lr &amp;#39;1e-07&amp;#39; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --label-smoothing 0.1 --criterion label_smoothed_cross_entropy \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --dropout 0.3 --weight-decay 0.0001 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    # Change the checkpoint \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --save-dir checkpoints&#x2F;multilingual_transformer_nl \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --max-tokens 4000 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    --update-freq 8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;checking-the-final-result&quot;&gt;Checking the final result&lt;a class=&quot;zola-anchor&quot; href=&quot;#checking-the-final-result&quot; aria-label=&quot;Anchor link for: checking-the-final-result&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;So now we have a model &lt;code&gt;checkpoints&#x2F;multilingual_transformer_nl&#x2F;checkpoint_best.pt&lt;&#x2F;code&gt;, let&#x27;s run it !&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Generate and score the test set with sacrebleu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SRC=nl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sacrebleu --test-set iwslt17 --language-pair ${SRC}-en --echo src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    | python scripts&#x2F;spm_encode.py --model examples&#x2F;translation&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F;sentencepiece.bpe.model \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;gt; iwslt17.test.${SRC}-en.${SRC}.bpe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cat iwslt17.test.${SRC}-en.${SRC}.bpe \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    | fairseq-interactive data-bin&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --task multilingual_translation --lang-pairs de-en,fr-en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --source-lang ${SRC} --target-lang en \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --path checkpoints&#x2F;multilingual_transformer_nl&#x2F;checkpoint_best.pt \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --buffer-size 2000 --batch-size 128 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      --beam 5 --remove-bpe=sentencepiece \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;gt; iwslt17.test.${SRC}-en.en.sys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But woops...&lt;code&gt;sacreBLEU: No such language pair &quot;nl-en&quot; sacreBLEU: Available language pairs for test set &quot;iwslt17&quot;: en-fr, fr-en, en-de, de-en, en-zh, zh-en, en-ar, ar-en, en-ja, ja-en, en-ko, ko-en&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So it looks like we&#x27;re going to need to pipe some of our own data into this pipeline, we can just use the validation set we used to train&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cat examples&#x2F;translation&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F;valid0.bpe.nl-en.nl |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;python scripts&#x2F;spm_encode.py --model examples&#x2F;translation&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F;sentencepiece.bpe.model \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;gt; iwslt17.test.${SRC}-en.${SRC}.bpe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There we go we have encoded with our multilingual BPE tokenizer our valid dataset. We can now run our translating command&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cat iwslt17.test.${SRC}-en.${SRC}.bpe     | fairseq-interactive data-bin&#x2F;iwslt17.nl_fr.en.bpe16k&#x2F;       --task multilingual_translation --lang-pairs nl-en,fr-en       --source-lang ${SRC} --target-lang en       --path checkpoints&#x2F;multilingual_transformer_nl&#x2F;checkpoint_best.pt       --buffer-size 2000 --batch-size 128       --beam 5 --remove-bpe=sentencepiece&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here are some outputs (not cherry picked):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;S&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;999&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;   Iedereen&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; heeft&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; een&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; vissenkom&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; nodig&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;H&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;999&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0272072553634644&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;     Everybody&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; needs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; a&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; fishing&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; ticket&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;D&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;999&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0272072553634644&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;     Everybody&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; needs&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; a&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; fishing&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; ticket&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;P&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;999&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;5687&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2169&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2363&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0637&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;6527&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2981&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1540&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;S&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;998&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;   Het&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; leidt&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; tot&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; meer&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; verlamming&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; en&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; minder&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; tevredenheid&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;H&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;998&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;32848915457725525&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;    It&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; leads&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; to&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; more&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; paralysis&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; less&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; satisfaction&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;D&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;998&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;32848915457725525&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;    It&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; leads&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; to&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; more&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; paralysis&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; and&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; less&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; satisfaction&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;P&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;998&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;9783&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3836&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1854&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;8328&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1779&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0163&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3334&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;3619&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2152&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0450&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;2831&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1289&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;S&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;987&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;   Ze&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; maken&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; ons&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; leven&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; minder&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; waard&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;H&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;987&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;5473383665084839&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;     They&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; make&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; our&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; lives&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; worth&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; less&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;D&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;987&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;   -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;5473383665084839&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;     They&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; make&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; our&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; lives&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; worth&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; less&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Seems good enough for now.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;productizing&quot;&gt;Productizing&lt;a class=&quot;zola-anchor&quot; href=&quot;#productizing&quot; aria-label=&quot;Anchor link for: productizing&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;flask-server&quot;&gt;Flask server&lt;a class=&quot;zola-anchor&quot; href=&quot;#flask-server&quot; aria-label=&quot;Anchor link for: flask-server&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Ok, in order to productionize, initially I wanted to move away from fairseq, but a lot of logic is actually tied to fairseq-interative (beam search, loading all the args, ensembling the model, source language selection and so on). It&#x27;s definitely possible to move out of it, but it felt like a few days job, so much more than I was willing to invest in this particular approach.&lt;&#x2F;p&gt;
&lt;p&gt;So the idea is to have a flask server sitting in front of the model, call the appropriate encoding with spm_encode, pass it to fairseq interactive, and output the D-XXX line back to the caller.&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;re going to containerize it and deploy to Kubernetes (it just happens I have a kubernetes cluster running, so less problems with deploying on it). I considered using ONNX-js (or TFlite) to deploy directly on the browser which saves a lot of headaches on deployment and keeping the service running in the long run (Like I did for the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;narsil.github.io&#x2F;assets&#x2F;face&#x2F;&quot;&gt;glasses&lt;&#x2F;a&gt; project). Here the main problem is the size of the model (600Mo). I could go back and try to optimize but that&#x27;s a pretty big model, it&#x27;s going to be hard to make it come to a comfortable level for browser-only mode (Again just too much work for what I have in mind here).&lt;&#x2F;p&gt;
&lt;p&gt;So let&#x27;s get started from the Flask&#x27;s &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;flask.palletsprojects.com&#x2F;en&#x2F;1.1.x&#x2F;quickstart&#x2F;&quot;&gt;hello world&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python&quot;&gt;@&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; hello_world&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Hello, World!&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s edit it a bit to include our translate function.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; Flask&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable z-magic z-python&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; translate&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;    #&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; TODO&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; later&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;This is a translation !&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-decorator z-python&quot;&gt;@&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-decorator z-python&quot;&gt;route&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; methods&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;POST&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; hello&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    text&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; request&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-indexed-name z-python&quot;&gt;form&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;input&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-string z-python&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;IN &lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-format z-placeholder z-other z-python&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-format z-placeholder z-other z-python&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    output&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; translate&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-function z-builtin z-python&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-string z-python&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;OUT &lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-format z-placeholder z-other z-python&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-format z-placeholder z-other z-python&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; json&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;dumps&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;en&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; output&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can run our example and check it&#x27;s running with curl&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ curl -d input=&amp;quot;Ik heft een appel.&amp;quot; http:&#x2F;&#x2F;localhost:5000&#x2F;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&amp;quot;en&amp;quot;: &amp;quot;This is a translation !&amp;quot;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;implementing-the-translate-function&quot;&gt;Implementing the translate function.&lt;a class=&quot;zola-anchor&quot; href=&quot;#implementing-the-translate-function&quot; aria-label=&quot;Anchor link for: implementing-the-translate-function&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Ok this is where we are super tied to fairseq-interactive code, I had to dig into the source code, copy most of it, and mainly split &lt;code&gt;Model loading&lt;&#x2F;code&gt; code from &lt;code&gt;Model running&lt;&#x2F;code&gt; code. For that I used a lot of globals as the original code does not separate these two concerns (tidying this will be a later goal if it every comes to that).&lt;&#x2F;p&gt;
&lt;p&gt;The final implementation is quite verbose but available &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Narsil&#x2F;translate&#x2F;blob&#x2F;master&#x2F;server&#x2F;translate.py&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;One good point about this implementation is that we load the model early, so that it&#x27;s available right away when the server comes up (but it does take some time to come up).
A negative point, is that because it&#x27;s loaded eagerly it&#x27;s going to make forking a nightmare and basically preventing us from using wsgi efficiently which is the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;flask.palletsprojects.com&#x2F;en&#x2F;1.1.x&#x2F;deploying&#x2F;&quot;&gt;recommended way of deploying Flask&lt;&#x2F;a&gt;. It&#x27;s fine for now, it&#x27;s a personnal project after all, to get more stable deployment I would try to remove python from the equation of the web part if possible, it&#x27;s really slow and hard to work with on webservers because of the forking&#x2F;threading nightmare in Python.&lt;&#x2F;p&gt;
&lt;p&gt;So know our backend can really translate !&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ curl -d input=&amp;quot;Ik heft een appel.&amp;quot; http:&#x2F;&#x2F;localhost:5000&#x2F;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&amp;quot;en&amp;quot;: &amp;quot;I have an apple.&amp;quot;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Before moving that to the cloud, let&#x27;s build a nice interface in front of it&lt;&#x2F;p&gt;
&lt;h3 id=&quot;react-front&quot;&gt;React front&lt;a class=&quot;zola-anchor&quot; href=&quot;#react-front&quot; aria-label=&quot;Anchor link for: react-front&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Ok so we&#x27;re going to use React with Typescript. React because we&#x27;re going JS anyway to get the translation without clicking a button with a form like html. It&#x27;s also more convenient to use Material-UI which I find helps make a website nice from scratch (and I&#x27;m tired of Bootstrap). Typescript because it&#x27;s just saner than VanillaJS (it won&#x27;t make much of a difference here).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;yarn create react-app app --template typescript&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;yarn add @material-ui&#x2F;core&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s edit our App.tsx to use Material-UI and get the initial layout looking like &lt;a href=&quot;https:&#x2F;&#x2F;nodata.dev&#x2F;ml&#x2F;nlp&#x2F;react&#x2F;2020&#x2F;07&#x2F;27&#x2F;creating-a-translation-app&#x2F;translate.google.com&quot;&gt;translate.google.com&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;tsx&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; React&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; from&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;react&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;makeStyles&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; from&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;@material-ui&#x2F;core&#x2F;styles&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; TextField&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; from&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;@material-ui&#x2F;core&#x2F;TextField&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; Card&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; from&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;@material-ui&#x2F;core&#x2F;Card&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; from&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;@material-ui&#x2F;core&#x2F;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant&quot;&gt; useStyles&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; makeStyles&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;theme&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    display&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;flex&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    justifyContent&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;center&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    alignItems&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;center&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    height&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;100vh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;function&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; App&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant&quot;&gt; classes&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; useStyles&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;  return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;div&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; className&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;classes&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;app&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;      &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Card&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;        &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;form&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;          &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; container&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;            &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; item&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; xs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;6&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;              &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;TextField&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt;                id&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;standard-basic&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt;                label&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;Dutch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt;                multiline&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt;                autoFocus&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;              &#x2F;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;            &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;            &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; item&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; xs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; md&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;6&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;              &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;TextField&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; id&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;standard-basic&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; label&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;English&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-attribute-name&quot;&gt; multiline&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt; &#x2F;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;            &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;          &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Grid&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;        &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;form&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;      &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-class z-component z-tsx&quot;&gt;Card&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;    &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag&quot;&gt;div&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-tag&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  )&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;export&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; default&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; App&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here is the result : &lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;ZszCVQU.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let&#x27;s look at the logic (simplified):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;typescript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; Timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; ReturnType&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-typeparameters&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-expression z-typeof z-ts&quot;&gt;typeof&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; setTimeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-typeparameters&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; setText&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; useState&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt;time&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; setTime&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; useState&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-typeparameters&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt;Timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; |&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-builtin z-ts&quot;&gt; null&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-typeparameters&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-null z-ts&quot;&gt;null&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; url&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;http:&#x2F;&#x2F;localhost:5000&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;const&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; translate&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-type z-primitive&quot;&gt; string&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-function z-arrow z-ts&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    setText&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; form&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-new&quot;&gt; new&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; FormData&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;  form&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;append&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;input&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; text&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;  fetch&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;url&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    method&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;POST&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    body&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt; form&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;response&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-function z-arrow z-ts&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;    response&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;then&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-function z-arrow z-ts&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;      console&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;log&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;      setText&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;json&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;en&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;  }&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then call it on the &lt;code&gt;onChange&lt;&#x2F;code&gt; attribute of our Dutch field.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;typescript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;onChange&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt;event&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-function z-arrow z-ts&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; We use a timeout handler to prevent very fast keystrokes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; from spamming our server.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;time&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; !==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-language z-null z-ts&quot;&gt; null&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;        clearTimeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;time&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; text&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; event&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-property z-ts&quot;&gt;value&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    const&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-constant z-ts&quot;&gt; timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; setTimeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-function z-arrow z-ts&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;        translate&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;text&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    }&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 500&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;    setTime&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other z-readwrite&quot;&gt;timeout&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There we have it:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;EYZ0EWR.gif&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;let-s-dockerize&quot;&gt;Let&#x27;s dockerize !&lt;a class=&quot;zola-anchor&quot; href=&quot;#let-s-dockerize&quot; aria-label=&quot;Anchor link for: let-s-dockerize&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;As I mentionned loading the whole model in the flask app is going to hinder a lot the wsgi process forking. I did try it, try to come up with easy fixes, but ultimately found that keeping the development server was just easier.&lt;&#x2F;p&gt;
&lt;p&gt;Ok so we&#x27;re going to need a python docker image, install pytorch, fairseq, and flask to our image (actually we need flask_cors too to make sure we can call from any website as it&#x27;s an API.)&lt;&#x2F;p&gt;
&lt;p&gt;As it turns out, fairseq 0.9 had a bug in the training loop and I was using master from a few month ago, and I needed to work with that specific version since there had been breaking changes since in master. That gives us the following &lt;code&gt;requirements.txt&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;torch&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;flask&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;flask_cors&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-e git:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;fairseq.git@7a6519f84fed06947bbf161c7b66c9099bc4ce53#egg=fairseq&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sentencepiece&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now our Docker file, is going to get the python dependencies, copy all the local files (including model and tokenizer file) and run the flask server. That gives us :&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; python:3.7-slim&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; pip install -U pip&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; apt-get update &amp;amp;&amp;amp; apt-get install -y git build-essential # Required for building fairseq from source.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; server&#x2F;requirements.txt &#x2F;app&#x2F;requirements.txt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; pip install -r &#x2F;app&#x2F;requirements.txt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; . &#x2F;app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; &#x2F;app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;CMD&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;python&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;, &lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;translate.py&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s build and check that it works:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker build -t translate:latest .&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker run -p 5000:5000 translate:latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Now check with curl that we can still hit the docker and get a correct answer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;curl -d input=&amp;quot;Ik heft een appel.&amp;quot; http:&#x2F;&#x2F;localhost:5000&#x2F;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# {&amp;quot;en&amp;quot;: &amp;quot;This is a translation !&amp;quot;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;kubernetes-cluster&quot;&gt;Kubernetes cluster&lt;a class=&quot;zola-anchor&quot; href=&quot;#kubernetes-cluster&quot; aria-label=&quot;Anchor link for: kubernetes-cluster&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Okay the following part will be pretty specific to my setup. I use a kubernetes cluster on GCP with ingress. I&#x27;m going to skip updating the SSL certificate.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s start with pushing the image to GCP:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker tag translate:latest gcr.io&#x2F;myproject-XXXXXX&#x2F;translate:1.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker push gcr.io&#x2F;myproject-XXXXXX&#x2F;translate:1.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kubectl apply -f deployment.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kubectl apply -f service.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kubectl apply -f ingress.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here are the (edited for brevity&amp;amp;security) service files I used:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt;deployment.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;piVersion&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; a&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;pps&#x2F;v1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ind&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; D&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;eployment&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;etadata&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  n&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ame&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate-deployment&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pec&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;eplicas&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;elector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    m&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;atchLabels&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  t&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;emplate&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    m&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;etadata&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      l&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;abels&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;        a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pec&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      c&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ontainers&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        -&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt; n&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ame&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;          i&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;mage&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; g&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;cr.io&#x2F;myproject-XXXXX&#x2F;translate:1.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;          p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;orts&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;            -&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt; c&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ontainerPort&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 5000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; service.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;piVersion&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; v&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ind&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; S&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ervice&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;etadata&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  n&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ame&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate-service&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pec&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  t&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ype&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; N&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;odePort&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;elector&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;orts&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    -&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt; p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;rotocol&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; T&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;CP&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ort&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 80&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      t&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;argetPort&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 5000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt;ingress.yaml&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;piVersion&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;etworking.k8s.io&#x2F;v1beta1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;k&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ind&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; I&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ngress&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;etadata&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  n&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ame&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ngress-front&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  a&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;nnotations&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    k&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ubernetes.io&#x2F;ingress.global-static-ip-name&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; a&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ddress-cluster&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;    n&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;etworking.gke.io&#x2F;managed-certificates&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; o&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ttomate-certificate-new&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;pec&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;  r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ules&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;    -&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt; h&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ost&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate.ottomate.app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;      h&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ttp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;        p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;aths&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;          -&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt; p&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ath&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;            b&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ackend&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;              s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;erviceName&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;ranslate-service&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;              s&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-tag z-yaml&quot;&gt;ervicePort&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-key-value&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 80&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Hopefully within a few minutes you have your pod running and you can hit your live own server with the API.&lt;&#x2F;p&gt;
&lt;p&gt;You just need to update your react App to point the the correct URL and boom your done, your very own translate server app.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-could-should-be-done-next&quot;&gt;What could&#x2F;should be done next.&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-could-should-be-done-next&quot; aria-label=&quot;Anchor link for: what-could-should-be-done-next&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;for-the-model&quot;&gt;For the model:&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-the-model&quot; aria-label=&quot;Anchor link for: for-the-model&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Add more data to the original training set, some words are missing, translation can become funky on some real world sentences I give the machine (Dutch companies tend to send very verbose emails)&lt;&#x2F;li&gt;
&lt;li&gt;Add some data augmentation in the pool as the current translation is very brittle to errors. Using Sentence piece algorihm with sampling instead of BPE could be used, some typo generator, word inversions to name a few. Training some error detection algorithm on top or using ready made ones could help (translate.google.com has some spellfixing magic applied before it seems.)&lt;&#x2F;li&gt;
&lt;li&gt;Making it smaller to make it portable to tflite, mobile phone for offline mode and so on (it&#x27;s a pretty big workload to make it work though)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;for-the-backend&quot;&gt;For the backend:&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-the-backend&quot; aria-label=&quot;Anchor link for: for-the-backend&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Battle testing the backend should be the first thing to do to check failure modes and fix naive DOS attacks.&lt;&#x2F;li&gt;
&lt;li&gt;Something like &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;serve&quot;&gt;TorchServe&lt;&#x2F;a&gt; seems like what we want for the model part. Never used it so far, but it seems to solve some problems encountered here and would make iterations faster on various models (also swapping out models).&lt;&#x2F;li&gt;
&lt;li&gt;On the other spectrum I could go for tighter control. Removing the fairseq-interative clutter would be my first move. If I can go pytorch barebones, then using Rust, with Hugging Face&#x27;s &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;huggingface&#x2F;tokenizers&quot;&gt;tokenizers&lt;&#x2F;a&gt; library would probably make inference faster and deployment easier. It would of course make iteration much slower so I would do that only when the model is very stable. It could make mobile offline possible (with a very large app data, ~1Go, but doable.)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;for-the-frontend&quot;&gt;For the frontend:&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-the-frontend&quot; aria-label=&quot;Anchor link for: for-the-frontend&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;Working a bit more on the mobile part of the design which is a bit broken at the moment.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe add buttons to switch languages easily, switch language sides (although I mostly use Dutch-&amp;gt;English and Dutch-&amp;gt;French)&lt;&#x2F;li&gt;
&lt;li&gt;Add a react-native app so that I can translate from my phone. (Without offline mode)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Super simple estimation of available solar energy</title>
		<published>2020-03-19T00:00:00+00:00</published>
		<updated>2020-03-19T00:00:00+00:00</updated>
		<link href="https://nodata.dev/energy/2020/03/19/solar-energy/"/>
		<link rel="alternate" href="https://nodata.dev/energy/2020/03/19/solar-energy/" type="text/html"/>
		<id>https://nodata.dev/energy/2020/03/19/solar-energy/</id>
		<content type="html">&lt;!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: _notebooks&#x2F;2020-03-19-solar-energy.ipynb
--&gt;
&lt;div class=&quot;container&quot; id=&quot;notebook-container&quot;&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h1 id=&quot;Solar-energy&quot;&gt;Solar energy&lt;a class=&quot;anchor-link&quot; href=&quot;#Solar-energy&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;&lt;h2 id=&quot;Stefan-boltzmann&#x27;s-law&quot;&gt;Stefan boltzmann&#x27;s law&lt;a class=&quot;anchor-link&quot; href=&quot;#Stefan-boltzmann&#x27;s-law&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;$ \text{Surface energy} = \sigma T^4$&lt;&#x2F;p&gt;
&lt;p&gt;For the sun, $T = \text{5,778 }K$&lt;&#x2F;p&gt;
&lt;p&gt;$\sigma = 5.67 \times 10 ^{-8} W.m^{-2}.K^{-4}$&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;sympy.physics.units&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;K&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;giga&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;sigma&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;5.67&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;K&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;T&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;5778&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;K&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;surface_energy&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;sigma&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;surface_energy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;63196526.5460292*watt&#x2F;meter**2
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Total-emitted-solar-energy&quot;&gt;Total emitted solar energy&lt;a class=&quot;anchor-link&quot; href=&quot;#Total-emitted-solar-energy&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;$ Radiation = \text{Surface of the sun} \times \text{Surface energy} $&lt;&#x2F;p&gt;
&lt;p&gt;$ Radiation = 4 \pi r^2 \times \text{Surface energy} $&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;sympy&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;r_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;696_340&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;surface_of_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;r_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt; 
&lt;span class=&quot;n&quot;&gt;radiation&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;surface_of_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;surface_energy&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;radiation&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;1.22573302243694e+26*pi*watt
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Energy-received-at-earth-average-distance&quot;&gt;Energy received at earth average distance&lt;a class=&quot;anchor-link&quot; href=&quot;#Energy-received-at-earth-average-distance&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;$ \text{Radiation received} = \frac{\text{Total sun radiation}}{ \text{sphere at earth&#x27;s distance}}$&lt;&#x2F;p&gt;
&lt;p&gt;$ \text{Radiation received} = \frac{Radiation}{ 4 \pi D_{earth-sun}^2} $&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;R_earth&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;6_371&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;D_earth_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;148.88&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;earth_perp_surface&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;R_earth&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;sphere&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;D_earth_sun&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;radiation_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;radiation&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;sphere&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;radiation_received&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;1382.49374484614*watt&#x2F;meter**2
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Energy-received-by-the-earth-surface-(before-atmosphere)&quot;&gt;Energy received by the earth surface (before atmosphere)&lt;a class=&quot;anchor-link&quot; href=&quot;#Energy-received-by-the-earth-surface-(before-atmosphere)&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;$ \text{Energy received} = \text{radiation received} \times \frac{ \text{visible surface}}{ \text{earth&#x27;s surface}} $&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;radiation_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;R_earth&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;surface_power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;R_earth&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;surface_power_received&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;power_received&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;345.623436211536*watt&#x2F;meter**2
1.76290235470883e+17*watt
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;blockquote&gt;&lt;p&gt;RADIATION RECEIVED BY SYSTEM EARTH  = $345 W.m^{-2}$&lt;&#x2F;p&gt;
&lt;p&gt;MAXIMUM POWER WITH EARTH &quot;DYSON SPHERE&quot;: $176 PW$&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h1 id=&quot;Human-consumption&quot;&gt;Human consumption&lt;a class=&quot;anchor-link&quot; href=&quot;#Human-consumption&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;&lt;p&gt;13 511 MTep &lt;a href=&quot;https:&#x2F;&#x2F;www.iea.org&#x2F;data-and-statistics?country=WORLD&amp;amp;fuel=Energy%20supply&amp;amp;indicator=Total%20primary%20energy%20supply%20%28TPES%29%20by%20source&quot;&gt;Source International Energy agency&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;sympy.physics.units&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;J&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;sympy.physics.units.util&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;convert_to&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;million&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;kilo&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;giga&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;toe&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;41.868&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;giga&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;J&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;ktoe&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kilo&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;toe&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;Mtoe&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;million&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;toe&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;hour&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;year&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;24&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;365.25&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;base&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;3852538&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2949909&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;670298&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;335519&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;204190&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1286064&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4329220&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;Humanity_total_annual_consumption&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ktoe&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;humanity_power_consumption&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Humanity_total_annual_consumption&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;year&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;convert_to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;humanity_power_consumption&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;W&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;18080149776408.9*watt
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;convert_to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;humanity_power_consumption&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;J&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;0.0102558997258785
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;We are currently consuming &lt;strong&gt;0.01% of the maximum capacity of the earth covered by a Dyson sphere of solar panels&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;A-bit-more-realistic-approach&quot;&gt;A bit more realistic approach&lt;a class=&quot;anchor-link&quot; href=&quot;#A-bit-more-realistic-approach&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;After the atmosphere only $168 W.m^{-2}$ hit the surface. It&#x27;s quite complicated to infer it depends on the wavelength of the incoming light, clouds, composition of the atmosphere and so on, so we just take the value from &lt;a href=&quot;https:&#x2F;&#x2F;fr.wikipedia.org&#x2F;wiki&#x2F;Bilan_radiatif_de_la_Terre&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Then we only have 29% of the earth surface that is landmass (where we can reasonably put solar panels in large quantity)&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Of that 31% is covered in forest which are already some natural solar panels we don&#x27;t  want to remove (for other obvious reasons) &lt;a href=&quot;http:&#x2F;&#x2F;www.earth-policy.org&#x2F;indicators&#x2F;C56&#x2F;forests_2012&quot;&gt;source&lt;&#x2F;a&gt;
And 38.4% is covered of agricultural land &lt;a href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Agricultural_land&quot;&gt;source&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Then solar panels are not 100% efficient. They are roughly only 20% efficient with current technology at a reasonable cost.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;earth_power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;168&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;W&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;available_surface&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;R_earth&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;0.29&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;-.&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;384&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;max_power&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;earth_power_received&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;available_surface&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max_power&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;convert_to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;humanity_power_consumption&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;max_power&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;J&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;1.52084087357243e+15*watt
1.18882587196246
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h1 id=&quot;Conclusion&quot;&gt;Conclusion&lt;a class=&quot;anchor-link&quot; href=&quot;#Conclusion&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;In the end we are currently consuming &lt;strong&gt;1.2% of the realistic available solar power energy&lt;&#x2F;strong&gt;. That&#x27;s would require posing solar panels everywhere on the planet that is not a forest or agricultural land. And we don&#x27;t account yet for Energy return on energy invested (EROEI) which is likely to increase that percentage.&lt;&#x2F;p&gt;
&lt;p&gt;NB: This is a very superficial attempt to evaluate these numbers, however the result should be correct within an order of magnitude.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Can we train neural networks without gradient descent ?</title>
		<published>2020-03-10T00:00:00+00:00</published>
		<updated>2020-03-10T00:00:00+00:00</updated>
		<link href="https://nodata.dev/ml/2020/03/10/no-gd-training/"/>
		<link rel="alternate" href="https://nodata.dev/ml/2020/03/10/no-gd-training/" type="text/html"/>
		<id>https://nodata.dev/ml/2020/03/10/no-gd-training/</id>
		<content type="html">&lt;!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: _notebooks&#x2F;2020-03-10-no-gd-training.ipynb
--&gt;
&lt;div class=&quot;container&quot; id=&quot;notebook-container&quot;&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;What&#x27;s-the-problem-?&quot;&gt;What&#x27;s the problem ?&lt;a class=&quot;anchor-link&quot; href=&quot;#What&#x27;s-the-problem-?&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;ML models usually are not really capable of predicting how well the data you&lt;br&gt;
feed them is close to what was in the dataset. It really matters in production 
models as they might make really stupid mistakes just because they are off&lt;br&gt;
the training set.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Let&#x27;s train a simple mnist model (straight out from pytorch tutorial &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;examples&#x2F;tree&#x2F;master&#x2F;mnist&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;examples&#x2F;tree&#x2F;master&#x2F;mnist&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;details class=&quot;description&quot;&gt;
      &lt;summary class=&quot;btn btn-sm&quot; data-open=&quot;Hide Code&quot; data-close=&quot;Show Code&quot;&gt;&lt;&#x2F;summary&gt;
        &lt;p&gt;&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;c1&quot;&gt;#collapse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;__future__&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;argparse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;nn&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn.functional&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;F&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.optim&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;optim&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.optim.lr_scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;StepLR&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;&#x2F;span&gt; &lt;span class=&quot;nc&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Module&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;super&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Conv2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Conv2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Dropout2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.25&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Dropout2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;9216&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;forward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max_pool2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;flatten&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_softmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_interval&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Train Epoch: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)]&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.6f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
                &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;  &lt;span class=&quot;c1&quot;&gt;# sum up batch loss&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;keepdim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;  &lt;span class=&quot;c1&quot;&gt;# get the index of the max log-probability&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eq&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;view_as&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Test set: Average loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.4f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;, Accuracy: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
        &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;mnist&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;mnist_cnn.pt&amp;quot;&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Training settings&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;PyTorch MNIST Example&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for training (default: 64)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--test-batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for testing (default: 1000)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--epochs&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;number of epochs to train (default: 14)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--lr&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;LR&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;learning rate (default: 1.0)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--gamma&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;M&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Learning rate step gamma (default: 0.7)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--no-cuda&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;disables CUDA training&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--seed&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;S&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;random seed (default: 1)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--log-interval&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;how many batches to wait before logging training status&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--save-model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;For Saving the current Model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;manual_seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;num_workers&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pin_memory&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                       &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;expanduser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adadelta&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;StepLR&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# mnist()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;p&gt;
    &lt;&#x2F;details&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Other out of distribution detector have been proposed. Here is a sample of methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Genetic algorithms&lt;&#x2F;li&gt;
&lt;li&gt;DFO&lt;&#x2F;li&gt;
&lt;li&gt;Simulated annealing&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Experiments&quot;&gt;Experiments&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiments&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;train_ticket&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_interval&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Train Epoch: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)]&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.6f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
                &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test_ticket&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;  &lt;span class=&quot;c1&quot;&gt;# sum up batch loss&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;keepdim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;  &lt;span class=&quot;c1&quot;&gt;# get the index of the max log-probability&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eq&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;view_as&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Test set: Average loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.4f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;, Accuracy: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
        &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;ticket_finder&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ticket_finder.pt&amp;quot;&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Training settings&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;PyTorch MNIST Example&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for training (default: 64)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--test-batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for testing (default: 1000)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--epochs&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;number of epochs to train (default: 14)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--lr&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;LR&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;learning rate (default: 1.0)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--gamma&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;M&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Learning rate step gamma (default: 0.7)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--no-cuda&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;disables CUDA training&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--seed&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;S&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;random seed (default: 1)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--log-interval&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;how many batches to wait before logging training status&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--save-model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;For Saving the current Model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;manual_seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;num_workers&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pin_memory&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                       &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;expanduser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;TicketFinder&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;train_ticket&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_ticket&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Running a docker with GPU enabled (for pytorch and tensorflow)</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2020-03-04T00:00:00+00:00</published>
		<updated>2020-03-04T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2020/03/04/running-gpu-enabled-docker/"/>
		<link rel="alternate" href="https://nodata.dev/2020/03/04/running-gpu-enabled-docker/" type="text/html"/>
		<id>https://nodata.dev/2020/03/04/running-gpu-enabled-docker/</id>
		<content type="html">&lt;p&gt;Sometimes if you want to contain dependencies you might want to use docker
to containerize your projects. You can also use it for GPU
In order to run docker images with GPU enabled, you are going to need:&lt;&#x2F;p&gt;
&lt;h1 id=&quot;install-docker&quot;&gt;Install docker&lt;a class=&quot;zola-anchor&quot; href=&quot;#install-docker&quot; aria-label=&quot;Anchor link for: install-docker&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo apt-get install \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    apt-transport-https \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ca-certificates \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    curl \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    gnupg-agent \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    software-properties-common&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;curl -fsSL https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;ubuntu&#x2F;gpg | sudo apt-key add -&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo add-apt-repository \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   &amp;quot;deb [arch=amd64] https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;ubuntu \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   $(lsb_release -cs) \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   stable&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo apt-get update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo apt-get install docker-ce docker-ce-cli containerd.io&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;docs.docker.com&#x2F;install&#x2F;linux&#x2F;docker-ce&#x2F;ubuntu&#x2F;&quot;&gt;source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;install-nvidia-container-toolkit&quot;&gt;Install nvidia-container-toolkit&lt;a class=&quot;zola-anchor&quot; href=&quot;#install-nvidia-container-toolkit&quot; aria-label=&quot;Anchor link for: install-nvidia-container-toolkit&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Add the package repositories&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;distribution=$(. &#x2F;etc&#x2F;os-release;echo $ID$VERSION_ID)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;curl -s -L https:&#x2F;&#x2F;nvidia.github.io&#x2F;nvidia-docker&#x2F;gpgkey | sudo apt-key add -&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;curl -s -L https:&#x2F;&#x2F;nvidia.github.io&#x2F;nvidia-docker&#x2F;$distribution&#x2F;nvidia-docker.list | sudo tee &#x2F;etc&#x2F;apt&#x2F;sources.list.d&#x2F;nvidia-docker.list&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install -y nvidia-container-toolkit&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sudo systemctl restart docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;NVIDIA&#x2F;nvidia-docker&quot;&gt;source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;launch-the-docker-for-pytorch&quot;&gt;Launch the docker for PyTorch&lt;a class=&quot;zola-anchor&quot; href=&quot;#launch-the-docker-for-pytorch&quot; aria-label=&quot;Anchor link for: launch-the-docker-for-pytorch&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;In order to use cuda you need a nvidia enabled image, that will make everything simpler.
You could of course link your own cuda library via volume mounting but it&#x27;s cumbersome (and I didn&#x27;t check that it works)&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create an account on &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;ngc.nvidia.com&#x2F;&quot;&gt;https:&#x2F;&#x2F;ngc.nvidia.com&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go to the create an API key page &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;ngc.nvidia.com&#x2F;setup&#x2F;api-key&quot;&gt;https:&#x2F;&#x2F;ngc.nvidia.com&#x2F;setup&#x2F;api-key&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Generate the key and copy it&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker login nvcr.io&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Username: $oauthtoken&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Password: &amp;lt;Your Key&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;docker run --gpus all -it --rm nvcr.io&#x2F;nvidia&#x2F;pytorch:20.02-py3 bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;python -c &amp;quot;import torch; print(torch.cuda.is_available())&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you fail to login the &lt;code&gt;docker run&lt;&#x2F;code&gt; command will fail with &lt;code&gt;unauthenticated&lt;&#x2F;code&gt; error.&lt;&#x2F;p&gt;
&lt;p&gt;Caveat: This is the only option for now, docker-compose &lt;em&gt;CANNOT&lt;&#x2F;em&gt; run the --gpu option.
To check updates for docker compose, look at this &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;docker&#x2F;compose&#x2F;issues&#x2F;6691&quot;&gt;issue&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Bonus: Nvidia put up &lt;em&gt;a lot&lt;&#x2F;em&gt; of containers with various libraries enabled check it out in their &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;ngc.nvidia.com&#x2F;catalog&#x2F;&quot;&gt;catalog&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;enjoy&quot;&gt;Enjoy !&lt;a class=&quot;zola-anchor&quot; href=&quot;#enjoy&quot; aria-label=&quot;Anchor link for: enjoy&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Self KL-divergence for detecting out of distribution data and unsupervised text classification</title>
		<published>2020-02-26T00:00:00+00:00</published>
		<updated>2020-02-26T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2020/02/26/self-kl-models/"/>
		<link rel="alternate" href="https://nodata.dev/2020/02/26/self-kl-models/" type="text/html"/>
		<id>https://nodata.dev/2020/02/26/self-kl-models/</id>
		<content type="html">&lt;!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: _notebooks&#x2F;2020-02-26-self-kl-models.ipynb
--&gt;
&lt;div class=&quot;container&quot; id=&quot;notebook-container&quot;&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;blockquote&gt;&lt;p&gt;TL;DR. By training two models in the same dataset order with same architecture, same loss, but different initialization, 
I was able to obtain a consistent out-of-distribution detector by measuring the kl-divergence between model outputs.
This out-of-distribution measure used on text could lead to unsupervised text classification.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;What&#x27;s-the-problem-?&quot;&gt;What&#x27;s the problem ?&lt;a class=&quot;anchor-link&quot; href=&quot;#What&#x27;s-the-problem-?&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;&lt;p&gt;ML models usually are not really capable of predicting how well the data you&lt;br&gt;
feed them is close to what was in the dataset. It really matters in production 
models as they might make really stupid mistakes just because they are off&lt;br&gt;
the training set.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Let&#x27;s train a simple mnist model (straight out from pytorch tutorial &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;examples&#x2F;tree&#x2F;master&#x2F;mnist&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;pytorch&#x2F;examples&#x2F;tree&#x2F;master&#x2F;mnist&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;details class=&quot;description&quot;&gt;
      &lt;summary class=&quot;btn btn-sm&quot; data-open=&quot;Hide Code&quot; data-close=&quot;Show Code&quot;&gt;&lt;&#x2F;summary&gt;
        &lt;p&gt;&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;c1&quot;&gt;#collapse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;__future__&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;argparse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;nn&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn.functional&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;F&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.optim&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;optim&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.optim.lr_scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;StepLR&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;&#x2F;span&gt; &lt;span class=&quot;nc&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Module&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;fm&quot;&gt;**init**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;super&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;fm&quot;&gt;**init**&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Conv2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Conv2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Dropout2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.25&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Dropout2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;9216&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;forward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max_pool2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;flatten&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dropout2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_softmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_interval&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Train Epoch: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)]&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.6f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;_&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
&lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;_&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;c1&quot;&gt;# sum up batch loss&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;keepdim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;c1&quot;&gt;# get the index of the max log-probability&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eq&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;view_as&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Test set: Average loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.4f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;, Accuracy: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
        &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;mnist&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;mnist_cnn.pt&amp;quot;&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# Training settings&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;PyTorch MNIST Example&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for training (default: 64)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--test-batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for testing (default: 1000)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--epochs&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;number of epochs to train (default: 14)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--lr&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;LR&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;learning rate (default: 1.0)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--gamma&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;M&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Learning rate step gamma (default: 0.7)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--no-cuda&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;disables CUDA training&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--seed&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;S&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;random seed (default: 1)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--log-interval&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;how many batches to wait before logging training status&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--save-model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;For Saving the current Model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;manual_seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;num_workers&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pin_memory&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                       &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;expanduser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adadelta&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;StepLR&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# mnist()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;p&gt;
    &lt;&#x2F;details&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;details class=&quot;description&quot;&gt;
      &lt;summary class=&quot;btn btn-sm&quot; data-open=&quot;Hide Code&quot; data-close=&quot;Show Code&quot;&gt;&lt;&#x2F;summary&gt;
        &lt;p&gt;&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;c1&quot;&gt;#collapse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.distributions&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn.parameter&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Parameter&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;attack_simple&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;verbose&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Parameter&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;rand&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;28&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;28&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;requires_grad&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adadelta&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;c1&quot;&gt;# print(f&amp;#39;Entropy {entropy.item():.2f}&amp;#39;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Resize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;240&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;240&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToPILImage&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;check_attack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;mnist_model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;mnist_model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;mnist_cnn.pt&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;attack_simple&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;mnist_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;MNIST Model says : This is a &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;indices&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; with probability &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;display&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;success_rate&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;attack_simple&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;mnist_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Success rate &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;success_rate&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; .2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# check_attack()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;p&gt;
    &lt;&#x2F;details&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Then generate an random image for which the model is highly confident yet it&#x27;s completely absurd. This new image is out of distribution yet the model does not know it. We want to avoid doing such mistakes in production.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Other-approaches&quot;&gt;Other approaches&lt;a class=&quot;anchor-link&quot; href=&quot;#Other-approaches&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Other out of distribution detector have been proposed. Here is a sample of methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1906.02845.pdf&quot;&gt;Likelihood Ratios for Out-of-Distribution Detection&lt;&#x2F;a&gt;: Propose to learn 2 distinct models, one &quot;raw&quot;, one with perturbation instilled into the dataset, and look at the log likelihood ratio of the two models, claim is that the difference between the two will reflect how &quot;far&quot; input is from the semantic part of the manifold of X. $p(x) = p(x_{background})p(x_{semantic})$, the perturbation needs to lie only on $x_{semantic}$.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1910.04241.pdf&quot;&gt;Out-of-distribution Detection in Classifiers via Generation&lt;&#x2F;a&gt;: Propose to use autoencoder (or GANs) to generate a low dimensional representation of the manifold of the dataset X, then perturb X on that representation. Those perturbated examples are trained to become a new &quot;class&quot; of the output of the classifier. &lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1706.02690.pdf&quot;&gt;Enhancing the reliability of Out-of-Distribution Image Detection in Neural Networks (Odin)&lt;&#x2F;a&gt;: This one uses temperature scaling regarding softmax to generate perturbated input, then look at the probability of the softmax if it passes a threshold. IMO, this paper is interesting as it supposes smoothness properties on In distribution data, and less smooth for out-of-distribution. It does require some examples of out-of-distribution for fitting 3 hyperparameters (temperature, threshold and magnitude of perturbation)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;openreview.net&#x2F;pdf?id=Hkxzx0NtDB&quot;&gt;Your classifier is secretly an energy based model and you should treat it like one&lt;&#x2F;a&gt;: This one adds a new term in the loss to estimate p(x) basically. Multiple ood detectors are proposed, the most efficient being the second derivative of p(x), claiming again that density of p(x) will change more widly in ood space, leading to a good ood detector.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1810.01392.pdf&quot;&gt;WAIC, but Why? Generative Ensembles for Robust Anomaly Detection&lt;&#x2F;a&gt;: This paper proposes to use an ensemble of models and look at WAIC criterion to detect OOD. It makes many comparison to VAE and GANs&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1802.04865v1.pdf&quot;&gt;Learning Confidence for Out-of-Distribution Detection in Neural Networks&lt;&#x2F;a&gt; : The core idea in this paper is to change the learning loss, to learn confidence as prior task to classification task, a model is allowed to see real label only when it claims it can solve the problem, outputting via another head directly a confidence score. Caveat is that the model might choose to give up and always claim confidence, and another trick is proposed to emphasize the in-distribution vs out-of-distribution by preprocessing inputs to move them towards region of higher confidence. In-distribution tends to move closer to 1 than out-of-distribution. So the direct confidence estimator seems to be &lt;em&gt;smoother&lt;&#x2F;em&gt; out-of-distribution than in-distribution, where peaks are more likely to be found.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;paperswithcode.com&#x2F;task&#x2F;out-of-distribution-detection&quot;&gt;Papers with code&lt;&#x2F;a&gt;: More links on that hopefully&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Our-approach&quot;&gt;Our approach&lt;a class=&quot;anchor-link&quot; href=&quot;#Our-approach&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Tl;dr : Make two similar models, with two different random initialization, then train them at the same time.&amp;gt; The ood detector will simply be the a threshold classifier on the KL-divergence between the two outputs.&lt;&#x2F;strong&gt;
The core argument for this approach is that the neural network captures the dataset manifold (which means it will produce &quot;regular&quot; outputs for in dataset items). For the range of possible values it has random values for a random initialization. If that is true, then we train the model, we shift it&#x27;s output only on the dataset manifold, and not anywhere else. If that assumption is correct, then the 2 models have very low probability of concurring in their output outside of the manifold if they have been initialized differently.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;It&#x27;s quite close to WAIC, &lt;em&gt;but&lt;&#x2F;em&gt; the two models need to be trained at the same time. The argument is that is should align gradients during the training phase, leading to more correlation for in-dataset prediction for the models. The argument for this supposes that the lottery ticket hypothesis is true, and adds that lottery ticket is unique (or at least that the class of lottery tickets is very thin, and they all highly correlate to each other). If this is true, then the gradients within the network that correspond to this lottery ticket winner in &lt;em&gt;both&lt;&#x2F;em&gt; networks should be the same (or highly correlated).&lt;&#x2F;p&gt;
&lt;p&gt;In order to fix the threshold, we found that simply setting it to be 10x the average kl-divergence obtained on the train dataset worked pretty well. As kl divergence is measured in bits, 10x is a quite large margin. More work could be done to study more closely the behaviour of this self kl-divergence.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Experiments&quot;&gt;Experiments&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiments&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-1&quot;&gt;Experiment 1&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-1&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;MNIST attack like failure presented before.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;class&lt;&#x2F;span&gt; &lt;span class=&quot;nc&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Module&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;super&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ModuleList&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;forward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;train_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_interval&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Train Epoch: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)]&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.6f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;_&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
&lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;_&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_idx&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nll_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;keepdim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;c1&quot;&gt;# get the index of the max log-probability&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eq&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;view_as&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Test set: Average loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.4f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;, Accuracy: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.0f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;%)&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
        &lt;span class=&quot;mf&quot;&gt;100.&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;correct&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;mnist_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# Training settings&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;mnist_multi_cnn.pt&amp;quot;&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;PyTorch MNIST Example&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for training (default: 64)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--test-batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for testing (default: 1000)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--epochs&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;number of epochs to train (default: 14)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--lr&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;LR&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;learning rate (default: 1.0)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--gamma&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;M&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Learning rate step gamma (default: 0.7)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--no-cuda&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;disables CUDA training&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--seed&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;S&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;random seed (default: 1)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--log-interval&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;how many batches to wait before logging training status&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--save-model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;For Saving the current Model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;manual_seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;num_workers&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pin_memory&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                       &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;expanduser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                           &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                       &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adadelta&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;StepLR&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;step_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;gamma&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;train_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# mnist_multi()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;eval&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;&#x2F;span&gt;
                    &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;
                    &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;sum&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;Test set: Average loss: &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{:.4f}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;, len &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loss&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;get_reference_kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;mnist_multi_cnn.pt&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;expanduser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                           &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# ref_kl_loss = get_reference_kl()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Now we have 2 models capable of detecting digits, we have instantly 3 checks for checking if the output of our model is valid. The 2 models need to be concording (they need to outputs the same digit as an output), they need to have similar kl-divergence, we actually have a reference for the test set, so we know what kind of divergence we should look for, anything 10x more is definitely ood (we could look at the test set distribution for more fine grain estimation). Because kl divergence is asymetric we have 2 values (it&#x27;s harder for spiked distribution to have another distribution be close in the kl sense, so taking the max of kl-divergence should be used for out-of-distribution.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;details class=&quot;description&quot;&gt;
      &lt;summary class=&quot;btn btn-sm&quot; data-open=&quot;Hide Code&quot; data-close=&quot;Show Code&quot;&gt;&lt;&#x2F;summary&gt;
        &lt;p&gt;&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;c1&quot;&gt;#collapse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.distributions&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn.parameter&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Parameter&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;attack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;loss_fn&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;verbose&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;mnist_multi_cnn.pt&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Parameter&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;rand&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;28&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;28&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;requires_grad&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adadelta&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;multi_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss_fn&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;c1&quot;&gt;# print(f&amp;#39;Entropy {entropy.item():.2f}&amp;#39;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;MAX1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;MAX2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX1&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;indices&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;indices&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX1&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MAX2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;verbose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;MNIST Model says : This is a &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX1&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;indices&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; with probability &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX1&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;MNIST Model 2 says : This is a &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;indices&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; with probability &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MAX2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;KL-divergence is &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ATTACK SUCCEEDED&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ATTACK FAILED&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Resize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;240&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;240&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToPILImage&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dummy_input&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;display&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;pil_img&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;p&gt;
    &lt;&#x2F;details&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Now if we simply attack the first model like we did earlier, we can see that we can trick it as easily as before. &lt;em&gt;BUT&lt;&#x2F;em&gt; the second model, does not get attacked which is to be expected.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;\_&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;attack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;MNIST Model says : This is a 3 with probability 99.32%
MNIST Model 2 says : This is a 3 with probability 33.50%
KL-divergence is 587.7392578125 152.96902465820312
ATTACK FAILED
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_png output_subarea &quot;&gt;
&lt;img src=&quot;data:image&#x2F;png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAAAAAAbPrZOAABr+klEQVR4nOz965YkuZE0COoNgJm5e2Rmkezu2efdR93eM9+wqjIzwt3MAOhlfwAWWWTPzAPsrvOQh3WLCrjioioqIor&#x2F;TwDAnEsen5JzyTn9MT96v93v9&#x2F;vt&#x2F;ucfv&#x2F;&#x2F;++++&#x2F;&#x2F;&#x2F;4qJZeSS0k555RzplrPWs9at3+Mz28f7x&#x2F;vHx&#x2F;vHx+v5+v5fD1fX&#x2F;&#x2F;2229&#x2F;++1vv31Z1mVdlnXR8zyP8zz333&#x2F;&#x2F;4&#x2F;fff&#x2F;&#x2F;j9&#x2F;z3v&#x2F;&#x2F;j73&#x2F;&#x2F;+9&#x2F;&#x2F;vqzrsi7ruv&#x2F;3f&#x2F;&#x2F;3f&#x2F;+&#x2F;&#x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ezqffeRut9R9V3o8DCjYBc71rrXavCqgRBUc0fBVt+Bq33+52Cx63m57r3b9h7sxJiLT&#x2F;s+foF1YFMkKmvNM4mOIQwQWa7v97XMLTv55LWbctkvZLVmCGdWJIcQ0yplNrWj5CzU7AutmCPe2qt1V5bg5JLKYweTOC2mr5tNrQ4h5jzt6J1jd5bIZ9yzpn&#x2F;zmrOfiTidOQ7KhLavD2FVB7&#x2F;+LUdyHSfGf4EWITYVaL21zXHGnOs&#x2F;5hhFoFlZERBQsrPZ9GiU44x5VwfJ1ET1EDsT+0c6405lPJ4lFLKmUd8PV9TgKKwyBKW2RR1aj7o+Z5LTuEIPNccvYVE+fl6vSRHDbtUQCxFo&#x2F;Vs7K16BFYleXm+fgnwJLdthtWhlQKFGJRv&#x2F;&#x2F;7rSztK&#x2F;LNgm2G7r04XEob8&#x2F;P2w22JKKbfcWmut1uZApvwoWIdlQTzKfdXrvurlf&#x2F;2aAj4JG1Y+emutt9qDOEIf06OkFMl7Yx6P3gtQev3x+48dg4fNq0cLRgmKCm3sl3dbpttnSbPMQR5kaavHwWeGPfDs99e&#x2F;vnT1&#x2F;njdt0OJ99JQrRHyEym9fj+zeVL33HrpvdcrkQeZukvPnwXjnHOGtcyncAw&#x2F;zRhN+yif31cMScBD2fv0ZcR2HQr75BUYW9r7o1NYypk5Zufew7EYM&#x2F;tm&#x2F;B5Gy1z75Czv03bWP6cPb00TlQWcQUzMbKkJ+h0d&#x2F;I+N&#x2F;xf83z7+DRGKQbk6wMnLAAAAAElFTkSuQmCC
&quot;
&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Even if we try a smarter and attack &lt;strong&gt;both&lt;&#x2F;strong&gt; models at the same time, we can&#x27;t succeed at a consistent rate. Be warned, it will succeed sometimes, just not consistently.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;entropy1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;entropy2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;distance&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;mse_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;entropy1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;entropy2&lt;&#x2F;span&gt;  &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;distance&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;\_&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;attack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_wrapper&quot;&gt;
&lt;div class=&quot;output&quot;&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_subarea output_stream output_stdout output_text&quot;&gt;
&lt;pre&gt;MNIST Model says : This is a 1 with probability 11.50%
MNIST Model 2 says : This is a 7 with probability 11.48%
KL-divergence is 0.474844753742218 0.47643253207206726
ATTACK FAILED
&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;output_area&quot;&gt;
&lt;div class=&quot;output_png output_subarea &quot;&gt;
&lt;img src=&quot;data:image&#x2F;png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAAAAAAbPrZOAABnvElEQVR4nOz925IkOZIlCPINgIiomUdkddcu0f7zfufU9nRlRriZqggAvuwDQ9QjquYLdladKIkyMsPcWBlg8OWcw&#x2F;j&#x2F;BgCUIlJEBD3cw8NxfSAiAiLCPdzdHWuptZZav&#x2F;&#x2F;Iz&#x2F;M4jv04jr0yMxMzEyIhEnpfn7Y+&#x2F;s&#x2F;&#x2F;zD8f&#x2F;&#x2F;4&#x2F;&#x2F;&#x2F;1&#x2F;&#x2F;vv&#x2F;&#x2F;PffiQiJCPvX9&#x2F;fX99f38&#x2F;fffv&#x2F;9t99&#x2F;&#x2F;03&#x2F;4z&#x2F;+4z&#x2F;+4&#x2F;&#x2F;zH&#x2F;&#x2F;x+O3Hj99+&#x2F;Pjt0Wqtrdb2z&#x2F;&#x2F;4P&#x2F;7jP&#x2F;7j&#x2F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0eriTSVNWu1Dqe4z7SSAzIlhsX08MLakzZZySwyNfcPbE1GvY2OIPWZo5u47pUPYkw5VfQei&#x2F;IXHW+zX5+&#x2F;&#x2F;xzsrTtUIs1F3+dlmydXx7OvCsVHxKpuXpL2dMyXIMMZEQyYxNfBpfCnjL8V44dR5ebAQhIyWF4e5gLMxfOhbZIsY60J58SHEJ9IStKqaXWrc2JoeN8zSSBcMntk8vD&#x2F;vegNfrr+fOPmdogt4fP86lz6mxvg7+ftXpl+P+2dy3JDcMglI+M09z&#x2F;oJ2p3EiWBV0ATtqmF8iUhVYeC88g89V7tCShpgS1YAAyq3k2CEhMPG1O1XJJk46kszGZHqM576RbzN1rlGuG6EWWQmoJIo7ExXACAJrZdJNmJnfUsmJHPXrbdixyUWQR9sThnN355pZu9eN9l7dr64dajHp8blFfG73WWmvdtmnAilTEIU5lXdgrgTCH2RxzYES0FNdLrcTlcvH6NVBD1GPva3glIjLgAGf52VtCVQPFU9VzajBbRiesCGWskkRTD0&#x2F;&#x2F;EkcfTNKDAODR55Iv8zz2LLCAxn7oPHauBQA4cmLoFOfff873pgNCLgD0h44vK&#x2F;8f&#x2F;OryBZ6pZjRd&#x2F;4oJAAAAAElFTkSuQmCC
&quot;
&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Be warned, it will succeed sometimes, just not consistently. For comparison, the first attack succeeds with close to 100% (we couldn&#x27;t make it fail). Actually because we have 10 classes, and if we supposed out-of-distribution probability distribution is uniformly random, it should be something close to 10%, when our initial random image finds a place where the 2 models intersect on the same digit.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;entropy1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;entropy2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Categorical&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;logits&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;entropy&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;batchmean&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;distance&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;mse_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;entropy1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;entropy2&lt;&#x2F;span&gt;  &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;distance&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;attack_rate&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;attacks&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;attack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;verbose&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;F&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;.&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;attacks&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Attack success rate &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;attacks&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;attacks&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# attack_rate()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;The actual attack range seems to stagnate at around 0% (30% if we remove the confidence rate &amp;gt; 80%) with various learning rates and attack steps. There probably are better strategies to attack, this, but the main point is that it became &lt;strong&gt;harder&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-2&quot;&gt;Experiment 2&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-2&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Now let&#x27;s test this on common ood detection for classic datasets. We will add ood detection for the train dataset, just to check that we don&#x27;t &lt;em&gt;exclude&lt;&#x2F;em&gt; too much of the original dataset. Datasets used will be MNIST, FashionMNIST&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;details class=&quot;description&quot;&gt;
      &lt;summary class=&quot;btn btn-sm&quot; data-open=&quot;Hide Code&quot; data-close=&quot;Show Code&quot;&gt;&lt;&#x2F;summary&gt;
        &lt;p&gt;&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;c1&quot;&gt;#collapse&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision.datasets&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Omniglot&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;dataset_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# Training settings&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;PyTorch MNIST Example&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for training (default: 64)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--test-batch-size&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;input batch size for testing (default: 1000)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--epochs&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;number of epochs to train (default: 14)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--lr&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;1e-2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;LR&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;learning rate (default: 1.0)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--gamma&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;M&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Learning rate step gamma (default: 0.7)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--no-cuda&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;disables CUDA training&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--seed&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;S&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;random seed (default: 1)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--log-interval&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;metavar&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;N&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;how many batches to wait before logging training status&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;--save-model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;store_true&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;For Saving the current Model&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;no_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;manual_seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;seed&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;num_workers&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pin_memory&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;use_cuda&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                       &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Adam&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr_scheduler&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;CyclicLR&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
          &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;base_lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;max_lr&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;lr&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;cycle_momentum&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;step_size_up&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;&#x2F;span&gt;                    &lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;epochs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;train_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;optimizer&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;scheduler&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;run_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;create_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;.pt&amp;#39;&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;create_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
                                    &lt;span class=&quot;p&quot;&gt;])&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;dataset_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;create_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# run_datasets(create_model, suffix=&amp;#39;&amp;#39;)&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;p&gt;
    &lt;&#x2F;details&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;sklearn.metrics&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;roc_auc_score&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;500&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;.pt&amp;#39;&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Ref loss&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;  &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Trained on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; we detected on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%) out of distribution&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;roc_auc_score&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;AUC for &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; : &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;exp_2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# exp_2()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;So we can see that we achieve, with no tuning whatsoever a decent out of distribution detector. We seem to achieve much better AUROC on MNIST, probably because the in-distribution learning seems to be much better (99% test accuracy vs 92% for fastionMNIST). So to False positives for fashionMNIST probably come from this hard to learn in-distribution. Some fine tuning needs to be done to get better results. We also have to keep in mind, that the models to learn this are quite small (2M parameters but only 2 convolution layers) so the lottery hypothesis validity for such a network might be questionned.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-2-bis&quot;&gt;Experiment 2 bis&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-2-bis&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Same experiment but with fine tuned, larger networks on the same datasets&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;&#x2F;span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision.models.resnet&lt;&#x2F;span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;BasicBlock&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;&#x2F;span&gt; &lt;span class=&quot;nc&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;super&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;fm&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;BasicBlock&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;num_classes&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;conv1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Conv2d&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;stride&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;bias&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;forward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;log_softmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;super&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;forward&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;run_datasets_res&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cuda&amp;quot;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;cpu&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;_resnet.pt&amp;#39;&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;multi_res&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Resize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))])&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;dataset_multi&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;multi_res&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test_datasets_bis&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;_resnet.pt&amp;#39;&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Resize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Ref loss&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Resize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt;  &lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Trained on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; we detected on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%) out of distribution&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;roc_auc_score&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;AUC for &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; : &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;exp_2_bis&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;multi_res&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MnistResNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;test_datasets_bis&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;multi_res&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# run_datasets_res()&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# exp_2_bis()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-3&quot;&gt;Experiment 3&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-3&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Check that two identical networks (same initalization) actually don&#x27;t work. It&#x27;s just a sanity check. We should obtain always kl_div = 0 no matter where we are in the input space.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;create_same_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;exp_3&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;run_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;create_same_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_exp3&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;test_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;create_same_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_exp3&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# exp_3()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-4&quot;&gt;Experiment 4&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-4&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Run this method with 2, 3, 4, and so on models. We should get exponential improved accuracy, if the random behavious for out-of-distribution for models is correct.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing code_cell rendered&quot;&gt;
&lt;div class=&quot;input&quot;&gt;
&lt;div class=&quot;inner_cell&quot;&gt;
    &lt;div class=&quot;input_area&quot;&gt;
&lt;div class=&quot; highlight hl-ipython3&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;create_n_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;MultiNet&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;test_datasets_4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;MNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;FashionMNIST&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;
    &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;.pt&amp;#39;&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load_state_dict&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model_arch&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Ref loss&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;utils&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;DataLoader&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;..&#x2F;data&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;train&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;download&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt;
                               &lt;span class=&quot;n&quot;&gt;transform&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Compose&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;ToTensor&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt;
                                   &lt;span class=&quot;n&quot;&gt;transforms&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;Normalize&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.1307&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,),&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;mf&quot;&gt;0.3081&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;&#x2F;span&gt;
             &lt;span class=&quot;p&quot;&gt;])),&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;shuffle&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
            &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_losses&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;&#x2F;span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;&#x2F;span&gt;
                    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;kl_losses&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                        &lt;span class=&quot;n&quot;&gt;kl_losses&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;F&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_div&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;reduction&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;none&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;stack&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_losses&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;argmax&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dim&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;kl_loss&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;ref_kl_loss&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;similar&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;&#x2F;span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;nb&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;kl_anomaly&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;non_concordant&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;boolean&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;normed&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;&#x2F;span&gt;
                &lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;out_of_distrib&lt;&#x2F;span&gt;
            &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Trained on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; we detected on &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;OOD&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;test_loader2&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;%) out of distribution&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;roc_auc_score&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;all_labels&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;all_scores&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;AUC for &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;dataset_cls&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;vm&quot;&gt;__name__&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt; : &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;auc&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;&#x2F;span&gt; &lt;span class=&quot;nf&quot;&gt;exp_4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;&#x2F;span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cuda&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;cuda&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;is_available&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;&#x2F;span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cpu&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;&#x2F;span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;=&amp;#39;&lt;&#x2F;span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;N = &lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;run_datasets&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;create_n_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_exp4_&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
        &lt;span class=&quot;n&quot;&gt;test_datasets_4&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;create_n_model&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;&#x2F;span&gt; &lt;span class=&quot;n&quot;&gt;suffix&lt;&#x2F;span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;&#x2F;span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_exp4_&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;&#x2F;span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;&#x2F;span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;&#x2F;span&gt;
&lt;span class=&quot;c1&quot;&gt;# exp_4()&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;Seems not to be working too great, we ARE improving AUC. Not by a strong margin, it is probably just that we are having a better approximator of our metric by ensembling.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-5&quot;&gt;Experiment 5&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-5&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Test on a larger output space, like CIFAR-100 and SVHN, to check that part of the limits are actually due to small number of output classes
for MNIST&#x2F;FashionMNIST
Other idea is to test on Transformers. Early experiment seems to show that we can use that idea to detect different language within text with just the kl_div used as a distance.&lt;&#x2F;p&gt;
&lt;p&gt;Found French book within english books dataset, AND english paragraphs &lt;em&gt;within&lt;&#x2F;em&gt; this french book.
Needs some work to clean this experiment&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;ul&gt;
&lt;li&gt;Show that small network trained on a single english book enables to detect different languages
or different patterns of writing (old english, irish, french, or event dictionnaries)&lt;&#x2F;li&gt;
&lt;li&gt;The detection is super fined grained capable of detecting english within a French book.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;For brevity, we won&#x27;t include training code. We just trained a simple transformer (6 layers deep) on a english text and checked our metric on some other texts.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;copied_from_nb&#x2F;images&#x2F;self-kl-train-eng.png&quot; alt=&quot;title&quot;&gt;
&lt;img src=&quot;&#x2F;images&#x2F;copied_from_nb&#x2F;images&#x2F;self-kl-test-eng.png&quot; alt=&quot;title&quot;&gt;
&lt;img src=&quot;&#x2F;images&#x2F;copied_from_nb&#x2F;images&#x2F;self-kl-test-fr.png&quot; alt=&quot;title&quot;&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h3 id=&quot;Experiment-6&quot;&gt;Experiment 6&lt;a class=&quot;anchor-link&quot; href=&quot;#Experiment-6&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;&lt;p&gt;Need to test with various training schemes, regularization schemes (dropout, batchnorm, l2 penalization) and so on. We should find that the smoother in-distribution our models behave the more this method should work. Hopefully test accuracy &lt;em&gt;should&lt;&#x2F;em&gt; be a good smoothness proxy.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Limits&quot;&gt;Limits&lt;a class=&quot;anchor-link&quot; href=&quot;#Limits&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;The pros for this method are that:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It&#x27;s super simple to implement, and only costs a constant factor in training time.&lt;&#x2F;li&gt;
&lt;li&gt;You could also extend this to 3, 4 side models, and it &lt;em&gt;should&lt;&#x2F;em&gt; improve robustness exponentially if the random factors are correct. If we keep this number small, it will still be constant cost factor.&lt;&#x2F;li&gt;
&lt;li&gt;It does &lt;em&gt;not&lt;&#x2F;em&gt; require a perturbation model for input data, which in itself is subject to fine-tuning.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The cons is that:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It does not work so well on low dimensional output spaces. &lt;&#x2F;li&gt;
&lt;li&gt;It seems other methods have better results than this one.&lt;&#x2F;li&gt;
&lt;li&gt;It only works for models that output probability distributions (hard to extend to object detection, generation and other tasks)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;h2 id=&quot;Future-Work&quot;&gt;Future Work&lt;a class=&quot;anchor-link&quot; href=&quot;#Future-Work&quot;&gt; &lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;cell border-box-sizing text_cell rendered&quot;&gt;&lt;div class=&quot;inner_cell&quot;&gt;
&lt;div class=&quot;text_cell_render border-box-sizing rendered_html&quot;&gt;
&lt;p&gt;There is a lot more experiments necessary to verify that the hypothesis in favor of that approach hold. Try to find ways to implement that in other tasks. How to improve out-of-distribution detection.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Model based encodings (3)</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2019-08-06T00:00:00+00:00</published>
		<updated>2019-08-06T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2019/08/06/model-based-bpe-encodings-3/"/>
		<link rel="alternate" href="https://nodata.dev/2019/08/06/model-based-bpe-encodings-3/" type="text/html"/>
		<id>https://nodata.dev/2019/08/06/model-based-bpe-encodings-3/</id>
		<content type="html">&lt;p&gt;In the &lt;a href=&quot;&#x2F;2019&#x2F;05&#x2F;16&#x2F;model-based-bpe-encodings&#x2F;&quot;&gt;first segment&lt;&#x2F;a&gt;
we looked into how we could make a BPE
based encoding, not only based on frequency in the dataset, but directly on the
model probability measure of the next token. In that article I mention that
dynamic BPE are costly because they stop being a one time operation but have to
be done for every batch because the vocabulary might have changed. In this
article I try to completely remove the “static” BPE approach and replace it
completely with ML blocks.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;h1 id=&quot;tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot;&gt;TL;DR In this article we present an idea to replace classical BPE algorithm with a pure ML version of it.&lt;a class=&quot;zola-anchor&quot; href=&quot;#tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot; aria-label=&quot;Anchor link for: tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-is-the-goal&quot;&gt;What is the goal ?&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-is-the-goal&quot; aria-label=&quot;Anchor link for: what-is-the-goal&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;So the goal is to replace BPE algorithm. So it’s go from something like&lt;&#x2F;p&gt;
&lt;p&gt;“T|h|e| |c|a|t| |a|t|e| |t|h|e| |a|p|p|l|e|.”&lt;&#x2F;p&gt;
&lt;p&gt;To something that has less elements :&lt;&#x2F;p&gt;
&lt;p&gt;“The |ca|t |at|e |the| |app|le|.”&lt;&#x2F;p&gt;
&lt;p&gt;In one sentence, BPE fuses bytes to form tokens based on frequency in the full
dataset. For a more detailed example, look that &lt;a href=&quot;&#x2F;2019&#x2F;05&#x2F;16&#x2F;model-based-bpe-encodings&#x2F;&quot;&gt;the previous
article&lt;&#x2F;a&gt;.
In this example, you can see there is always a split after a space. That’s a
limitation of BPE so actually our target might look different, maybe more like&lt;&#x2F;p&gt;
&lt;p&gt;“The cat |at|e |the app|le|.”&lt;&#x2F;p&gt;
&lt;p&gt;Here we can notice that “The cat” is a full token and contain 2 actual words.
So the goal is to fuse some starting bytes into N tokens (let’s say ~10k) that
hopefully capture regularities in our dataset and are at least correlated to
frequency in the original dataset like BPE was.&lt;&#x2F;p&gt;
&lt;p&gt;Another property we need to have from BPE is that it can encode an arbitrary
string of text. It does not matter if it’s not the same language or even if it
makes sense, you CAN encode it, that is a very desirable property. It avoids
the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;cisco-emerge&#x2F;creating-semantic-representations-of-out-of-vocabulary-words-for-common-nlp-tasks-842dbdafba18&quot;&gt;out-of-vocabulary&lt;&#x2F;a&gt; problem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;approach&quot;&gt;Approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#approach&quot; aria-label=&quot;Anchor link for: approach&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;tokenization&quot;&gt;Tokenization&lt;a class=&quot;zola-anchor&quot; href=&quot;#tokenization&quot; aria-label=&quot;Anchor link for: tokenization&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;So let’s imagine we have a trained transformer like
&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;openai.com&#x2F;blog&#x2F;better-language-models&#x2F;&quot;&gt;GPT-2&lt;&#x2F;a&gt;. But trained on bytes
directly NOT on tokens like the original transformer. Now we can use the idea
that when a model is highly confident, it probably means that what it’s about
to predict is “in the same token”. Let’s take an example. Try to predict the
following Character (as in a single letter) in the next 2 sentences&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Sentence 1: “Who are yo…”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Sentence 2 : “I like …”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;In the first sentence, normally you would vote with very high confidence for
“u”, whereas in the second sentence, you lack a lot of context to be exactly
sure on what’s coming next. So “you” would be a token, whereas “like …” can’t
be a single token, it has to be at least 2, &quot;like &quot; and &quot;…&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a small gif of actual probabilities of the language model on a small sentence&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-approach.gif&quot;&#x2F;&gt;
&lt;p&gt;You can see the in the left of the graph the probabilities drop, those are the
tokens that try to get predicted but are missing context (because we have very
few characters before them. For the right side, you can see the drops in probability
are pretty consistent and correspond to word boundaries most often.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;handling-unknown-tokens&quot;&gt;Handling unknown tokens&lt;a class=&quot;zola-anchor&quot; href=&quot;#handling-unknown-tokens&quot; aria-label=&quot;Anchor link for: handling-unknown-tokens&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Now we know how we are going to “fuse” characters, but we are not done yet. BPE
tokens are a discrete SET of identified values from 0 to N (~10k in this
experiment). Also BPE can encode an arbitrary new string by using it’s fusion
table. So we can’t just run our algorithm on some specific dataset, count all
the tokens created and declare that these are the N tokens for eternity. Let’s
imagine I feed my algorithm a new sentence, in a different language, French for
instance.&lt;&#x2F;p&gt;
&lt;p&gt;“J’adore l’Italie.”&lt;&#x2F;p&gt;
&lt;p&gt;We can run our “tokenizer” on this, and receive something like this&lt;&#x2F;p&gt;
&lt;p&gt;“J|’|ado|re |l’|Ita|lie.”&lt;&#x2F;p&gt;
&lt;p&gt;Now “ado” might not be in our original list, so what do we do with it ? Do we
declare the token wrong and split it ? That would be odd.&lt;&#x2F;p&gt;
&lt;p&gt;A key insight, is to remember that the first step of the discrete “token” once
it enters the model (all of them do that, it’s really not specific to
transformer or GPT-2) it gets embedded, meaning we go from a number between 1
and N, to a vector in &lt;em&gt;d&lt;&#x2F;em&gt; dimension space (&lt;em&gt;d&lt;&#x2F;em&gt; is between 100 and 1000 generally).&lt;&#x2F;p&gt;
&lt;p&gt;For instance token 3 gets mapped to [0.3, -0.15, 1.4, ...] while token 4 gets mapped
to [-2.4, -0.014, 0.45, ...]&lt;&#x2F;p&gt;
&lt;p&gt;So the idea it to generate directly a token embedding (a vector in &lt;em&gt;d&lt;&#x2F;em&gt;-dimension), not necessarily a
discrete value (a number between 0 and vocabulary size).&lt;&#x2F;p&gt;
&lt;p&gt;In order to do that we need that all tokens should now be represented in the
same way by a &lt;em&gt;d&lt;&#x2F;em&gt; dimension space vector. One way to achieve that is to use an
autoencoder.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;upload.wikimedia.org&#x2F;wikipedia&#x2F;commons&#x2F;2&#x2F;28&#x2F;Autoencoder_structure.png&quot; alt=&quot;&quot; &#x2F;&gt;
or with code&lt;&#x2F;p&gt;
&lt;p&gt;The core idea is that when we encounter a new unseen token like &quot;ado&quot; it will still have
a representation through the VAE, and will probably be close to a known token like &quot;add&quot;.
This can help the network overcome odd tokenization or spelling errors.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt;# The name is VAE but I didn&amp;#39;t use the internal KL loss in the end as it prevented&#x2F;slowed down the learning.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; VAE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-inherited-class&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-inherited-class&quot;&gt;Module&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt;        super&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;VAE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;CONTEXT_SIZE&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; nn&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 400&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc21&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc22&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc3&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc4&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; encode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;        #&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; x is [Batch, Context size, Embedding dim]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;view&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; F&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc21&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc22&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; reparameterize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0.5&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        eps&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;randn_like&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;std&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; eps&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; std&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; decode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        h3&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; F&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;tanh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;            self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;view&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;CONTEXT_SIZE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; forward&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;encode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        z&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;reparameterize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;decode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;final-network&quot;&gt;Final network&lt;a class=&quot;zola-anchor&quot; href=&quot;#final-network&quot; aria-label=&quot;Anchor link for: final-network&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;img src=&quot;&#x2F;images&#x2F;model-based-2.png&quot;&#x2F;&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Here is a summary of the values of the tokenization we got.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;&#x2F;th&gt;&lt;th&gt;Raw&lt;&#x2F;th&gt;&lt;th&gt;BPE&lt;&#x2F;th&gt;&lt;th&gt;Model based&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Vocabulary size&lt;&#x2F;td&gt;&lt;td&gt;256&lt;&#x2F;td&gt;&lt;td&gt;10000&lt;&#x2F;td&gt;&lt;td&gt;26262&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;#Tokens&lt;&#x2F;td&gt;&lt;td&gt;387k&lt;&#x2F;td&gt;&lt;td&gt;90k&lt;&#x2F;td&gt;&lt;td&gt;92k&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Avg token length&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;3.3&lt;&#x2F;td&gt;&lt;td&gt;6.65&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Here is a excerpt of the kind of tokenization we created&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;i&gt;|He w|as on|e of|
the |most |n|oticea|ble member|s of the| Reform| Club|, |th|ough| he| s|eemed
|always |to |avoid |att|racting at|tention|; an en|ig|mat|i|cal |p|erson|age|,|
|ab|out whom l|ittle| was |known|, |e|xc|ept that |he| w|as |a |poli|shed m|an|
o|f |th|e |wo|rld|.  |Pe|ople sa|id| that h|e |re|sembl|ed| |Byron|--at least|
t|hat |his hea|d w|as |Byronic|; |but| he was |a |b|earde|d, tranquil| Byron|,
who| |might live| on a |thousand year|s |w|ithout g|r|owing o|ld|.|

|Certainly| an| English|man|, it |was |m|ore |doubt|ful w|h|ether |Phileas Fogg|
w|as |a |London|er|.&lt;&#x2F;i&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;txt&#x2F;80day_tokenized_exp2.txt&quot;&gt;Full text&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This version has been done with epsilon=0.0015.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, &quot;Phileas Fogg&quot; is already a token in this situation, which is a multi-word token not
achievable by regular BPE. You can also see, a lot of words contain only single bytes tokens which
is why this method compresses LESS than regular BPE at the same vocabulary size.
Another note is that classical words like &quot;was&quot; is already a token (in the last sentence) but it&#x27;s not always
the case, this token is context dependent now !&lt;&#x2F;p&gt;
&lt;h2 id=&quot;vae&quot;&gt;VAE&lt;a class=&quot;zola-anchor&quot; href=&quot;#vae&quot; aria-label=&quot;Anchor link for: vae&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;After the VAE step, the reconstruction is not perfect yet perfectly legible.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;i&gt;|He w|as on|e of|
the |most |n|oticea|ihe member|s of the| reform| Club|, |th|ough| he| s|eemed
|always |to |asoid |att|nacting at|tention|, an en|ig|mat|i|cal |p|erson|age|,|
|ab|
it whom l|ittle| was | nown|, |e|xc| pt that |he| w|as |a |poli|shed m|an|
o|f |th|e |wo|rld|.  |Pe|ople sa|id| that h|e |re|sembl|ed| |pyron| cat least|
t|hat |has hea|d w|as |blronic|; |but| he was |a |b|earde|in tranquil| pyron|
who| |eight live| on a |dar  and year|s |w|ithout g|r|owing o|ld|.|

|rertainly| an| English|man|, it |was |m|ore |doubt|ful w|h|ether |Phileas Fogg|
w|as |a |London|er|.&lt;&#x2F;i&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;txt&#x2F;80day_reconstructed2.txt&quot;&gt;Full text&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Most of the errors tend to lie in the first characters of &lt;em&gt;long tokens&lt;&#x2F;em&gt;.That&#x27;s because, I&#x27;m forced to padd
the input of the VAE and to mask that padding. In practice that means that the first characters of long tokens get updated
less that the others so necessarily they contain more errors. &lt;a href=&quot;https:&#x2F;&#x2F;nodata.dev&#x2F;2019&#x2F;08&#x2F;06&#x2F;model-based-bpe-encodings-3&#x2F;#notes&quot;&gt;More information&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;upper-level&quot;&gt;Upper level&lt;a class=&quot;zola-anchor&quot; href=&quot;#upper-level&quot; aria-label=&quot;Anchor link for: upper-level&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;In order to complete the experiment, we need to check that the original language model
done directly at BPE level can be done with this new model-based BPE encoding.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s pretty slow to train that upper level because we need to flow the
gradients all the way through the VAE decoder, and the lower layer decoding
step, in order to get the &lt;strong&gt;character level loss&lt;&#x2F;strong&gt; (softmax + nll_loss) to properly train something.
That&#x27;s a limit of the current approach.&lt;&#x2F;p&gt;
&lt;p&gt;If we randomly split the text into train&amp;amp;validation, we can learn almost perfectly (97% top-1 character level accuracy)
the language model on top of that Model based BPE.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-overfit.png&quot;&#x2F;&gt;
&lt;p&gt;However this can be considered &lt;strong&gt;overfitting&lt;&#x2F;strong&gt; because even though a specific input
was never seen in the valid set, a very close one &lt;em&gt;was&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If instead we try to compare with a fixed split, where the last part of the book
is considered the valid set, then we get much lower result.&lt;&#x2F;p&gt;
&lt;p&gt;We could achieve 25% exact character matching, and ~77%
top-10 character matching on the valid set, which is the end of the book !
The same results happen with BPE, even worse ! we can&#x27;t get past 13% top-1 and 25% top-10
on the regular BPE. That&#x27;s understandable because the dataset is very small and
the last part of the book is different so it&#x27;s very hard to infer it from just the
beginning and no other text.&lt;&#x2F;p&gt;
&lt;p&gt;Another note, is that model based BPE are not tokenizing deterministicly, there
is some variance to it, depending on the context of a particular word.
This actually seems to be a good property (See &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1804.10959&quot;&gt;this&lt;&#x2F;a&gt;) and
might explain away the better performance of model based BPE over regular BPE.
Keep in mind it&#x27;s 25% of the &lt;strong&gt;characters&lt;&#x2F;strong&gt; that are correct.
If we looked at a discrete view of &lt;strong&gt;tokens&lt;&#x2F;strong&gt; we probably would have a much higher prediction rate (it&#x27;s left for future work for now).&lt;&#x2F;p&gt;
&lt;p&gt;Here is a picture from the tensorboard values, P_1 is probability that the
character predicted is the correct one, P_10 is that it is in the top-10
values.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-upper.png&quot;&#x2F;&gt;
&lt;p&gt;The overfitting starts happening around the ~1M steps mark.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;notes&quot;&gt;Notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#notes&quot; aria-label=&quot;Anchor link for: notes&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;In the experiment we learned model by model, freezing the lower model
before training something on top. It&#x27;s because the batching of different
layers occur differently. Learning the whole thing end-to-end is probably going
to need some thought. The batching is easy for the lower level, every batch
needs a tensor of shape CONTEXT_SIZE (=64) of [0-255] ints. For the VAE, we
need to have a variable length (depending on the length token) times EMBEDDING_DIM
(=128). The upper level needs only tensors of size CONTEXT_SIZE *
EMBEDDING_DIM yet if we want to try and end-to-end training, we have &lt;strong&gt;no
idea&lt;&#x2F;strong&gt; how many bytes we need to generate 1 correct tensor in the upper layer.
We know it&#x27;s no more than CONTEXT_SIZE² but that would be prohibitive to use
that value.&lt;&#x2F;li&gt;
&lt;li&gt;The loss NEEDS to always be the byte-level nll loss. At first I thought a
simple MSE loss in the embedding space could be enough to learn the proper
models. It seems to not be the case. I could only achieve meaningful results by
always referring to the original strings and calculating the NLL Loss. When
using this loss, the MSE actually &lt;em&gt;increases&lt;&#x2F;em&gt;. This leads me to think that
encoding&#x2F;decoding + softmax are highly anisotropic operators. Looking at the
singular values of the embedding matrix, we can see that the highest one is
7.35, the lowest one 0.12, so there are 2 orders of magnitude between the 2.
This anisotropy means that the MSE loss which considers all dimensions of the
embeddding equal is actually couting way too much some irrelevant dimensions.
It would be much faster and simpler if we could train directly on MSE (it would
enable us to train without running all the decoding steps to generate the
loss). So we need to add some spectral loss on the embedding on the lower
language model to test that hypothesis.&lt;&#x2F;li&gt;
&lt;li&gt;The tokens have variable lengths. In order to fix this, we have to padd all
sequences during learning. Because we padd, we have to mask the padding
during training for both VAE and upper LM. Keeping track of this is pretty
nifty and it means gradients on rarely used places will rarely get updated. So
we will almost surely miss some letters in our tokens. Either at the front or
the end of the token depending on how we padd the tokens.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;future-work&quot;&gt;&lt;strong&gt;Future work&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#future-work&quot; aria-label=&quot;Anchor link for: future-work&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Actually testing discretizing the tokens to compare with the regular BPE. In that direction,
also comparing with a randomized tokenizer as used in &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;sentencepiece&quot;&gt;SentencePiece&lt;&#x2F;a&gt;
to make sure the results are actually comparable and are indeed linked to tokenization variance.&lt;&#x2F;li&gt;
&lt;li&gt;The masking problem really seems to be a current limit of the model. Finding a workaround would be really valuable.&lt;&#x2F;li&gt;
&lt;li&gt;The fact that the NLL loss is required slows down upper layers. It would be awesome if we could smooth out
the encoding&#x2F;decoding matrix so that L2 directly for VAE and the upper layer works. It probably goes against regular
language model embedding so not sure it&#x27;s doable.&lt;&#x2F;li&gt;
&lt;li&gt;Making the epsilon based tokenization directly after the embedding layer. This would help &lt;em&gt;stack&lt;&#x2F;em&gt; those levels hopefully learning
higher and higer representations of text leading the sentence embedding and so on.&lt;&#x2F;li&gt;
&lt;li&gt;On the same idea, another direction would be to do actual discrete tokenization to allow for the models to stack.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Model based encodings (2)</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2019-06-06T00:00:00+00:00</published>
		<updated>2019-06-06T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2019/06/06/model-based-bpe-encodings-2/"/>
		<link rel="alternate" href="https://nodata.dev/2019/06/06/model-based-bpe-encodings-2/" type="text/html"/>
		<id>https://nodata.dev/2019/06/06/model-based-bpe-encodings-2/</id>
		<content type="html">&lt;p&gt;In the &lt;a href=&quot;&#x2F;2019&#x2F;05&#x2F;16&#x2F;model-based-bpe-encodings&#x2F;&quot;&gt;first segment&lt;&#x2F;a&gt;
we looked into how we could make a BPE
based encoding, not only based on frequency in the dataset, but directly on the
model probability measure of the next token. In that article I mention that
dynamic BPE are costly because they stop being a one time operation but have to
be done for every batch because the vocabulary might have changed. In this
article I try to completely remove the “static” BPE approach and replace it
completely with ML blocks.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;h1 id=&quot;tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot;&gt;TL;DR In this article we present an idea to replace classical BPE algorithm with a pure ML version of it.&lt;a class=&quot;zola-anchor&quot; href=&quot;#tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot; aria-label=&quot;Anchor link for: tl-dr-in-this-article-we-present-an-idea-to-replace-classical-bpe-algorithm-with-a-pure-ml-version-of-it&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-is-the-goal&quot;&gt;What is the goal ?&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-is-the-goal&quot; aria-label=&quot;Anchor link for: what-is-the-goal&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;So the goal is to replace BPE algorithm. So it’s go from something like&lt;&#x2F;p&gt;
&lt;p&gt;“T|h|e| |c|a|t| |a|t|e| |t|h|e| |a|p|p|l|e|.”&lt;&#x2F;p&gt;
&lt;p&gt;To something that has less elements :&lt;&#x2F;p&gt;
&lt;p&gt;“The |ca|t |at|e |the| |app|le|.”&lt;&#x2F;p&gt;
&lt;p&gt;In one sentence, BPE fuses bytes to form tokens based on frequency in the full
dataset. For a more detailed example, look that &lt;a href=&quot;&#x2F;2019&#x2F;05&#x2F;16&#x2F;model-based-bpe-encodings&#x2F;&quot;&gt;the previous
article&lt;&#x2F;a&gt;.
In this example, you can see there is always a split after a space. That’s a
limitation of BPE so actually our target might look different, maybe more like&lt;&#x2F;p&gt;
&lt;p&gt;“The cat |at|e |the app|le|.”&lt;&#x2F;p&gt;
&lt;p&gt;Here we can notice that “The cat” is a full token and contain 2 actual words.
So the goal is to fuse some starting bytes into N tokens (let’s say ~10k) that
hopefully capture regularities in our dataset and are at least correlated to
frequency in the original dataset like BPE was.&lt;&#x2F;p&gt;
&lt;p&gt;Another property we need to have from BPE is that it can encode an arbitrary
string of text. It does not matter if it’s not the same language or even if it
makes sense, you CAN encode it, that is a very desirable property. It avoids
the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;cisco-emerge&#x2F;creating-semantic-representations-of-out-of-vocabulary-words-for-common-nlp-tasks-842dbdafba18&quot;&gt;out-of-vocabulary&lt;&#x2F;a&gt; problem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;approach&quot;&gt;Approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#approach&quot; aria-label=&quot;Anchor link for: approach&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;tokenization&quot;&gt;Tokenization&lt;a class=&quot;zola-anchor&quot; href=&quot;#tokenization&quot; aria-label=&quot;Anchor link for: tokenization&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;So let’s imagine we have a trained transformer like
&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;openai.com&#x2F;blog&#x2F;better-language-models&#x2F;&quot;&gt;GPT-2&lt;&#x2F;a&gt;. But trained on bytes
directly NOT on tokens like the original transformer. Now we can use the idea
that when a model is highly confident, it probably means that what it’s about
to predict is “in the same token”. Let’s take an example. Try to predict the
following Character (as in a single letter) in the next 2 sentences&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Sentence 1: “Who are yo…”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Sentence 2 : “I like …”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;In the first sentence, normally you would vote with very high confidence for
“u”, whereas in the second sentence, you lack a lot of context to be exactly
sure on what’s coming next. So “you” would be a token, whereas “like …” can’t
be a single token, it has to be at least 2, &quot;like &quot; and &quot;…&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a small gif of actual probabilities of the language model on a small sentence&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-approach.gif&quot;&#x2F;&gt;
&lt;p&gt;You can see the in the left of the graph the probabilities drop, those are the
tokens that try to get predicted but are missing context (because we have very
few characters before them. For the right side, you can see the drops in probability
are pretty consistent and correspond to word boundaries most often.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;handling-unknown-tokens&quot;&gt;Handling unknown tokens&lt;a class=&quot;zola-anchor&quot; href=&quot;#handling-unknown-tokens&quot; aria-label=&quot;Anchor link for: handling-unknown-tokens&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;p&gt;Now we know how we are going to “fuse” characters, but we are not done yet. BPE
tokens are a discrete SET of identified values from 0 to N (~10k in this
experiment). Also BPE can encode an arbitrary new string by using it’s fusion
table. So we can’t just run our algorithm on some specific dataset, count all
the tokens created and declare that these are the N tokens for eternity. Let’s
imagine I feed my algorithm a new sentence, in a different language, French for
instance.&lt;&#x2F;p&gt;
&lt;p&gt;“J’adore l’Italie.”&lt;&#x2F;p&gt;
&lt;p&gt;We can run our “tokenizer” on this, and receive something like this&lt;&#x2F;p&gt;
&lt;p&gt;“J|’|ado|re |l’|Ita|lie.”&lt;&#x2F;p&gt;
&lt;p&gt;Now “ado” might not be in our original list, so what do we do with it ? Do we
declare the token wrong and split it ? That would be odd.&lt;&#x2F;p&gt;
&lt;p&gt;A key insight, is to remember that the first step of the discrete “token” once
it enters the model (all of them do that, it’s really not specific to
transformer or GPT-2) it gets embedded, meaning we go from a number between 1
and N, to a vector in &lt;em&gt;d&lt;&#x2F;em&gt; dimension space (&lt;em&gt;d&lt;&#x2F;em&gt; is between 100 and 1000 generally).&lt;&#x2F;p&gt;
&lt;p&gt;For instance token 3 gets mapped to [0.3, -0.15, 1.4, ...] while token 4 gets mapped
to [-2.4, -0.014, 0.45, ...]&lt;&#x2F;p&gt;
&lt;p&gt;So the idea it to generate directly a token embedding (a vector in &lt;em&gt;d&lt;&#x2F;em&gt;-dimension), not necessarily a
discrete value (a number between 0 and vocabulary size).&lt;&#x2F;p&gt;
&lt;p&gt;In order to do that we need that all tokens should now be represented in the
same way by a &lt;em&gt;d&lt;&#x2F;em&gt; dimension space vector. One way to achieve that is to use an
autoencoder.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;upload.wikimedia.org&#x2F;wikipedia&#x2F;commons&#x2F;2&#x2F;28&#x2F;Autoencoder_structure.png&quot; alt=&quot;&quot; &#x2F;&gt;
or with code&lt;&#x2F;p&gt;
&lt;p&gt;The core idea is that when we encounter a new unseen token like &quot;ado&quot; it will still have
a representation through the VAE, and will probably be close to a known token like &quot;add&quot;.
This can help the network overcome odd tokenization or spelling errors.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt;# The name is VAE but I didn&amp;#39;t use the internal KL loss in the end as it prevented&#x2F;slowed down the learning.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-type&quot;&gt; VAE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-inherited-class&quot;&gt;nn&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-other z-inherited-class&quot;&gt;Module&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support z-type z-python&quot;&gt;        super&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;VAE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function z-magic z-python&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;CONTEXT_SIZE&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; nn&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;Linear&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 400&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc21&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc22&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc3&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt;fc4&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt; layer&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; encode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment&quot;&gt;        #&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment&quot;&gt; x is [Batch, Context size, Embedding dim]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        x&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;view&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;M&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; F&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc21&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc22&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; reparameterize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;exp&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;0.5&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        eps&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;randn_like&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;std&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; eps&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; std&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; decode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        h3&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; F&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;relu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; torch&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;tanh&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt;            self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;fc4&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;h3&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;view&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;CONTEXT_SIZE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; config&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;EMBEDDING_DIM&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;        )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-function z-python&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt; forward&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function z-language z-special z-self z-python&quot;&gt;self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter&quot;&gt; x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;encode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;x&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;        z&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;reparameterize&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword z-control z-flow z-python&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; mu&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; logvar&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language z-special z-self z-python&quot;&gt; self&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-python&quot;&gt;decode&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-arguments z-python&quot;&gt;z&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;final-network&quot;&gt;Final network&lt;a class=&quot;zola-anchor&quot; href=&quot;#final-network&quot; aria-label=&quot;Anchor link for: final-network&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;img src=&quot;&#x2F;images&#x2F;model-based-2.png&quot;&#x2F;&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Here is a summary of the values of the tokenization we got.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;&#x2F;th&gt;&lt;th&gt;Raw&lt;&#x2F;th&gt;&lt;th&gt;BPE&lt;&#x2F;th&gt;&lt;th&gt;Model based&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Vocabulary size&lt;&#x2F;td&gt;&lt;td&gt;256&lt;&#x2F;td&gt;&lt;td&gt;10000&lt;&#x2F;td&gt;&lt;td&gt;26262&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;#Tokens&lt;&#x2F;td&gt;&lt;td&gt;387k&lt;&#x2F;td&gt;&lt;td&gt;90k&lt;&#x2F;td&gt;&lt;td&gt;92k&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Avg token length&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;3.3&lt;&#x2F;td&gt;&lt;td&gt;6.65&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Here is a excerpt of the kind of tokenization we created&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;i&gt;|He w|as on|e of|
the |most |n|oticea|ble member|s of the| Reform| Club|, |th|ough| he| s|eemed
|always |to |avoid |att|racting at|tention|; an en|ig|mat|i|cal |p|erson|age|,|
|ab|out whom l|ittle| was |known|, |e|xc|ept that |he| w|as |a |poli|shed m|an|
o|f |th|e |wo|rld|.  |Pe|ople sa|id| that h|e |re|sembl|ed| |Byron|--at least|
t|hat |his hea|d w|as |Byronic|; |but| he was |a |b|earde|d, tranquil| Byron|,
who| |might live| on a |thousand year|s |w|ithout g|r|owing o|ld|.|

|Certainly| an| English|man|, it |was |m|ore |doubt|ful w|h|ether |Phileas Fogg|
w|as |a |London|er|.&lt;&#x2F;i&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;txt&#x2F;80day_tokenized_exp2.txt&quot;&gt;Full text&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This version has been done with epsilon=0.0015.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, &quot;Phileas Fogg&quot; is already a token in this situation, which is a multi-word token not
achievable by regular BPE. You can also see, a lot of words contain only single bytes tokens which
is why this method compresses LESS than regular BPE at the same vocabulary size.
Another note is that classical words like &quot;was&quot; is already a token (in the last sentence) but it&#x27;s not always
the case, this token is context dependent now !&lt;&#x2F;p&gt;
&lt;h2 id=&quot;vae&quot;&gt;VAE&lt;a class=&quot;zola-anchor&quot; href=&quot;#vae&quot; aria-label=&quot;Anchor link for: vae&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;After the VAE step, the reconstruction is not perfect yet perfectly legible.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;i&gt;|He w|as on|e of|
the |most |n|oticea|ihe member|s of the| reform| Club|, |th|ough| he| s|eemed
|always |to |asoid |att|nacting at|tention|, an en|ig|mat|i|cal |p|erson|age|,|
|ab|
it whom l|ittle| was | nown|, |e|xc| pt that |he| w|as |a |poli|shed m|an|
o|f |th|e |wo|rld|.  |Pe|ople sa|id| that h|e |re|sembl|ed| |pyron| cat least|
t|hat |has hea|d w|as |blronic|; |but| he was |a |b|earde|in tranquil| pyron|
who| |eight live| on a |dar  and year|s |w|ithout g|r|owing o|ld|.|

|rertainly| an| English|man|, it |was |m|ore |doubt|ful w|h|ether |Phileas Fogg|
w|as |a |London|er|.&lt;&#x2F;i&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;txt&#x2F;80day_reconstructed2.txt&quot;&gt;Full text&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Most of the errors tend to lie in the first characters of &lt;em&gt;long tokens&lt;&#x2F;em&gt;.That&#x27;s because, I&#x27;m forced to padd
the input of the VAE and to mask that padding. In practice that means that the first characters of long tokens get updated
less that the others so necessarily they contain more errors. &lt;a href=&quot;https:&#x2F;&#x2F;nodata.dev&#x2F;2019&#x2F;06&#x2F;06&#x2F;model-based-bpe-encodings-2&#x2F;#notes&quot;&gt;More information&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;upper-level&quot;&gt;Upper level&lt;a class=&quot;zola-anchor&quot; href=&quot;#upper-level&quot; aria-label=&quot;Anchor link for: upper-level&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;In order to complete the experiment, we need to check that the original language model
done directly at BPE level can be done with this new model-based BPE encoding.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s pretty slow to train that upper level because we need to flow the
gradients all the way through the VAE decoder, and the lower layer decoding
step, in order to get the &lt;strong&gt;character level loss&lt;&#x2F;strong&gt; (softmax + nll_loss) to properly train something.
That&#x27;s a limit of the current approach.&lt;&#x2F;p&gt;
&lt;p&gt;If we randomly split the text into train&amp;amp;validation, we can learn almost perfectly (97% top-1 character level accuracy)
the language model on top of that Model based BPE.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-overfit.png&quot;&#x2F;&gt;
&lt;p&gt;However this can be considered &lt;strong&gt;overfitting&lt;&#x2F;strong&gt; because even though a specific input
was never seen in the valid set, a very close one &lt;em&gt;was&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If instead we try to compare with a fixed split, where the last part of the book
is considered the valid set, then we get much lower result.&lt;&#x2F;p&gt;
&lt;p&gt;We could achieve 25% exact character matching, and ~77%
top-10 character matching on the valid set, which is the end of the book !
The same results happen with BPE, even worse ! we can&#x27;t get past 13% top-1 and 25% top-10
on the regular BPE. That&#x27;s understandable because the dataset is very small and
the last part of the book is different so it&#x27;s very hard to infer it from just the
beginning and no other text.&lt;&#x2F;p&gt;
&lt;p&gt;Another note, is that model based BPE are not tokenizing deterministicly, there
is some variance to it, depending on the context of a particular word.
This actually seems to be a good property (See &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1804.10959&quot;&gt;this&lt;&#x2F;a&gt;) and
might explain away the better performance of model based BPE over regular BPE.
Keep in mind it&#x27;s 25% of the &lt;strong&gt;characters&lt;&#x2F;strong&gt; that are correct.
If we looked at a discrete view of &lt;strong&gt;tokens&lt;&#x2F;strong&gt; we probably would have a much higher prediction rate (it&#x27;s left for future work for now).&lt;&#x2F;p&gt;
&lt;p&gt;Here is a picture from the tensorboard values, P_1 is probability that the
character predicted is the correct one, P_10 is that it is in the top-10
values.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;images&#x2F;models-2-upper.png&quot;&#x2F;&gt;
&lt;p&gt;The overfitting starts happening around the ~1M steps mark.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;notes&quot;&gt;Notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#notes&quot; aria-label=&quot;Anchor link for: notes&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;In the experiment we learned model by model, freezing the lower model
before training something on top. It&#x27;s because the batching of different
layers occur differently. Learning the whole thing end-to-end is probably going
to need some thought. The batching is easy for the lower level, every batch
needs a tensor of shape CONTEXT_SIZE (=64) of [0-255] ints. For the VAE, we
need to have a variable length (depending on the length token) times EMBEDDING_DIM
(=128). The upper level needs only tensors of size CONTEXT_SIZE *
EMBEDDING_DIM yet if we want to try and end-to-end training, we have &lt;strong&gt;no
idea&lt;&#x2F;strong&gt; how many bytes we need to generate 1 correct tensor in the upper layer.
We know it&#x27;s no more than CONTEXT_SIZE² but that would be prohibitive to use
that value.&lt;&#x2F;li&gt;
&lt;li&gt;The loss NEEDS to always be the byte-level nll loss. At first I thought a
simple MSE loss in the embedding space could be enough to learn the proper
models. It seems to not be the case. I could only achieve meaningful results by
always referring to the original strings and calculating the NLL Loss. When
using this loss, the MSE actually &lt;em&gt;increases&lt;&#x2F;em&gt;. This leads me to think that
encoding&#x2F;decoding + softmax are highly anisotropic operators. Looking at the
singular values of the embedding matrix, we can see that the highest one is
7.35, the lowest one 0.12, so there are 2 orders of magnitude between the 2.
This anisotropy means that the MSE loss which considers all dimensions of the
embeddding equal is actually couting way too much some irrelevant dimensions.
It would be much faster and simpler if we could train directly on MSE (it would
enable us to train without running all the decoding steps to generate the
loss). So we need to add some spectral loss on the embedding on the lower
language model to test that hypothesis.&lt;&#x2F;li&gt;
&lt;li&gt;The tokens have variable lengths. In order to fix this, we have to padd all
sequences during learning. Because we padd, we have to mask the padding
during training for both VAE and upper LM. Keeping track of this is pretty
nifty and it means gradients on rarely used places will rarely get updated. So
we will almost surely miss some letters in our tokens. Either at the front or
the end of the token depending on how we padd the tokens.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;future-work&quot;&gt;&lt;strong&gt;Future work&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#future-work&quot; aria-label=&quot;Anchor link for: future-work&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Actually testing discretizing the tokens to compare with the regular BPE. In that direction,
also comparing with a randomized tokenizer as used in &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;sentencepiece&quot;&gt;SentencePiece&lt;&#x2F;a&gt;
to make sure the results are actually comparable and are indeed linked to tokenization variance.&lt;&#x2F;li&gt;
&lt;li&gt;The masking problem really seems to be a current limit of the model. Finding a workaround would be really valuable.&lt;&#x2F;li&gt;
&lt;li&gt;The fact that the NLL loss is required slows down upper layers. It would be awesome if we could smooth out
the encoding&#x2F;decoding matrix so that L2 directly for VAE and the upper layer works. It probably goes against regular
language model embedding so not sure it&#x27;s doable.&lt;&#x2F;li&gt;
&lt;li&gt;Making the epsilon based tokenization directly after the embedding layer. This would help &lt;em&gt;stack&lt;&#x2F;em&gt; those levels hopefully learning
higher and higer representations of text leading the sentence embedding and so on.&lt;&#x2F;li&gt;
&lt;li&gt;On the same idea, another direction would be to do actual discrete tokenization to allow for the models to stack.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Model based encodings</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2019-05-16T00:00:00+00:00</published>
		<updated>2019-05-16T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2019/05/16/model-based-bpe-encodings/"/>
		<link rel="alternate" href="https://nodata.dev/2019/05/16/model-based-bpe-encodings/" type="text/html"/>
		<id>https://nodata.dev/2019/05/16/model-based-bpe-encodings/</id>
		<content type="html">&lt;p&gt;&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Byte_pair_encoding&quot;&gt;Byte-pair encodings&lt;&#x2F;a&gt; (BPE) are now very commonly used in NLP. In &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;openai.com&#x2F;blog&#x2F;better-language-models&#x2F;&quot;&gt;GPT-2&lt;&#x2F;a&gt;, Byte-pair encodings are used to preformat the raw texts before feeding the model. But this is a relatively costly step for your preprocessing and has some limitations. For instance, you have to split your data on spaces if you want your byte pair algorithm to compute in reasonable time.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;h1 id=&quot;tl-dr-in-this-article-we-present-an-idea-to-generate-byte-pair-encodings-not-based-on-frequency-in-the-dataset-but-on-the-quality-of-the-prediction-of-our-model-this-enables-us-to-predict-multi-word-tokens-like-new-york-and-address-languages-that-don-t-use-spaces-to-split-words&quot;&gt;TL;DR In this article we present an idea to generate Byte pair encodings, not based on frequency in the dataset, but on the quality of the prediction of our model. This enables us to predict multi word tokens like &quot;New York&quot; and address languages that don&#x27;t use spaces to split words.&lt;a class=&quot;zola-anchor&quot; href=&quot;#tl-dr-in-this-article-we-present-an-idea-to-generate-byte-pair-encodings-not-based-on-frequency-in-the-dataset-but-on-the-quality-of-the-prediction-of-our-model-this-enables-us-to-predict-multi-word-tokens-like-new-york-and-address-languages-that-don-t-use-spaces-to-split-words&quot; aria-label=&quot;Anchor link for: tl-dr-in-this-article-we-present-an-idea-to-generate-byte-pair-encodings-not-based-on-frequency-in-the-dataset-but-on-the-quality-of-the-prediction-of-our-model-this-enables-us-to-predict-multi-word-tokens-like-new-york-and-address-languages-that-don-t-use-spaces-to-split-words&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-are-byte-pair-encodings&quot;&gt;What are Byte Pair Encodings ?&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-are-byte-pair-encodings&quot; aria-label=&quot;Anchor link for: what-are-byte-pair-encodings&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Byte-pair encodings are a way to compress information from pairs of bytes that will form tokens. Let&#x27;s take an example :&lt;&#x2F;p&gt;
&lt;p&gt;&quot;I love carrots and I love apples.&quot;&lt;&#x2F;p&gt;
&lt;p&gt;This sentence read by a computer is only a sequence of bytes (bytes are simply a number between 0 and 255). That means to a computer our sentence looks like&lt;&#x2F;p&gt;
&lt;p&gt;&quot;I love carrots and I love apples.&quot; -&amp;gt; [73, 32, 108, 111, 118, 101, 32, 99, 97, 114, 114, 111, 116, 115, 32, 97, 110, 100, 32, 73, 32, 108, 111, 118, 101, 32, 97, 112, 112, 108, 101, 115, 46]&lt;&#x2F;p&gt;
&lt;p&gt;From that example, you may remark that some bytes are occurring multiple times together like [108, 111] that occurs twice (it&#x27;s &quot;lo&quot; from &quot;love&quot;). So let&#x27;s build a new token for this frequent pair. Numbers from 0 to 255 are already taken so we&#x27;ll take the next available number which is 256, and we are going to store that information in a table&lt;&#x2F;p&gt;
&lt;p&gt;[108, 111] -&amp;gt; 256&lt;&#x2F;p&gt;
&lt;p&gt;Now if we use that new token to encode our original bytes, whenever we encounter [108, 111], we&#x27;ll replace that by 256, so the original byte string becomes :&lt;&#x2F;p&gt;
&lt;p&gt;[73, 32, 108, &lt;strong&gt;256&lt;&#x2F;strong&gt;, 101, 32, 99, 97, 114, 114, 111, 116, 115, 32, 97, 110, 100, 32, 73, 32, &lt;strong&gt;256&lt;&#x2F;strong&gt;, 118, 101, 32, 97, 112, 112, 108, 101, 115, 46]&lt;&#x2F;p&gt;
&lt;p&gt;We went from 33 numbers to 31 numbers. We can rinse and repeat to compress the number of numbers even further. Originally, BPE was proposed as a compression algorithm. It&#x27;s not the best compression tool, so we won&#x27;t look at that side of the algorithm. Now you get what we are looking at when we train a model on BPEs, just a list of numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Typically a BPE vocabulary contains ~10k tokens (GPT-2 has 50k), that means it can capture very frequent words like &quot;the&quot; entirely, and parts of words that contain many variations like &quot;ment&quot; (&lt;strong&gt;ment&lt;&#x2F;strong&gt;ally, environ&lt;strong&gt;ment&lt;&#x2F;strong&gt; …). What&#x27;s great about it it that you can now have words share semantic parts of them for their representation in your model so (environ-ment, environ-ment-al, environ-ment-ally will all share &quot;environ&quot; which will contain most of the semantic meaning, the rest will contain grammar information hopefully).&lt;&#x2F;p&gt;
&lt;p&gt;The real advantage of BPE over classical Word Embeddings is that it does not fall into the out-of-vocabulary error (when a word was not seen). At worse you can always fall back to single bytes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-s-the-problem-with-bpe&quot;&gt;&lt;strong&gt;What’s the problem with BPE ?&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-s-the-problem-with-bpe&quot; aria-label=&quot;Anchor link for: what-s-the-problem-with-bpe&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;BPE algorithm is pretty bad in terms of complexity to calculate (roughly O(n²), you can look at a very good implementation &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;glample&#x2F;fastBPE&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;glample&#x2F;fastBPE&lt;&#x2F;a&gt;). BPE is also pretty bad when you want to encode some new text. A greedy algorithm will be O(n) but not the best encoding possible, the best encoding possible is actually O(n²) in the general case.&lt;&#x2F;p&gt;
&lt;p&gt;To be honest, most implementations split on spaces as mentioned earlier which speeds up the algorithm quite a bit. Once we have encoded a full word like “the” there is no way to add tokens to it, so it’s not necessary to look at it anymore for potential byte pairs, so we can assume the encoding&amp;amp;table creation go from O(n²) to something much closer to O(n). In addition, at encoding time, once we know the encoding for “the” we can cache that information leading to further speed ups. But using spaces as a special character has drawbacks, namely:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We can’t address as well languages that don’t use a space to separate words like Chinese (arguably German).&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;We can’t encode frequently occurring multi words like “New York” or “European Union” or “black holes”&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The second problem is especially bad when you consider examples where semantic is very different from the composing words like “Chicago Bulls” have nothing to do with bulls.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;e-bpe-or-model-based-bpe-encoding&quot;&gt;&lt;strong&gt;ε-BPE or model based BPE encoding&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#e-bpe-or-model-based-bpe-encoding&quot; aria-label=&quot;Anchor link for: e-bpe-or-model-based-bpe-encoding&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;The core idea is that instead of using frequency in the dataset to create the byte pairs, we can use the probability transition of the model to create the BPE. Let’s use some kind of transformer, GPT-2 for instance. The core idea of that model, is to predict the next token (in the BPE sense) given a fixed context size. But we can use the output probability of the model in order to create new tokens, not because they are frequent but because they are easy to predict. For instance in a book that contains a character &quot;Sir Francis&quot; that appears rarely, but there is only one character named &quot;Sir …&quot;, the algorithm might learn quite easily that &quot;Sir &quot; is followed by &quot;Francis&quot; with great confidence, even if the occurence of the words is pretty low compared to common words like &quot;the&quot;, &quot;like&quot; and &quot;I&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;So the core algorithm, will train a simple transformer on a dataset on regular bytes (at least at the start). Then, as the algorithm learns, some predictions will be above 1-ε. We can keep track of those and keep track of the last token we received, to check if we were correct.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s keep a hit map to see how successful our algorithm is. For instance, I predicted &quot;Fo&quot; will be followed by &quot;gg&quot; (Phileas Fogg is a character in Around the world in 80 days) with probability &amp;gt; 1-ε. I was correct in 14 cases, and got it wrong in 1 case (let&#x27;s say it was classical &quot;Fo&quot; &quot;g &quot;). We were correct 14&#x2F;15 times that&#x27;s 93% accuracy. If we look at the fluctuation interval associated with that, we get [92.74-93.25%] range. If 92.74 &amp;gt; 1–ε we can conclude that our transition prediction is really very good, it&#x27;s not a fluke of the model.&lt;&#x2F;p&gt;
&lt;p&gt;More generally, if we want 95% confidence when we upgrade this transition, we need to respect the following inequality : k &#x2F; n - 1&#x2F;sqrt(n) &amp;gt; 1-ε, where k is the number of successful predictions, n is the total number of predictions and ε the probability margin explained earlier.&lt;&#x2F;p&gt;
&lt;p&gt;This model is slightly different from byte pair encoding, but now we don’t suffer from the 2 problems mentioned above, we can get pretty long tokens if the dataset allows for it, and we can use Chinese or German as the space character does not play any special role.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;results&quot;&gt;&lt;strong&gt;Results&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Implementation can be found here. On the first run, we ran on a book &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Around_the_World_in_Eighty_Days&quot;&gt;Around the world in 80 days&lt;&#x2F;a&gt; by Jules Verne. It’s a very small dataset but the idea is to check that we can actually overcome BPE’s limitations. Here are a few telling tokens that were created while running on the dataset :&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Promotion #&lt;&#x2F;th&gt;&lt;th&gt;Token created&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;338&lt;&#x2F;td&gt;&lt;td&gt;&quot;Mr. Fogg&quot;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;357&lt;&#x2F;td&gt;&lt;td&gt;&quot;Phileas Fogg&quot;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;360&lt;&#x2F;td&gt;&lt;td&gt;&quot;Passepartout&quot;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;635&lt;&#x2F;td&gt;&lt;td&gt;&quot;ir Franc&quot; (Sir Francis)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;781&lt;&#x2F;td&gt;&lt;td&gt;&quot;It was&quot;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;900&lt;&#x2F;td&gt;&lt;td&gt;&#x27;&quot; asked&#x27; (contains a quote character)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;What is interesting, it that:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We managed to create multi word tokens like “Phileas Fogg”&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Multi word tokens are a minority in terms of tokens created by the algorithm. Out of 421 tokens that contain a space character only 27 are multi word tokens like “New York”. The remaining 394 tokens contain an ending space, meaning our algorithm is learning word boundaries. It is reassuring because traditional BPE are usually hardcoding that information.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Multi word tokens are name of characters in the book, which are occurring frequently, they are an entity by themselves (Fogg even has 2 tokens associated to him)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;2 Multi word tokens are &lt;strong&gt;not&lt;&#x2F;strong&gt; specific to the book, “it was” is a pretty common 2 word token in English in descriptions, “(…) asked” is a very common continuation when we start a quote and end a sentence with a question mark. We can guess that “(…) said” would be a token further down the line, but it’s harder as there are probably a wider variety of verbs that can fit (said, replied, answered and so on…)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here is a more complete comparison of standard BPE with ε-BPE, with the first 100 tokens generated, as you can see more tokens are dedicated to syntax in eBPE, which Standard BPE ignore gladly by splitting on newlines and spaces.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Standard BPE&lt;&#x2F;th&gt;&lt;th&gt;eBPE&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&#x27;th&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;the &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;, &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;an&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;d &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;in&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Th&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ou&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ve&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;er&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;y &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ed &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;; &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ar&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;f &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;hi&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;,\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;on&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;\r\n\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;re&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;th&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;en&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;qu&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;and &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;the&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;of &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27; &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;st&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;the &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;to &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;The&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;as &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;se&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;, &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr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#x2F;td&gt;&lt;td&gt;&#x27;d &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;at &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;y &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ro&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Th&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;er &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ve&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;al&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;f &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;es&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;; &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;on &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27; &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;was &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;,\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;no&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;th&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;his &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ed&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;, &#x27;&lt;&#x2F;td&gt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&gt;&#x27;ra&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;the&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;di&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;the &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;art&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;The&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;Fog&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;qu&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;the&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;s &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ma&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;The &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ve &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;g &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;is &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;,&quot;&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;or &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;no&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ld &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;t &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;whi&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;th &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;il&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;o &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ur&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;?&quot;&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;s, &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;\r\n\r\n&quot;&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;de&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;,&quot; &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;wh&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Mr&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;lo&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;e &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ch &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;yo&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ere &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Yo&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ith &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ou&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;The &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;. &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;am&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;nd &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ent&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;h &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;un&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;n &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;gh&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;;\r\n&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;with &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;og&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;an &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;you&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;oun&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;r &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;part&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;of &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ver&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;to &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;si&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;s F&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;had &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Pa&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;not &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;as &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ould &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;&#x27;s &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ing&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;. F&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;out &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;is &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;el&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ld &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;sa&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ng &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ce&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;at &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;that &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;re&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;asse&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ve &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;fi&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;gh&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ol&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ut &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;sh&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ll&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;r. &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;Pas&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;.&quot;\r &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;re &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;Passe&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ed &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;Passepart&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;. Fog&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ut &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ch &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;which &#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;and &#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&#x27;ay&#x27;&lt;&#x2F;td&gt;&lt;td&gt;&#x27;ea&#x27;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;I would love to check the tokenization of German or Chinese but I’m not a speaker of either language so it’s hard for me to analyze the results anyway. What’s for sure is that the technique is applicable.&lt;&#x2F;p&gt;
&lt;p&gt;I also tried the technique on different types of files like wav files or mp3 files, even jpeg images. Analysis is harder to do. Still some interesting notes, it took longer for the model to emit new tokens on the mp3 files than on the wav files. The mp3 file is encoded, therefore should have a lower entropy (meaning it’s harder to predict the next token) than the wav files so the model takes longer to actually get good at predicting. It’s probable (I haven’t checked) that we have to overfit the mp3 file and jpeg files before we can predict any meaningful content (except maybe the header part)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;future-work&quot;&gt;&lt;strong&gt;Future Work&lt;&#x2F;strong&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#future-work&quot; aria-label=&quot;Anchor link for: future-work&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h2&gt;
&lt;p&gt;Many interesting ideas are still left to explore to continue exploring the idea of models creating their own tokenization. For now a limiting factor is the actual BPE encoding process that takes longer and longer as the model creates new tokens. That&#x27;s because the encoding process is done in Python, so it&#x27;s quite slow and can’t be precalculated as you would do with fixed BPE encodings. To give a sense of the slowdown, the training loop starts at ~11it&#x2F;s on a GTX970 and finished at roughly 10s&#x2F;it. That’s a 100x slowdown over the course of the training, with only 1k tokens in the end, far from the 50k used by GPT-2 for instance.&lt;&#x2F;p&gt;
&lt;p&gt;It’s going to be an actual requirement to train on larger and more representative datasets. Training on bigger datasets would help us understand how important are those multi word tokens and maybe what are those multi words. The token &quot;(…) &lt;strong&gt;asked&lt;&#x2F;strong&gt;&quot; was pretty surprising to me, I&#x27;m eager to see what else can be discovered.&lt;&#x2F;p&gt;
&lt;p&gt;The actual epsilon used was 40% which actually quite a big (value was chosen with trial and error, to get a small but not null rejection rate of new tokens, to add tokens as fast as possible but not making too many mistakes). That value probably has a sweet spot depending on the number of current tokens, after speeding up the process it would be interesting to look at the best value for epsilon as a function of the number of tokens.&lt;&#x2F;p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>A third of your math homework is useless</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2018-04-13T00:00:00+00:00</published>
		<updated>2018-04-13T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2018/04/13/a-third-of-your-math-homework-is-useless/"/>
		<link rel="alternate" href="https://nodata.dev/2018/04/13/a-third-of-your-math-homework-is-useless/" type="text/html"/>
		<id>https://nodata.dev/2018/04/13/a-third-of-your-math-homework-is-useless/</id>
		<content type="html">&lt;h1 id=&quot;a-third-of-your-math-work-is-useless&quot;&gt;A third of your math work is useless&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-third-of-your-math-work-is-useless&quot; aria-label=&quot;Anchor link for: a-third-of-your-math-work-is-useless&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;At Kwyk, we use AI to predict student’s performance, especially in maths. Our most recent results show that on &lt;strong&gt;one-third of the exercises&lt;&#x2F;strong&gt; given by the teacher &lt;strong&gt;we know beforehand that the student will succeed&lt;&#x2F;strong&gt;, raising the question of its usefulness. Despite the clickbait title &lt;em&gt;(sorry for that)&lt;&#x2F;em&gt;, the answer might not be as simple as you would expect. We are going to attempt to explain that &lt;strong&gt;the biggest threat in AI is not AI in itself, but our human over-interpretation of its results.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;a class=&quot;zola-anchor&quot; href=&quot;#introduction&quot; aria-label=&quot;Anchor link for: introduction&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;In this article, we will analyze prediction data done on 1 million maths exercises done between March 7th, 2018 and March, 23rd 2018 on &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.kwyk.fr&quot;&gt;Kwyk&lt;&#x2F;a&gt;. &lt;strong&gt;The predictions were done in real time.&lt;&#x2F;strong&gt; The training was done on a 5 Million exercises dataset from September and October 2016 results.&lt;&#x2F;p&gt;
&lt;p&gt;Kwyk is an online learning platform where students do their homework online. The students are age 11 to 18 and are assigned homework by teachers on the platform. Each individual has a different homework generated automatically, but all questions are equivalent in terms of difficulty : 1&#x2F;3 + 1&#x2F;2 is roughly the same as 2&#x2F;3 + 1&#x2F;4 for instance. Because homework is generated, students can retry anytime on a new version of the homework to get the best grade. They can also work freely on any given chapter at any times. To be fair, 90% of the activity is work assigned by teachers.&lt;&#x2F;p&gt;
&lt;p&gt;We also grade automatically every exercise, using &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Computer_algebra_system&quot;&gt;formal analysis&lt;&#x2F;a&gt;. This is how we evaluate if a student succeeded an exercise or not. What we evaluate is the &lt;strong&gt;probability of success of a student on a specific exercise.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;how-we-got-our-results&quot;&gt;How we got our results&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-we-got-our-results&quot; aria-label=&quot;Anchor link for: how-we-got-our-results&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;The results were obtained using an AdaBoost regression, on manually crafted features, which included various averages, including the student’s average on this particular chapter for instance. We also used automatically crafted features, which are sort of the map of maths, which we explain in detail &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;data-science&#x2F;a-non-nlp-application-of-word2vec-c637e35d3668&quot;&gt;here&lt;&#x2F;a&gt;. In total there are 10 manual features and 50 automatic features.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;results-summary&quot;&gt;Results summary&lt;a class=&quot;zola-anchor&quot; href=&quot;#results-summary&quot; aria-label=&quot;Anchor link for: results-summary&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;Now the results. First, we get an AUC score of 0.89. Unfortunately, we don’t have an expert reference (different teachers estimating success likelihood of students). Not having comparison points makes it really hard to evaluate if this score is interesting or not. We can only compare to previous versions of our algorithms, which started with AUC 0.72 so we definitely improved our assessment of students, you can read our other articles for details on our algorithms and how we assess them.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;a-third-1.png&quot; alt=&quot;&quot; &#x2F;&gt;
Area Under Curve of our predictions (Prediction data was evaluated in real time)&lt;&#x2F;p&gt;
&lt;p&gt;Out of the 1 Million exercises we assessed, we estimated on 300k exercises that the student would succeed over 95% of the times. They succeeded on average over 96% of the time. In other words,  our algorithm was able to predict that you knew how to do this exercise a third of the time. &lt;strong&gt;If this is so, was it really necessary for you to do it ?&lt;&#x2F;strong&gt; The temptation to answer no is exactly the problem that AI poses to us, humans.&lt;&#x2F;p&gt;
&lt;p&gt;On the other end of the spectrum, we estimated on 100k exercises that the student would succeed less than 5% of the times. In reality, they succeeded 10% of the times. So our algorithm is less accurate on low probabilities. This is expected as we don&#x27;t control what happens between exercises, so if a student asks for help or reviews his notes before answering, we have no way of capturing that in our data.&lt;&#x2F;p&gt;
&lt;p&gt;But in the end, it means that we roughly know a student’s result in advance on 40% of the questions asked by his teacher.&lt;&#x2F;p&gt;
&lt;p&gt;Overall you can see how precise is our algorithm on the following graph&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;a-third-2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Each dot is a group of predictions. The closer the dots are to the blue line, the better the prediction was for that group. The two big dots at each end are the one mentioned in this article.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;With AI we know a student&#x27;s result in advance on 40% of the questions asked by his teacher.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h1 id=&quot;discussion&quot;&gt;Discussion&lt;a class=&quot;zola-anchor&quot; href=&quot;#discussion&quot; aria-label=&quot;Anchor link for: discussion&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;So 40% of the time we know in advance with a small margin of error if a student is going to succeed at a specific exercise. Why is it that we should NOT conclude that it was a waste of time. There are two types of reasons for this.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The first type of reasons is over-interpretation of the results.&lt;&#x2F;strong&gt; The algorithm used tried to assess the likelihood of success of a given student. It was NOT to assess if it was necessary for this student to answer this question (which by the way is a much more difficult question to ask an algorithm). AI works by using correlations. So imagine a new student being transferred to an excellent class that never makes any mistake. An algorithm will most likely categorize this student as being very likely to succeed. This new student will be categorized as &quot;no need to work&quot; even if he did not do any exercise yet. This is obviously wrong.&lt;&#x2F;p&gt;
&lt;p&gt;The error is not in the algorithm, as most students that get transferred into excellent classes will be excellent students, the error is in us humans, that over-interpret what the algorithm says. The likelihood of success is not the proven mastery of a given subject, yet we humans will tend to think that both are the same because we estimate the likelihood of success with our estimate of a student&#x27;s mastery. AI does not work that way. Not understanding this is really the core of the problem with AI. Because we cannot ask our algorithms questions like humans, we need to find proxy questions that we hope will be close to our real questions. In our case the real question we would like to ask is &quot;What does this student know&quot;, and the proxy we found is &quot;How likely is he to succeed at this task&quot;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;AI forces us to change our real world vague questions into extremely specific proxy questions. The human confusion between the two questions is the biggest threat to integrating AI into our products.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;The same problem is found over and over. Facebook question should be &quot;How to maximize our users&#x27; happiness&quot;, and the proxy they use is &quot;How to maximize view time on our site&quot;. Google&#x27;s question is &quot;What is the answer to this user&#x27;s query&quot; and its proxy is &quot;What is the link with the lowest bounce rate on this user&#x27;s query ?&quot;. Understanding that there is a fundamental gap between the question we would like to ask our algorithm and the actual proxy we use is extremely important if we want to avoid errors in the future.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The second type is related to neuroscience and is specific to this problem&lt;&#x2F;strong&gt;. Suppose now that our proxy is perfectly valid to estimate a student&#x27;s mastery. Our prediction still does not take into account our human brains. We forget all the time. In order to memorize something, we need to recall it many times. &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Spaced_repetition&quot;&gt;Spaced repetition&lt;&#x2F;a&gt; is an example of how to take this into account. So even if you already know something, if you want to fix it in your memory you need to do it over and over at regular intervals. Once again, even if our algorithm knows that you know something in advance, it might be in your best interest to do the exercise anyway to fix the knowledge in your brain.&lt;&#x2F;p&gt;
&lt;p&gt;In addition to &lt;em&gt;memory&lt;&#x2F;em&gt;, the &lt;em&gt;student&#x27;s emotional state&lt;&#x2F;em&gt; is another variable that we might want to take into account when we look at the bigger picture of education.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;how-to-prevent-this-over-interpretation&quot;&gt;How to prevent this over-interpretation&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-to-prevent-this-over-interpretation&quot; aria-label=&quot;Anchor link for: how-to-prevent-this-over-interpretation&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;Exactly like the &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Simpson%27s_paradox&quot;&gt;Simpson&#x27;s paradox,&lt;&#x2F;a&gt; there is no silver bullet here. The main way to prevent over-interpreting is to be extremely conscious of the problem. We, as practitioners, need to be aware of the questions we asked our algorithm and to be extremely careful not to over-interpret the answers they give us. We also need to alert everyone else to the types of conclusions that should not be drawn from our results.&lt;&#x2F;p&gt;
&lt;p&gt;We can also multiply the different questions to ask our algorithms. If many specific algorithms seem to converge on their answers, maybe it is a hint that it could be a good answer to our human questions.&lt;&#x2F;p&gt;
&lt;p&gt;If only we could add dropout to our interpretations…&lt;&#x2F;p&gt;
&lt;h1 id=&quot;further-work&quot;&gt;Further work&lt;a class=&quot;zola-anchor&quot; href=&quot;#further-work&quot; aria-label=&quot;Anchor link for: further-work&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;At Kwyk we have many goals in order to improve overall student&#x27;s success. In addition to ever improving our student&#x27;s success estimate, we need to try and address the problems evoked in this article.&lt;&#x2F;p&gt;
&lt;p&gt;For instance, we are looking to take into account the sequencing of personalized sequences (the second type of problems). For this we still cannot ask the human questions, we need to find a proxy question. The proxy question will be &quot;What is the best strategy of homework to give a specific student to maximize his future likelihood of success on all exercises ?&quot;. For this, we will use RL approaches. Of course, we will necessarily encounter problems along the road but we hope we can come closer and closer to answering our real question which is &quot;How do we maximize each student&#x27;s success ?&quot;.&lt;&#x2F;p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>A non-NLP application of Word2Vec</title>
        <author>
            <name>nicolas</name>
        </author>
		<published>2017-07-31T00:00:00+00:00</published>
		<updated>2017-07-31T00:00:00+00:00</updated>
		<link href="https://nodata.dev/2017/07/31/a-non-nlp-application-of-word2vec/"/>
		<link rel="alternate" href="https://nodata.dev/2017/07/31/a-non-nlp-application-of-word2vec/" type="text/html"/>
		<id>https://nodata.dev/2017/07/31/a-non-nlp-application-of-word2vec/</id>
		<content type="html">&lt;p&gt;When using &lt;strong&gt;Machine Learning&lt;&#x2F;strong&gt; to solve a problem, having the right &lt;strong&gt;data&lt;&#x2F;strong&gt; is crucial. Unfortunately, raw data is often “unclean” and &lt;strong&gt;unstructured&lt;&#x2F;strong&gt;. &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Natural_language_processing&quot;&gt;Natural Language Processing&lt;&#x2F;a&gt; (&lt;strong&gt;NLP&lt;&#x2F;strong&gt;)  practitioners are familiar with this issue as all of their data is &lt;strong&gt;textual&lt;&#x2F;strong&gt;. And because most of Machine Learning algorithms can’t accept raw &lt;em&gt;strings&lt;&#x2F;em&gt; as inputs, &lt;strong&gt;word embedding&lt;&#x2F;strong&gt; methods are used to transform the data before feeding it to a learning algorithm. But this is not the only scenario where textual data arises, it can also take the form of categorical features in standard non-NLP tasks. In fact, many of us struggle with the processing of these kinds of features, so are word embedding of any use in this case ?&lt;&#x2F;p&gt;
&lt;p&gt;This article aims to show how we were able to use &lt;strong&gt;Word2Vec&lt;&#x2F;strong&gt; (&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1301.3781.pdf&quot;&gt;2013, Mikolov et al.&lt;&#x2F;a&gt;), a word embedding technique, to convert a &lt;strong&gt;categorical feature&lt;&#x2F;strong&gt; with a &lt;strong&gt;high number of modalities&lt;&#x2F;strong&gt; into a smaller set of easier-to-use &lt;strong&gt;numerical features&lt;&#x2F;strong&gt;. These features were not only easier to use but also successfully &lt;strong&gt;learned relationships&lt;&#x2F;strong&gt; between the several modalities similar to how classic word embeddings do with language.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;word2vec&quot;&gt;Word2Vec&lt;a class=&quot;zola-anchor&quot; href=&quot;#word2vec&quot; aria-label=&quot;Anchor link for: word2vec&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;blockquote&gt;
&lt;p&gt;You shall know a word by the company it keeps (&lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;John_Rupert_Firth&quot;&gt;Firth, J. R.&lt;&#x2F;a&gt; 1957:11)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;The above is exactly what Word2Vec seeks to do : it tries to determine the meaning of a word by analyzing its neighboring words (also called &lt;strong&gt;context&lt;&#x2F;strong&gt;). The algorithm exists in two flavors &lt;strong&gt;CBOW&lt;&#x2F;strong&gt; and &lt;strong&gt;Skip-Gram&lt;&#x2F;strong&gt;. Given a set of sentences (also called &lt;strong&gt;corpus&lt;&#x2F;strong&gt;) the model loops on the words of each sentence and either tries to use the current word of to predict its neighbors (its context), in which case the method is called “Skip-Gram”, or it uses each of these contexts to predict the current word, in which case the method is called “Continuous Bag Of Words” (CBOW). The limit on the number of words in each context is determined by a parameter called “&lt;strong&gt;window size&lt;&#x2F;strong&gt;”.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;non-nlp1.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Both Word2Vec architectures. The current word is w(t) and w(t-2)..w(t+2) are context words. (Mikolov et al. 2013)&lt;&#x2F;p&gt;
&lt;p&gt;So if we choose for example the Skip-Gram method, Word2Vec then consists of using a &lt;strong&gt;shallow neural network&lt;&#x2F;strong&gt;, i.e. a neural network of only one hidden layer, to learn the word embedding. The network first initializes randomly its weights then iteratively adapt these during training to minimize the error it makes when using words to predict their contexts. After a hopefully successful training, the word embedding for each word is obtained by multiplying the network’s &lt;strong&gt;weight matrix&lt;&#x2F;strong&gt; by the word’s &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.quora.com&#x2F;What-is-one-hot-encoding-and-when-is-it-used-in-data-science&quot;&gt;one-hot vector&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note : Besides allowing for a numerical representation of textual data, the resulting embedding also learn interesting &lt;a rel=&quot;nofollow external&quot; href=&quot;http:&#x2F;&#x2F;www.aclweb.org&#x2F;anthology&#x2F;N13-1090&quot;&gt;&lt;strong&gt;relationships between words&lt;&#x2F;strong&gt;&lt;&#x2F;a&gt;  and can be used to answer questions such as : &lt;em&gt;king is to queen as father is to …?&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;For more details on Word2Vec you can have a look at this &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ERibwqs9p38&quot;&gt;Stanford lecture&lt;&#x2F;a&gt; or this &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.tensorflow.org&#x2F;tutorials&#x2F;word2vec&quot;&gt;tutorial by Tensorflow&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;application&quot;&gt;Application&lt;a class=&quot;zola-anchor&quot; href=&quot;#application&quot; aria-label=&quot;Anchor link for: application&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;At &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;www.kwyk.fr&#x2F;&quot;&gt;&lt;strong&gt;Kwyk&lt;&#x2F;strong&gt;&lt;&#x2F;a&gt;  we provide math exercises online. Teachers assign &lt;strong&gt;homework&lt;&#x2F;strong&gt; to their students and each time an exercise is done some &lt;strong&gt;data&lt;&#x2F;strong&gt; is stored. Then, we use the collected data to &lt;strong&gt;evaluate the students’ level&lt;&#x2F;strong&gt; and give them &lt;strong&gt;tailored&lt;&#x2F;strong&gt; review exercises to help them progress. For each exercise that is answered we store a list of identifiers that help us tell : &lt;strong&gt;what is the answered exercise ?&lt;&#x2F;strong&gt;, &lt;strong&gt;who is the student ? , what is the chapter ?&lt;&#x2F;strong&gt;… In addition to that, we store a &lt;strong&gt;score&lt;&#x2F;strong&gt; value that is either (0) or (1) depending on the student success. To evaluate the students’ levels we then simply have to predict this score value and get success probabilities from our classifier.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, a lot of our features are &lt;strong&gt;categorical&lt;&#x2F;strong&gt;. Usually, when the number of &lt;strong&gt;modalities&lt;&#x2F;strong&gt; is small enough, one can simply transform a categorical feature with (n) modalities into (n-1) dummy variables then use that for training. But when the number of modalities is in the many thousands — as it is the case for some of our features — relying on dummy variables becomes inefficient and impracticable.&lt;&#x2F;p&gt;
&lt;p&gt;In order to address this issue our idea is to use Word2Vec to &lt;strong&gt;transform categorical features&lt;&#x2F;strong&gt; into a relatively small number of usable &lt;strong&gt;continuous features&lt;&#x2F;strong&gt; using a little trick. To illustrate, let’s consider “exercise_id”, a categorical feature telling us which exercise was answered. In order to be able to use Word2Vec we have to provide a &lt;strong&gt;corpus&lt;&#x2F;strong&gt;, a set of sentences to feed to the algorithm. But the raw feature — a list of ids — isn’t a corpus &lt;em&gt;per se :&lt;&#x2F;em&gt; the order is completely &lt;strong&gt;random&lt;&#x2F;strong&gt; and closer ids don’t carry any &lt;strong&gt;information&lt;&#x2F;strong&gt; about their neighbors. &lt;strong&gt;Our trick&lt;&#x2F;strong&gt; consists of considering each homework given by a teacher as a “sentence”, a &lt;strong&gt;coherent&lt;&#x2F;strong&gt; list exercise ids. As a result, ids are &lt;strong&gt;naturally&lt;&#x2F;strong&gt; gathered by levels, chapters… and Word2Vec can start learning exercise embedding directly on that.&lt;&#x2F;p&gt;
&lt;p&gt;Indeed, thanks to these artificial sentences we were able to use Word2Vec and get beautiful results :&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;non-nlp2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Exercise embedding (3 main components of PCA) colored by level. 6e, 5e, 4e, 3e, 2e, 1e and tm are the french equivalents of the 6th, 7th, 8th, 9th, 10th, 11th and 12th grades in the US.&lt;&#x2F;p&gt;
&lt;p&gt;As we can see, the resulting embedding has a &lt;strong&gt;structure&lt;&#x2F;strong&gt;. In fact, the 3d-projected cloud of exercises is spiral-shaped with &lt;strong&gt;exercises of higher levels following directly those of previous levels&lt;&#x2F;strong&gt;. This means that the embedding successfully learned to &lt;strong&gt;distinguish&lt;&#x2F;strong&gt; exercises of different school levels and regrouped similar exercises together. But that’s not all, using a &lt;a rel=&quot;nofollow external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Nonlinear_dimensionality_reduction#Locally-linear_embedding&quot;&gt;&lt;strong&gt;non-linear dimensionality reduction&lt;&#x2F;strong&gt;&lt;&#x2F;a&gt; technique we were able to reduce the whole embedding into a single real valued variable with the same characteristics. In other terms, we obtained an &lt;strong&gt;exercise complexity&lt;&#x2F;strong&gt; feature that is minimum for 6th grade exercises and &lt;strong&gt;grows&lt;&#x2F;strong&gt; as the exercises get more and &lt;strong&gt;more complex&lt;&#x2F;strong&gt; until it is maximum for 12th grade exercises.&lt;&#x2F;p&gt;
&lt;p&gt;Moreover, the embedding also learned &lt;strong&gt;relationships&lt;&#x2F;strong&gt; between exercises just like Mikolov’s did with English words :&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;images&#x2F;non-nlp3.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The diagram above shows some examples of the relationships our embedding was able to learn. So if we were to ask the question &lt;em&gt;“an exercise of&lt;&#x2F;em&gt; &lt;strong&gt;&lt;em&gt;number addition&lt;&#x2F;em&gt;&lt;&#x2F;strong&gt; &lt;em&gt;is to an exercise of&lt;&#x2F;em&gt; &lt;strong&gt;&lt;em&gt;number subtraction&lt;&#x2F;em&gt;&lt;&#x2F;strong&gt; &lt;em&gt;as an exercise of&lt;&#x2F;em&gt; &lt;strong&gt;&lt;em&gt;time addition&lt;&#x2F;em&gt;&lt;&#x2F;strong&gt; &lt;em&gt;is to … ?”&lt;&#x2F;em&gt; the embedding gives us the answer “&lt;em&gt;an exercise of&lt;&#x2F;em&gt; &lt;strong&gt;&lt;em&gt;time subtraction&lt;&#x2F;em&gt;&lt;&#x2F;strong&gt;”. Concretely, this means that if we take the difference embedding[Substract(Numbers)] - embedding[Add(Numbers)] and add it to the embedding of an exercise where students are asked to add time values (hours, minutes …) then the closest embedding is one of an exercise that consists of subtracting time values.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;&lt;i class=&quot;fas fa-link&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt; 
&lt;&#x2F;h1&gt;
&lt;p&gt;All in all, word embedding techniques are useful to transform textual data into real valued vectors which can then be plugged easily into a machine learning algorithm. Despite being principally used for NLP applications such as &lt;em&gt;machine translation&lt;&#x2F;em&gt;, we showed that these techniques also have their place for categorical feature processing by giving the example of a particular feature we use at Kwyk. But in order to be able to apply a technique such as Word2Vec, one has to build a corpus — i.e. a set of sentences where labels are arranged so that a context is implicitly created. In our example, we used homework given on the website to create “sentences” of exercises and learn an exercise embedding. As a result we were able to get new numeric features that successfully learned the relationships between exercises and are then more useful than the bunch of labels they originated from.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Credits go to Christophe Gabard, one of our developers at Kwyk, for having the idea of applying Word2Vec to process categorical features.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
</content>
	</entry>
</feed>
