<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Qiurui Chen on Medium]]></title>
        <description><![CDATA[Stories by Qiurui Chen on Medium]]></description>
        <link>https://medium.com/@rachel_95942?source=rss-cbd32a3f303d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JMvWfK41-HQS7b2ofFVlSg.jpeg</url>
            <title>Stories by Qiurui Chen on Medium</title>
            <link>https://medium.com/@rachel_95942?source=rss-cbd32a3f303d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:58:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rachel_95942/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Configure Rstudio Server with SSL on AWS EC2 (ARM)]]></title>
            <link>https://medium.com/@rachel_95942/configure-rstudio-server-with-ssl-on-aws-ec2-arm-e10fa2c36ef8?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e10fa2c36ef8</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[rstudio]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Sat, 04 Dec 2021 09:02:29 GMT</pubDate>
            <atom:updated>2021-12-04T09:02:29.410Z</atom:updated>
            <content:encoded><![CDATA[<p>This story demonstrates how to secure and set up Rstudio Server on AWS EC2 ARM machine.</p><p>Steps are:</p><ol><li>Installing Rstudio in ARM machines (here we choose Debian)</li><li>Securing Rstudio Server by configuring the nginx webserver to <a href="https://en.wikipedia.org/wiki/Reverse_proxy">reverse proxy</a></li></ol><p>3. Configuring startup bash to automatically map EC2 dynamic IPs to Nginx.</p><p>Installing Rstudio Server Natively on ARM machine, please follow steps on this <a href="https://github.com/dipterix/arm-rstudio-server">git repo</a>. I slightly changed the steps in `Configure rstudio-server` part:</p><pre>sudo rstudio-server stop<br>sudo mkdir /etc/rstudio/<br>sudo rm /etc/rstudio/rserver.conf # delete the original file if exists<br>sudo rm /etc/rstudio/rsession.conf<br>sudo touch /etc/rstudio/rserver.conf<br>sudo touch /etc/rstudio/rsession.conf<br><br># Listen to port 80<br>echo &quot;www-port=80&quot; | sudo tee -a /etc/rstudio/rserver.conf<br>echo &quot;www-address=0.0.0.0&quot; | sudo tee -a /etc/rstudio/rserver.conf<br>echo &quot;rsession-which-r=$(which R)&quot; | sudo tee -a /etc/rstudio/rserver.conf<br><br># No session time out<br>echo &quot;session-timeout-minutes=0&quot; | sudo tee -a /etc/rstudio/rsession.conf<br><br># Finally, update and restart the service<br>sudo rstudio-server verify-installation<br>sudo rstudio-server start<br><br># To add users<br>sudo adduser rstudio # add user rstudio<br>sudo usermod -aG sudo rstudio # grant root rights<br>getent group sudo # check root users<br>su -rstudio # login in as rstudio user</pre><p>After installing Rstudio Server on ARM machine, I followed instructions from <a href="https://stackoverflow.com/questions/53102584/how-can-i-set-up-an-rstudio-server-to-run-with-ssl-on-aws">here</a> to configure the Nginx web server to <a href="https://en.wikipedia.org/wiki/Reverse_proxy">reverse proxy</a> RStudio server to the web browser and use SSL. Every step is pretty much the same except configuring rstudio.config part: `sudo nano /etc/nginx/conf.d/rstudio.conf`</p><pre>server {<br>        listen 80;<br>        listen [::]:80;<br><br>        listen 443 ssl;<br>        ssl_certificate /etc/nginx/ssl/nginx.crt;<br>        ssl_certificate_key /etc/nginx/ssl/nginx.key;<br><br>        server_name EC2_DYNAMIC_IP_ADDRESS;<br><br>        location / {<br>             proxy_pass http://localhost:80/;<br>             proxy_redirect http://localhost:80/ $scheme://$host/;<br>             proxy_http_version 1.1;<br>             proxy_set_header Upgrade $http_upgrade;<br>             proxy_set_header Connection $connection_upgrade;<br>             proxy_read_timeout 20d;<br>        }<br>}</pre><p>You can also allocate an Elastic IP address to your EC2 instance so that your EC2 public IP is fixed.</p><p>I also configure Ngnix to redirect all HTTP traffic to HTTPS: `sudo nano /etc/nginx/sites-available/default`</p><pre>server {<br>    listen 80 default_server;       <br>    server_name _;       <br>    return 301 https://$host$request_uri;<br>}</pre><p>The last step is dynamically mapping EC2 public IP into `rstudio.config` file since IP address changes every time EC2 restarts. Create a bash file in `/var/lib/cloud/scripts/per-boot`:</p><pre>#!/bin/bash<br>mypubip=$(curl <a href="http://checkip.amazonaws.com/">http://checkip.amazonaws.com</a>)<br>sed -i &quot;s|EC2_DYNAMIC_IP_ADDRESS|${mypubip}|g&quot; /etc/nginx/conf.d/rstudio.conf<br>sudo rstudio-server restart<br>sudo systemctl restart nginx</pre><p>That’s it.</p><p>Most browsers may complain it’s unsafe given OpenSSL generated certificate it’s a self-signed cert. Self-signed certs are inherently insecure in that you cannot verify that the server is who or what it claims, but the data is still encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7dzzy-bABO5skMmvKETuA.png" /></figure><p>Rstudio server is now secured with HTTPS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxTxm1URZXMRx5hbrvdzrA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e10fa2c36ef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[T5: a detailed explanation]]></title>
            <link>https://medium.com/analytics-vidhya/t5-a-detailed-explanation-a0ac9bc53e51?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0ac9bc53e51</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 15:01:01 GMT</pubDate>
            <atom:updated>2020-06-11T16:03:49.165Z</atom:updated>
            <content:encoded><![CDATA[<h4>Given the current landscape of transfer learning for NLP,<strong> T</strong>ext-<strong>t</strong>o-<strong>T</strong>ext <strong>T</strong>ransfer <strong>T</strong>ransformer (T5) aims to explore what works best, and how far can we push the tools we already have.</h4><p>Recently, there are lots of transfer learning techniques for NLP. But some techniques may work almost identical — just with different datasets or optimizers — but they achieve different results, then can we say the technique with better results is better than the other? Given the current landscape of transfer learning for NLP,<strong> T</strong>ext-<strong>t</strong>o-<strong>T</strong>ext <strong>T</strong>ransfer <strong>T</strong>ransformer (T5) aims to explore what works best, and how far can we push the tools we already have.</p><h3>Baseline model</h3><h4>T5 framework</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*QOVXAn0bx8HKGrBIXAgydw.png" /><figcaption>A diagram of the T5 framework. Source: T5 <a href="https://arxiv.org/pdf/1910.10683.pdf">paper</a>.</figcaption></figure><p>Many tasks are cast into this framework: machine translation, classification task, regression task ( for example, predict how similar two sentences are, the similarity score is in range 1 to 5), other sequence to sequence tasks like document summarization (for example, summarising articles from CNN daily mail corpus).</p><h4>T5 model structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*iJcUH1F0TmCQE5p2wQt9og.png" /><figcaption>Model structure. From: <a href="http://jalammar.github.io/illustrated-transformer/">Jay Alammar’s blog</a></figcaption></figure><p>The mode structure is just a standard sort of vanilla encoder-decoder transformer.</p><h4>Pretrained dataset</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*kTc83HCd6a9nptgLMX93CA.gif" /><figcaption>T5 cleans datasets. Source: Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>T5 uses <a href="https://commoncrawl.org/">common crawl web extracted text</a>. The authors apply some pretty simple heuristic filtering. T5 removes any lines that didn’t end in a terminal punctuation mark. It also removes line with the word javascript and any pages that had a curly bracket (since it often appears in code). <strong><em>It deduplicates the dataset by taking a sliding window of 3 sentence chunks and deduplicated it so that only one of them appeared the dataset</em></strong>. For example, above 3 pages, the last paragraph on the middle page is removed since the same content appears on the first page. It ends up with 750 gigabytes of clean-ish English text. The dataset is publicly available on<a href="https://www.tensorflow.org/datasets/catalog/c4"> tensorlow.text.c4</a>.</p><h4>The unsupervised objective</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*9yFICqDlfprn-I_VZ5RHgw.png" /><figcaption>The unsupervised objective. Source T5 <a href="https://arxiv.org/pdf/1910.10683.pdf">paper</a>.</figcaption></figure><p>With the framework, the model architecture, and the unlabeled dataset, the next step is to look for the unsupervised objective which gives the model some ways of learning from the unlabeled data. In the original text, some words are dropped out with a unique sentinel token. Words are dropped out independently uniformly at random. The model is trained to predict basically sentinel tokens to delineate the dropped out text.</p><h4>Workflow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-drd83Rs_JphZ7oAYlAP2Q.png" /><figcaption>The pretraining, fine-tuning, and evaluating steps. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>So the model pretrained based on Bert-base size encoder-decoder transformer with the denoising objective and C4 dataset, It trained 2¹⁹ steps on 2³⁵ or ~348 tokens with inverse square root learning rate schedule. Finetuning tasks include <a href="https://gluebenchmark.com/">GLUE,</a> <a href="https://arxiv.org/abs/1506.03340">CNN/DM</a>(CNN / Daily Mail), <a href="https://rajpurkar.github.io/SQuAD-explorer/">SQuAD</a>, <a href="https://super.gluebenchmark.com/">SuperGLUE</a>, and <a href="https://nlp.stanford.edu/projects/nmt/">translation tasks</a>: WMT14 EnDe, WMT14 EnFr, and WMT14 EnRo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nbjijmtJJ-eKmkdaqnzg4w.png" /><figcaption>The table structure.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RfzVjzpod7Da-pXwKEwJNg.png" /><figcaption>the baseline model performance. Source: T5 <a href="https://arxiv.org/pdf/1910.10683.pdf">paper</a>.</figcaption></figure><p>Next, different strategies in different settings were tried out to test how they influence performance.</p><h3>Strategy comparison</h3><h4>Architectures</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*l1jqv50E_rKOEkBCI2mHug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hlBep8nQfxkdUwSTvHBH7w.png" /><figcaption>different attention mask patterns (left) and its corresponding models (right). Source: T5 <a href="https://arxiv.org/pdf/1910.10683.pdf">paper</a>.</figcaption></figure><p>Fully-visible mask where every output entry is able to see every input entry. In the middle, there is a casual mask that is good for predicting a sequence due to the model is not allowed to look into the future to predict. The causal with prefix mask allows the model to look at the first bit of the input sequence as it with full visuality and then it starts predicting what comes next later on in the input sequence. The result shows that <strong>given the model bi-directional context on the input is valuable.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*quZpSZjw0pEK88KjXpngeA.gif" /><figcaption>Model performance on different tasks. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><h4>Objectives</h4><p>Three objectives are concerned: <strong>language modeling (predicting the next word), BERT-style objective (which is masking/replacing words with a random different words and predicting the original text), and deshuffling ( which is shuffling the input randomly and try to predict the original text).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*8hCjg1hdicbrHGrFcEl4zw.gif" /><figcaption>different objectives and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>There are 3 options for<strong> corruption strategies:</strong> <strong>only masking tokens and do not swap tokens; masking tokens and replacing them with a single sentinel token; and removing tokens.</strong> The performance shows that <strong>‘replacing corrupted spans’ strategy works best</strong>. What’s more, different corruption rates are applied and the result shows that <strong>unless a large corruption rate is taken (s.t. 50%), this setting is not sensitive to performance</strong> due to similar model performance with 10%,15%, and 25% corruption rates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*eS81GEgaCvEjnsLzjkOtSQ.gif" /><figcaption>different corruption strategies and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*kcWGJIYo0rR8J2iIvnf41A.gif" /><figcaption>different span lengths and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>Given a good corruption rate, what happens if entire spans are dropped instead of iid decision being taken for each token ( IID decision: uniformly at random to decide whether we should corrupt the word or not). Basically at each position in the input, should a span of tokens be dropped and how long should that span be? Similar to the corruption rate setting,<strong> this setting doesn&#39;t influence performance a lot unless a large span of tokens is dropped</strong> (such as 10 tokens).</p><p>The highlight from this objective experiment is<strong> word corruption objectives tend to work best.</strong> Models tend to work pretty similarly with different corruption rates, and given this fact<strong>, it is suggested to use objectives that result in short target sequences since the shorter sequence is cheaper to do pretrain.</strong></p><h3>Datasets</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*z5F5uPeZU-FBSHo2cMoWfQ.gif" /><figcaption>different datasets for pertaining and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>Besides the clean-ish C4 dataset, the same data without any filtering also tried. The result shows that<strong> filtering does help the model to perform better. </strong>Other datasets with a smaller order of magnitude (which means more on some constrained domains) are also applied. Results show that <strong>pre-training on domain data helps downstream task performance.</strong> For example, pretrained model on RealNews-like dataset performed much better on ReCORD (a QA dataset on news articles) — the model pretrained on news tends to do better on a news QA task. The model pretrained on Wikipedia and TBC dataset (Tronoto book corpus) works better on multiRC dataset (a QA dataset that includes some data from novels).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*SapsvvsDQuTmWUGBpFf_QA.png" /><figcaption>different training steps and their performance. Source:<a href="https://arxiv.org/pdf/1910.10683.pdf"> T5 paper</a></figcaption></figure><p>What if the <strong>training dataset is limited and being repeated during training</strong>? How about setting these training steps? If you aren&#39;t going to be pertaining for that long, you might not have to worry about this. <strong>but if you start to repeat your dataset a bunch of times, the model can start to memorize your pertaining dataset </strong>(as bigger training steps lead to smaller training loss)<strong>and it causes a significant drop in performance on the downstream tasks</strong></p><h4>Multi-task</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*5MUuWyi6Y7566p-Yk9guVQ.gif" /><figcaption>different mixing strategies and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>Instead of doing unsupervised pretraining and fine-tuning, <strong>the model is trained on multi-tasks.</strong> There are several mixing strategies<strong>. Tasks can be equally trained</strong>. The next option is to<strong> weight each dataset by the number of examples in the dataset</strong> as we don’t want to overfit the small dataset and underfit the big dataset. Because the unsupervised task is so big so that<strong> we need to set an artificial limit </strong>on how much we train on that task. This is what multilingual BERT does — sampling from different languages. We can also <strong>take these number of example proportions and apply a temperature to them to make then more close to uniform</strong>. Training equally on multi-tasks leads to worse performance. Setting threshold and temperatures correctly would have somewhat similar performance to the pretrained and fine-tuned setting. <strong>Especially on GLUR and SQUAD and superGLUE, there is a significant drop in performance</strong> when trying to train a single model on all these tasks at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*6AMAl7vZO7GZ9eBchynWXw.gif" /><figcaption>different training strategies and their performance. source: Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><p>Besides <strong>multi-task training</strong>, there are also other training strategies. Original one is <strong>pretraining on unsupervised tasks and fine-tuning on each individual downstream tasks.</strong> Another option is offered by <a href="https://arxiv.org/abs/1901.11504">MT-DNN</a><strong>: training on a multitask mixture and then fine-tuning on each individual task.</strong> This strategy closes the gap between unsupervised pertaining and fine-tuning. <strong>Leave-one-out multi-tasks training is pertaining on a multi-task mixture and then fine-tuning on a task which isn&#39;t used during pertaining.</strong> The result shows that this strategy still generates pretty good pretrained model. The final option is <strong>pertaining only on supervised tasks and fine-tuning on the same set of supervised tasks</strong>, which quite similar to what computer vision does. However, this strategy hurts performance pretty significantly.</p><h3>Scaling</h3><p>How to scale the model up? What if you are given four times as much compute, how should you use it? Should you train the model for longer, or use a bigger batch size, or train a bigger model, or train four models and ensemble them? <strong>Training the model longer does improve performance</strong> and this is one of the main things that <a href="https://arxiv.org/abs/1907.11692">Roberta</a> did (pertaining to the model for longer). <strong>Making model bigger by making it both deeper and wider and training it two times as long also produces pretty significant gains.</strong> <strong>Training four models and assembling them also help a lot.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jriKYJn_BTDoouyMNMvUhg.gif" /><figcaption>different scaling strategies and their performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><h3>Putting it all together</h3><p>After combining all these ideas together and scaling things up, the authors trained 5 variants: small model, base model, large model, and models with 3 billion and 11 billion parameters (which is by making the feed-forward layers wide). They achieved good performance except for translation. <em>For translation, it seems like back-translation which is a very important ingredient for these state-of-the-art results works better than the English only pre-training</em>. Noteworthy, superGLUE was designed to be hard for BERT but easy for humans. T5 performs very closely to the human level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*WKWaVDoZbPCbx3WtTScnCw.png" /><figcaption>T5 model size variants. Source: <a href="https://arxiv.org/pdf/1910.10683.pdf">T5 paper.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*IZGxfqttzSaG1NI1tRz6CQ.png" /><figcaption>T5 model performance. Source:<a href="https://www.youtube.com/watch?v=eKqWC577WlI&amp;list=UUEqgmyWChwvt6MFGGlmUQCQ&amp;index=4"> Collin Raffel video</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0ac9bc53e51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/t5-a-detailed-explanation-a0ac9bc53e51">T5: a detailed explanation</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Policy gradient in multi-task/meta-learning]]></title>
            <link>https://medium.com/data-science/policy-gradient-in-multi-task-meta-learning-2aeeaf23817d?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aeeaf23817d</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[meta-learning]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Sat, 16 May 2020 19:53:16 GMT</pubDate>
            <atom:updated>2020-06-05T03:44:18.494Z</atom:updated>
            <content:encoded><![CDATA[<h4>This story introduces multi-task reinforcement learning problem, and policy gradient &amp; their multi-task/meta counterparts. The second part covers Q-learning and Multi-task Q-learning. This story is a short summary of the course ‘<a href="https://www.youtube.com/watch?v=UPT4Rndftc8&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=6">Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 6 — Reinforcement Learning Primer’</a>.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*1aU70oZX_OgoVPtQe4DCnw.png" /><figcaption>via <a href="https://wordart.com/">WordArt</a></figcaption></figure><p>When do you not need sequential decision making? when your system is making a single isolated decision (such as classification, regression), and when that decision does not affect future inputs or decision, you do not need sequential decision making. The common application areas include robotics, language and dialog, autonomous driving, business operations and finance.</p><p>This story will cover</p><ul><li>Multi-task reinforcement learning problem</li><li>Policy gradient &amp; their multi-task/meta counterparts</li></ul><p>The second part of this story will cover Q-learning and Multi-task Q-learning. This story is a short summary of the course ‘<a href="https://www.youtube.com/watch?v=UPT4Rndftc8&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=6">Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 6 — Reinforcement Learning Primer’</a>.</p><h3>Multi-task reinforcement learning problem</h3><p>In supervised learning, data is iid and we need a large labeled, curated dataset, while in sequential decision making, the action affects the next state instead of iid, and for the dataset, how to collect data? what are the labels?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*5f8YO298jCGrVsbrwjFxqw.png" /><figcaption>supervised learning</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*Byi2CO1ZN30c0fnhOIcZ6g.gif" /><figcaption>RL setting. Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>For supervised learning, we have a function π which is parameterized by θ that takes o in and generates output a. For example, the input could be imaged while the output could be the image class (s.t. tiger). In RL, we use policy that will be taking actions and the actions will affect the next state. These will be this feedback loop that goes from the action back to the observations, and our class (a) will be the actions, such as “runaway”,” ignore” or “pet the tiger”. O denotes the observations that the agent (system) receives as input, a denotes as action, π is denoting the policy which is parameterized by θ. <strong><em>Typically we assume that there is some underlying state of the world s. in the fully observed situation, s is observed. in the partially observed setting, o is observed.</em></strong></p><p>What’s the concrete difference between o and s? for example, you try to chase a hyena, if you are given an image, then the images would be an observation o, whereas in contrast if you are given the pose of the respective animals, then these poses would state s. You basically be able to fully observe the system underlying state of the system and the things that matter for making decisions in the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2onRDD24Ljk68nUvq7lq7g.png" /><figcaption>imitation learning.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p><strong><em>One basic approach to the sequential decision-making problem is to treat it as supervised learning(SL) problem.</em></strong> For example, <strong>you want to imitate some experts</strong>. <a href="https://images.nvidia.com/content/tegra/automotive/images/2016/solutions/pdf/end-to-end-dl-using-px.pdf">Maybe you could collect a bunch of driving data</a>, collect the observation that the person sees and collect the action that they took in those states, put this into some big training dataset, and then sample iid from this training datasets during supervised learning to train your policy to predict actions from observations. This approach works well in some context if you have a lot of expert data on performing the right actions. But these systems don’t reason about outcomes in any way instead of just mimicking what the data is doing.</p><p>In RL, <strong>reward functions </strong>are needed. These reward function should capture what states and actions are better or worse for the system. It typically takes in both a state and an action( r(s,a) ), and tells us which states and actions are better. For example, if we are driving, we might have a very high reward if we drive smoothly and we will have a low reward is we have a car crash.</p><p>In aggregate the states s, the actions a, and the rewards r(s,a), as well as the dynamics of the system p(s&#39;|s,a) define a <strong>Markov decision process,</strong> because this is encapsulating the notion of a sequential decision-making problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*nzUjAVp3icmn72i3_P1SIA.gif" /><figcaption>RL example.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p><strong><em>So the goal of reinforcement learning is typically to learn parameters of the policies that take as inputs.</em></strong> In this case, we will look at the fully observed setting takes as input some state, and make predictions about actions. The goal is to learn the parameters of the policy. In a deep RL setting, your policy will probably be parameterized as a neural network where the states are being processed as input, actions are outputs. The actions are fed into the world and then the world gives you the next state that’s feeding back into your policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AtDGAsxeyc2Fq4jU2A2Ymw.png" /><figcaption>an RL graphical model.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>We can actually characterize a system as the graphical model here where we have a policy that takes the observation and produce an action (partially observed setting), the dynamics take in the current state, and the current action and produce a distribution over the next state. <strong><em>The dynamic function is independent of the previous state, and this is known as the Markov property.</em></strong> Basically the definition of a state in a<strong><em> Markov decision process </em></strong>is that <strong><em>you can fully define the reward function and the dynamics from the information in that state variable independent of previous states.</em></strong> If you look at the diagrams here, it only depends on St and At and doesn’t depend on st-1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdI9VDj4FxJW6IjU1xuRIA.png" /><figcaption>RL objective in infinite/finite horizon cases.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>The concrete objective for RL is to maximize the expected reward under the policy. And in the infinite horizon case, we want to maximize the reward function under that stationary distribution the stationary distribution over states and actions arising from the policy. In the finite horizon case, we might have some horizon capital T and you want to maximize the rewards of the states and actions when rolling out our policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98XsZdoDJvfjRuwQ24cA4Q.png" /><figcaption>SL task and RL task</figcaption></figure><p>We’ve talked RL problem, then what is the RL tasks?<em> If you compare the RL to the supervised learning setting, the initial state distribution and the dynamics basically are the same as the data generating distributions. The reward function corresponds to the loss function, and the state and action space are just kind of telling you what is the general set that your states and actions lie within. </em>So this is just as a Markov decision process. But if the different MDPs are different tasks, then this is much more than just the semantic meaning of a task. Because different tasks could have the same exact reward function but have different action spaces or different dynamics. So we use the term task loosely to describe these different Markov decision processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tEmz6e5noIgPzfrFQjSklQ.png" /><figcaption>personalized recommendation and across maneuvers.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>How to apply RL in meta-learning? <strong>One application is personalized recommendations, </strong>where different people are different tasks. The dynamics correspond to how that person will react to a particular action that you take and the reward function corresponds to whether or not you recommend something to the results in a state that is good. In some contexts, the initial state distribution may also vary for different people, it depends on how you formulate your problem. <strong>Another application is across maneuvers</strong>, which is animating different characters in computer graphics across different maneuvers, for example. If you treat this as a multitask learning problem, different tasks would have different reward functions in the setting but the dynamics would be the same, as well as the state and action space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZzBjvStjEq9Jp5R5Hmgh3g.png" /><figcaption>An alternative view of RL.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>One alternative way to view multitask RL is as follows. <strong><em>We typically have some sort of task identifier that’s part of the state and this is required to make it a fully observable setting or a fully observable MDP</em></strong>. S bar denotes as original state, and zi denotes the task identifier. Basically tasks viewed as a standard Markov decision process, where the state space and the action space are the unions of the state spaces and action spaces in the original tasks. The initial state distribution just corresponds to a mixture distribution over the initial state distribution for each of those tasks, the dynamics and the reward function are a single dynamics and single reward function that takes as input the task identifier and produces either the next state or the reward. So you can basically apply standard single task RL algorithms to the multitask problem with this view on multitasking RL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*BbeM0i-AHafIa_GutMJNvQ.png" /><figcaption>the reward function for goal-conditioned RL</figcaption></figure><p><strong>Multi-task RL</strong> is the same as the single task RL problem, <strong>except a task identifier is part of the sate ( s = (s bar, zi)).</strong> For example, a task identifier could be a one-hot task ID, a language description of the task, or the desired goal state that you want to reach.<em> This </em><strong><em>goal state</em></strong><em> would be known as</em><strong><em> goal-conditioned RL</em></strong><em> where you conditioned it on a particular state that you want to be able to reach in the future</em>. <strong>The reward function could be the same as before</strong> w<em>here it takes as input the task id and outputs the reward function corresponds to that task for that state, or for things like goal-conditioned RL, it can correspond to simply the negative distance between your (original) current state and the goal state.</em> Some example of distance function might be Euclidean distance in some latent space or a sparse 0/1 where 1 indicates s bar equals sg and 0 indicate not equal. If it’s still a standard Markov decision process, then why not apply standard RL algorithms? You can, but it will be more challenging than the individual single tasks because you will have a wider distribution of things in general.</p><h3>Policy gradients &amp; their multi-task/meta counterparts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dfgij3OSWSnaIjYLyDipKw.png" /><figcaption>The anatomy of a reinforcement learning algorithm.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p><em>You can generally review RL algorithms in the following flow graph where we first generate samples in the environment, this is just running the policy forward typically, then we fit some model to estimate the return, then we use that model to improve the policy.</em> <em>Different algorithms typically correspond to just differences in this green box and in this blue box</em>. So for example, one example of fitting a model might be estimating the empirical return such as using the Monte-Carlo policy gradient. Another example of estimating the return might be to try to fit a Q function, using, for example, dynamic programming algorithms. Another example of fitting a model would be to estimate a function that models the dynamics. Once we have any of these models we can then, for example, apply the policy gradient to our policy parameters, we can improve the policy by taking the max over Q values for our current Q-function, or in the case of model-based algorithms, we can optimize a policy by for example backpropagating through a model into our policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccghglnv2a3ryZ80K3ao5Q.png" /><figcaption>Evaluating the objective.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>So let’s start with policy gradients. Above is our objective in RL, so we want to be able to sample trajectories from our policy and estimate the return. We will refer to this objective as J of θ. We could rewrite J of θ . You can view this or estimate this as rolling out and trajectories, for example, shown in the graph right, which is computing the reward for each of those trajectories, and maybe the first trajectory has a high reward, the middle trajectory has a medium reward and the last trajectory has a bad reward. <strong><em>And so this first sum is the sum over the samples from our policy and the second sum is a sum over time.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFakXg0UrkluNgx0uboCkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9WhY3_hJEECf9u4YRjzNQ.png" /><figcaption>Direct policy differentiation.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p><strong><em>Can we differentiate through this objective directly into our policy?</em></strong> So<em> if our objective is the expected reward and we can estimate this with the reward of a trajectory</em>. You can view this as this expectation as an integral over π θ because the expectation is with respect to π θ of τ. If you want to compute the gradient of this objective with respect to our policy parameters, you can <em>move the gradient inside the integral because it’s a linear operation and then you basically have the integral of the gradient of the policy times reward function integrated over trajectories</em>. How do we actually go about evaluating this gradient? We don’t have to integrate over all possible trajectories. So we are going to <strong><em>use the likelihood ratio trick.</em></strong> If we are looking at the policy probability for a trajectory time the gradient of the log of the policy, this is basically we just differentiate to the log which is equal to the policy times the gradient of π divided by π. The two πs are canceled and it equals the gradient of π or the gradient of the policy w.r.t the policy parameters. After applying the convenient identity, <strong><em>we can simply evaluate the gradient or estimate the gradient by taking an expectation over a trajectory sampled from our policy and using those samples to evaluate the gradients of the log probability of our policy weighted by the reward of that trajectory. </em></strong>The π of the full trajectory which can be broken down into the initial state density times a product over time of the policy probability and the dynamics probability. After calculation, the final gradient is something we can evaluate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*P02PmxPmI1Bfj6BqvCd8TA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dfgij3OSWSnaIjYLyDipKw.png" /><figcaption>Evaluating the policy gradient.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>We can basically rule out our policy to get trajectories, then estimate the policy gradient by averaging over those trajectories over time of log π times the reward function and then apply the gradient to our policy parameters. If we go back to the diagram, collecting data corresponds to the orange box (corresponds to orange underline part in the right formulas) evaluating the return corresponds to the green box(corresponds to green underline part), and actually using that to improve the policy in the last step corresponds to the blue box(corresponds to blue underline part). <strong><em>The reinforce algorithm is explicitly sampling trajectories from your policy and then computing the gradient, using those trajectories, and then using that estimated gradient to update your policy parameters. And then you can repeat this step to iteratively improve your policy</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0EIlpORfA7KSlDuOxFgWfQ.png" /><figcaption>comparison to maximum likelihood.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>How does this compare to something like imitation learning like the maximum likelihood of expert actions? <strong><em>The maximum likelihood objective looks pretty similar to the policy form</em></strong>. And in particular, the difference is that just the reward term on the right. So basically policy gradient will correspond to maximizing the probability of actions that have a high reward. If they have a low reward, then you will try to maximize it less essentially. Because it is just basically a gradient descent algorithm, it’s very easy to apply to multitask learning algorithms to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*-Zdy8swDRKMlqUV-k61eig.gif" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>If we do maximum likelihood imitation learning, we are just trying to imitate the best trajectories whereas in policy gradient, we have some distribution over these trajectories, and then we are going to try to increase the probability of the actions that had a high reward and place less probability mass on the actions that had a low reward. So as a result, we will basically just be making the good stuff more likely, and making the stuff gets bad reward less likely, and formalizing this notion of “trial and error”.</p><p>So that’s policy gradient. It’s pretty easy to combine with things like multitask learning. It’s also pretty easy to combine with things like meta-learning. The meta-learning algorithms (such as MAML and black-box approaches) assume that you can get some gradient of your objective. And so we can readily apply these algorithms in combination with policy gradient algorithms.</p><p>For example, let’s combine MAML and policy gradient. There were 2 tasks: running forward and backward. We are not evaluating generalization in any way. We are just gonna look at whether or not it can learn to adapt its policy with a single gradient step for one of these two tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*YXtSEoVaROGQ17f8-BuirQ.gif" /><figcaption>At the end of meta-learning but before taking a gradient step to one of the tasks, we get a policy that looks like right: running in place, ready to run in either of the two directions.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*uy0F06z0irXHm4Fb_khhJA.gif" /><figcaption>If we take one gradient with respect to the task with the reward function of running backward/forward, we get policies run in the corresponding direction.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>The above example shows that there exists a representation under which RL is fast and efficient.</p><p>We could also combine the black-box meta-learning and policy gradient. Here is the maze example. This experiment is learning to navigate a maze, it is trained on 1000 small mazes and test on held-out small mazes and large mazes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*ru367kfcGQX35LZpYKVk7Q.gif" /><figcaption>In this case, it does not know the task and it needs to navigate the maze. The left shows the agent’s point of view and the right shows the maze. After it gets the experience, it then is able to learn how to solve the maze with basically just a single trajectory. So first navigate around that maze to explore and then at the end of that episode, the memory of the architecture is not reset. Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p>MAML is very expressive in the supervised learning setting, but it’s actually not very expressive in RL because of the policy gradient. Basically, if the reward function is 0 for all of your trajectories, then your gradient will always be 0. And so even if it gets lots of rich experience about the environment with 0 rewards, it can NOT actually incorporate that experience to update the policy. As a result, <strong><em>MAML with policy gradients isn’t actually very expressive.</em></strong> <em>In general, these meta-learning algorithms to the RL setting is pretty easy to combine with policy gradients, combining them with methods like Q-learning and actor-critic algorithms is a lot more challenging</em>.</p><h3>summary policy gradients</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*wVRggW8w4bitxEMuyYluCg.png" /><figcaption>policy gradient.Source: <a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">the course slide</a></figcaption></figure><p><strong>The policy gradient approach is simple </strong>and<strong> easy to combine with existing multitask and meta-learning algorithms</strong>. But <strong>it produces a high-variance gradient,</strong> which can be mitigated with baseline or trust regions. Another downside of the policy gradient is that<strong> it requires on-policy data</strong>. You can see the expectation in respect to πθ, and πθ is your current policy. So in order to improve your policy, you need data from your current policy. And this is really important because this means you cant reuse any data from your previous policies to try to improve your policy. As a result, these algorithms tend to be less sample efficient than other algorithms that are able to reuse data from previous policies and other experiences, etc. Things like importance weighting can help with this. So you can basically add a weight that corresponds to the ratio between your current policy and the policy that you collected data with. But these importance weights also give you high variance especially when those two policies are very different.</p><h3>Reference</h3><ol><li>‘<a href="https://www.youtube.com/watch?v=UPT4Rndftc8&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=6">Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 6 — Reinforcement Learning Primer’</a>.</li><li>T<a href="http://cs330.stanford.edu/slides/cs330_mtrl.pdf">he course slide</a></li><li><a href="https://images.nvidia.com/content/tegra/automotive/images/2016/solutions/pdf/end-to-end-dl-using-px.pdf">End to End Learning for Self-Driving Cars</a></li><li><a href="https://arxiv.org/abs/1703.03400">Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks</a></li><li><a href="https://arxiv.org/abs/1707.03141">A Simple Neural Attentive Meta-Learner</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aeeaf23817d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/policy-gradient-in-multi-task-meta-learning-2aeeaf23817d">Policy gradient in multi-task/meta-learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bayesian meta-learning]]></title>
            <link>https://medium.com/data-science/bayesian-meta-learning-fa4eedcb89fc?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa4eedcb89fc</guid>
            <category><![CDATA[meta-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Sat, 16 May 2020 19:52:10 GMT</pubDate>
            <atom:updated>2020-05-20T06:46:20.560Z</atom:updated>
            <content:encoded><![CDATA[<h4>This story introduces bayesian meta-learning approaches, which covers bayesian black-box meta-learning, bayesian optimization-based meta-learning, ensembles of MAMLs, and probabilistic MAML. This a short summary of the course <a href="https://www.youtube.com/watch?v=QY8JXpnllb0&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=5">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 5 — Bayesian Meta-Learning’</a>.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*qvipJGFrYHBqlSQR9UU5_w.png" /><figcaption>via <a href="https://wordart.com/create">WordArt</a></figcaption></figure><p>This story covers the reason why we need Bayesian approaches, and how to implement and evaluate these approaches. It is a summary of the course <a href="https://www.youtube.com/watch?v=QY8JXpnllb0&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=5">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 5 — Bayesian Meta-Learning’</a>.</p><p><strong><em>For meta-learning algorithms, 3 algorithmic properties are important: expressive power, consistency, and uncertainty awareness. </em></strong>Expressive power is the ability for f to represent a range of learning procedures, it measures scalability and applicability to a range of domains. Consistency means learned learning procedure will solve tasks with enough data, this property reduces reliance on meta-training tasks, which leads to good out-of-distribution performance. Uncertainty awareness is the ability to reason about ambiguity during learning. It allows us to think about how we might explore new environments in a reinforcement learning context in order to reduce our uncertainty. It also thinks about if we are in safety-critical settings, we want to calibrate uncertainty estimates. It also allows us to think about, from the Bayesian perspective of Meta-learning, what sort of principle approaches can be derived from those graphical models?</p><p>This story covers 1. Why be Bayesian? 2. Bayesian meta-learning approaches 3. How to evaluate Bayesians</p><h3>Why be Bayesian?</h3><p>The principle of multi-task and meta-learning principles are training and the test must match, and tasks must share “structure”. What does “structure” mean? it means statistical dependence on shared latent information theta.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmuI7PC8V-zxG0a1R-QxBQ.png" /><figcaption>source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>The graphical model, where theta is the meat parameters that are shared across all tasks. Φi is the task-specific parameters for each task i. In particular, this graphical model shows some dependency on θ. Basically, each of the parameters ϕi has an arrow coming from θ. If your condition on the information in θ, the task parameters (ϕs) become independent, which is ϕi is independent of another ϕi conditioned on θ. If you do condition on θ on the latent information, then they are not otherwise independent. These properties indicate that the distribution over ϕ given θ has lower entropy than the distribution of the marginal of ϕ. Essentially, θ tells you information about task-specific parameter ϕ.</p><p>What if you could identify θ (for example, through meta-learning),<strong> in which situations would it not be faster to learn ϕ in comparison to learning from scratch?</strong> If ϕs are independent before knowing to condition on θ, which means their entropies will be the same, then learning from scratch will just as fast as learning from the shared information θ. If a single point carries all the information of θ, then the shared information basically doesn’t tell you that much because the information also exists in a single data point. The entropy conditioned on θ is going to be fairly high as well as the marginal entropy. <strong>What if the entropy of ϕ given θ is zero? </strong>It means there isn’t any additional information in ϕ that isn’t captured in θ, then θ can solve all of the tasks, and you don’t need to do anything to learn from θ.</p><p><strong>What information might theta contain?</strong> If the family of tasks corresponds to sinusoids with different amplitudes and different phases, then Theta will correspond to that family of sinusoid functions. In machine translation example, θ corresponds to the family of all language pairs, and the information in ϕ that isn&#39;t present in theta is going to correspond to things that are specific to a particular language. Note that in both of these examples, theta is narrower than the space of all possible functions (this why we can get benefit from using meta-learning in principle)</p><p>If you have an infinite number of tasks, you should be able to recover theta exactly, or basically recover that family with high precision. <strong>What if you meta-learn without a lot of tasks? i</strong>f you have a space of tasks, it won&#39;t necessarily cover the true distribution of tasks but will potentially<strong> meta overfitting</strong> to that space of tasks, such that actually doesn’t recover θ that corresponds to all language pairs for example, but it finds the θ that corresponds to a set of language pairs that looks like the things in your training data, and not something that captures the full distribution. <strong>As a result, you won’t be as effective at adapting to new things from that distribution unless the test data are very close to the training examples</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*-U52QwETOjiirkoOWZFstw.png" /><figcaption>few-shot learning problems may be ambiguous. There are two classes “+” and “-”. For “+” class, characteristics of pictures maybe “Smiling”, “Wearing Hat”, and “Young”. But the rightmost test-images contains some characteristics but not all of them, so it’s ambiguous to tell which class these test-images belong to. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/1*5brl8XqQLtsfMJBFc7nGfA.png" /><figcaption>parametric approaches use a deterministic estimate of this distribution, while the Bayesian meta-learning approach tries to sample from this distribution. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>For<strong> the parametric approaches,</strong> what we recovered was the deterministic estimate of the task-specific parameters ϕ, given the dataset and meta-parameters θ. So you’d essentially<strong> get a point estimate for this distribution.</strong> Where/why is this a problem? <strong>We need more than just a point estimate in some situations.</strong> For example, some few-shot learning problems may not be fully determined by their data, maybe the underlying functions are ambiguous given the evidence that you have your prior information. Here in this example, ambiguity is because the dataset is small. To reconcile this problem, <strong>what if we can generate hypotheses about the underlying function? </strong>If we can sample from this distribution, we can then reason about our uncertainty, and this is important for safety-critical few-shot learning. It allows us to learn active learn and explore in meta-RL. That’s where Bayesian meta-learning approaches come in.</p><h3>Bayesian meta-learning approaches</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-wYju7s80ndF2UYd5z4oVA.png" /><figcaption>From the computation graph perspective. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>If we care about generating a distribution over our predictions, <strong><em>one approach is to let function f output the parameters of distribution over labels</em></strong>. For example, you let f output something that corresponds to the probability of discrete categorical distribution if your label y is discrete; you can also output the mean and variance of the Gaussian distribution to represent a Gaussian distribution over your labels; or if you have a more multi-modal distribution, you could try to represent the means and variances and mixture weights of a mixture of Gaussian; or if you have a multidimensional output label y, then you could output the parameters of a sequence of conditional distributions to allow you to represent the joint distribution over those variables, which is an autoregressive model. Once you output the parameters of the distribution, you can then train any of these approaches with<strong><em> the maximum likelihood estimate optimizing</em></strong> both over the mean of the distribution as well as the variance or basically all the full probability values of that distribution.</p><p>The <strong>benefits</strong> of this approach are they are <strong>simple</strong> and<strong> can combine with a variety of methods</strong>. The <strong>downside</strong> is this approach <strong>can not reason about uncertainty over the underlying function</strong> to determine how uncertainty across datapoints relate. It also tends to <strong>produce poorly-calibrated uncertainty estimates.</strong> For example, you cant disentangle model uncertainty versus label noise. It is also <strong>limited to a particular class of distributions over y</strong>.</p><p>Can we do the same maximum likelihood training for ϕ? We can not do it exactly the same way because we don’t have labels corresponding to ϕ, unless we generated labels.</p><h3>Bayesian meta-learning approaches</h3><h4>The bayesian deep learning toolbox</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*HlXiPYH0fOhtTn3HQP1O1w.png" /><figcaption>a variational auto-encoder. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>The bayesian deep learning aims to represent distribution with neural networks. There are numbers of approaches to representing distributions with neural networks. <a href="https://arxiv.org/abs/1312.6114"><strong><em>One popular approach</em></strong></a><strong><em> is to use latent variable models and then optimize them with variational inference.</em></strong> So in particular, we have a graphical model where we have latent variable Z and observed variables X. For example, the left graphical model for a variational auto-encoder. You can formulate a lower bound of the likelihood objective and use that to optimize over a distribution over X where that distribution over X may be non-Gaussian because it has this latent variable.</p><p><a href="https://papers.nips.cc/paper/7219-simple-and-scalable-predictive-uncertainty-estimation-using-deep-ensembles.pdf">Another approach</a> that has been fairly popular in some regard and is quite simple is to <strong><em>use a particle-based representation of your distribution</em></strong>. And in particular, you can train separate models on different bootstraps of your data. Each of those models will correspond to a particular of your distribution, and then you together those particles represent samples from that distribution.</p><p><a href="https://arxiv.org/abs/1505.05424"><strong><em>Another approach</em></strong></a><strong><em> is to represent an explicit distribution over the weights of neural network parameters.</em></strong> And then practice these distributions tend to be Gaussian with a diagonal covariance matrix, so you have basically an independent variance for each neural network parameter. This allows you to represent a distribution over functions with the caveat that this independent assumption that two parameters are independent is violated in practice all the time.</p><p><a href="https://arxiv.org/pdf/1410.8516.pdf"><strong><em>Normalizing flows</em></strong></a><strong><em> try to represent a function over a data distribution by inverting some latent distribution into your data distribution or transforming from latent space into your data space and back into your latent space</em></strong>.</p><p>In e<a href="https://papers.nips.cc/paper/5423-generative-adversarial-nets.pdf">nergy-based models and GAN</a>, <strong><em>the way to estimate unnormalized density is to have low-energy for your data and higher energy for everything else where everything else is approximated by your generator in a GAN.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*aZ1Ok7opUX9AEWPP_mu0bA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I50kTqsfQv4NVCEE10F0Lw.png" /><figcaption>ELBO. Source:<a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf"> the course slide</a></figcaption></figure><p>This graphical model contains observed variable x, and latent variable z. <strong><em>The evidence lower bound or ELBO wants to be able to estimate a lower bound on the likelihood of data</em></strong> so that the likelihood of data can be optimized. ELBO can be represented by the expectation with respect to q(z|x), plus an entropy term that is regularizing or operating on q(z|x). Q is representing the variational distribution of the probability of x and z. This can be rewritten two terms plus each other, <strong><em>the first term corresponds to the reconstruction loss of the decoder, basically the likelihood of data according to the decoder after sampling from the inference network q, and the second term corresponds to the KL divergence between the inference network and the prior.</em></strong> <strong><em>P corresponds to model and q corresponds to a variational distribution that is introduced in order to approximate the likelihood objective</em></strong>. There are a couple of design choices to how to represent p: p(z) and p(x|z). <strong>P<em>(x|z) can be represented as a neural network,</em></strong> for example, in the case of a variational autoencoder, it represented a neural network that takes in the latent variable and outputs an image or whatever datatype you are modeling.<em> </em><strong><em>P(z) is typically represented as a diagonal Gaussian with unit variance. </em></strong><em>It could also be represented by a neural network as well or as a learned mean and a learned variance. </em>In practical variational autoencoders typically don’t learn it, because the layer afterward can transform it into a learned mean and variance. <strong><em>q(z|x) is also represented by a neural network, which is inferred to as the inference network or your variational distribution.</em></strong> When using variational inference in the context of deep learning, θ represents model parameters and ϕ represents the parameters of inference networks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*DYCGKOI1uyhSyXSWQ3L2bw.png" /><figcaption>reparametrization trick. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>But there is a problem to optimize ELBO<em>. ELBO contains an expectation with respect to q, which means we need to able to back-propagate into the q distribution, but sampling is not differentiabl</em>e. We can use the <strong><em>reparameterization trick</em></strong>. <em>For a gaussian q(z|x), it can be represented in a differentiable way, </em>which is reparametrized in terms of the noise that is sampled from a unit Gaussian. <em>In particular, if we represent the distribution of latent variable as a Gaussian that corresponds to the output of the neural network q, which is outputting both the mean and variance, then you can represent the output of q (Gaussian distributed) as being reparameterized by the noise rather than sampling from that particular distribution of the mean plus the variance times that noise. </em>Fortunately, this equation is something that’s differentiable. If your inference network is expressive enough, it should be able to transform your data distribution into this Gaussian distribution over latent variables.</p><p>This is often called<strong><em> amortized variational inference</em></strong>, we have an inference network that’s predicting what the variational distribution will be as basically amortizing the process of estimating that distribution. Can we use amortized variational inference for meta-learning?</p><h3>Bayesian meta-learning approaches</h3><h4>Bayesian black-box meta-learning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*aMKfcTD7VhirLXgFrlCqlQ.png" /><figcaption>black-box meta-learning approaches. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>First, let’s think about black-box meta-learning approaches for simplicity. In particular, what we want to have a neural network that takes as input a training dataset and produces a distribution over our parameters Φ. Then applying ϕ to parametrize a neural network that takes as input x and outputs y. The goal is to be able to maximize the likelihood of the test data points given task-specific parameters when sampling task-specific parameters as a function of our training dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*Gv84wBc-cJahIO45xOWUXA.png" /><figcaption><strong><em>amortized variational inference into meta-learning. Source: </em></strong><a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf"><strong><em>the course slide</em></strong></a></figcaption></figure><p>In standard VAE, the observed variable is x and the latent variable is z. While in meta-learning, the observed variable is dataset and the latent variable is ϕ. ELBO is taken into mat-learning. It has a variational distribution over the task-specific parameters ϕ, where we will sample from and estimate the likelihood of the data given ϕ. The KL term indicates that the variational distribution and the prior over phi should be similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1z1ksEuIIr31-C9c7GQFsA.png" /><figcaption>source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>There are two design options for<strong> q condition on.</strong> If you want to be able to sample parameters as a function of our dataset, then we should<strong> condition q on our training data</strong> (this is shown in the first equation). How does this training data differ from the probability of test data points? <strong><em>So you want to be able to maximize the likelihood of the test data points given our task-specific parameters when sampling our task-specific parameters as a function of our training dataset </em></strong>(this is shown in the second equation).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*FrLlyFRl4NnFAHA7mbtSEw.png" /><figcaption>the meta-parameter theta. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>What about the meta-parameters θ? We will have a prior over the task-specific parameters ϕ be conditioned on θ. The distribution over test data points is a function only of Φ. We could also condition on θ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*1Q8miCSHuqQuAj-CUwRzTg.png" /><figcaption>the final objective(for completeness). Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>The final objective maximizes w.r.t. the meta parameters and expectations over all of the tasks. Task-specific parameters are sampled from the neural network q, and then they are applied to maximize the likelihood of p. The term one the right encourages q to stay close to some prior distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61DIQMyV6vkrvdjrqq4GOg.png" /><figcaption>bayesian black-box mete-learning overview. Source:<a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf"> the course slide</a></figcaption></figure><p>To summarize bayesian black-box meta-learning, some benefits and downsides are listed. One benefit is that <strong>it can represent non-Gaussian distributions over y</strong>, and it also <strong>generates distribution over task-specific parameters ϕ,</strong> rather than just generating distribution over labels (y^{ts}). This allows it to represent uncertainty over the underlying function, and not just about the underlying data points. The downside is that <strong>it can only represent Gaussian distributions of p of ϕ given θ.</strong> There are 2 reasons for that. One is the reparameterization trick, which holds for Gaussian. The second thing is that the KL terms that come up in the objective is something that can be evaluated in closed form for Gaussians but can not be evaluated in closed form for other non-Gaussian objectives.</p><h3>Bayesian meta-learning approaches</h3><h4>Bayesian optimization-based meta-learning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJ2dTMyTHt_5Rex2qbDFUQ.png" /><figcaption>recasting Gradient-based Meta-learning as Hierarchical Bayes. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p><a href="https://arxiv.org/abs/1801.08930">We can recast gradient-based meta-learning as hierarchical Bayes.</a> This is nice in that it provides a Bayesian interpretation of MAML as a kind of learning meta parameters such that at test time you are doing map inference under a Gaussian prior represented by your meta parameters. It’s using a map estimate of task-specific parameters ϕ as a function of θ, which means that it’s representing a point estimate of this distribution and it’s only giving you one set of parameters for this distribution and you can’t sample from this distribution or more easily represent the full distribution of your task parameters for example.</p><h3>Bayesian meta-learning approaches</h3><h4>Amortized bayesian meta-learning</h4><p><strong><em>Q is an arbitrary function</em></strong>, it can include a gradient operator. It’s <em>so you can have an inference network that is basically performing gradient descent inside your inference network</em>. Because q doesn’t need to be a neural network, it could be anything that outputs a distribution over ϕ. <a href="https://openreview.net/pdf?id=rkgpy3C5tX"><strong><em>In the paper (Amortized Bayesian Meta-learning)</em></strong></a><strong><em>, we are going to be running gradient descent w.r.t. the mean of a set of parameters and the variance of the set of parameters w.r.t. some training data, and then everything else is the same. </em></strong>In contrast to things like MAML, this is not just running a gradient descent on a parameter, <em>it’s running gradient descent on the mean and the variance of the parameters and at the end of this procedure, you get both the mean and variance of the parameter instead of just a mean. </em>The <strong>benefit</strong> is you running <strong>gradient descent at test time,</strong> so we get an optimization-based meta-learning approach by basically stuffing gradient descent into the reference network. The downside is that p(ϕi|θ) is modeled as a Gaussian.</p><p>Can we model non-gaussian posterior?</p><h3>Bayesian meta-learning approaches</h3><h4>Ensembles</h4><p>We can model non-Gaussian posterior with maintaining separate model instances. There are several papers about ensembling MAMLs.</p><p><a href="https://papers.nips.cc/paper/7963-bayesian-model-agnostic-meta-learning.pdf">Ensemble of MAMLs (aka EMAML) </a>trains M independent MAML models, it doesn&#39;t work well if ensemble members are too similar. We can take this idea to ensemble black-box and non-parametric methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*LWLWDG26pBgvkQNs7gi7Nw.png" /><figcaption>source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p><a href="https://arxiv.org/pdf/1806.03836.pdf">BMAML</a> is a more diverse ensemble of mammals, basically, it does is it pushes the different ensemble members away from each other encourages them to represent different models.<strong><em> The way that you accomplish this is that when you are running gradient descent, you have your typical likelihood term, but you also have a term that encourages by different ensemble members to be different from one another. And there’s different kernel like functions that you can do to represent the similarity between models.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*66SW265pR6ycF7z4Mzm3ww.png" /><figcaption>BMAML optimization. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>Instead of just pushing the particles away from one another, they also optimized such that the ensemble gives you a distribution of particles that produce high likelihood. And so instead of completely separately training these different models, t<strong><em>hey took their ensemble and they optimized a term that they optimized them all jointly together.</em></strong> So you are optimizing for the likelihood that’s averaged over those M particles.</p><p>The benefits of these ensemble models are they are simple, tend to work well, and also they can model non-gaussian posterior. The downside is you need to maintain M models instances or do gradient-based inference on the last layer only. Can we model non-Gaussian posterior over all parameters without having to maintain separate model instances?</p><h3>Bayesian meta-learning approaches</h3><h4><a href="https://arxiv.org/abs/1806.02817">Probabilistic MAML</a></h4><p>Can we sample parameter vectors with a procedure like Hamiltonian Monte Carlo? in particular what Hamiltonian Monte Carlo does is it adds noise and then runs gradient descent, repeatedly in order to be able to sample from some distributions. The intuition is learning a prior where a random kick can put us in different modes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*x017_aUkVXwNCbdiyZMwiQ.gif" /><figcaption>The loss landscape. source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>In this loss landscape, there are different modes of solutions. One corresponds to a classifier that classifies on “smiling” and “wearing a hat”, one that classifies on “smiling” and “being young”. We want essentially parameter vector in the middle such that if we add some noise to that parameter vector and then run gradient descent, we get 2 different modes of this solution. We get different functions that represent different modes of the correct answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DnTqWELNa5EoILIPP7Aj3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*_pSZL7vFZ_iaktOm42oKqg.png" /><figcaption>inference at test time in probabilistic MAML. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>In this case, theta would be a distribution instead of a single parameter vector. Our goal will be to sample different task-specific parameters given all of the observed variables at test time, which are x train, y train, and x test. We can cross over x testbecause y testis not given and others remain conditionally independent, so you can just sample from the function ϕ given x train and y train. The exact solution for this distribution is completely intractable because of its integral. If we knew how to sample phi given theta x train and y train, then sampling becomes a lot easier. We can crudely approximate this distribution using a point estimate for ϕ by MAP inference. We can still actually sample from ϕ where we first sample from θ then we run a few steps of gradient descent. This is what happens at test time where we want to do inference. Training can be done with amortized variational inference, you can check out the <a href="https://arxiv.org/abs/1806.02817">paper</a> for details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytBBWe8zL4tVdKsD0rQqVw.png" /><figcaption>ancestral sampling in probabilistic MAML. Source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>What does ancestral sampling look like? There are 2 steps: <strong><em>first, we sample from P of θ which has a mean and variance; then we run gradient descent starting from the sample theta, running gradient descent w.r.t our theta. It allows us to represent these types of multimodal distributions.</em></strong></p><p>The <strong>benefits</strong> of this approach are <strong>it has non-gaussian posterior, simple at test time, and has only one model instance</strong> (in contrast to ensembles of MAML). The downside is <strong>it has a more complex training procedure</strong>.</p><h3>Bayesian meta-learning approaches</h3><h4>Methods summary</h4><p>Three methods are covered. The first is train a function f to output a distribution over y test. The benefits are it is simple and can combine with a variety of methods. But it can not reason about uncertainty over the underlying function and also a limited class of distribution over y test can be expressed. The second approach is black-box approaches, where using latent variable models and amortized variational inference. The benefit is it can represent non-gaussian distribution over y test but it can only represent gaussian distribution p(ϕi |θ), it is okay when ϕi is a latent vector. For optimization-based approaches, we mentioned 3 types: amortized inference; ensembles, and hybrid inference. Amortized inference is simple but it model p(ϕi |θ) as a Gaussian. Ensembles approach is simple, tends to work well, and has non-Gaussian distribution but it contains M model instance. The hybrid inference has a non-gaussian posterior, it’s simple at test time and only has one model instance, but it has more complex training procedure.</p><h3>How to evaluate Bayesians</h3><h4>How to evaluate a Bayesian meta-learner?</h4><p>How about using the standard benchmarks, such as Minilmagenet accuracy? The benefit is it’s standardized so we can easier compare papers. Minilmagene also has real images. But metrics like accuracy do not evaluate uncertainty. Tasks may not exhibit ambiguity, and uncertainty may not be useful on this dataset. What are better problems and metrics? It depends on the problem you care about.</p><p>One way to check the performance of these algorithms is to look at varied toy examples. For example, visualize the underlying function that you are sampling from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_w_QOn1Fh_pXF2NoQJB5g.png" /><figcaption>source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>This example corresponds to the underlying meta-learning functions are both sinusoids and linear functions where there’s noise in the labels to make the task ambiguous. The types of functions that it’s reasoning about in some situations, it’s ambiguous even if it’s sinusoid function or a linear function. And you see this sort of multimodal output from the sampling distribution. It shows that the function can actually represent something that’s multimodal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIYpjpFav9MtL2ZRgFBF5w.png" /><figcaption>source: <a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">the course slide</a></figcaption></figure><p>The second example is a classification example where you are just given one data point, all of the tasks corresponding to circular decision boundaries. And you are trying to classify between positive points and negative points. The D train only contains one positive point and D test contains both positive and negative data points. So basically you can see a visualization of the decision boundaries here shown in the dash-lines, where the neural network is representing these different decision boundaries that kind of represent the structure of the class of functions that it was trained on.</p><p><a href="https://arxiv.org/abs/1806.02817">We can also use likelihood or a combination of accuracy as well as coverage of the distribution to measure performance</a>.<a href="https://openreview.net/pdf?id=rkgpy3C5tX"> Or we can plot the confidence of the predictor versus the accuracy of the predictor</a>.<a href="https://arxiv.org/abs/1806.02817"> There are also active learning evaluations</a>.</p><h3>Reference</h3><ol><li><a href="https://www.youtube.com/watch?v=QY8JXpnllb0&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=5">Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 5 — Bayesian Meta-Learning</a></li><li><a href="http://cs330.stanford.edu/slides/cs330_bayesian_metalearning.pdf">The course slide</a></li><li><a href="https://arxiv.org/abs/1807.05960">Meta-Learning with Latent Embedding Optimization</a></li><li><a href="https://arxiv.org/abs/1903.03096">Meta-Dataset: A Dataset of Datasets for Learning to Learn from Few Examples</a></li><li><a href="https://cs.stanford.edu/~woodward/papers/active_one_shot_learning_2016.pdf">Active One-shot Learning — Stanford Computer Science</a></li><li><a href="https://arxiv.org/abs/1708.00088">Learning Algorithms for Active Learning</a></li><li><a href="https://arxiv.org/abs/1312.6114">Auto-Encoding Variational Bayes</a></li><li><a href="https://arxiv.org/abs/1612.01474">Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles</a></li><li><a href="https://arxiv.org/abs/1806.02817">Probabilistic Model-Agnostic Meta-Learning</a></li><li><a href="https://papers.nips.cc/paper/8161-probabilistic-model-agnostic-meta-learning.pdf">Probabilistic Model-Agnostic Meta-Learning — NIPS Proceedings</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa4eedcb89fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/bayesian-meta-learning-fa4eedcb89fc">Bayesian meta-learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Non-parametric meta-learning]]></title>
            <link>https://medium.com/data-science/non-parametric-meta-learning-bd391cd31700?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd391cd31700</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[meta-learning]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Sat, 16 May 2020 19:51:07 GMT</pubDate>
            <atom:updated>2020-06-05T03:44:12.708Z</atom:updated>
            <content:encoded><![CDATA[<h4>This story covers non-parametric few-shot learning algorithms, which include siamese networks, matching networks, and prototypical networks. This course is a short summary of the course <a href="https://www.youtube.com/watch?v=bc-6tzTyYcM&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=4">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 4 — Non-Parametric Meta-Learners’</a>.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*7tvK_Rv3zsXP8FlGs70Xmw.png" /><figcaption>via W<a href="https://wordart.com/">ordArt</a></figcaption></figure><p>This story covers non-parametric few-shot learning algorithms, which include siamese networks, matching networks, and prototypical networks. It also covers the properties of meta-learning algorithms. This is a summary of the course <a href="https://www.youtube.com/watch?v=bc-6tzTyYcM&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=4">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 4 — Non-Parametric Meta-Learners’</a>.</p><h3>Non-parametric methods</h3><p>Non-parametric methods are simple and work well in low data regimes in ML, such as nearest neighbours. During meta-test time, few-shot learning is exactly precisely in low data regime, so these non-parametric methods are likely to perform pretty well. But during meta-training, we still want to be parametric because we want to be able to scale to large datasets. The key idea of non-parametric approaches is can we use parametric meta learners to produce effective non-parametric learners?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*W84CnulgIRCOwGy5uj-8zw.gif" /><figcaption>compare test image with training images. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>The key idea is using non-parametric learners, such as nearest neighbours. The way to do this is to take a test data point and compare it to all the training dataset data points and find the one training data that looks the most similar and then return the label corresponding that training data. The problem is in what space do you compare? with what distance metric? We could do this in pixel space with L2 distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*Ay0XfPlGJmo9Q8A34hIXUg.gif" /><figcaption>L2 distance in pixel space works poorly.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>But L2 distance works poorly. For example, L2 distance would choose the right image to be the most similar image compared to the middle one. So instead of using L2 distance in pixel space, we can <strong><em>learn to compare using meta-training data</em></strong>.</p><h3>siamese networks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*SSTYwypxK6iJWM-_pOVGxw.gif" /><figcaption>Siamese networks.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>One approach is to train the <strong>Siamese network </strong>to predict whether or not two images are the same class. So you’re essentially just learning to compare pairs of images and classify whether or not they are the same class. You can learn a more semantic distance between two images. So you could take two images from the met-training dataset, and label these two images into 1 or 0 if they are the same classes or not. You repeat this for different pairs of images in your meta-training dataset. At meta test time, we compare each image X-test to each of your images in your training dataset for that task, then you output the label corresponding to the closest images. In short, at the meta-training time, we are training this binary classifier and then at meta test-time, we are performing an N-way classification by doing each of these pairwise comparisons. Since meta-training(train a binary classifier) and meta-testing(testing an n-way classifier) do not match each other, can we do better to match these two procedures?</p><p>The key idea in the <a href="https://papers.nips.cc/paper/6385-matching-networks-for-one-shot-learning">matching network paper</a> is: If we are gonna be doing nearest neighbours at test time in order to match our test query image to each of our training data points, how about we<strong><em> train an embedding space such that nearest neighbours produce accurate predictions</em></strong>?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*OSqXojjUQem0PiQJPFhi_g.png" /><figcaption>the matching network.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p><em>So we take each of the images in our training dataset and them into a learned embedding space. We also take our test query image and embed that into an embedding space. And we compare each of these embeddings to make a prediction.</em> So each of these black dots (where fθ points)will correspond to a comparison between the test embedding and the training embeddings. We take the labels corresponding to each of our training images, and our prediction will correspond to the training labels weighted by their similarity score. <strong><em>The model is trained end-to-end.</em></strong> Most critically here meta-training is about showing what’s happening at meta-testing. During meta-training, you are making comparisons to all the images in your training dataset and at meta test-time you are doing the same thing, making predictions for each of the n-way classification problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NglCDd7WbrynoxpSvrzpA.png" /><figcaption>The general algorithm for non-parametric method.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>The <strong>general algorithm</strong> for non-parametric methods is basically the same as the algorithm for amortized (the black-box )approach. We first sample a bunch of tasks(step1), we sample a train and test dataset for each of those tasks(step2), then compute predictions using the learned similarity metric (step 3). Note here unlike the parametric methods, <em>we don’t have parameters phi, which are essentially integrated out into this comparison. </em>Then once we have these predictions, we update the parameters of this learned embedding function with respect to the loss function of how accurate our predictions are on the test set (step4). This loss function would be something like cross-entropy, for example, and we’ use the predicted distribution over test labels rather than only the output that the max labeled.</p><p>For one-shot classification where we have one example per class, the matching network is pretty straightforward since it makes comparisons to each of those classes. But what if we have more than one shot? <strong>If we have more than one data point per class, then the matching network performs these comparisons independently</strong>. Maybe we could aggregate information per class in a way that is smarter than just performing these independent comparisons. That’s what <strong>prototypical networks </strong>do.</p><h3><strong>prototypical networks</strong></h3><p><strong><em>Prototypical networks aggregate class information to create a prototypical embedding of that class and then perform comparisons to each of those prototypical class embeddings in order to predict the label corresponding to our test image.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*f_v3IfIIm4nAPqB6uNjmpA.png" /><figcaption><em>Prototypical networks.</em>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>So what this more concretely looks like is, <em>we will have a number of images for different classes</em>. On the left picture, different colors correspond to different image classes in our training dataset for a particular task. We embed each of our training images into this embedding space. And then take the average in this embedding space in order to compute the prototypical embedding for class 1,2, and 3. Then we embed our test image into the same space, same exact space, and compute the distance to each of those prototypical class embeddings. Finally, we can output the class for which it is closest to in this embedding space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*ZH6hc64IxjrC1cfeiUuZPQ.png" /><figcaption><em>Prototypical networks equations.</em>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>The equation shows it will embed each of the images in for a particular class into this embedding space and then take the average for each of those images. To compute the class of our test data point, we will take the distance between the embedded test data point in each of those classes and perform a softmax over each of those negative distance in order to compute the probability for the test data point. In this case, d corresponds to Euclidean or cosine distance.</p><h3>Other non-parametric methods</h3><p>Basically these non-parametric approaches embed your data points and then do nearest neighbours in that learned embedding space. <strong><em>One challenge is what if you want to reason about the more complex relationship between data points rather than just doing nearest neighbours in your embedding space?</em></strong> In principle, if you have an expressive enough encoder in your embedding space, then nearest neighbours should be able to represent a wide range of complex relationships, particularly for high-dimensional embedding spaces. But in practice, people have found it to be useful to think about <em>more expressive ways</em> to perform these types of comparisons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lO2TxkST9a9CfAgz2gVWvg.png" /><figcaption>other non-parametric methods.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>For example, <a href="http://openaccess.thecvf.com/content_cvpr_2018/papers/Sung_Learning_to_Compare_CVPR_2018_paper.pdf"><strong>relation networks </strong></a><strong>basically take prototypical networks and learn the non-linear relation module on top of those embeddings.</strong> This basically just corresponds to learning that function D in prototypical networks, instead of using a Euclidean distance metric or a cosine distance metric. So it’s learning both the embedding and the distance metric.<strong> </strong><a href="https://arxiv.org/pdf/1902.04552.pdf"><strong>Another approach</strong></a><strong> is to instead of having a single prototype per class, have a mixture of prototypes per class</strong>. This allows you to, for example, represent more multimodal class distributions to maybe one class. Lastly, <a href="https://arxiv.org/abs/1711.04043"><strong>another paper </strong></a><strong>performs an embedding on all of our data points and then do some sort of message passing scheme</strong> in order to think about how these different data points relate to each other and in order to make the predicted output. What this does is it uses graph neural networks in order to perform this message passing and differentiate through it.</p><h3>Properties of meta-learning algorithms</h3><p>parametric approaches. First, we compare this in the computation graph perspective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfEH8-eaATrj8iwRKid_fA.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>The <strong>black-box approaches are repressing this computation graph at a completely black-box approach. T</strong>he optimization-based approaches can be viewed as embedding an optimization into the computation graph. This view can also be taken for non-parametric approaches. For your test datapoint, prototypical networks embed it and compare it to each of your per class prototypes, where those per task prototypes are computed using the embedding of each of those classes’ data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tc1MXkqHK1iMuSjarPCjHA.png" /><figcaption>hybrid models.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>With this view, we can also mix components of the computation graph to generate hybrid models<strong><em>. So</em></strong><a href="https://openreview.net/forum?id=BJfOXnActQ"><strong><em> one approach </em></strong></a><strong><em>which is a bit of a hybrid of black-box and optimization-based approache</em></strong>s, or maybe an optimization-based non-parametric approach (it is dependent on the way you view things). This hybrid approach tries to<em> condition a model on an embedding of the training dataset and also run gradient descent on that model.</em> Although these sources of information by conditioning on the data in a direct way as well as through gradient descent could potentially be redundant, in practice it works well. <a href="https://arxiv.org/abs/1807.05960"><strong><em>Another way </em></strong></a><strong><em>is embedding of your function and then do gradient descent on that embedding space.</em></strong> So this paper use relation network to embed your training dataset and think about how different data points relate to one another. And then they decode this embedding into the parameters of a neural network that makes predictions about new data points. Instead of running gradient descent on the parameters of that function, they run gradient descent in the learned embedding space Z, which produces different functions. You can essentially view it as running gradient descent on a lower-dimensional space of your weights rather than running gradient descent in the original space of your weights. <a href="https://arxiv.org/abs/1903.03096"><strong><em>The last approach </em></strong></a><strong><em>is doing something exactly look like MAML, but initialize the last layer of the network to correspond to prototypical networks</em></strong>. It is basically a specific form of a particular choice of the network architecture for MAML that initializes it to do something like a comparison-based prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*23lbwJvOLT4s5JngTFSr5w.png" /><figcaption>optimization-based approaches (s. tMAML and SNAL) work well on skewed digits, which are not trained during training time; while the black-box approach (metaNet) performs badly on out of distribution task. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">the course slide</a></figcaption></figure><p>we can also compare those three approaches in <strong><em>the algorithm properties perspective</em></strong>. <strong><em>Consistency</em></strong> and <strong><em>expressive power</em></strong> are two properties that important for most applications. E<em>xpressive power is the ability to represent a range of learning procedures, it measures scalability and applicability to a range of domains</em>. <em>Consistency means learned learning procedure will solve tasks with enough data regardless of the properties of that task</em>. For example, gradient descent approach corresponds to a consistent learning procedure because if we just run gradient descent at test time, you can expect given enough data for that test task, you will be able to solve a task regardless of what your meta-training data was. <em>Consistency would reduce reliance on meta-training tasks, which leads to good out of distribution (OOD) performance</em>.</p><p><strong><em>For supervised learning, very deep models usually are expressive</em></strong> (this does not hold for some RL algorithms). So the black-box approach has complete expressive power while the optimization-based approach is expressive for very deep models and the non-parametric approach is expressive for most architectures. In terms of consistency,<strong> black-box is not consistent at all</strong>, while the o<strong>ptimization-based approach is consistent </strong>since it reduces to gradient descent problems. <strong>Non-parametric methods are consistent in the sense</strong> <em>that if your embedding is not losing information about the input, which is important for making decisions,</em> <em>then as you accumulate more and more data, asymptotically it will eventually get to a data point that’s arbitrarily close to your test datapoint and then be able to make the correct prediction for that test data point</em>.</p><p>There are some other (dis)advantages to these methods. <strong>As the black-box approach is easy to combine with a variety of learning problems</strong>, such as supervised learning and RL; but <strong>it is often data-inefficient </strong>since you need to train a neural network from scratch, and it is <strong>challenging to optimize</strong> since there’s no inductive bias at the initialization<strong>.</strong> <strong>The optimization-based approach has positive inductive bias at the start of meat-learning </strong>and it <strong>handles varying k and large k well. </strong>For example, if you have more data than what you trained on, these approaches still tend to work well because they are consistent. It is <strong>model-agnostic.</strong> But it includes<strong> second-order optimization, </strong>which leads to this approach<strong> compute and memory intensive</strong>. Non-parametric approaches are<strong> entirely feedforward</strong>, they don’t evolve any backpropagation within that computation graph, so as a result, they tend to be very <strong>computationally fast </strong>and<strong> easy to optimize.</strong> But if you test them on more k than what they’re trained on, they tend to underperform what other algorithms are able to achieve. So they are <strong>harder to generalize to varying K </strong>and <strong>hard to scale to very large K</strong>. Besides, so far, they are<strong> limited to classification</strong>.</p><p>Generally, well-tuned versions of each perform comparably on existing few-shot benchmarks. <strong>Which method to use depends on your use-case</strong>.</p><h3>Reference</h3><ol><li><a href="https://www.youtube.com/watch?v=bc-6tzTyYcM&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=4">Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 4 — Non-Parametric Meta-Learners</a></li><li>T<a href="http://cs330.stanford.edu/slides/cs330_lecture4.pdf">he course slide</a></li><li><a href="https://arxiv.org/abs/1801.03924">The Unreasonable Effectiveness of Deep Features as a Perceptual Metric</a></li><li><a href="https://www.cs.cmu.edu/~rsalakhu/papers/oneshot1.pdf">Siamese Neural Networks for One-shot Image Recognition</a></li><li><a href="https://arxiv.org/abs/1606.04080">Matching Networks for One-Shot Learning</a></li><li><a href="https://arxiv.org/abs/1703.05175">Prototypical Networks for Few-shot Learning</a></li><li><a href="https://arxiv.org/pdf/1902.04552">Infinite Mixture Prototypes for Few-Shot Learning — arXiv</a></li><li><a href="https://arxiv.org/abs/1711.04043">Few-Shot Learning with Graph Neural Networks</a></li><li><a href="https://arxiv.org/abs/1711.06025">Learning to Compare: Relation Network for Few-Shot Learning</a></li><li><a href="https://arxiv.org/pdf/1806.02817">Probabilistic Model-Agnostic Meta-Learning — arXiv</a></li><li><a href="https://arxiv.org/abs/1807.05960">Meta-Learning with Latent Embedding Optimization</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd391cd31700" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/non-parametric-meta-learning-bd391cd31700">Non-parametric meta-learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Black-Box Adaptation, Optimization-Based Approaches]]></title>
            <link>https://medium.com/swlh/black-box-adaptation-optimization-based-approaches-268250c49bd9?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/268250c49bd9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[meta-learning]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Sat, 16 May 2020 19:47:40 GMT</pubDate>
            <atom:updated>2020-05-19T07:52:31.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimization-Based Meta-Learning</h3><h4>This story introduces optimization-based meta-learning, which covers black-box Adaptation and optimization-Based Approaches. This story is a short summary of the course <a href="https://www.youtube.com/watch?v=v7otSgpTc0Q&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=3">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 3 — Optimization-Based Meta-Learning’</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*OceYGJimxjRkUWjqmziTvA.png" /></figure><p>This story covers black-box Adaptation and optimization-Based Approaches. This story is a summary of the course <a href="https://www.youtube.com/watch?v=v7otSgpTc0Q&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=3">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 3 — Optimization-Based Meta-Learning’</a></p><h3>Black-box adaptation approaches</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGKjVnKvF_oxB8_kxRnkvw.png" /><figcaption>the general recipe for designing a meta-learning algorithm. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>As mentioned before, most meta-learning algorithms vary based off of the first plan, basically how do you actually design this function that’s going to infer task-specific perimeters.</p><p>The first class of approaches that we will look at are going to be considering is can we treat this distribution as an inference problem. In particular, neural networks are pretty good at inference. So can we just treat this function as a neural network? This is where Black-box approaches come in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*BUE7WzEbwyZyMEsegAFtGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*HRnK8_x08Y84uNjZ2Qn9vw.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>What this black-box adaptation approach is they essentially just train a neural network to represent the function. A neural network outputs parameters given a training dataset and a set of meta parameters. For now, we are going to be using a deterministic or point estimate of this distribution.</p><p>You will have some neural network that has parameters theta, it takes as input the training data, it can take it as input a sequential fashion or it can take it in all as one batch, and it outputs a set of tasks specific parameters phi i. Then you have a separate neural network that’s parameterized by phi I that makes predictions about test data points. You train this network by using your test dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*MoHJc6Wgb6-c4LVikFC_JQ.png" /><figcaption>Black-box adaptation training goal.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>This nice thing about this approach is that we can just train it with standard supervised learning.<strong><em> We want to be able to maximize the probability of the labels under the distribution that G is producing for all of the test data points and for all of the tasks in your meta-training dataset.</em></strong> So essentially, you are training this neural network such that it outputs parameters that represent an accurate classifier. If you denote this right-hand part as the loss for a set of parameters ϕ given a test data point, then you can essentially view this optimization as the loss function, which also takes parameters that are outputted by fθ, evaluates on your test dataset averaged all of your tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*xXzLKDvYOQ90cOQ7q43bIQ.gif" /><figcaption>Black-box adaptation steps.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>If we want to the optimization, we first sample a task or a mini-batch of tasks (step 1). Then we sample disjoint datasets from that task dataset( which are meta-training dataset of tasks instead of the training dataset), which we will refer to as D train and D test (step 2). So if we have Di, which is all of the data for the task i, then we are going to partition Di into a training dataset and a test set for task i. So particular we can basically randomly select half of them to be used for the training dataset and half of them to be used for the test set at this iteration of the algorithm. Then we will take the training dataset (Di^{tr}, which shows in the green box) to compute the task per-specific parameters ϕ i(step3). Then we will update our meta-parameters using the gradient of the objective with respect to the meta-parameters using the computed task-specific parameters (step 4). And then we will repeat this iteratively using an optimizer, such as Adam, SGD, etc.</p><p>Notably, we are not computing gradients using the training dataset. Instead, we are using the meta-training dataset of tasks. So the task-specific parameters are computed using D train, then we evaluate those parameters using the test dataset for that meta-training task.</p><p>θ is meta parameters and ϕ are considered the task-specific parameters, which is essentially not considered part of the meta parameters. ϕ could be the parameters of an entire neural network, it could also be something that’s more compact. The challenge of black-box adaptation is that if ϕ is literally representing all the parameters of another neural network, <strong>it may not be that scalable to actually output all of those neural network parameters</strong> because neural networks can be very large. <em>You don’t need necessarily to output all of the parameters of a neural network. You could instead just output</em><strong><em> the sufficient statistics of that task </em></strong><em>such that you could effectively make predictions for that task</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*wc8Jh4zD6vDqPIQqwTM8kQ.gif" /><figcaption>replacing ϕi with hi.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p><em>You could use low-dimensional vector hi for task i to represent contextual task information.</em> Instead of having a neural network that outputs all of the parameters phi, it will output some set of sufficient statistics h. Then your new parameters Phi I corresponds to hi as well as part of theta that will parameterize g (ϕi={hi,θg})</p><p>One interesting connection here is that if you recall <em>multi-task learning where we were concatenating task information z into the network, you could view h (hidden state), essentially as a summarization of the task that is used to make predictions for that task</em>. So h and z are very similar. In this case, unlike z, in the multi-task learning setting, we are actually learning the task representation h: we are learning how to produce that task representation h given a small dataset of that task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*A9HJwFVtWVtLitvnfzXmdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*0G19ioiJKOd8Tr_8-HJsww.png" /><figcaption>works that applying the black-box approach.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>One of the earlier approaches <a href="http://proceedings.mlr.press/v48/santoro16.pdf">(left picture) </a>to these sorts of black-box approaches is using LSTMs or Neural Turing Machines that take as input the test inputs and basically the dataset, and be able to use that to make predictions about new data points. Neural Turing Machines are something that has more of an external memory mechanism for which it can essentially store information about the training data points and then access that information when making predictions about new data points. This is not permutation-invariant because you are taking the data points sequentially.</p><p>You could also use an architecture that is permutation-invariant by having a feed-forward function that takes as input each of training data points, x, and y (x1 y1, x2, y2 et cetera)<a href="https://arxiv.org/abs/1807.01613">(right picture)</a>. And then aggregates that information using something like an average operation to compute something that looks like, in this case, what’s denoted as a or r. And then that is passed into another feed-forward network to make predictions about new data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*4RcK0EFdO6z4oxiZy2m29w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*Qg00rysUHPRU9T9Wrp6RcQ.png" /><figcaption>works that applying the black-box approach.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>There’s a wide range of others that have been proposed that have used other memory mechanisms as well in combination with ideas from having slower weights and faster weights (<a href="https://arxiv.org/abs/1703.00837">left picture</a>). Often when people use the term slow weights and fast weights, they refer to the task-specific parameters as fast weights and the meta parameters as slow weights. Because one of them is updated much more quickly than the other one.</p><p>There’s also an architecture that has used a combination of attention mechanisms and convolutions <a href="https://arxiv.org/abs/1707.03141">(right picture)</a>. So in this case, convolutions are usually going to be not permutation-invariant although attention-based architectures can be permutation-invariant. As a representative approach of the black-box approach in general, this type of method that uses convolutions and attention is able to do quite well on things like Omniglot.</p><p>So in summary, the <strong>advantages</strong> of the black-box adaptation approach are: they are <strong>expressive</strong>, and <strong>easy to combine with a variety of learning problems</strong> (e.g. supervised learning, reinforcement learning). The <strong>downside</strong> to this approach is in general, these <strong>neural networks are fairly complex</strong> because they need to be taking in datasets and making predictions about new data points. They essentially need to figure out how to learn from data, and they need to do this basically completely from scratch. As a result, they are often fairly<strong> data inefficient </strong>(not data inefficient at meta-test time) and they often require a large number of meta-training data, a large number of tasks in order to perform well.</p><h3>The optimization-based inference</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGKjVnKvF_oxB8_kxRnkvw.png" /><figcaption>the general recipe for designing a meta-learning algorithm.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>As mentioned before, if we want to infer all of the parameters of a neural network, having a neural network output is not a very scalable way. Instead of treating the function(shown in the first step in the left picture) as an inference problem, we can instead treat it as an optimization procedure. That’s where optimization-based inference comes in.</p><p>The key idea is<strong><em> obtaining our task-specific parameters ϕi through optimization</em></strong>. And then we will differentiate through that optimization procedure to the meta parameters to optimize for a set of meta parameters such that optimization procedure for ϕi leads to good performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*L_aD64EPG0EsQBrIA2AmqA.png" /><figcaption>breaking down the meta-learning problem into 2 terms.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>You can essentially break down the meta-training problem as having 2 terms, <strong><em>one is maximizing the likelihood of your training data given your task-specific parameters and one is optimizing the likelihood of your task-specific parameters under your meta parameters</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYvQlfUTVal5ablAspYM8Q.png" /><figcaption>fine-tuning.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>Your<strong><em> meta parameters are serving as your prior</em>,</strong> what form of prior should we basically impose using meta parameters. One very successful form of prior knowledge that we’ve used in deep learning optimization is the <strong>initialization</strong>. One thing is quite successful is called<strong> fine-tuning,</strong> <em>where we take some set of initial parameters and then run gradient descent on training data for some new task</em>. Typically, this is not for just a single gradient step as shown here but for many gradient steps.</p><p>In many ways, this is a valid approach to the meta-learning problem where you first pre-train a set of parameters on your meta-training dataset and then fine-tune on your dataset at test time. But <strong>where do you get your pre-training parameters</strong>? <strong>For vision problem,</strong> the typical way to do this is by pre-trained on <strong>ImageNet classification</strong> as suing supervised learning. <strong>In language</strong>, one very popular approach for doing this is using models trained on large language corpus, <strong>models like BERT or Language Models</strong>. Or we could get pre-training parameters by other unsupervised learning techniques. <em>You can train a large and diverse dataset and then fine-tune those parameters on whatever dataset you actually want to perform inference on.</em></p><p>Fine-tuning is very common, so there’s a range of common practices for performing fine-tuning successfully. This includes things like<strong><em> fine-tuning with a smaller learning rate, using a lower learning rate for lower layers of the network.</em></strong> Typically for many fine-tuning problems, <strong><em>the low-level features are the things that need the change the least, and the higher-level concepts are the things that need to change the most for a new task.</em></strong> You may actually freeze earlier layers of the network. Potentially even basically setting a learning rate of zero for those layers. You could also consider<strong><em> re-initializing the laster layer</em></strong>. And then typically people<strong><em> search over these hyperparameters using cross-validation</em></strong>. <strong><em>Architecture choices tend to matter</em> </strong>a lot when choosing how to fine-tune. For example, things like <em>residual network </em>tend to be actually quite good at fine-tuning because the gradient flows relatively easily through various parts of the network when you have residual connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WYZbVio2WD2b4Az_WcB4KA.png" /><figcaption>Fine-tuning less effective with very small datasets.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p><strong>Fine-tuning is less effective with a very small dataset.</strong> <a href="https://arxiv.org/abs/1801.06146">This paper </a>shows as you the number of training examples for the test task varies (on the x-axis), how does the performance on that task vary? The blue line indicates training from scratch, while orange and green lines are trained with pre-trained parameters from universal language models or ULM. The gap between the blue line and the orange/green lines indicates that <em>there’s a big difference between training from scratch versus using pre-trained parameters.</em> Besides, <em>as you have fewer examples in your new test dataset, performance gets worse</em> as our error goes up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLidbfRwiFXpanUggxNe7g.png" /><figcaption>optimization-based inference.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>How about we design a meta-learning algorithm with the goal of being able to fine-tune with small amounts of data at test time? In particular, <em>we could take our fine-tuning procedure, and evaluate how well those task-specific parameters did on a test dataset or on new data points, then optimize for pre-trained parameters such that fine-tuning gives a set of parameters that do well on the test data points</em>. You can do this optimization <em>across all of the tasks in your meta-training dataset such that fine-tuning with small amounts of data leads to good generalization. </em>So essentially, <strong><em>it’ll be training for a set of parameters theta across many different tasks such that it can transfer effectively via fine-tuning</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*dAZGnMbRYJ3_eNaCtg8EUg.gif" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>At a more intuitive level, <em>θ is the meta parameters, and ϕi* is the optimal parameter vector for task i.</em> Then you can view the meta-training process of this optimization as the thick black line where when you are at this point during the meta-training process and you take a gradient step with respect to task 3, you are quite far from the optimum for task 3. Whereas at the end of the meta-training process, you take a gradient with respect to task 3, you are quite close to the optimum. And likewise, for a range of other tasks. We refer to this as the <strong><em>Model-Agnostic Meta-Learning algorithm,</em></strong><em> in the sense that it embeds this optimization procedure in a way that’s agnostic to the model that’s used and the loss function that’s used, as long as both of them are amenable to gradient-based optimization</em>. This diagram is intuitive but also misleading. First, typically neural network parameters do not exist in 2 dimensions. Besides, there often is not a single optimum, but actually a whole space of optima for neural network parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*66GMfbMdREcNsVbFEIqCcg.png" /><figcaption>optimization-based inference.Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>Let’s look into the algorithm. We take first take the algorithm for a black-box approach, then adapt it to the optimization-based meta-learning case. Essentially, you first sample a task, you can sample your datasets. Then instead of computing your task-specific parameters using a neural network, you are going to be computing them using one or a few steps of fine-tuning. And then you update your meta-parameters by differentiating through those fine-tuning steps into your initial set of parameters.</p><p>One thing worth mentioning about this algorithm is that<em> it brings up second-order derivative </em>because we are optimizing for a set of meta parameters. There a gradient indirectly calculating theta, and inside the inductive term ϕi we also have a gradient need to be calculated. It would be troublesome to compute the full hessian of the neural network. What if you want more than one integrated step, does that give us higher-order derivatives? To answer these questions, we need to go through what meta gradient update looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysW60kZa0H0qd4FDjj6hJQ.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide</a></figcaption></figure><p>Here u denotes as the update rule, and that’s gonna be a function of theta and your training point D train. `d` denotes the total derivatives, the nabla symbol denotes partial derivatives. The result shows that we don’t need to compute the full Hessian of the neural network instead of <strong><em>the Hessian vector product.</em></strong> And there are much more efficient ways to compute Hessian vector products via backpropagation for neural networks and it doesn’t require you to construct the entire Hessian of the neural network. This is the single step in the inner loop. What if we have multiple inner gradient steps in the inner loop?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*Ev1ffcEdJT2CeQemE8yG5w.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide</a></figcaption></figure><p>What if we have 2 gradient steps. The nice thing here is we don&#39;t have high-order terms showing. Basically computing with additional backward passes without having to basically construct any full Hessians or without having to compute higher-order derivatives which is nice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*OWVEecX5C5S4PUlEedzbuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*60LPafFkVi0LeNU8JEtHGQ.png" /><figcaption>black-box adaptation and MAML. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>Let’s compare black-box adaptation and MAML. Black-box adaptation takes a training dataset and test input to train a neural network. MAML also takes a training dataset and a test input, and in MAML you have a function phi that takes the test input as input, and the parameters phi are computed with gradient descent.<strong><em> MAML can be viewed as a computation graph with an embedded gradient operator</em></strong>. You can mix and match components of the computation graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*7KwTaeZcQ5RIsmJ1ngbdKA.png" /><figcaption>Replace gradient update with a learned network. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>For example, <a href="https://openreview.net/pdf?id=rJY0-Kcll">one paper </a>learns initialization but replace gradient update that MAML does with a learned network that produces that gradient update.</p><p>How these approaches not just compare conceptually, but also in practice and in theory. <strong><em>What if your test task is different than the meta-training tsks that you were optimizing on?</em></strong> We were aiming to compare MAML to black-box type approaches, such as SNAIL which the architecture used attention and convolutions, as well as MetaNetworks. We look at <em>Omniglot image classification </em>where we tried to vary the tasks and see how the performance did as you vary the tasks away from the meta-training distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*xGTvMxCJF2vap5IYgK8V9g.png" /><figcaption>MAML and black-box adaptation performance on out of distribution tasks. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>So <a href="https://arxiv.org/pdf/1710.11622.pdf">in this case</a>, <em>the x-axis shows the task variability, and the y-axis shows performance</em>. Models were trained on unskewed digits which were shown in the middle. <em>We move away from the meta-training task distribution testing its ability to adapt to tasks that involve skewed digits</em>. <em>It shows that all approaches, their performance deteriorated as you moved away from the meta-trained distribution.</em> <strong><em>But algorithms like MAML are better able to perform these out of distribution tasks </em></strong><em>because they are performing an optimization procedure at test time, so you can still expect it to give you some reasonable answer, at least an answer that achieves good accuracy on the training dataset for example.</em> Whereas black-box approached are just taking in a dataset as input and producing an answer, so when you move away from the training distribution, this algorithm does nothing useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knwTEBgpBTqOqy_XbowAeQ.png" /></figure><p>We are embedding the structure of optimization into the Mediterranean process, does this come at a cost ? How far can you actually get with a single gradient step or a few gradient steps? Are these methods actually as expressive as the black-box approaches? <strong><em>For a sufficiently deep function f, the MAML function can approximate any function of the training data set and the test input.</em></strong><em> It can basically represent anything that the black-box approaches can represent under a few fairly mild assumptions, which are </em>the inner learning rate is non-zero; the loss function gradient does not lose information about the label; and also that the data points in your training dataset are unique.</p><p><strong>MAML has the benefit of inductive bias without losing expressive power, </strong>which means even before you do any meta-training for MAML, you still have an optimization procedure that’s going to point you roughly in the right direction, so you are still running gradient descent and you will still be able to improve on your training data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*qG4vnCnaV0SO02jWI1PO3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*63vB7va8Li7RrIa6eG4Zqg.png" /><figcaption>Probabilistic interpretation of Optimization-Based Inference. Source: <a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">the course slide.</a></figcaption></figure><p>You can view meta-parameters theta as serving as a prior for task-specific adaptation. The prior is encapsulating the knowledge in your mate training dataset. One form of prior knowledge is initialization for fine-tuning. In the graphical model, theta is representing our meta parameters and ϕi is denoting the task-specific parameters. The shaded circles representing the data points that we have for each task and it’s shaded because we could observe those during the meta training process. How to do inference in this graphical model? We want to maximize the likelihood of our dataset given our meta parameters. This likelihood can be rewritten in integrating ϕ. But this rewritten form is intractable, we can approximate this integral with a point estimate for ϕi which represents the maximum a posterior(MAP) estimate. How to compute MAP? <strong>It turns out under specific conditions, gradient descent with early stopping corresponds to MAP inference with under a Gaussian prior with mean at the initial parameters and a variance that is determined by the number of gradient steps and the step size.</strong> This is exact in the linear case, approximate in non-linear cases. This means <em>obtaining the MAP estimate by running gradient descent with early stopping that corresponds to the inner loop of the MAML objective,</em> and then you can loosely view MAMLs approximating hierarchical Bayesian inference in this graphical model. It involves several approximations, one is the MAP estimate and another is thinking about gradient descent with early stopping as MAP inference in the nonlinear case with neural networks (Unlike typical neural network training, in MAML, the number of gradients steps were chosen rather than a stopping criterion based on a validation error for example). This interpretation is helpful for getting some intuition for what these kinds of approaches are doing.</p><p>You can view this form of initialization with a few gradient steps as one form of implicit prior on the task-specific parameters. There are other ways to think about priors that we could impose on the optimization process. So for example, <strong>instead of having this implicit prior which is imposed by only doing a small number gradient steps, </strong><a href="https://arxiv.org/pdf/1909.04630.pdf"><strong>we could have an explicit Gaussian prior where we regularize the inner optimization to be close to the meta parameters theta</strong></a><strong>.</strong> So this would correspond to an explicit Gaussian prior with mean θ and variance (which is a function of λ). <strong>Another form of prior is a </strong><a href="https://arxiv.org/pdf/1807.08912.pdf"><strong>Bayesian linear regression on top of learned features</strong></a><strong>,</strong> the mean and variance of the Bayesian linear regression are meta parameters themselves. These are 2 forms of gradient-based meta-learning algorithms that tried to place explicit priors on it. Another class of methods just have the prior be imposed based on the feature space in which you are learning. It’s similar to the last approach where they are doing Bayesian linear regression on the last layer. There are also a number of approaches that have done an optimization on top of learned features, such as performing <a href="https://openreview.net/forum?id=HyxnZh0ct7">ridge regression or logistic regression on top of learned features</a> in the inner loop, as well as <a href="https://arxiv.org/pdf/1904.03758.pdf">a support vector machine on those learned features.</a> <strong><em>So essentially these correspond to different inner loops of the meta optimization algorithm, and then the meta-training process involves differentiating through these inner loops by either treating them as a close form optimization, as a convex optimization problem that you can differentiate through, or other optimizations</em></strong>.</p><h4>challenges</h4><p><strong>There are several challenges. </strong>One challenge is about how MAML you may need much deeper networks in order to be able to effectively get an expressive gradient update that can represent a number of different update rules to your parameters. <em>How to choose an architecture that is effective for inner gradient-step</em>? <a href="https://arxiv.org/abs/1806.06927">One approach</a> is <strong><em>we can do neural architecture search on the MAML architecture such that meta-learning works well</em></strong>. They called this<strong><em> auto-meta</em></strong> in the sense that you are doing both AutoML and meta-learning. They found that highly non-standard architectures were actually effective for MAML in contrast to their effectiveness for kind of standard supervised learning problem, for example, d<em>eep and narrow networks work well.</em> For example, if you take Minimagenet with the basic architecture that reaches around 63% performance, MAML with this kind of optimized architecture saw an 11% absolute improvement in performance which is pretty substantial.</p><p>Another challenge that comes up in that you have this <strong>bi-level optimization</strong> procedure that we need to perform in order for meta-learning. This can exhibit some instabilities, particularly if you don’t have as much expressive power that you’d like in your current architecture. There have been a few different ideas for trying to mitigate this. <a href="https://eng.ox.ac.uk/media/2299/behl-2019-alphamaml.pdf"><em>One approach </em></a><em>was to try to automatically learn the inner learning rate of the algorithm, </em>basically learn that alpha parameter that was in those equations. And specifically one of the things that these papers have found to be particularly important is that the learning rate is different for each parameter or different for each layer of the network. This is because things like biases and weights may want to have different learning rates. Biases may want to have larger learning rates, while weights might want to have smaller learning rates. You want to be able to decouple from those different choices for the different layers such that they don’t have the sort of conflicting optimization. There is also an approach to tune the outer learning rate as well. <a href="https://arxiv.org/abs/1802.03596"><em>There are </em></a><a href="https://arxiv.org/abs/1810.03642"><em>approaches</em></a><em> that try to authorize only a subset of the parameters in the inner loop, </em>subsets like some of the parameters that are like affine transformation on each of the layers.<em> </em><a href="https://arxiv.org/abs/1810.09502"><em>There are papers</em></a><em> that have looked at decoupling the inner learning rate as well as the batch storm statistics per gradient step since that you have a different learning rate for each gradient step, </em>or a different batch storm statistics for each gradient step as well. <em>And </em><a href="https://arxiv.org/abs/1810.03642"><em>lastly</em></a><em>, </em><a href="https://arxiv.org/pdf/1710.11622.pdf"><em>there are also some papers</em></a><em> that have introduced context variables for increased expressive power that basically introduce additional variables into the neural network that are appended onto the activations at each layer and allow the gradient steps to store information in those parameters</em>, in a way that doesn’t interfere with the other parts of the network computation. The main takeaway for all these papers is there is a range of simple tricks that can help the optimization process significantly.</p><p>One more challenge is that <strong>backpropagating through many integrating steps is going to be very compute-intensive and memory-intensive</strong>. If you have one inner gradient step or a few inner gradient steps, it’s generally quite practical to think about how you might backpropagate through only a couple of those. But if you have an extended optimization process in the inner loop, then it is very challenging to think about how you’d actually backpropagate through that in a way that does not require storing the entire optimization process in memory, and ideally doesn’t require backpropagating through the optimization process. There are 2 approaches to deal with this.<a href="https://dl.acm.org/doi/pdf/10.5555/3305381.3305498"> The first </a>is just<strong> </strong><a href="https://pdfs.semanticscholar.org/672c/586880655dc544474280a6e086c1fc901c85.pdf"><strong>approximate the Jacobian of the task-specific ϕi with respect to the meta parameters θ as identity, which is dϕ/dθ = I.</strong></a><strong> </strong>This is a very crude approximation that basically corresponds to a truncated backpropagation in some regard where it copies a lot of parameters over to theta. Somewhat surprisingly, this actually <strong>works pretty well on a number of simple few-shot problems</strong> like Minimagenet and Omniglot, but (anecdotally)<strong> it does not work in more complex meta-learning problems</strong>, such as in meta-learning imitation problems.</p><p>Another approach is can we try to compute the meta-gradient without differentiating through this optimization process, and in a way that doesn’t approximate this optimization process as identity?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PWkMc7E8rAwTKJg8SSiNDg.png" /><figcaption>implicit MAML</figcaption></figure><p><em>Basically you need to be able to compute d of u of theta with respect to your parameters theta (dU(θ)/dθ)). And this requires storing all of the iterates of this update rule.</em> In particular, we are going to <em>use the update rule that has an explicit Gaussian prior on the parameters</em>. Φ is equal to the output of our update procedure takes as input a set of training data points (u(θ, Dtr)). Let’s say this is equal to the solution to some optimization problem on the parameters with respect to our training dataset (argmin L(ϕ’, Dtr)), and also with respect to explicit Gaussian regularization that tries to keep our task parameters close to the parameters theta ( λ/2 ||ϕ’-θ||²). This gaussian regularization has a mean θ and variance that’s a function of λ. In this case, the inner optimization tries to take the full argument to converge rather than just run one or a few steps of gradient descent. <em>The final calculation result shows that dU(θ)/dθ only depends on the Hessian at the final optimization point.</em> This is actually something that we can compute without actually differentiating through the inner optimization process. <strong><em>You can use conjugate gradient algorithms to try to estimate this inverted matrix term</em></strong>. A<em>nd basically the number of iterations that you run of the conjugate gradient, the more accurate your estimate of this term will be. If you run an infinite number of iterations you will approach an exact estimate of this. If you do zero iterations of the conjugate gradient, you actually just estimate this as the identity, which is exactly the kind of first-order MAML algorithm that’s shown before </em>( idea: [crudely] approximate dΦ/dθ as identity).<a href="https://arxiv.org/abs/1909.04630"> This approach </a>used what’s called the <strong>implicit function theorem</strong>, which is a way to think about how to differentiate function implicitly. This approach is very memory efficient, so you don’t have to store that optimization process, <strong>and computationally as you increased the number of conjugate gradients steps, it will become more compute-intensive</strong>. This allows you to basically trade off how accurate you want the meat gradient to be with how much compute you want to spend.</p><h4>summary</h4><p><em>The takeaway for optimization-based methods is that you do them by constructing a bi-level optimization procedure where the inner optimization is something like gradient descent, SVM, hessian free optimization procedures</em>. The <strong>benefit</strong> of this type of approach is that you get a <strong>positive inductive bias at the start of meta-learning </strong>because you are already had this optimization procedure in the loop and you can already expect it to do something reasonable at initialization time. In contrast, a black-box approach is where the initial optimization procedure is just some neural network. Another advantage is t<strong>hese procedures are consistent</strong>. Since the procedure that you run at test time corresponds to an actual optimization method, as a result, <strong>it tends to extrapolate better t</strong>o learning problems that are outside of the distribution of what you&#39;ve seen during meta-training. They are also <strong>maximally expressive</strong> if you have a very deep neural network. The last thing is it’s <strong>model-agnostic</strong> so it’s pretty easy to combine with different model architectures. In terms of <strong>limitations</strong>, it r<strong>equires typically a second-order optimization</strong> either by differentiating through that optimization or by doing something like implicit MAML where you still have second-order terms that pop up. As a result, it is usually pretty <strong>compute-intensive or memory-intensive</strong>.</p><h3>Reference</h3><ol><li><a href="https://www.youtube.com/watch?v=v7otSgpTc0Q&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=3">‘Stanford CS330: Multi-Task and Meta-Learning, 2019 | Lecture 3 — Optimization-Based Meta-Learning’</a></li><li>T<a href="http://cs330.stanford.edu/slides/cs330_lecture3.pdf">he course slide.</a></li><li><a href="https://science.sciencemag.org/content/350/6266/1332">Human-level concept learning through probabilistic program induction</a></li><li><a href="https://ai.stanford.edu/~cbfinn/_files/dissertation.pdf">Learning to Learn with Gradients</a></li><li><a href="http://proceedings.mlr.press/v48/santoro16.html">Meta-Learning with Memory-Augmented Neural Networks</a></li><li><a href="https://arxiv.org/abs/1807.01613">Conditional Neural Processes</a></li><li><a href="http://proceedings.mlr.press/v70/munkhdalai17a/munkhdalai17a.pdf">Meta Networks</a></li><li><a href="https://arxiv.org/abs/1707.03141">A Simple Neural Attentive Meta-Learner</a></li><li><a href="https://arxiv.org/abs/1703.03400">Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks</a></li><li><a href="https://arxiv.org/abs/1801.08930">Recasting Gradient-Based Meta-Learning as Hierarchical Bayes</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=268250c49bd9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/black-box-adaptation-optimization-based-approaches-268250c49bd9">Black-Box Adaptation, Optimization-Based Approaches</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-task & Meta-learning basics]]></title>
            <link>https://medium.com/@rachel_95942/multi-task-meta-learning-basics-259abe7a868?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/259abe7a868</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[meta-learning]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Tue, 12 May 2020 10:21:41 GMT</pubDate>
            <atom:updated>2020-05-19T07:58:35.463Z</atom:updated>
            <content:encoded><![CDATA[<h4>This story covers multi-task and meta-learning basics. For multi-task, it covers models, training steps, challenges, and a case study. Regards to meta-learning, it goes from problem formulation into the general recipe of meta-learning algorithms. This story is a short summary of the first two lessons of `<a href="https://www.youtube.com/watch?v=0rZtSwNOTQo&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=1">Stanford CS330: Multi-Task and Meta-Learning, 2019</a>`.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*kSF8ZVTTXk9QJinxxsi2vQ.png" /></figure><p>This story will cover what is multi-task and meta-learning basics. For multi-task, this story will cover models, training steps, challenges, and a case study of real-word multi-task learning. Regards to meta-learning, it will go from problem formulation into the general recipe of meta-learning algorithms. This story is a summary of the first two lessons of `<a href="https://www.youtube.com/watch?v=0rZtSwNOTQo&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=1">Stanford CS330: Multi-Task and Meta-Learning, 2019</a>`.</p><h4>What is multi-task</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*qekRnB4es41Yov3cnxSE4w.gif" /><figcaption>Supervised single-task learning. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>In supervised single-task learning, we have a dataset (x,y) and want to minimize the loss function. Usually, the typical loss function is negative log-likelihood. Then, what is the task in multi-task learning/meta-learning?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0PSXh6-W2NRuP1DATVidA.png" /><figcaption>Task definition. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p><strong><em>The task is defined by 3 parts: distribution over inputs (pi(x)), distribution over the labels given the inputs (pi(y|x)), and a loss function (Li). </em></strong>Essentially, these two distribution P are going to correspond to the true data generating distributions. Also, we will have a training set and a test set for each task. We will assume that each of these distributions is drawn from the same data generating distribution P. So essentially, different tasks may vary based on the input distribution, the label distribution given the input, or the loss function.</p><p><strong><em>For multi-task classification, loss functions (Li) are the same across all tasks.</em></strong> Examples for multi-task classification could be per-language handwriting recognition where each language corresponds to one task. Another example is a personalized spam filter where each person’s spam filter is a task and corresponds to a different distribution. <strong><em>For multi-label learning, loss functions(Li) and distribution over input (P(x)) are the same across all tasks.</em></strong> Examples of multi-label learning could be attribute recognition. Suppose you have a dataset of faces, one task might correspond to detecting whether or not the person is wearing a hat, while another might correspond to detecting their hair color. So there pi(x) and loss functions are the same, but y given x is different because you have different binary classification tasks. <em>What might loss function vary across tasks? </em>If there are mixed discrete, continuous labels across tasks, the loss functions would be different. Also, if you care more about one task than another, you maybe have a loss function weight corresponding to one task that’s higher than the weight of another task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*PW7oBiYijXW_flmlurYdwA.gif" /><figcaption>Basic setup. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Now we also need a task descriptor zi in function f. <strong><em>For the task descriptor, it could be a one-hot encoding of the task index</em></strong>. For example, if you input a paper text into and the task descriptor could be one-hot encoding to indicate task length of paper, summary of paper or paper review. <strong><em>It could also be whatever met-data you have. </em></strong>If your task corresponds to a personalization, then the task descriptor might include information about that person or that user. If it’s something maybe you have kind of a language description of the task you want to perform. Or maybe you have some formal specification of the task or maybe you are trying to design circuits that you might want your neural network to be producing.</p><p>Let’s assume zi is the task index. Essentially, how should you structure your neural network model such that it shares basically as little as possible between the different tasks?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJg4cgKLXGpZpJmMgsAbbg.png" /><figcaption>condition on the task. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p><em>You could have separate networks for tasks, each network has separable weigh</em>t. <em>And then you can condition on your task descriptor: you pick the corresponding task which corresponds to this multiplicative gating, where you are just selecting which of the outputs you are going to produce based on your task index.</em> It’s complicated. And it’s one way to represent independent networks within a single model with no shared parameters essentially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*zQCZ11O-xWl-vd4QVa6sUw.png" /><figcaption>The other extreme. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>You could also concatenate zi with input and/or activations. So in this case, all parameters are shared except the parameters directly following zi. An alternative view on the multi-task objective is you can split your parameter vector into these shared parameters and task-specific parameters. The task-specific parameters are only optimized with respect to the objective of that task. Whereas the shared parameters are optimized overall tasks.</p><h4>Different conditioning choices</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2-dPdAE3fEg4a8nTEiwag.png" /><figcaption>concatenation-based conditioning and additive conditioning. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>There are some common choices of conditioning. For<strong><em> concatenation-based conditioning,</em></strong> we basically take that task descriptor and concatenate it with the features and then do a linear layer after that. For the<strong><em> additive conditioning,</em></strong> we add the task vector to your hidden units to your features where you basically have a linear layer. Further, we can combine those two conditionings. So the bottom model architecture in the above picture shows the combination, where the right-side corresponds to the additive conditioning, the left-hand side is concatenation-based conditioning. It’s assuming that the task descriptor is one-hot encoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cESOBniW8gpWXOS7flSqtQ.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p><strong>Multiplicative conditioning</strong> is basically identical to additive conditioning, except instead of adding, your multiply. So you project tour task matrix onto a vector, then you multiply that onto the activations either in the input or at kind of intermediate representations of your neural network. why might multiplicative conditioning be a good idea? <strong><em>Because multiplicative conditioning generalizes independent networks and independent heads</em></strong>. In multiplicative conditioning, you are multiplying the conditioning representation embedding onto your activations, allowing it to modulate different features, such that you can completely turn off features, you can complete only use some heads for one task, only use some parts of the network for one task versus another task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IcsH1sxTpAzpW6gRhg2Oqw.png" /><figcaption>More complex choices on conditioning. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Unfortunately, these design decisions are like neural network architecture tuning. They are problem-dependent. They are largely guided by intuition or knowledge of the problem and currently more of an art than a science.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kn-ZRPU7EVbnl13Ysbq5yg.png" /><figcaption>optimizing the objective. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p><em>When optimizing the objectives, ensure that tasks are sampled uniformly, regardless of data quantities.</em> If you care more about the task that has more data, then it makes sense to weight those differently and sample at different proportions as well. I<em>f your different tasks correspond to regression problems</em>, this isn&#39;t really necessarily specific to the optimization algorithm but <em>it’s pretty important to make sure your tasks labels are on the same scale</em>. Otherwise inherently your loss function is going to have a greater scale for which the labels have greater magnitude.</p><h4>Challenges for multi-task learning</h4><p>One challenge is the <strong>negative transfer,</strong> which means sometimes independent networks work the best. Why? <strong><em>Because optimization challenges caused by cross-task interference and tasks may learn at different learning rates.</em></strong> If basically gradients of one task or interfering with the training of another task, you compute the gradient for task 1 then task 2. If the gradient 1 hurts the weights for task 2, the optimization will be more difficult. And also tasks we learn at different rates. If one task is learning a lot faster than another task, you might end up learning one task very quickly, and then it might get stuck trying to learn task 2 because it’s kind of already learned something and it doesn’t want to learn something else. <strong><em>Multitask networks in general often need to be much larger than single task networks, this is very intuitive but it can be easy to forget</em>. </strong>But if it isn’t as large as it needs to be then you are going to see underfitting, so that’s kinda symptom of <strong>limited representational capacity</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*4H6N-tikacePoRABZ35QWg.png" /><figcaption>Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p><strong>If you have negative transfer, share less across tasks, and train a bigger network.</strong> And one of the interesting things here is actually sharing versus not sharing parameters is not just a binary decision. You could actually also do what’s called soft parameter sharing. <em>You can break down your objectives into shared parameters and task-specific parameters and then basically add the “soft parameter sharing” term that encourages the task-specific parameters to be similar to one another.</em> You could do this at different layers of the network, you could do it for different pairs of tasks, for some pairs but not other pairs. You could also do it with respect to a single set of global parameters and tie them all to a single set of global parameters instead of doing this sort of pairwise loss. If you set the weight of this right-hand loss to 0, then you have 0 parameter sharing. If you set it to be a very high value, such that essentially constraining the optimization, then you have hard parameter sharing.</p><p>The second challenge may be <strong>overfitting</strong>. If you only have a small amount of data per task and you find yourself overfitting to those tasks then it actually may be that you are not sharing enough.<strong> </strong><em>If you share more that would act as a stronger form of regularization and you may be able to overfit less</em>.</p><h4>Case Study： <a href="https://daiwk.github.io/assets/youtube-multitask.pdf">Recommending what video to watch Next: A multitask ranking system</a></h4><p>The goal of this <a href="https://daiwk.github.io/assets/youtube-multitask.pdf">paper</a> is to make recommendations for YouTube. The way that they formulate it as a multitasking problem is to make predictions about user engagement and about user satisfaction. The objectives would be 3 parts: videos that users will rate highly; videos that users they will share; and video that user will watch. The implicit bias is caused by feedback: users may have watched it because it was recommended.</p><p>To framework up, the input is what the user is currently watching (query video) and user features. The steps are 1) generate a few hundred candidate videos; 2) rank candidates; 3) serve top ranking videos to the user. From pooling videos from multiple candidate generation algorithms, candidate videos are videos that match topics of query video, or videos most frequently watched with query video, and other videos. The ranking is the central topic of this paper.</p><p>The inputs are query and candidate video features (e.g. context topic, title and upload time), and user and context features (e.g. time, user, profile, etc). These inputs are transformed into 3 type features: embeddings for query and candidate items; embeddings for visual and language, and context features; and dense features. The model output would be engagement and satisfaction with candidate video. Engagement is binary classification tasks like clicks and it is also a regression task for tasks related to time spent. Satisfaction is binary classification tasks like clicking ‘like’ and it is also regression tasks for tasks such as rating. The ranking score is the weight combination of engagement and satisfaction prediction, while score weights are manually tuned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*zjPQHoSfjb2-4kCBRiUEUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*5SEese34NFsMM7sRW_A95g.png" /><figcaption>The architecture. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*jTTHySt8XPPkGMBvWhxWtQ.png" /><figcaption>MMoE</figcaption></figure><p>The basic option for the architecture would be the “shared-bottom model”, which belongs to multi-head architecture as mentioned before. But this model structure harms learning when the correlation between tasks is low. Instead, authors use a form of soft-parameter sharing “multi-gate Mixtur-of-Experts (MMoE)” model.</p><p>The authors trained in temporal order where they are feeding in the videos over time and training continues to consume the newly arriving data. They that this is really important so that because the distribution over time of user engagement is changing as different trends become popular et cetera. They had various offline and online metrics. For offline, they looked at AUC for classification tasks and squared error metrics for regression tasks. But the most important things were actually the online metrics because those were actually the ones that you ultimately care about. Live metrics based on time spent, survey response, rate of dismissals are collected to do online A/B testing comparisons to the production system.</p><h4>Meta-learning basics</h4><p>There are 2 ways to view meta-learning algorithms: mechanistic view and probabilistic view. In the mechanistic view, a deep neural network model can read in an entire dataset and make predictions for new data points. Training this network uses a meta-data set, which itself consists of many datasets, each for a different task. This view makes it easier to implement meta-learning algorithms. With regard to the probabilistic view, extracting prior information from a set of (meta-training) tasks allows efficient learning of new tasks. Leaning a new task uses this prior and (small) training set to infer most likely posterior parameters. This view makes it easier to understand meta-learning algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*Lyvd5f6YZ9QCND_ohx1nUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*q5g9ZXTqBWqj3nIj1_Y4gA.png" /><figcaption>left is the meta-learning problem definition, right is an example. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Can we incorporate additional data in some way? <strong>We want to be able to use the meta-training data such that when we perform a new task, we can lean it more efficiently and effectively.</strong> So for example, if you want to solve a few shot classification problems, maybe you are given 5 images and you want to be able to classify new images as being among one of those 5 classes. If you try to train a neural network from scratch on this problem, you will overfit massively, or if your regularizer is too strong, it won&#39;t do anything. But if you have data from other image classes, which is your meta-training data, then you may be able to use that meta-training data in a way that allows you to learn from only 5 examples in a manner that is effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JdTMmemIN8I32unGFgctrQ.png" /><figcaption>the meta-learning problem. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>What if we are going to be training on all our past experience across tasks and we do not want to assume that every time training new tasks, we have the meta-training dataset. Then we need to <strong><em>compile our meta-training dataset down to a set of parameters θ. </em></strong><em>θ basically corresponds to what we need to know about the meta-training data in order to solve new tasks quickly. </em>The likelihood of our parameters for our dataset given our past meta-training data can be re-written in a way that integrates over our meta-parameters θ. <em>This rewriting assumes that our task-specific parameters and our meta-training data are independent conditioned on θ</em>. We can then approximate the integral with a point estimate for our meta-parameters,<strong> <em>where the right-hand side of the objective (</em></strong><strong>logP(θ*|D_{meta-trin})<em>) is going to correspond to meta-training,</em></strong><em> where we want to learn a set of meta-parameters given our meta-training data</em>. <strong><em>And the left-hand side of the objective (</em></strong><strong><em>logP(ϕ|D,θ*)) is going to correspond to adaptation</em></strong> <em>where we want to be able to learn new parameters for a new task, given data from that task and our meta-parameters: θ*, where θ* is equal to basically argmax of log p θ given our meta-training data.</em> So essentially this right-hand side<em>(</em>logP(θ*|D_{meta-trin})<em>)</em> is the meta-learning problem where we are optimizing over our meta-parameters such that when we use them for adaptation, we can effectively learn parameters for that task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*68PH0QyWtp1kHxCYho3wsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*X4Iqhcd--d9_MLmmwZ_W6g.png" /><figcaption>An example. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Let’s go over how we can go about adaptation. For example, we want to be able to make predictions about test data points. The parameters corresponding to ϕ*. We want to be able to infer ϕ* from data. One simple example we use a neural network to take the dataset in and output ϕ*. <em>The key idea here is we can basically match test-time to training time</em>. So the test-time, we are going to be predicting ϕ* in order to make predictions about test data points. We want to be able to do the same thing in meta-training and basically train this RNN such that it produces parameters that lead to effective/accurate predictions.<a href="https://arxiv.org/abs/1606.04080"> <em>Train and test conditions should match. That’s basically the principal rule of meta-learning basically</em></a>. If you want to be able to learn at test-time, you should basically train it to learn during meta-training. <strong>So the process of optimizing for θ is meta-training, the optimize for producing ϕ is meta-testing</strong>.</p><p>One challenge is if at meta-training time you are actually training it to make predictions about test data points, where do these data points come from? How do we optimize for it to make predictions on new data points?</p><p>The important thing here is that we need to be able to essentially<strong><em> reserve a test set for each task that we are going to be meta-learning over.</em></strong> If we have a set of tasks, then we have basically trained data for each task, we also need corresponding test sets for each of those tasks. For example, if we train images, then test sets are going to be held out images from the same image categories. Now we are moving from meta-training from the training set to meta-train sets, and test sets to meta test sets.<em> So each of those tasks, the training set and the test sets for the task corresponding to the meta-training dataset, and then at meta-test time were given new tasks, and we don’t wanna train on the meta-test set</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*drgioab8eSuKK1W-rk1ZEg.png" /><figcaption>The complete meta-learning optimization. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>So the above picture shows that the graphic model (right bottom on the top picture) <em>where ϕ is your task-specific parameters for a given task and you have a training set and a test set for each task.</em> <strong><em>So ϕ leads to the data and θ acts as a prior on the task-specific parameters for all the tasks. So θ is essentially the information that’s shared across tasks</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MisJNpnYuTQhgBAUMeZj6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*MaAZ9ABmnL0rcZ5-cmthMQ.png" /><figcaption>some meta-learning terminology. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Let’s go over some meta-learning terminology. On the left picture. there are meta-training and meta-testing dataset. <em>Each row is a meta-training/meta-test task</em>. Each of these tasks has a corresponding<strong> train set (or support set)</strong> and <strong>test set(or query).</strong><em> If you are doing </em><strong><em>k-shot learning,</em></strong><em> you are learning from k examples.</em> For example, 5-shot learning means you are learning from 5 pictures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w48WLwUNzlYD-Giz_bY6_Q.png" /><figcaption>closely related problem settings. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>multi-task learning is a learning model with parameters θ* that solve multiple tasks. It can be seen as a special case where ϕ = θ. Hyperparameter optimization and auto-ML can also be cast as meta-learning. Hyperparameter optimization is where θ corresponds to hyperparameters and ϕ corresponds to network weights. For architecture search, θ corresponds to architecture, and ϕ corresponds to network weights.</p><h4>Optimization-based meta-learning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*WnfM3wrWPagV6lAXkshSUg.png" /><figcaption>Omniglot dataset. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>Let’s first introduce the <a href="https://github.com/brendenlake/omniglot">Omniglot dataset,</a> it actually really kind of exemplifies some of the weak points with neural networks that they are gonna be learning from small amounts of data. So this dataset has 1600 characters from 50 different alphabets. The left picture shows different alphabets like “Hebrew”,” Bengali” etc. Each character has only 20 instances. So unlike MINIST that has a few number of characters and a huge number of data points per character, this dataset is sort of like the transpose of MINIST dataset.<em> It has many classes and a few examples per class. </em>The statistics of this dataset are in many ways more reflective of the types of things that we see in the real world. For example, if you want to learn how to recognize forks, you are not going to see thousands of different types of forks. You may see a wide range of objects, but for per objects, you only see a small number of instances of that object throughout your lifetime.</p><p>The <a href="https://science.sciencemag.org/content/350/6266/1332">author</a> proposes both a<strong> few-shot discriminative </strong>and<strong> few-shot generative problems</strong>. <em>The few-shot discriminative learning is given a few examples of new characters, can you learn to classify between those characters?</em> <em>The derivative problem is likewise, given a few examples of some characters, can you actually generate new instances of those characters?</em> In all of these datasets, the goal is to be able to learn something from the given small number of examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dU5vCY60gtKiZ5_GSsQaA.png" /><figcaption>the general recipe for meta-learning evaluation. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>For example, we have a 5-way, 1-shot image classification problem. In particular, you can have one example of 5 different classes. <strong><em>‘Way’ means the number of classes, ‘shot’ means the number of examples per class</em></strong>. Your goal is given these 5 examples (fist line left part: ice cream, dog, lion, worm, and bowls), classifying new examples(s.t lion and bowls) as being among one of the five classes. This is the few-shot learning problem. In meta-learning, our goal is to be able to <em>leverage data from other image classes in order to solve this problem.</em> Leveraging the meta-train dataset in order to learn a few shot classifiers that can learn from these data points on the left (ice cream, dog, lion, worm, and bowls etc). <strong>S<em>o you can structure the data into training sets and test sets where these are going to mimic what you are going to be seeing at test-time, matching meta-training time and meta-testing time</em></strong><em>.</em> <em>So you can take five other image classes (s.t. the second row left: bird, mushroom, dog, women, piano) and break it into a train set and test set, and do this for a wide range of other image classes that you’ve seen in the past</em>. These will be tour training classes and you will perform meta-training the classifier such that after it sees the images on the left, it can successfully classifying images on the right. Critically after you do this, you will <em>test it on held-out image classes</em> as shown on the top (first line right: lion and bawls), it will essentially be able to perform this few-shot learning problem. This is image classification, you can replace this with a regression problem, language generation problems, skill learning problems, etc.</p><p>The difference between multi-task learning and meta-learning is: in multitask learning, your goal would be to try to solve all of the training tasks shown in the gray box (on the left picture); whereas in meta-learning your goal is to use these training tasks in order to solve new tasks with a small amount of data, so the model could evaluate new tasks and quickly learn new tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7yonynUBfrcS57d3ANUZg.png" /><figcaption>The meta-learning problem: a mechanistic view. Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>We can view the meta-learning problem from a<strong><em> mechanistic </em></strong>standpoint<strong><em>.</em></strong> So in particular, if we say supervised learning is trying to learn a mapping from X to Y given input-output pairs, we can view meta-supervised learning as trying to learn from a dataset, where the dataset contains k input-output pairs from a k shot learning problem, to make predictions about new test data point X test. <em>Our goal is to produce a function that takes as input a training dataset and a test input and produces the label corresponding to the test input</em>. Essentially we want to learn function f that takes in the training dataset and the test input and produce the label. <strong><em>One nice thing about this particular problem statement is that it reduces the problem of meta-learning to designing and optimizing the function f</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckPTGtd-z4PrvP_gXIhQqA.png" /><figcaption>The meta-learning problem: the probabilistic view.Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>How does this connect to the <strong>probabilistic</strong> viewpoint? You can view supervised learning as doing inference over parameters given a dataset. <em>Similarly, you can view the adaptation process of meta-learning as doing inference over your task-specific parameters ϕi given a training dataset and a set of meta parameters θ, the meta-learning optimization as doing maximum likelihood inference over the meta parameters over all your training tasks</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*HRqkB8-clgNZCsv11ymU3w.png" /><figcaption>General recipe: how to design a meta-learning algorithm.Source: <a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">the course slide</a></figcaption></figure><p>So the general recipe for what an algorithm looks like is<em> first, you choose a form of a function that could be probabilistic or a deterministic, where you output a set of task-specific parameters given a training dataset and your meta parameters; then you need to figure out how you want to choose to optimize your parameter’s data w.r.t your meta-training dataset.</em> <strong>Most meta-learning algorithms vary based off of the first plan,</strong> basically how do you actually design this function that’s going to infer task-specific perimeters.</p><h4>References:</h4><ol><li>`<a href="https://www.youtube.com/watch?v=0rZtSwNOTQo&amp;list=PLoROMvodv4rMC6zfYmnD7UG3LVvwaITY5&amp;index=1">Stanford CS330: Multi-Task and Meta-Learning, 2019</a>`.</li><li>T<a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">he course slide</a></li><li><a href="https://distill.pub/2018/feature-wise-transformations/">Feature-wise transformations</a></li><li><a href="https://daiwk.github.io/assets/youtube-multitask.pdf">Recommending What Video to Watch Next: A Multitask Ranking System</a></li><li><a href="http://cs330.stanford.edu/slides/cs330_lec2.pdf">The course slide for `Stanford CS330: Multi-Task and Meta-Learning, 2019`.</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=259abe7a868" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The neural approaches to Natural Language Generation]]></title>
            <link>https://medium.com/@rachel_95942/the-neural-approaches-to-natural-language-generation-f8b541e6bb08?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8b541e6bb08</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[language-model]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Tue, 12 May 2020 07:49:26 GMT</pubDate>
            <atom:updated>2020-05-12T07:49:26.803Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*LIDwuiqqw87yeSdaM1Ahjw.png" /></figure><p>This story includes 5 parts: introduction to natural language generation (NLG), decoding algorithms, NLG tasks, and neural approach to them, NLG evaluation, and concluding thoughts on NLG research. This is a summary of <a href="https://www.youtube.com/watch?v=4uG1NMKNWCU&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=15">`Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 15 — Natural Language Generation</a>`.</p><h3>1. Introduction</h3><p><strong><em>Natural Language Generation refers to any setting in which we generate (i.e. write) new text</em></strong>. It is a subcomponent of many tasks, such as machine translation, (abstractive) summarization, dialogue (chit-chat and task-based), creative writing (s.t. storytelling and poetry-generation), freeform question answering (i.e. the answer is generated, not extracted from text or knowledge base), Image captioning, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/167/1*vZNR_hB8zl_muiINp2HWow.png" /><figcaption>LM model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*jv7sttvEl7HOyH1E2HzrrQ.png" /><figcaption>conditional LM model</figcaption></figure><p><strong><em>Language modeling is the task of predicting the next word, given the words so far. </em></strong>A system that produces the probability distribution P(y_{t}|y_{1},…y_{t-1}) is called a Language model. If that system is an RNN, it is called an RNN-LM. <strong><em>Conditional LM is the task of predicting the next word, given the words so far, and also some other input x. </em></strong><em>Examples of conditional LM are: 1) Machine Translation (x = source sentence, y = target sentence); 2) Summarization (x = input text, y = summarised text) 3) Dialogue ( x= dialogue history , y = next utterance) etc</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*vQkohg7dsq1JDy-_LOB8JA.png" /><figcaption>RNN-LM, neural machine translation example.</figcaption></figure><p>How to train a (conditional) LM? The training model could be a transformer-based language model or a CNN-based language model. Here shows the RNN model. When you are training the system, you feed in the target sequence that you are trying to generate into RNN-model and then it predicts what words are going to come next.</p><p><strong><em>During training, we are feeding the reference target sentence into the decoder, regardless of what the decoder is predicting. So even if this is a very bad decoder that isn’t predicting the correct words</em></strong><em>, </em>that doesn’t matter, we still just input the gold target sequence into the decoder. This training method is called <strong><em>Teacher Forcing.</em></strong></p><h3>2. More on decoding algorithms</h3><h4>2.1 G<strong>reedy decoding</strong></h4><p>Once you’ve trained your (conditional) LM, how do you use it to generate tet? It’s about decoding algorithms. A <strong><em>decoding algorithm</em></strong><em> </em>is an algorithm you use to generate text from your language model. There are 2 common decoding algorithms: <strong><em>greedy decoding and beam search.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*CDJDAOXWRSwhhiP5FiSyHQ.png" /><figcaption>Greedy decoding example</figcaption></figure><p><strong><em>Greedy decoding </em></strong>is a simple algorithm, where on each step, it takes the most probable words (i.e agrmax). And it uses that as the next word and feeds it as input on the next step. It keeps going until you produce &lt;END&gt; (or reach some max length). However,<strong><em> due to the lack of backtracking</em></strong>, <em>the output can be poor </em>( which means ungrammatical, unnatural, and nonsensical).</p><h4>2.2. <strong><em>beam search</em></strong></h4><p><strong><em>Beam search decoding</em></strong> is a <strong>search algorithm</strong> that aims to find a <strong>high-probability sequence</strong> (not necessarily the optimal sequence, though) by tracking multiple possible sequences at once. The core idea of it is on each step of decoder, keep track of the<strong> k most probable</strong> partial sequences( which we can <strong>hypotheses</strong>), where k is the beam size. After you reach some stopping criterion,<strong> choose the sequence with the highest probability</strong> (factoring in some adjustment for length)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*SWd3C64RWUs07MHbjWL_mA.png" /><figcaption>beam search example</figcaption></figure><p>So the left picture shows what it looks like after we’ve done this exploration problem this shows the full tree that we explored, and then we’ve come to some kind of stopping criterion and we identify the top. The hypothesis is highlighted in green.</p><p>What’s the effect of changing beam size K?<strong> <em>Small k has similar problems to greedy decoding,</em> </strong>which means output could be ungrammatical, unnatural, nonsensical, and incorrect. When k =1, beam search is exactly greedy decoding. <strong>Larger K means you consider more hypotheses.</strong> Increasing k reduces some of the problems mentioned before. But <strong>larger k is more computationally expensive</strong> and it could also introduce other problems. For example, For NMT, increasing k too much decreases BLEU. This is primarily because large-k-beam search produces too-short translations (even with sore normalization). In open-ended tasks like chit-chat dialogue, large k can make the output more generic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*MEWfDL7PtHd4n7zhogV77Q.png" /><figcaption>effect of beam size in chitchat dialogue</figcaption></figure><p>So these are examples from the chit-chat dialogue project (Persona-chat). It’s a chitchat dialog dataset where each conversational partner has a persona which is a set of traits. So the reason it keeps talking about being a nurse, I think is because it was in the persona.</p><p>There are also <strong>sampling-based decoding algorithms</strong>, where you could do <strong><em>pure sampling or top-n sampling</em></strong>. In pure sampling, on each step t, you randomly sample from the probability distribution Pt to obtain your next word. It’s like greedy decoding, but sample instead of argmax. For top-n sampling, on each step t, you randomly sample from Pt, restricted to just the top-n most probable words. It’s like pure sampling but truncates the probability distribution. <em>When n equals 1, top-n sampling is exactly the greedy search; when n equals o vocabulary size, top-n sampling behaves the same as pure sampling. Increasing n, you will get more diverse/risky output while decrease n, you will get more generic/safe output. </em>Both pure sampling and top-n sampling methods are more efficient than beam search because they do not have multiple hypotheses.</p><h4>2.3 <strong><em>softmax temperature</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*0CKxbmoYPnOWGmhAna-4wQ.png" /><figcaption>softmax function in LM</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*Oq0T_PxW7WadRKQDCtlAfA.png" /><figcaption>softmax function in LM with temperature hyperparameter τ</figcaption></figure><p><em>There is a technique you can apply at test time, in conjunction with a decoding algorithm (such as beam search or sampling)</em>. It is the<strong><em> softmax temperature</em></strong>. On timestep t, the LM computes a probability distribution Pt by applying the softmax function to a vector of scores s∈R^|V|. <em>You can apply a temperature hyperparameter τ to the softmax. </em><strong><em>Raise the temperature τ: Pt becomes more uniform, thus more diverse output (probability is spread around vocab); while lowering the temperature τ: Pt becomes spikier, thus less diverse output (probability is concentrated on top words). </em></strong>Notably, the softmax temperature is not a decoding algorithm!</p><p>Let’s summarize decoding algorithms. There are 3 decoding algorithms we’ve talked so far: <strong><em>greedy decoding, beam search, and sampling methods.</em></strong><em> Greedy decoding is a simple method and it gives a low-quality output. Beam search (especially with high beam size) searches for high-probability output, it delivers better quality than greedy, but if beam size if too high, it can return high-probability but the unsuitable output (e.g. generic, short). Sampling methods are a way to get more diversity and randomness, they are food for open-ended/ creative generation (poetry, stories) and top-n sampling allows you to control diversity.</em><strong><em> Softmax temperature</em></strong><em> is another way to control diversity, </em>it’s a technique that can be applied alongside any decoding algorithm.</p><h3>3. NLG tasks and neural approaches to them</h3><h4>3.1 summarization</h4><p><em>Summarization is a task that given input text x, write a summary y which is shorter and contains the main information of x. Summarization can be</em><strong><em> single-document </em></strong><em>or </em><strong><em>multi-document</em></strong><em>.</em> Single-document means we write a summary y of a single document x; while Multi-document means we write a summary y of multiple documents x_{1},..,x_{n}. Typically x_{1},…x_{n} have overlapping content: e.g. news articles about the same event. Within single-document summarization, there are <strong>datasets</strong> with source documents of <strong>different lengths and styles: </strong>1) Gigaword: From first one or two sentences of a news article to generate headline (a.k.a sentence compression); 2) LCSTS( Chinese microblogging): from paragraph into generating sentence summary; 3) NYT, CNN/DailyMail: from news article into generating (multi) sentence summary; 4) Wikihow: from a full how-to article into generating summary sentences. Sentence simplification is a different but related task, which is rewriting the source text in a simpler (sometimes shorter) way. There are 2 datasets: 1) Simple Wikipedia: from standard Wikipedia sentence into simple version; 2) Newsela: from new article to the version written for children. You can find a list of summarization datasets, papers, and codebases <a href="https://github.com/mathsyouth/awesome-text-summarization">here</a>.</p><p>There are 2 main strategies in summarization: <strong><em>extractive summarization and abstractive summary. </em></strong>Extractive summarization selects parts (typically sentences) of the original text to form a summary, it is easier and restrictive (no paraphrasing). Abstractive summary generates new text using natural language generation techniques, it is more difficult and more flexible (more human).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*CFzdUAKAEFDDJ3ws8FUsfA.png" /><figcaption>pre-neural summarization</figcaption></figure><p>Let’s first talk about <strong><em>pre-neural summarization</em></strong>. Pre-neural summarization systems were mostly extractive, it behaves like pre-neural MT, they typically had a pipeline: 1) <strong>Content selection:</strong> choose some sentences to include; 2) <strong>Information ordering:</strong> choose an ordering of those sentences; 3) <strong>Sentence realization:</strong> edit the sequence of sentences(e.g. simplify, remove parts, fix continuity issues) There are 2 pre-neural content selection algorithms: sentence scoring functions and graph-based algorithms. Sentence scoring functions can be based on the presence of topic keywords (computed via e.g. TF-IDF ) and features such as where the sentence appears in the document. Graph-based algorithms view the document as a set of sentences (nodes), with edges between each sentence pair. Edge weight is proportional to sentence similarity. Graph algorithms are applied to identify sentences that are <em>central</em> in the graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*1_cIzMFNz9S7zSLm4LHHRA.png" /><figcaption>ROUGE</figcaption></figure><p><strong><em>As for summarization evaluation, ROUGE (Recall-Oriented Understudy for Gisting Evaluation) is applied.</em></strong> <em>Like BLEU, it is based on n-gram overlap</em>. The differences are: 1) ROUGE has no brevity penalty; 2) ROUGE is based on recall, while BLUE is based on precision. Arguably, <em>precision is more important for machine translation</em>, that is, you only want to generate text that appears on one of your translations, this leads you to only generate really safe things in a really short translation. That’s why you add the brevity penalty to make sure that it tries to write something long enough. By contrast, recall is more important for summarization (assuming you have a max length constraint) because you want to include important information in your summary. However, <em>often an F1 (combination of precision and recall) version of ROUGE </em>is reported anyway since you want to include all the information (recall part) but you can&#39;t be too long as a summary(precision part).</p><p><em>BLUE is reported as a single number, which s a combination of the precisions for n=1,2,3,4 n-grams.</em> Differently, <strong><em>ROUGE scores are reported separately for each n-gram.</em></strong> The most commonly-reported ROUGE scores are 1) ROUGE-1: unigram overlap; 2) ROUGE-2: bigram overlap; 3) ROUGE-L: longest common subsequence overlap.</p><p>Since 2015, there have been lots more developments in<strong> neural abstractive summarization</strong>.<a href="https://arxiv.org/abs/1804.04589"> And you can group together these developments in a collection of themes</a>: 1) Making it easier to copy. This seems pretty obvious because, in summarization, you are going to want to copy quite a few words and even phrases, but don’t copy too much.; 2) Hierarchical or multi-level attention. The attention has been pretty key to abstractive neural summarization so far. 3) having some more kind of global content selection. 4) Using Reinforcement Learning to directly maximize ROUGE, or other distance discrete goals (e.g. length) 5) Resurrecting pre-neural ideas (e.g. graph algorithms for content selection) and working them into neural systems. We will dive into 2parts: <em>copy mechanism and better context selection.</em></p><p>The reason why we want copy mechanisms is that although Seq2seq with attention systems are good at writing fluent output, it is bad at copying over details(like rare words) correctly. <strong><em>Copy mechanisms use attention to enable a seq2seq system to easily copy words and phrases from the input to the output. </em></strong>Clearly this is very useful for summarization and it allows both copying and generating gives us a hybrid extractive/abstractive approach. There are several papers proposing copy mechanism variants:<a href="https://arxiv.org/abs/1609.07317"> Language as a Latent Variable: discrete generative models for sentence compression</a>, <a href="https://arxiv.org/abs/1602.06023">Abstractive Text Summarization using sequence-to-sequence RNNs and Beyond</a>, and <a href="https://arxiv.org/abs/1603.06393">Incorporating copying mechanism in sequence-to-sequence learning</a>. The big problem with coping mechanisms is they copy too much and most of them are long phrases, sometimes even whole sentences. This leads that what should be an abstractive system collapses to a mostly extractive system. Another problem is they’re bad at overall content selection, especially if the input document is long and there is no overall strategy for selecting content.</p><p>Recall that pre-neural summarization had separate stages for content selection and surface realization (i.e. text generation). In a standard seq2seq with attention summarization system, these two stages are mixed in together: on each step of the decoder (i.e. surface realization), we do word-level content selection (attention). This is bad because of no <em>global</em> content selection strategy. One solution is <a href="https://arxiv.org/abs/1808.10792">bottom-up summarization</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*BT9DpDSh1_2r7ZrlnTYGcw.png" /><figcaption>bottom-up summarization</figcaption></figure><p>In this paper, if you are looking at the figure, the main idea is pretty simple. <em>First, you are going to have a content selection stage and this is thought of as a neural sequence tagging model problem</em>. You run through your source documents and <strong><em>tag every word as include or don’t include</em></strong>. <em>Then the bottom-up attention stage applies a hard constraint that </em><strong><em>you can not attend to words that were tagged don’t-include</em></strong><em>.</em> This turns out to be pretty simple but effective. What the model ends up doing is skipping around the parts that are meant to include, and then it’s forced to be more abstractive to put the parts together.</p><h3>3. NLG tasks and neural approaches to them</h3><h4>3.2 Dialogue</h4><p>“Dialogue” encompasses a large variety of settings such as<strong><em> task-oriented dialogue and social dialogue.</em></strong> Task-oriented dialogue is assistive (e.g. customer service, giving recommendations, question answering, helping user accomplish a task like buying or booking something), co-operative (two agents solve a task together through dialogue), and adversarial (two agents complete in a task through dialogue). While the social dialogue is applied in chit-chat (for fun or company) and therapy / mental wellbeing.</p><p>Due to the difficult of open-ended free from NLG, pre-neural dialogue systems more often used predefined templates, or retrieve an appropriate response from a corpus of responses. As in summarization research, since 2015 there have been many papers applying seq2seq methods to dialogue — thus leading to a renewed interest in open-ended freeform dialogue systems. Some early seq2seq dialogue papers include<a href="https://arxiv.org/abs/1506.05869"> A neural conversational model</a> and <a href="https://www.aclweb.org/anthology/P15-1152.pdf">Neural responding machine for short-text conversation</a>. <a href="https://medium.com/gobeyond-al/a-reading-list-and-mini-survey-of-conversational-ai-32fceea87180">This is a nice overview of recent(mostly neural) conversational AI work</a>.</p><p>People quickly applied<strong><em> seq2seq with attention method </em></strong>to dialogue but it quickly became very apparent that this kind of naïve application of standard NMT methods has some serious pervasive deficiencies when applied to a task like a chitchat dialogue. And this is even more true than it was for summarization. <strong><em>These problems are genericness / boring responses, irrelevant response (not sufficiently related to context), repetition, lack of context (not remembering conversation history), and lack of consistent persona</em></strong>. We will dive into these problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*BM7scrsgWpcHzyu7Oxd4ug.png" /><figcaption>MMI between input S and response T</figcaption></figure><p><strong>As for irrelevant response problems</strong>, seq2seq often generates a response that’s unrelated to the user’s utterance. This is either because it’s generic (e.g. I don’t know) or because changing the subject to something unrelated. One solution is <a href="https://arxiv.org/abs/1510.03055"><strong>optimizing for Maximum Mutual information (MMI) between input S and response T</strong></a><strong>. </strong>So instead of trying to optimize mapping from input S to response T (such that you are maximizing the conditional probability of T given S),<strong><em> you should maximize the maximum mutual information.</em></strong> The idea is that you are trying to find your response T that kind of maximize mutual information ( logp(S,T)/p(S)p(T)), so if T is a very high likelihood, then it gets penalized. The idea is that this is meant to discourage generic things that just have a high p(T) by themselves.</p><p><strong><em>As for genericness / boring response problem, </em></strong><a href="https://arxiv.org/abs/1809.01941"><strong><em>an easy test-time fix</em></strong></a><strong><em> is directly up-weighting rare words during beam search or using a sampling decoding algorithm rather than beam search</em></strong>. <strong><em>Another solution is </em></strong><a href="https://arxiv.org/abs/1809.01941"><strong><em>conditioning fix</em></strong></a><strong><em>, which is conditioning the decoder on some additional content (e.g. sample some content words and attend to them) by training a retrieve-and-refine model rather than a generate-from-scratch model</em></strong>. For example, sampling un utterance from your corpus of human-written utterances, and editing to fit the current scenario. This usually produces much more diverse /human-like /interesting utterances!</p><p><strong><em>Regards to the repetition problem, the simple solution is directly blocking repeating n-grams during beam search.</em></strong> It’s usually pretty effective. More complex solutions are 1) training a coverage mechanism — in seq2seq, this is an objective that prevents the attention mechanism from attending to the same words multiple times; 2) defining a training objective to discourage repetition. If this is a non-differentiable function of the generated output, then it will need some technique like e.g. RL to train.</p><h3>3. NLG tasks and neural approaches to them</h3><h4>3.3 storying telling</h4><p>Most neural storytelling work is some kind of prompt, such as generating a story-like paragraph given an image, generating a story given a brief writing prompt, or generating the next sentence of a story, given the story so far (story continuation). You can <a href="http://www.visionandlanguage.net/workshop2019/">check out</a>.</p><p>An <a href="https://medium.com/@samim/generating-stories-about-images-d163ba41e4ed">example </a>of generating stories about images. How to get around the lack of parallel data? You can use a common sentence-encoding space. <a href="https://arxiv.org/abs/1506.06726">Skip-thought vectors are a type of general-purpose sentence embedding method</a>. The idea is similar to how we lean an embedding for a word by trying to predict the words around it. The idea is using COCO (an image captioning dataset) and learn a mapping from images to the skip-thought encodings of their captions. The using the target style corpus (Taylor Swift lyrics) and train an RNN-LM to decode a skip-thought vector to the original text. In the end, put the two together and go from the picture to the embedding (to the Tayler Swift style output).</p><h3>4. NLG evaluation</h3><h4>3.3 Automatic evaluation metrics for NLG</h4><p>We’ve talked about <strong><em>Automatic Evaluation Metrics for NLG</em></strong>, and we know that these words overlap based metrics, such as BLEU, and ROUGE and METEOR. We know they are<strong><em> not ideal for machine translation. </em></strong>They are kind of <strong><em>even worse for summarization</em></strong>, mostly because summarization is even more open-ended than machine translation. And that means that having this kind of rigid notion if you’ve got to match the N-grams, is even less useful. And then for something even more open-ended like dialogue, that it’s just kind of a disaster. It’s not even a metric that gives you a good signal at all. And this also applied to anything else open-ended, like story generation. Please<a href="https://arxiv.org/abs/1707.06875"> check out.</a></p><p>So you might think, what other automatic metrics can we use? What about <strong>perplexity</strong>?<strong> So perplexity certainty captures how powerful your language model is, <em>but it doesn’t tell you anything about the generation.</em> </strong>So for example, if your decoding algorithm is bad in some way, then perplexity is not going to tell you anything about that. Because decoding is something you apply to your trained language model. Perplexity can tell if you’ve got a strong something you apply to your trained language model, but it’s not gonna tell you necessarily how good your generation is. What about <strong>word embedding based metrics</strong>? The main idea is comparing the similarity of the word embeddings (or an average of word embeddings), not just the overlap of the words themselves. it captures semantics in a more flexible way. Unfortunately, it still doesn&#39;t correlate well with human judgments for open-ended tasks like dialogue.</p><p>We have no automatic metrics to adequately capture overall quality (i.e. a proxy for human quality judgment). But we can define more focused <strong><em>automatic metrics</em> t</strong>o capture particular aspects of the generated text: <strong><em>fluency</em></strong> (compute probability w.r.t. well-trained LM), <strong><em>correct style</em></strong> (prob w.r.t. LM trained on target corpus), <strong><em>diversity</em></strong> (rare word usage, uniqueness of n-grams), <strong><em>relevance to input </em></strong>(semantic similarity measures), <strong><em>simple things like length and repetition, and task-specific metrics </em></strong>(e.g. compression rate for summarization). Though these don’t measure overall quality, they can help us track some important qualities that we care about.</p><h3>5. Thoughts on NLG research, current trends, and the future</h3><p>Exciting current trends in NLG are: 1) Incorporating discrete latent variables into NLG. This may help with modeling structure in tasks that really need it, like storytelling,task-oriented dialogue, etc; 2) Alternatives to struct left-to-right generation, such as parallel generation, iterative refinement, top-down generation for longer pieces of text; 3) Alternative to maximum likelihood training with teacher forcing. There’s some interesting work on looking at more kind of holistic sentence level rather than word level objectives.</p><p>There are some tops. The more open-ended the task, the harder everything becomes. Constraints are sometimes welcome. Aiming for a specific improvement can be more manageable than aiming to improve overall generation quality. If you are using an LM for NLG<strong>:</strong> improving the LM(i.e. perplexity) will most likely improve generation quality. But it is not the only way to improve generation quality. You need an automatic metric, even if it’s imperfect (The biggest roadblock for NLG progress is the evaluation). You probably need several automatic metrics. If you do human eval, make the question as focus as possible. Reproducibility is aa huge problem in today’s NLP + Deep Learning, and a huger problem in NLG.</p><h3>Reference</h3><ol><li><a href="https://www.youtube.com/watch?v=4uG1NMKNWCU&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=15">Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 15 — Natural Language Generation</a></li><li><a href="https://arxiv.org/abs/1611.01874">Neural Machine Translation with Reconstruction</a></li><li><a href="https://www.aclweb.org/anthology/W17-3204.pdf">Six Challenges for Neural Machine Translation — ACL</a></li><li><a href="https://github.com/mathsyouth/awesome-text-summarization">List of summarization datasets, paper, and codebases</a></li><li><a href="https://github.com/google-research/google-research/tree/master/rouge">Python implementation of ROUGE</a></li><li><a href="https://medium.com/gobeyond-ai/a-reading-list-mini-survey-of-conversational-ai-32ceea97180">This is nice overview of recent(mostly neural) conversational conversational AI work</a></li><li><a href="http://www.visionandlanguage.net/workshop2019/">Storytelling workshop 2019</a></li><li><a href="https://medium.com/@samim/generating-stories-about-images-d163ba41e4ed">Generating stories about images</a></li><li><a href="https://arxiv.org/abs/1808.10792">Bottom-Up Abstractive Summarization</a></li><li><a href="https://arxiv.org/abs/1705.04304">A Deep Reinforced Model for Abstractive Summarization</a></li><li><a href="https://staff.fnwi.uva.nl/m.derijke/wp-content/papercite-data/pdf/jiang-why-2018.pdf">Why are Sequence-to-Sequence Models So Dull?</a></li><li><a href="https://arxiv.org/abs/1506.06726">Skip-Thought Vectors</a></li><li><a href="https://arxiv.org/abs/1805.04833">Hierarchical Neural Story Generation</a></li><li><a href="https://arxiv.org/abs/1902.08654">What makes a good conversation? How controllable attributes affect human judgments</a></li><li><a href="https://arxiv.org/abs/1603.08023">How NOT To Evaluate Your Dialogue System: An Empirical Study of Unsupervised Evaluation Metrics for Dialogue Response Generation</a></li><li><a href="https://arxiv.org/abs/1510.03055">A Diversity-Promoting Objective Function for Neural Conversation Models</a></li><li><a href="https://arxiv.org/abs/1704.04368">Get To The Point: Summarization with Pointer-Generator Networks</a></li><li><a href="https://arxiv.org/abs/1804.04589">A Survey on Neural Network-Based Summarization Methods</a></li><li><a href="https://arxiv.org/abs/1509.00685">A Neural Attention Model for Abstractive Sentence Summarization</a></li><li><a href="https://www.aclweb.org/anthology/W04-1013.pdf">ROUGE: A Package for Automatic Evaluation of Summaries</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8b541e6bb08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Language models and RNN]]></title>
            <link>https://medium.com/@rachel_95942/language-models-and-rnn-c516fab9545b?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c516fab9545b</guid>
            <category><![CDATA[language-modeling]]></category>
            <category><![CDATA[recurrent-neural-network]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Tue, 12 May 2020 05:20:36 GMT</pubDate>
            <atom:updated>2020-05-19T08:24:36.420Z</atom:updated>
            <content:encoded><![CDATA[<h4>This story covers two topics: Language models(LM) and RNN. For LM, it includes the N-gram language model and neural LM; for RNN, this story goes from vanilla RNN to vanishing gradient problem, and introduce LSTM/GRU and variants of RNN: bidirectional RNN and multi-layer RNN.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*hSV_3P3JIySXoRgLGrE-5w.png" /></figure><p>This story covers topics: Language models(LM) and RNN. In detail, for LM, this story goes from the N-gram language model to neural LM; for RNN, this story goes from vanilla RNN to vanishing gradient problem, and introduce LSTM/GRU and variants of RNN: bidirectional RNN and multi-layer RNN. This article is a summary of the course <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">‘Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 6 — Language Models and RNNs’</a>.</p><h3>1. Language models</h3><p><strong><em>Language modeling is the task of predicting what word comes next. More formally: given a sequence of words x(1),x(2), …x(t), compute the probability distribution of the next word x(t+1)</em></strong>. A system that does language modeling is called a Language Model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ha0iVk4CCZT0doWL2JcGbQ.png" /><figcaption>Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong><em>You can also think of a Language Model as a system that assigns a probability to a piece of text. </em></strong>For example, if we have some text x(1),x(2), …x(t), then the probability of this text (according to the Language model is) is shown on the left picture.</p><h4>1.1 N-gram language models</h4><p>For example, let’s complete the sentence the students opened their ____. How to learn a Language Model (LM)? <strong><em>The pre- deep learning method is learning an n-gram Language Model.</em></strong> An n-gram is a chunk of n consecutive words. Unigrams could be the, student, openedand their. Bigrams could be the students, students openede, and opened their. The idea is collecting statistics about how frequent different n-grams are, and use these to predict the next word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eH-x4p5HTX2HTUPNacs0Jw.png" /><figcaption>N-gram LM. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*acrsvRa8PMDeVsbAW3oF1A.png" /><figcaption>calculating n-grams and (n-1)-gram probabilities. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong><em>First, we make a simplifying assumption: x(t+1) depends only on the preceding n-1 words.</em></strong> We can get these n-grams and (n-1)-gram probabilities by counting them in some large corpus of text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_PRdiRitCOqB7W-nVn4Zog.png" /><figcaption>4-gram LM example. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>For example, suppose we are learning a 4-gram LM, the sentence is as the proctor started the clock, the student opened their ___. Suppose that in the corpus: students opened their occurred 1000 times, students opened their booksoccurred 400 times. So P(books|students opened their)=0.4. Suppose students opened their exams occurred 100 times, then P(exams|students opened their)=0.1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MLP6MvZ5nd_cGFR7SPf5g.png" /><figcaption>sparsity problems with n-gram language models. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong>The problem of n-gram LM is sparsity.</strong> Increasing n makes sparsity problems worse, typically we can not have n bigger than S. Increasing n or increasing corpus increases model size!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*_8xJIiByQPxshxyhzPse8Q.gif" /><figcaption>generating text with an n-gram LM. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>You can also use n-gram LM to generate text, which is surprisingly grammatical. But <strong>incoherent</strong>. We need to consider more than three words at a time if we want to model language well. But increasing n worsens sparsity problem and increases model size.</p><h4>1.2 A neural LM</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*gwTfA_jlsHCtJsBX-l0Lwg.gif" /><figcaption>a fixed-window neural LM. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong><em>A fixed-window neural LM improves over n-gram LM.</em></strong> There is no sparsity problem and you do not need to store all observed n-grams. <em>There are still some remaining problems: 1) the fixed window is too small; 2) enlarging window enlarges W; 3) Window can never be large enough; 4) X¹ and X² are multiplied by completely different weights in W. </em>No symmetry in how the inputs are processed. We need a neural architecture that can proceed with any length input.</p><h3>2. RNN</h3><h4>2.1 Vanilla RNN</h4><p>To address the need for a neural architecture that can proceed with any length input, we introduce RNN<strong><em>. The core idea is we can apply the same weight W repeatedly.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0D0Ayw6xmsrEC0eiHtp7hg.png" /><figcaption>this diagram shows the most important features of RNN. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Ob_lVraqWoAr_8JbtYhExQ.gif" /><figcaption>A RNN LM. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><em>RNN advantages are: it can proces</em><strong><em>s </em></strong><em>any length input; computation for step t can (in theory) use information from many steps back; model size doesn’t increase for longer input; same wights applied on every timestep, so there is symmetry in how inputs are processed</em>.<em> Downsides are: recurrent computation is slow; in practice, difficult to access information from many steps back.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyxW6URTc8lqG2a50WgEyg.png" /><figcaption>The loss function for RNN LM training. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><em>How to train an RNN LM?</em> First, we need to get a big corpus of text which is a sequence of words x¹,x²,x³,…. Then we feed these inputs into RNN-LM and compute output distribution y_hat(t) for every step t. For example, predict the probability distribution of every word, given words so far. The right picture shows the loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VDvr7ZS4R243lgT0FSolgQ.gif" /><figcaption>Training an RNN Language Model. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><em>However, computing loss and gradients across the entire corpus are too expensive. </em><strong><em>Stochastic Gradient Descent (SGD) allows us to compute loss and gradient for a small chunk of data, and update.</em></strong> So we could apply SGD into computing loss for a sentence (actually a batch of the sentence), compute gradients and update weights and repeat this process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*5QL2PguOiWy6RRyywt4QdQ.png" /><figcaption>“ The gradient w.r.t. a repeated weight is the sum of the gradient w.r.t each time it appears”. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSJ4d1YhQfHrpVXWByhApQ.png" /><figcaption>backpropagation through time. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>What is the derivative of loss w.r.t the repeated weight matrix Wh? By backpropagating over timesteps i=t,..,0, summing gradients as you go, it turns out <strong><em>“ The gradient w.r.t. a repeated weight is the sum of the gradient w.r.t each time it appears”.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxmP-J-9w-49a19yU6n_Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9oyfWBsbabD3EcRwM8wSQ.png" /><figcaption>math explanation for backpropagation calculation. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><h4>2.2 RNN applications</h4><p>Just like an n-gram Language Model, you can use an <strong>RNN Language Model to generate text </strong>by repeated sampling. The sampled output is the next step’s input. You can train an RNN-LM on any kind of text, then generate text in that style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*dIP7uNLsuYeW0_cCGcnM_Q.gif" /><figcaption>RNN LM example. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rSjxR_UkZxWHUGbnw7C3WA.jpeg" /><figcaption>Evaluating Language Models. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>The standard evaluation metric for Language Models is perplexity. And it is equal to the exponential of the cross-entropy loss. Lower perplexity is better. Results show that RNN-LM outperforms n-gram models.</p><p><strong><em>Language Modeling is a benchmark task that helps us measure our progress in understanding language</em></strong>. Language Modeling is a subcomponent of many NLP tasks, especially those involving generating text or estimating the probability of text: predictive typing, speech recognition, handwriting recognition, spelling/grammar correction, authorship identification, machine translation, summarization, dialogue Etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*ZVfcYD0PPsLp76IQ6qlHxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*5g3n3nJde0DreqoIk04SFg.png" /><figcaption>RNN for text classification. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*Xp2fqP_x35KC54lk11gxBw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*QJYF6cp90mypZtXj4J1laQ.gif" /><figcaption>RNN as an encoder in question answering (left); RNN applied in speech recognition (right). Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><h4>2.3 vanishing gradient</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eFTq3UNWMczBcg7OHVWX1A.png" /><figcaption>vanishing gradient proof sketch. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cx8aEWkd1wqRJArldaDzg.png" /><figcaption>why is vanishing gradient a problem? Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong><em>The gradient can be viewed as a measure of the effect of the past on the future. </em></strong>If the gradient becomes vanishingly small over longer distances (step t to step t+n), then there is no dependency between step t and t+n in the data and we have wrong parameters to capture the true dependency between t and t+n. <em>Due to the vanishing gradient, RNN-LMs are better at learning from sequential recency than syntactic recency</em><strong>,</strong> so they make this type of error more often than we’d like. For example, In the sentence The writer of the book is, is and writer are syntactic recency; In the sentence the writer of the books are , are and books (instead of writer ) are sequential recency.</p><h4>2.4 <strong>exploding</strong> gradient</h4><p>The <strong>exploding gradient </strong>is also a problem.<strong><em> If the gradient becomes too big, then the SGD update step becomes too big.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*tm0hhjk2_2imCuC6A8Ro2g.png" /><figcaption>SGD. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>This can cause bad updates: we take too large a step and reach a bad parameter configuration (with large loss) In the worst case, this will result in inf or NaN in your network (then you have to restart training from an earlier checkpoint).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*P_M9z-ORb9RancNB6R9uQg.png" /><figcaption>gradient clipping. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><strong>Gradient clipping </strong>could fix the exploding gradient. Gradient clipping is if the norm of the gradin is greater than some threshold, scale it down before applying the SGD update. The intuition behind the gradient clipping is when finding the minima of a local function, we take a step in the same direction, but a smaller step.</p><h4>2.5 Long short-term memory (LSTM)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*u9vi2dbigC_7K9pZg2W2FQ.png" /><figcaption>hidden state in the vanilla RNN where the hidden state is constantly being rewritten. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><em>How to fix the vanishing gradient problem?</em> <strong><em>The main problem is that it’s too difficult for the RNN to learn to preserve information over many timesteps</em></strong>. In a vanilla RNN, the hidden state is constantly being rewritten. How about an RNN with separate <em>memory</em>?</p><p><a href="https://www.bioinf.jku.at/publications/older/2604.pdf">A type of RNN proposed by Hochreiter and Schmihuber in 1997</a> as a solution to the vanishing gradients problem. On step t, there is a hidden state h(t) and a cell state c(t). Both are vectors length n and the cell stores long-term information. The LSTM can erase, write, and read information from the cell. The selection of which information is erased/written read is controlled by three corresponding gates. The gates are also vectors length n. On each time step, each element of gates can be open (1), closed(0), or somewhere in-between. The gates are dynamic: their value is computed based on the current context.</p><p>We have a sequence of inputs x(t), and we will compute a sequence of hidden states h(t), and cell states c(t).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*4Iaow6h8888ADgxWDESPtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I2odErbFMHNzFoLT0c1ZUg.png" /><figcaption>LSTM. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>How does LSTM solve vanishing gradient? <strong><em>The LSTM architecture makes it easier for the RNN to preserve information over many timesteps.</em></strong> E.g. If the forget gate is set to remember everything on every timestep, then the info in the cell is preserved indefinitely. By contrast, it is harder for vanilla RNN to learn a recurrent weight matrix Wh that preserves info in a hidden state. LSTM doesn’t <em>guarantee</em> that there is no vanishing/exploding gradient, but it does provide an easier way for the model to learn long-distance dependencies</p><p>LSTMs obtain real-world success. In 2013–2015, LSTMs stated achieving state-of-art results. Successful tasks include handwriting recognition, speech recognition, machine translation, parsing, image captioning. LSTM became the dominant approach. However, from 2019, other approaches (e.g.. Transformers) have become more dominant for certain tasks. For example in WMT (an MT conference + competition), in WMT 2016, the summary report contains “RNN” 44 times; in WMT 2018, the report contains “RNN” 9 times and “Transformer” 63 times.</p><h4>2.5 Gated Recurrent Units (GRU)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E_EoMbj25Xj3H2GNMNPUqg.png" /><figcaption>GRU. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><a href="https://arxiv.org/abs/1412.3555">GRU</a> is proposed by Cho in 2014 as a simpler alternative to the LSTM. On each time step t, we have input x(t) and hidden state h(t) (no cell state)</p><p>Researchers have proposed many gated RNN variants, but LSTM and GRU are the most widely-sued.</p><p><strong>What is the difference between GRU and LSTM? </strong>The biggest difference is that<strong> GRU is quicker to compute and has fewer parameters.</strong> There is no conclusive evidence that one consistently performs better than the other. LSTM is a good default choice (especially if your data has [particularly long dependencies, or you have lots of training data). Rule of thumb: start with LSTM, but switch to GRU if you want something more efficient.</p><h4>2.6 Vanishing/exploding gradient is not just an RNN problem</h4><p>Vanishing/exploding gradient is not just an RNN problem. It can be a problem for all neural architectures (including feed-forward and convolutional), especially deep ones. Due to the chain rule/choice of nonlinearity function, the gradient can become vanishingly small as t backpropagates. Thus lower layers are learned very slowly (hard to train). To fix this problem, lots of new deep feedforward/convolutional architectures that add more direct connections (thus allowing the gradient to flow), such as ResNet, DenseNet, and HighwayNet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*lRYXuQYrJx13Ilq5LDZSMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*snYE6dv2y4Lo2vtOs7aj7g.png" /><figcaption>ResNet (left) and DenseNet (right). Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>Residual connections aka “<a href="https://arxiv.org/pdf/1512.03385.pdf">ResNet</a>”, also known as skip-connections. The identity connection preserves information by default. This makes deep networks much easier to train. Dense connections aka “<a href="https://arxiv.org/pdf/1608.06993.pdf">DenseNet</a>”, it directly connects everything to everything. Highway connections aka “<a href="https://arxiv.org/abs/1505.00387">HighwayNet</a>”. It is similar to residual connections, but the identity connection vs the transformation layer is controlled by a dynamic gate. It is Inspired by LSTMs but applied to deep feedforward/convolutional networks.</p><p>In conclusion, though vanishing/exploding gradients are a general problem, RNNs are particularly unstable due to the repeated multiplication by the same weight matrix.</p><h4>2.7 bidirectional RNNs</h4><p>Since hidden states (cotextual representations) in RNN only contains information about the left (the backward) context but not the right (forward) context, and these right context might be useful in some NLP tasks (such as text classification), bidirectional RNNs were proposed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbReyNfVpxamhn-PyPBoFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*510ahzyfO4fcLLaJ63aoQA.png" /><figcaption>Bidirectional RNNs. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p><a href="https://papers.nips.cc/paper/5651-bidirectional-recurrent-neural-networks-as-generative-models.pdf"><em>Bidirectional RNNs </em></a><em>are only applicable if you have access to the entire input sequence.</em> They are not applicable to Language Modeling, because in LM you <em>only</em> have left context available. If you do have an entire input sequence (e.g. any kind of encoding), bidirectionality is powerful (you should use it by default). For example, BERT (Bidirectional Encoder Representations from Transformers) is a powerful pretrained contextual representation system built on bidirectionality.</p><h4>2.8 Multi-layer RNNs</h4><p>RNNs are already “deep” on one dimension (they unroll over many timesteps) We can also make them “deep” in another dimension by applying multiple RNNs — this is a multi-layer RNN. This allows the network to compute more complex representations. The lower RNNs should compute lower-level features and the higher RNNs should compute higher-level features. Multi-layer RNNs are also called stacked RNNs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hOtO0_baSZmoIcaWd5t6ww.png" /><figcaption>multi-layer RNN example. Source: <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">the course slide</a></figcaption></figure><p>High-performing RNNs are often multi-layer (but aren’t as deep as convolutional or feed-forward networks). For example: In <a href="https://arxiv.org/abs/1703.03906">a 2017 paper</a>, Britz et al find that for Neural Machine Translation, 2 to 4 layers is best for the encoder RNN, and 4 layers are best for the decoder RNN. However, skip-connections/dense-connections are needed to train deeper RNNs ( e.g. 8 layers). Transformer-based networks (e.g. BERT) can be up to 24 layers. Transformers have a lot of skipping-like connections.</p><p>Reference</p><ol><li><a href="https://arxiv.org/abs/1505.00387">Highway Networks</a></li><li><a href="https://arxiv.org/pdf/1608.06993.pdf">Densely Connected Convolutional Networks</a></li></ol><p>3. <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep Residual Learning for Image Recognition</a></p><p>4. <a href="https://www.youtube.com/watch?v=iWea12EAu6U&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=6">Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 6 — Language Models and RNNs</a></p><p>5.<a href="https://www.bioinf.jku.at/publications/older/2604.pdf">LONG SHORT-TERM MEMOR</a></p><p>6. <a href="https://arxiv.org/abs/1412.3555">Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c516fab9545b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Word Vectors]]></title>
            <link>https://medium.com/@rachel_95942/word-vectors-d1df9e81c16d?source=rss-cbd32a3f303d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1df9e81c16d</guid>
            <category><![CDATA[word-vectors]]></category>
            <category><![CDATA[word-embeddings]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Qiurui Chen]]></dc:creator>
            <pubDate>Tue, 12 May 2020 05:18:01 GMT</pubDate>
            <atom:updated>2020-05-12T05:18:01.744Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*oa64MptfpW3vyucLwCjZaw.png" /></figure><p>This story main introduces word vectors. It covers word2vec, co-occurrence counts, Glove, and evaluation of word vectors. It’s the short summary of <a href="https://www.youtube.com/watch?v=kEMJRjEdNzM&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=2">Stanford CS224N: NLP with Deep Learning</a> lecture 1–2.</p><h4>Why we need word vectors?</h4><p>How to represent the meaning of a word? Definition of <strong>meaning</strong> (webster dictionary): 1) The idea that is represented by a word, phrase, etc; 2) The idea that a person wants to express by using words, signs, etc; 3) The idea that is expressed in a work of writing, art, etc. The Commonest linguistic way of thinking of the meaning is denotational semantics.</p><p>How do we have usable meaning on a computer? A common solution is using e.g. WordNet, a thesaurus containing lists of synonym sets and hypernyms (“is a” relationship). The problems with resources like WordNet are: 1) great as a resource but missing nuance, such as “proficient” is listed as a synonym for “good”, while this is only correct in some context; 2) missing new meanings of words, such as Wicked, badass, nifty, wizard, genius, ninja, and bombast. It is impossible to keep up-to-date 3) it is subjective; 4) it requires human labor to create and adapt; 5) it can not capture accurate word similarity.</p><p><strong>In traditional NLP, we regard words as discrete symbols</strong>. Word can be represented by one-hot vectors. The vector dimension equals the number of words in vocabulary (e.g. 500,000).<em> </em><strong>The problem with this representation is there is no natural notion of similarity for one-hot vectors</strong>! For example, motel may be represented as [0 0 0 0 0 0 0 1] while hotel may be represented as [1 0 0 0 0 0 0 0] .Although these two words are similar, the two vectors are orthogonal. The solution is maybe we can lean to encode similarity in the vectors themselves. We can<strong><em> represent words by their context</em></strong><em>. </em>Distributional semantics means a word’s meaning is given by the words that frequently appear close-by. When a word w appears in a text, its context is the set of words that appear nearby (within a fixed-size window). <strong><em>So the idea is using the many contexts of w to build up a representation of w.</em></strong> That’s where word vectors come in.</p><h4>Word2vec</h4><p>Word2vec is a framework for learning word vectors. We have a large corpus of text, and every word in a fixed vocabulary is represented by a vector. We go through each position t in the text, which has a center word c and context (“outside”) words o, and use the similarity of the word vectors for c and o to calculate the probability of o given c (or vice versa). We keep adjusting the word vectors to maximize this probability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*cZuwmwXOteA-BcgxoFnMdg.png" /><figcaption>Example windows and process for computing P(w_{t+j}|w_{t})</figcaption></figure><p>Slightly more graphically, the left picture shows the situation. So we’ve got part of our corpus ...problems turning into bankingcrises as..., and we want to know the meaning of the word into. We hope this word representation will make precise to predict what words appear in the context of into.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*sKjTpIbaIz6kax0MU_ASig.png" /><figcaption>Word2vec: objectuive function</figcaption></figure><p><strong>So overall, we have a big long corpus of capital T words. For each position t =1,…, T, we want to predict context words within a window of fixed size m, given center word wj. </strong>Firstly, we go through all the words and choose a fixed-size window (for example, it might be 5 words on each side), then we predict around words given the center word. In the end, we multiply these probabilities for all words T in our corpus, and our model likelihood now measures how good a job it does at predicting the words around every word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*xVgIZm8-XySBhTVhQ4ODRQ.png" /><figcaption>softmax function as prediction function</figcaption></figure><p>How to calculate P(context words|center word)? Assuming Vw is word V when word w is given as a center word, then for a center word c and context word o, the probability equation that predicting o by c is shown on the right picture.</p><p>There are two model variants, they are the<strong> </strong><a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf"><strong>skip-gram</strong></a><strong>(SG) </strong>and <strong>continuous bag of word(CBOW) models.</strong> <strong>The Skip-gram model predicts context (“outside”) words (position independent) given center word, while CBOW predicts center word from (bag of ) context words</strong>.</p><h4>co-occurrence counts</h4><p>But why not capture <strong>co-occurrence counts</strong> directly? With a co-occurrence matrix X, there are 2 options: X for windows or X for full document. X for windows is similar to word2vec, using a window around each word to captures both syntactic (POS) and semantic information. Word-document co-occurrence matrix will give general topics (all sports terms will have similar entries) leading to “latent semantic analysis”. <strong>The problem with simple co-occurrence vectors is that the matrix size is increased with vocabulary.</strong> It is a very<strong> high dimensional and requires a lot of storage</strong>. Subsequent classification models have sparsity issues, which makes models are less robust. The solution for this is low-dimensional vectors. The idea is storing “most” of the important information in a fixed, small number of dimensions, which are a dense vector. Usually, it is 25-1000 dimensions, similar to word2vec. Then <em>how to reduce the dimensionality</em>? One solution is applying <strong>singular value decomposition on the co-occurrence matrix x.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*xdGdKXdy95Jzix7sfwd9Vg.png" /><figcaption>SVD of co-occurrence matrix X.</figcaption></figure><p><strong>Scaling the counts in the cells can help a lot</strong>. The problem is that<strong> function words (s.t. the, he, and has) are too frequent,</strong> which leads this syntax to have too much impact. Some fixes could be <strong>either minimizing these words’ occurrences to a fixed number (s.t 100) or ignoring all these words</strong>. The second way to <strong>scale the counts is using Pearson correlation instead of counts, and then setting negative values to zero</strong>.</p><h4>GloVE</h4><p>There had been 2 schools of work. One is <strong>count-based </strong>and another is <strong>direct prediction. Count-based work is based on counting and transforming counts. </strong>These works are such as <a href="https://escholarship.org/content/qt9j14z1rq/qt9j14z1rq.pdf">COALS, Hellinger-PCA</a>, and <a href="https://link.springer.com/chapter/10.1007/978-3-540-30497-5_111">LSA, HAL </a>etc. The advantages of count-based work are fast training and efficient usage of statistics. But <strong>they are primarily used to capture word similarity </strong>and <strong>disproportionate importance given to large counts.</strong> <strong>The direct-prediction methods are directly defining that probability distribution and trying to predict the words that occur.</strong> Skip-gram/CBOW, NNLM,HLBL, and RNN belong to this method. This method has some advantages, <strong>it can generate improved performance on other tasks and can capture complex patterns beyond word similarity.</strong> The downside of it is it scales with corpus size and it is an inefficient usage of statistics. How about <strong>combining these two different methods</strong>? That exactly what <strong>GloVE</strong> does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8eNi2rkDQy7F2x46H9m9sw.png" /><figcaption>example co-occurrence probabilities</figcaption></figure><p><strong><em>The ratios of co-occurrence probabilities can encode meaning components. </em></strong>For example, from the right picture, we can see P(solid|rice) and P(solid|steam) are both very small. But P(solid|rice)/P(solid|steam) is large, which means ice and steam have similar meanings. we could use a log-bilinear model with vector difference to capture that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*mJg5-q2yoS5V_02CNJQA8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*pSzpwBHum9Wvy563xE5Lyg.png" /><figcaption>GloVE loss function</figcaption></figure><p>Let the matrix of word-word co-occurrence counts be denoted by X, <em>whose entries Xij tabulate the number of times word j occurs in the context of the word i. </em>Essentially the loss function is shown on the top left picture. <em>The dot product on the top is the ratios of co-occurrence probabilities for word i and j. </em>The squared part in the loss shows that<strong> GloVE wants the dot-product to be as similar as possible to the log of the co-occurrent probability (logXij).</strong> The loss function is complexified a little by putting in bias terms for both of the two words. <em>GloVe did a trick to use f function in front to cap the effect that very common word pairs can have on the performance of the system</em>. GloVe performs well due to its fast training and scalability to huge corpora. It achieves good performance even with small corpus and small vectors.</p><h4>Evaluation</h4><p><strong>How to evaluate word vectors</strong>? There are intrinsic and extrinsic methods. For intrinsic methods, evaluation is done on a specific /intermediate subtask. It is fast to compute and helps to understand that system. But it is not clear if really helpful unless correlation to the real task is established. Regards extrinsic methods, evaluation is done on a real task. It can take a long time to compute the accuracy and it is unclear if the subsystem is the problem or its interaction or other subsystems.<strong><em> For intrinsic word vector evaluation,</em></strong> <strong><em>we could evaluate word vectors by how well their cosine distance after addition captures intuitive semantic and syntactic analogy questions.</em></strong> Please check out <a href="http://code.google.com/p/word2vec/source/browse/trunk/questions-words.txt">&lt;Word vector analogies: syntactic and semantic examples&gt;</a> for more detail. Another intrinsic word vector evaluation could be word vector distances and theory correlation with human judgments. An example dataset could be wordSim353.</p><p><strong><em>Most words have lots of meanings</em></strong>, especially common words and words that have existed for a long time, for example pike. Does one vector capture all these meanings or do we have a mess? <strong><em>We could cluster word windows around words, retrain with each word assigned to multiple different clusters</em></strong>.</p><p>The <a href="https://nlp.stanford.edu/pubs/glove.pdf">results</a> show that GloVE outperforms skip-gram models.</p><h4>References</h4><ol><li><a href="https://www.youtube.com/watch?v=kEMJRjEdNzM&amp;list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z&amp;index=2">Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 2 — Word Vectors and Word Senses</a></li><li><a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf">Distributed Representations of Words and Phrases and their Compositionality</a></li><li><a href="https://nlp.stanford.edu/pubs/glove.pdf">GloVe: Global Vectors for Word Representation</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1df9e81c16d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>