<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>David Merrell&apos;s Blogsite</title>
    <description>I am a computer scientist and Bayesian who knows some biology. This blog/website shows some of the things I&apos;ve been up to.
</description>
    <link>/</link>
    <atom:link href="/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 20 Jan 2026 19:58:03 +0000</pubDate>
    <lastBuildDate>Tue, 20 Jan 2026 19:58:03 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Map of the cat</title>
        <description>&lt;p&gt;I think of this Richard Feynman story pretty often.&lt;/p&gt;

&lt;p&gt;Apparently Feynman spent a short episode of his career dabbling in biology.
This story recounts his experience taking a graduate level biology course. 
The professor has assigned him to present a paper to the class:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“I began to read the paper. It kept talking about extensors and flexors, the gastrocnemius muscle, and so on. 
This and that muscle were named, but I hadn’t the foggiest idea of where they were located in relation to the nerves or to the cat. 
So I went to the librarian in the biology section and asked her if she could find me a map of the cat.&lt;/p&gt;

  &lt;p&gt;“‘A map of the cat, sir?’ she asked, horrified. ‘You mean a zoological chart!’ From then on there were rumors about some dumb biology graduate student who was looking for a ‘map of the cat.’&lt;/p&gt;

  &lt;p&gt;“When it came time for me to give my talk on the subject, I started off by drawing an outline of the cat and began to name the various muscles.&lt;/p&gt;

  &lt;p&gt;“The other students in the class interrupt me: ‘We know all that!’&lt;/p&gt;

  &lt;p&gt;“‘Oh,’ I say, ‘you do? Then no wonder I can catch up with you so fast after you’ve had four years of biology.’ 
They had wasted all their time memorizing stuff like that, when it could be looked up in fifteen minutes.”&lt;/p&gt;

  &lt;p&gt;—Richard Feynman (&lt;em&gt;Surely You’re Joking, Mr. Feynman!&lt;/em&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This story resonates with me as a computer scientist/mathematician working on biological problems.&lt;/p&gt;

&lt;p&gt;I’ve found that physicists (and computer scientists) have very different sensibilities from biologists.
I think Ernest Rutherford had these differences in mind when he said “All science is either physics or stamp collecting.”&lt;/p&gt;

&lt;p&gt;Biologists are required to memorize a great many facts.
In contrast, computer scientists, mathematicians, and physicists only memorize a small number of “first principles”.
Those principles serve as a starting point to reason/solve problems/understand the world—you can get a lot of mileage out of a small number of good abstractions.&lt;/p&gt;

&lt;p&gt;Meanwhile, biological systems are like Rube Goldberg machines.
Very little of biology can be explained from anything resembling “first principles.”
The central dogma is the closest thing to a first principle I can think of, but it explains only a small fraction of the mechanisms people find interesting.&lt;/p&gt;

&lt;p&gt;A competent biologist must (a) learn a large number of facts and (b) form a unified understanding from them.
I feel optimistic that algorithms, ML, and AI can do a good job of this.
I’m not very interested in stamp collecting—but I am very keen to develop algorithms that collect stamps for me.&lt;/p&gt;

&lt;p&gt;Whenever I feel my computer scientist mindset collide with the stamp-collecting aspects of biology, I think of it as a “map of the cat” moment.
I only wish more people knew this Feynman story, so that I could say “map of the cat” out loud and people would understand what I mean.&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Fri, 10 Feb 2023 05:00:00 +0000</pubDate>
        <link>/personal/2023/02/10/map-of-the-cat.html</link>
        <guid isPermaLink="true">/personal/2023/02/10/map-of-the-cat.html</guid>
        
        <category>biology</category>
        
        <category>physics</category>
        
        <category>math</category>
        
        <category>computer-science</category>
        
        
        <category>personal</category>
        
      </item>
    
      <item>
        <title>A less-bad blog post about transformers</title>
        <description>&lt;p&gt;This is the &lt;em&gt;second&lt;/em&gt; post in a series!&lt;/p&gt;

&lt;p&gt;I recommend reading the &lt;em&gt;first&lt;/em&gt; post &lt;a href=&quot;/technical/2023/01/02/attention-intro.html&quot;&gt;(“A less-bad blog post about attention mechanisms”)&lt;/a&gt;
before reading this one.
It explains important prerequisite concepts. For example, “self-attention” and “multi-head attention.”&lt;/p&gt;

&lt;h2 id=&quot;why-im-writing-this&quot;&gt;Why I’m writing this&lt;/h2&gt;

&lt;p&gt;I suspect &lt;a href=&quot;https://arxiv.org/abs/1706.03762&quot;&gt;“Attention is All You Need” (AIAYN)&lt;/a&gt; was written with a very specific audience in mind.
I don’t think it actually explains transformers very well to a general ML audience.&lt;/p&gt;

&lt;p&gt;As a single example, consider this graphic from the original AIAYN paper:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/vaswani-transformer.png&quot; alt=&quot;AIAYN transformer image&quot; width=&quot;300px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This was incomprehensible to me when I first tried reading AIAYN.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;What’s being stacked N times? And in what fashion? How do connections work between stacked units on the left and right?&lt;/li&gt;
  &lt;li&gt;Why is there an arrow &lt;em&gt;from&lt;/em&gt; outputs &lt;em&gt;into&lt;/em&gt; the network?&lt;/li&gt;
  &lt;li&gt;What does it mean that the outputs are “shifted right?”&lt;/li&gt;
  &lt;li&gt;Why are there “outputs” in the lower right and “output probabilities” in the upper right?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Despite its (arguable) lack of clarity, this same image is copied and pasted into practically every blog post about transformers.
The typical blogger then proceeds to “explain” it by parroting the same explanation given in AIAYN.
It’s as though the bloggers only have a superficial understanding of the concepts in AIAYN, or haven’t thought carefully about how to explain them.&lt;/p&gt;

&lt;p&gt;This post aims to do a less-bad job of explaining transformers to a broad ML audience.&lt;/p&gt;

&lt;h2 id=&quot;a-gradual-explanation-of-the-transformer-architecture&quot;&gt;A gradual explanation of the transformer architecture&lt;/h2&gt;

&lt;p&gt;We’ll start with a 10,000-foot view of the transformer and gradually zoom in, focusing on important details as appropriate.&lt;/p&gt;

&lt;h3 id=&quot;broad-brush-strokes&quot;&gt;Broad brush strokes&lt;/h3&gt;

&lt;p&gt;Some important big-picture things to understand about the transformer architecture:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The transformer is a &lt;em&gt;sequence-to-sequence&lt;/em&gt; model.
    &lt;ul&gt;
      &lt;li&gt;That is, it receives a sequence \(x_1, x_2, \ldots, x_M \) as input and produces a new sequence \(y_1, y_2, \ldots, y_N\) as output.&lt;/li&gt;
      &lt;li&gt;Concretely, AIAYN presents the transformer as a model for translating text from one language to another (like in Google Translate).&lt;/li&gt;
      &lt;li&gt;Whenever appropriate, we’ll focus on concrete examples from text translation.
But keep in mind that the architecture may accommodate a much broader class of tasks.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;The transformer has two primary components: an &lt;em&gt;encoder&lt;/em&gt; and a &lt;em&gt;decoder&lt;/em&gt;.
    &lt;ul&gt;
      &lt;li&gt;The encoder receives an input sequence and transforms it into a latent representation.
The idea is that this latent representation &lt;em&gt;encodes&lt;/em&gt; the input in some informative way.&lt;/li&gt;
      &lt;li&gt;The decoder receives the latent representation and transforms it into a useful output.
(It operates differently from your typical decoder, though—pay special attention to the graphics in this post.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;The transformer is &lt;em&gt;autoregressive&lt;/em&gt;. That is:
    &lt;ul&gt;
      &lt;li&gt;it generates the output sequence &lt;em&gt;one item at a time&lt;/em&gt;; and&lt;/li&gt;
      &lt;li&gt;each new item in the output sequence is a function of the &lt;em&gt;previous items&lt;/em&gt;.&lt;/li&gt;
      &lt;li&gt;The output sequence terminates when a special “end token” is generated.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The situation is captured in this graphic:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/transformer-autoregressive.svg&quot; alt=&quot;transformer autoregressor&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The transformer’s encoder receives the input sequence \(x_1, x_2, \ldots, x_M \) and computes a latent representation for it.
This latent representation gets passed to the decoder.&lt;/p&gt;

&lt;p&gt;In this scenario, the transformer has already generated the first \(t \) items in the output sequence—\(y_1, y_2, \ldots, y_t\).
The decoder generates \(y_{t+1}\) as a function of (i) the latent representation and (ii) the first \(t\) items.
Finally, \(y_{t+1} \) is appended to the output sequence and the process repeats.
Note that the latent representation remains the same while the output items are being generated.
That is, the latent representation only needs to be computed once for the input sequence.&lt;/p&gt;

&lt;!--_--&gt;

&lt;h3 id=&quot;layers-of-the-model&quot;&gt;Layers of the model&lt;/h3&gt;

&lt;p&gt;It’s time to reveal more details.
The encoder and decoder are each composed of &lt;em&gt;layers&lt;/em&gt;.
For example, In AIAYN they both contain \(K = 6\) layers.&lt;/p&gt;

&lt;p&gt;The layers in the encoder all have identical architecture, though their weights are allowed to differ.
The same applies to the decoder: its layers have identical architecture but differing weights.
We’ll discuss the encoder and decoder layers later in much more detail.&lt;/p&gt;

&lt;p&gt;Here’s the graphic again, updated to show the layers:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/transformer-layers.svg&quot; alt=&quot;transformer layers&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The encoder’s final layer produces the latent representation.
Interestingly, it passes the latent representation to &lt;em&gt;every layer of the decoder&lt;/em&gt;.
This ensures that the input sequence thoroughly “informs” the generation of the next item in the output sequence.&lt;/p&gt;

&lt;p&gt;Here’s an important detail that isn’t captured in the graphic: the latent representation is actually a collection of \(M\) vectors; i.e., a collection as long as the original input sequence. 
And this collection of \(M\) vectors gets passed to each layer of the decoder.
Just imagine that each of the edges from encoder to decoder is &lt;em&gt;actually&lt;/em&gt; a collection of \(M\) edges.&lt;/p&gt;

&lt;p&gt;Notice that the next output item, \( y_{t+1} \), is a function of the outputs of the final decoder layer. 
A more complete explanation is that \(y_{t+1} \) is computed via a linear function followed by a &lt;strong&gt;softmax&lt;/strong&gt;.
Importantly, the transformer assumes you have a fixed-size &lt;em&gt;vocabulary&lt;/em&gt; of possible output items (e.g., the 10,000 most common English words). 
The decoder selects the next token by (i) assigning probabilities to the vocabulary items and (ii) choosing the most probable item.
(This amounts to a one-hot encoding of \(y_{t+1} \)—which was a point of confusion for me since one-hot encodings are not used anywhere else in the model.)&lt;/p&gt;

&lt;p&gt;Much of the credit for this graphic goes to Jay Alammar’s &lt;a href=&quot;https://jalammar.github.io/illustrated-transformer/&quot;&gt;“The Illustrated Transformer,”&lt;/a&gt; one of the few blog posts I found useful for understanding transformers.
Before reading his post I found it difficult to understand the connections between the encoder and decoder.&lt;/p&gt;

&lt;!-- _{} --&gt;

&lt;h3 id=&quot;encoder-layers-and-sublayers&quot;&gt;Encoder layers and sublayers&lt;/h3&gt;

&lt;p&gt;TODO&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Self-attention layer&lt;/li&gt;
  &lt;li&gt;Fully connected, position-wise neural network&lt;/li&gt;
  &lt;li&gt;Layer norm&lt;/li&gt;
  &lt;li&gt;Residual connections&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;decoder-layers-and-sublayers&quot;&gt;Decoder layers and sublayers&lt;/h3&gt;

&lt;p&gt;TODO&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Three sublayers, rather than two. Same layer norms and residual connections as before.&lt;/li&gt;
  &lt;li&gt;First sublayer: masked self-attention&lt;/li&gt;
  &lt;li&gt;Second sublayer: self-attention, including the input’s latent representation&lt;/li&gt;
  &lt;li&gt;Third layer: fully connected, position-wise neural network&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;input-representations&quot;&gt;Input representations&lt;/h3&gt;

&lt;p&gt;TODO&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Positional encoding&lt;/li&gt;
  &lt;li&gt;Connection to Fourier series&lt;/li&gt;
  &lt;li&gt;This is one of the very few ways sequence information is preserved in the input.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;beyond-sequence-to-sequence-tasks&quot;&gt;Beyond sequence-to-sequence tasks&lt;/h2&gt;

&lt;p&gt;The transformer described in AIAYN has very few attributes tailoring it specifically to sequence-to-sequence tasks:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The positional encoding&lt;/li&gt;
  &lt;li&gt;The masked self-attention in the decoder&lt;/li&gt;
  &lt;li&gt;The autoregressive generative process&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the right modification, it can be quite serviceable for other classes of tasks.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Domain-appropriate encodings can encourage relevant pairs of inputs tend to pay attention to each other.&lt;/li&gt;
  &lt;li&gt;The attention-masking can easily be removed from the decoder, if it’s not appropriate for a given application domain.&lt;/li&gt;
  &lt;li&gt;It’s not too difficult to define autoregressive processes for non-sequence data.&lt;/li&gt;
&lt;/ul&gt;

&lt;!-- Internal link
[Link to asset](/assets/myfile.pdf)
--&gt;

&lt;!-- Include an image
![title text](/assets/images/your-image.jpg){:height=&quot;200px&quot; :width=&quot;300px&quot;} 
--&gt;

&lt;h2 id=&quot;other-reading&quot;&gt;Other reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1706.03762&quot;&gt;Attention is All You Need (Vaswani et al. 2017)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jalammar.github.io/illustrated-transformer/&quot;&gt;The Illustrated Transformer (Jay Alammar)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://lilianweng.github.io/posts/2023-01-27-the-transformer-family-v2/&quot;&gt;The Transformer Family (Lilian Weng)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/2002.04745&quot;&gt;On Layer Normalization in the Transformer Architecture (Xiong et al 2020)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Mon, 23 Jan 2023 05:00:00 +0000</pubDate>
        <link>/technical/2023/01/23/transformers-intro.html</link>
        <guid isPermaLink="true">/technical/2023/01/23/transformers-intro.html</guid>
        
        <category>machine-learning</category>
        
        <category>ai</category>
        
        
        <category>technical</category>
        
      </item>
    
      <item>
        <title>Creativity and generative AI</title>
        <description>&lt;p&gt;&lt;em&gt;Yet another nerd’s take on ChatGPT/stable diffusion/etc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The thoughts in this post had been swirling in my head for a couple of weeks, but sort of &lt;em&gt;congealed&lt;/em&gt; today while I listened to &lt;a href=&quot;https://www.econtalk.org/ian-leslie-on-being-human-in-the-age-of-ai/&quot;&gt;this EconTalk episode.&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I theorize there are multiple kinds of creativity.
    &lt;ul&gt;
      &lt;li&gt;Combinatorial creativity: combining existing concepts in a way that hasn’t been done before. (Relatively common.)
        &lt;ul&gt;
          &lt;li&gt;Example: Harry Potter fan fiction.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Original creativity: generating novel concepts. (Much rarer.)
        &lt;ul&gt;
          &lt;li&gt;Example: inventing the Harry Potter universe.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;(In truth I think the reality is more complicated. The difference between “combinatorial” and “original” creativity seems like one of &lt;em&gt;abstraction level&lt;/em&gt;, rather than &lt;em&gt;kind&lt;/em&gt;. I.e., all new things come about from new configurations of atoms, but a creative person usually works at a higher level of abstraction than atoms.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;The creativity shown by generative models (ChatGPT, stable diffusion, Dall-E, etc.) falls almost completely in the “combinatorial creativity” bucket.
    &lt;ul&gt;
      &lt;li&gt;Modern deep neural networks are essentially &lt;em&gt;interpolators&lt;/em&gt;. In many cases they &lt;em&gt;literally&lt;/em&gt; interpolate their training sets.&lt;/li&gt;
      &lt;li&gt;Abstractly, concepts can be regarded as points in a high-dimensional space. A generative AI is trained on data that induce a point cloud in this space.&lt;/li&gt;
      &lt;li&gt;Those points from the dataset have a convex hull. Current generative models seem to do a great job of interpolating within that convex hull. This is, by itself, an impressive and valuable achievement (to say the least). A ton of economic and human value comes from fleshing out that convex hull, finding new combinations of ideas that make our lives better and more interesting.&lt;/li&gt;
      &lt;li&gt;What’s less clear is how well they can generate points outside of that convex hull. It’s rare even for humans to do that.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From this perspective, what can knowledge-workers or creatives do to maximize their comparative advantage against AI?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Pay attention to your environment. If you do encounter a novel concept, it will probably arise from some kind of interaction between you and your physical or social surroundings. This is your best chance at punching through that convex hull.&lt;/li&gt;
  &lt;li&gt;Embrace weirdness. You have something unique to contribute. Let the world see it!&lt;/li&gt;
  &lt;li&gt;Avoid being too predictable. De-correlate your thinking from that of other people. If I can predict your thoughts, words and actions from simple labels (“democrat”, “republican”, “religious”, “irreligious”, etc.) then you’re unlikely to provide any alpha to society.&lt;/li&gt;
  &lt;li&gt;Find ways to harness AI to enhance productivity.&lt;/li&gt;
  &lt;li&gt;There’s still room for a human touch. It helps to be a pleasant person to be around.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may also invoke the muse:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;O Divine Poesy,&lt;br /&gt;
Goddess-daughter of Zeus,&lt;br /&gt;
[…]&lt;br /&gt;
Make the tale live for us&lt;br /&gt;
In all its many bearings,&lt;br /&gt;
O Muse.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Mon, 09 Jan 2023 05:00:00 +0000</pubDate>
        <link>/personal/2023/01/09/llm-creativity.html</link>
        <guid isPermaLink="true">/personal/2023/01/09/llm-creativity.html</guid>
        
        <category>machine-learning</category>
        
        <category>creativity</category>
        
        <category>writing</category>
        
        
        <category>personal</category>
        
      </item>
    
      <item>
        <title>A less-bad blog post about attention mechanisms</title>
        <description>&lt;p&gt;A spectrum runs through the world of machine learning, with “curmudgeon statistician” at one end and “deep learning zealot” at the other.
I lean toward the “statistician” end of that spectrum, so I delayed learning about &lt;a href=&quot;https://en.wikipedia.org/wiki/Attention_(machine_learning)&quot;&gt;attention mechanisms&lt;/a&gt; until recently.&lt;/p&gt;

&lt;p&gt;It was surprisingly difficult to find clear explanations of attention.
Most sources tended to be poorly-written Medium posts with a formulaic structure:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Point to the famous &lt;a href=&quot;https://arxiv.org/abs/1706.03762&quot;&gt;“Attention Is All You Need” (AIAYN) paper&lt;/a&gt;;&lt;/li&gt;
  &lt;li&gt;bumble through an awkward discussion of “keys,” “values,” and “queries”;&lt;/li&gt;
  &lt;li&gt;show mathematical formulas for different attention mechanisms;&lt;/li&gt;
  &lt;li&gt;describe the transformer architecture in too much detail;&lt;/li&gt;
  &lt;li&gt;show some code snippets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Maybe that works for some people, but it didn’t work for me. 
AIAYN is an important paper, but it seems like a poor way to explain attention mechanisms&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;With that background in mind, I’ve compiled my current understanding of attention mechanisms into this blog post.&lt;/p&gt;

&lt;p&gt;This post is &lt;strong&gt;not&lt;/strong&gt; a thorough survey of the literature on attention mechanisms.
It only aims to be less bad than other blog posts on the topic.
I hope it makes your path easier than my own.&lt;/p&gt;

&lt;h1 id=&quot;a-gradual-explanation-of-attention&quot;&gt;A gradual explanation of attention&lt;/h1&gt;

&lt;p&gt;We’ll start with attention as &lt;em&gt;humans&lt;/em&gt; experience it.
Then we’ll present a mathematical description of attention, and show how it fits into machine learning.
Finally, we’ll arrive at the &lt;em&gt;keys, values,&lt;/em&gt; and &lt;em&gt;queries&lt;/em&gt; jargon of AIAYN.&lt;/p&gt;

&lt;h3 id=&quot;attention-in-humans&quot;&gt;Attention in humans&lt;/h3&gt;

&lt;p&gt;Machine learning researchers chose the word “attention” on purpose.
There is a strong analogy between attention mechanisms in ML and the human notion of attention.&lt;/p&gt;

&lt;p&gt;With every waking moment, your brain is flooded with sensory data. 
How are you able to process it? How are you not overwhelmed?&lt;/p&gt;

&lt;p&gt;The answer is that your brain filters out most of the data and only allows a small subset to be perceived.
At any given time, only a small amount of the sensory data is considered &lt;em&gt;relevant&lt;/em&gt; enough for perception.
When data enters your perception, we say you are “paying attention” to it.&lt;/p&gt;

&lt;p&gt;Human attention has certain key properties that will carry over to the machine learning version:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Attention assigns importance to items. It filters out irrelevant items and keeps relevant ones.&lt;/li&gt;
  &lt;li&gt;You have a finite amount of attention. You can &lt;em&gt;concentrate it&lt;/em&gt; on few items, or &lt;em&gt;spread it out&lt;/em&gt; over many items.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;attention-as-weight-assignment&quot;&gt;Attention as weight assignment&lt;/h3&gt;

&lt;p&gt;Our explanation of human attention suggests a mathematical description.&lt;/p&gt;

&lt;p&gt;Suppose you have some arbitrary set of items, \(x_1, x_2, \ldots, x_N \).
Then we can think of attention as an assignment of nonnegative &lt;em&gt;weights&lt;/em&gt; \(p_1, p_2, \ldots, p_N \) to those items.
We constrain the weights such that \(\sum_i p_i = 1 \).&lt;/p&gt;

&lt;p&gt;If we interpret the weights \(p_1, p_2, \ldots, p_N \) as &lt;em&gt;importances&lt;/em&gt;, then they satisfy the two properties of attention mentioned in the previous subsection.&lt;/p&gt;

&lt;p&gt;The weights can then inform judgments about the set of items, with heavier items being given greater importance (i.e., more attention).&lt;/p&gt;

&lt;h3 id=&quot;machine-learning-on-collections-of-items&quot;&gt;Machine learning on collections of items&lt;/h3&gt;

&lt;p&gt;This weight assignment becomes relevant for machine learning in settings where each input is a &lt;em&gt;collection of items&lt;/em&gt;.
Concretely, imagine we have a model that classifies documents.
In this case each &lt;em&gt;document&lt;/em&gt; would be regarded as a collection of &lt;em&gt;words&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a simple way our model could employ attention:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Represent each word with an embedding vector: \(x_1, x_2, \ldots, x_N\).&lt;/li&gt;
  &lt;li&gt;Assign a weight to each word: \(p_1, p_2, \ldots, p_N \).&lt;/li&gt;
  &lt;li&gt;Compute a &lt;em&gt;document vector&lt;/em&gt; \(z\) from the weighted average of word vectors: \(z = \sum_i p_i x_i\)&lt;/li&gt;
  &lt;li&gt;Let additional layers infer the class from the document vector.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is illustrated in the following graphic:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/simple-attention.svg&quot; alt=&quot;Simple attention model&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Edges indicate functional dependencies (i.e., an edge from A to B means “B is a function of A”).&lt;/p&gt;

&lt;p&gt;A practical advantage of this approach is that it naturally accommodates inputs of varying size.
In other words, the document embedding \(z\) does not necessarily depend on the document’s length—we could append an arbitrary number of irrelevant words to the document and \(z\) would not change.&lt;/p&gt;

&lt;p&gt;At this point we should discuss &lt;em&gt;where the weights come from.&lt;/em&gt;
The big ML idea is to &lt;em&gt;learn&lt;/em&gt; a function \(f\) that computes the weights.
We call this function that assigns weights to items an &lt;em&gt;attention mechanism&lt;/em&gt; or &lt;em&gt;attention head&lt;/em&gt;.
Typically \(f\) consists of two stages:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Compute a “relevance” or “compatibility” score for each word in the document;&lt;/li&gt;
  &lt;li&gt;use a softmax function to transform the relevance scores into nonnegative weights.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The relevance score for a word is usually a function of (1) that word’s vector representation \(x_i\) and (2) additional contextual information about that word.
For example, contextual information could include a word’s position in the document, its neighboring words, or some other vector embedding of the word. 
Some of this contextual information may be appended to the word vector \(x_i\), but it’s also typical to store context information in a separate vector.&lt;/p&gt;

&lt;p&gt;For illustration, contrast this graphic with the previous one:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/simple-attention-full.svg&quot; alt=&quot;attention model with context&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;(Note that it does not depict the full set of edges going into the “\(p\)” nodes.
Since the \(p\) nodes come from a softmax function, each \(p\) node depends on every input to the softmax.)&lt;/p&gt;

&lt;p&gt;So far we’ve focused on documents (collections of words) as a concrete example.
However, our discussion could just as easily apply to molecules (collections of atoms),
images (collections of pixels) or other domains.&lt;/p&gt;

&lt;h3 id=&quot;queries-keys-and-values&quot;&gt;Queries, keys and values&lt;/h3&gt;

&lt;p&gt;Somehow this terse, jargon-ridden paragraph from AIAYN made it fashionable to describe attention in terms of &lt;em&gt;queries, keys&lt;/em&gt; and &lt;em&gt;values&lt;/em&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is computed as a weighted sum of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our previous discussion maps onto that jargon in a fairly straightforward way.
Once again, let’s focus on the concrete example of a document model.&lt;/p&gt;

&lt;p&gt;It’s easiest to start with the queries and keys:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;“queries” = word vectors&lt;/li&gt;
  &lt;li&gt;“keys” = context vectors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This means the attention weights are primarily a function of the queries and keys. 
There are many ways to compute \(p_1, p_2, \ldots, p_N\) from the queries and keys: so-called “additive”, “dot-product”, “scaled dot-product”, and so on.
I recommend &lt;a href=&quot;https://lilianweng.github.io/posts/2018-06-24-attention/&quot;&gt;Lilian Weng’s blog post&lt;/a&gt; for coverage of those details.&lt;/p&gt;

&lt;p&gt;Here’s the figure from before, with “queries” and “keys” substituted in the appropriate places:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/simple-attention-kvq-1.svg&quot; alt=&quot;keys, values, queries&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That covers queries and keys. But what about “values?”&lt;/p&gt;

&lt;p&gt;Values require us to introduce new nodes to our diagram—an additional node for each word.
These new nodes will provide more flexibility to the model.
Specifically, they will allow the word vectors that form \(z\) to &lt;em&gt;differ&lt;/em&gt; from the word vectors used to compute the attention weights (i.e., the queries).
Here’s the figure again, showing the new &lt;em&gt;value&lt;/em&gt; nodes:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/simple-attention-kvq-2.svg&quot; alt=&quot;keys, values, queries&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Notice that before this, we only had one word vector representing each word (the &lt;em&gt;query&lt;/em&gt;).
In contrast, we now have &lt;em&gt;two&lt;/em&gt; word vectors representing each word (query &lt;em&gt;and&lt;/em&gt; value).
And we still have the keys, which represent context (roughly speaking).&lt;/p&gt;

&lt;p&gt;At this point we’ve arrived at a flexible and broadly applicable class of attention mechanisms.
The queries, keys and values will often be generated by other layers of the network. 
And the output \(z\) may be used as a query/key/value in another attention layer!&lt;/p&gt;

&lt;p&gt;There are many ways to incorporate these attention mechanisms into the design of a neural network.
The following sections describe a few of them.&lt;/p&gt;

&lt;h1 id=&quot;global-attention&quot;&gt;Global attention&lt;/h1&gt;

&lt;p&gt;The attention mechanism described above assigns attention weights to every item in the collection, and produces a vector representing the &lt;em&gt;entire&lt;/em&gt; collection.
For that reason it’s often called &lt;em&gt;global&lt;/em&gt; attention.
This is the simplest way to incorporate attention into a neural network.&lt;/p&gt;

&lt;p&gt;Global attention is interesting from an interpretability standpoint: for each input received by the model, the attention weights will indicate which items in that input are most relevant for that layer of the model.&lt;/p&gt;

&lt;h1 id=&quot;multi-head-attention&quot;&gt;Multi-head attention&lt;/h1&gt;

&lt;p&gt;The attention mechanism described above has a fairly strong inductive bias: it assumes the output is a weighted average of item-specific vectors.
To counter this bias, an attention layer can include &lt;em&gt;multiple&lt;/em&gt; attention heads.
That is, the same set of queries/keys/values can be passed to multiple attention mechanisms \(f_1, f_2, \ldots, f_K\); and afterward, the outputs of these mechanisms can be recombined in some fashion.
For example, AIAYN concatenates their outputs.&lt;/p&gt;

&lt;p&gt;Ideally, the different attention heads \(f_1, f_2, \ldots, f_K\) “pay attention” to \(K\) different aspects of the input; and their recombined output captures all of their “diverse perspectives”. 
This allows the output to &lt;em&gt;not&lt;/em&gt; be a simple weighted average of values.&lt;/p&gt;

&lt;p&gt;Multi-head attention is analogous to having multiple channels in a convolutional neural network.
Additional channels allow a CNN to learn multiple convolutional kernels that detect distinct patterns in the data.&lt;/p&gt;

&lt;h1 id=&quot;self-attention-or-intra-attention&quot;&gt;Self-attention (or intra-attention)&lt;/h1&gt;

&lt;p&gt;To keep things concrete, let’s once again assume we’re working with text data (documents of words).&lt;/p&gt;

&lt;p&gt;The high level idea of self-attention is to allow each word in the document to “pay attention” to the other words in the document.
This allows the model to capture pairwise interactions between words.
People call this “self-attention” or “intra-attention”; I prefer the term “intra-attention” since it seems more accurate.&lt;/p&gt;

&lt;p&gt;Recall that global attention applies a single attention head \(f\) to the entire document \(x_1, x_2, \ldots, x_N\), producing a single vector \(z\).
In contrast, imagine we have an attention head &lt;em&gt;for every word in the document&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;More accurately, imagine we have a single attention head \(f\), but for each word \(x_i\) in the document we compute a new set of attention weights tailored to that word: \( p_{i,1}, p_{i,2}, \ldots, p_{i,N} \).
These weights encode the strength of pairwise relationships between word \(x_i\) and words \(x_1, \ldots, x_N\).
Finally, suppose we use the attention head \(f\) to compute \(z_i \); a new vector for word \(i\).&lt;/p&gt;

&lt;p&gt;Here’s a graphic, showing the situation for \(i = 1\):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/intra-attention.svg&quot; alt=&quot;keys, values, queries&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If we do this for every word in the document, then we end up computing \(N^2\) attention weights and producing outputs \(z_1, z_2, \ldots, z_N\).
We can think of \(z_1, z_2, \ldots, z_N\) as &lt;em&gt;new&lt;/em&gt; vectors for the words in the document, updated to include information from pairwise relationships with other words in the document.&lt;/p&gt;

&lt;p&gt;Some important things to notice:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The complexity of intra-attention grows quadratically with the length of the document.
This is no surprise, since it introduces pairwise interactions between words.
There are domain-specific strategies for overcoming the \(O(N^2)\) complexity, like ignoring words past a certain distance in the document.&lt;/li&gt;
  &lt;li&gt;Multiple rounds of intra-attention allow a model to capture higher-order relationships between words, rather than just pairwise relationships.
Intra-attention can be thought of as a form of message passing, similar to that in graph convolutional networks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s straightforward to define a multi-head version of intra-attention.
Do the natural thing—replace the single attention head with a multi-head mechanism, just as in global attention.&lt;/p&gt;

&lt;h1 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h1&gt;

&lt;p&gt;&lt;del&gt;I would have liked to cover transformers, but they’re important enough to warrant their own post.
(Also, I already spent too much time on this post.)&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;Edit 2023-01-23: I’ve started writing a post about transformers. Read it here:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/technical/2023/01/23/transformers-intro.html&quot;&gt;(“A less-bad blog post about transformers”)&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;other-reading&quot;&gt;Other reading&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://lilianweng.github.io/posts/2018-06-24-attention/&quot;&gt;Attention? Attention! (Lilian Weng 2018)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1706.03762&quot;&gt;Attention is All You Need (Vaswani et al. 2017)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1710.10903&quot;&gt;Graph Attention Networks (Velickovic et al 2017)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Explanations organized around AIAYN have certain weaknesses. (1) The AIAYN paper doesn’t seem intended as a beginner’s introduction to attention. Its dense jargon of “keys, values, and queries” is more of a shorthand meant for people who are already familiar with the subject. (2) AIAYN describes a particular application of attention to text data. Its main purpose is to present a particular neural network architecture—the transformer. (3) If you want a broader conceptual understanding of attention mechanisms, then AIAYN will not serve you very well. The blog posts I read didn’t explain how attention generalizes to other data or neural network architectures. The general concept didn’t really &lt;em&gt;click&lt;/em&gt; in my brain until I digested additional papers about &lt;a href=&quot;https://arxiv.org/abs/1710.10903&quot;&gt;attention models for graph data&lt;/a&gt;. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Mon, 02 Jan 2023 05:00:00 +0000</pubDate>
        <link>/technical/2023/01/02/attention-intro.html</link>
        <guid isPermaLink="true">/technical/2023/01/02/attention-intro.html</guid>
        
        <category>machine-learning</category>
        
        <category>deep-learning</category>
        
        
        <category>technical</category>
        
      </item>
    
      <item>
        <title>Fusion confusion</title>
        <description>&lt;p&gt;I’m bothered by some of the media’s breathless, credulous coverage of recent events in fusion research.
People are too excited; they’re forming incorrect conclusions.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.science.org/content/article/historic-explosion-long-sought-fusion-breakthrough&quot;&gt;This article from &lt;em&gt;Science&lt;/em&gt; is one of the better ones I’ve seen on the subject.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are the facts?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;NIF has an inertial confinement reactor that shoots lasers at a pellet of hydrogen fuel; the goal is to ignite a fusion reaction.&lt;/li&gt;
  &lt;li&gt;In a recent NIF experiment, lasers shot ~2 MJ of energy into a fuel pellet. About 3 MJ came out… which is pretty exciting!&lt;/li&gt;
  &lt;li&gt;However, the lasers themselves required &lt;strong&gt;hundreds of MJ&lt;/strong&gt; to operate during that single shot.
So the reactor at NIF is &lt;em&gt;nowhere close&lt;/em&gt; to a self-sustaining fusion reaction.&lt;/li&gt;
  &lt;li&gt;This experiment was the latest in a series of very similar NIF experiments in recent years.
Its success resulted from (a) incremental improvements to the fuel pellet design and (b) increased power for the lasers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What’s bothering me?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The fact that the reaction is &lt;em&gt;not&lt;/em&gt; self-sustaining has not been given enough attention.
A lot of people I talk to seem to have missed that crucial detail. 
I don’t blame those people for missing it.
But I do blame journalists for not giving it more prominence in their coverage.&lt;/li&gt;
  &lt;li&gt;People keep calling this “revolutionary,” or a “breakthrough.” To me it seems more like an exciting—though &lt;strong&gt;incremental&lt;/strong&gt;—improvement in inertial confinement fusion.&lt;/li&gt;
  &lt;li&gt;I’ve heard some people say that this experiment proves a scientific principle.
They say it’s an existence proof that controlled fusion is possible.
However, I don’t think there was any doubt controlled fusion was physically &lt;em&gt;possible&lt;/em&gt;.
The physics was never in question; it has always been fundamentally an engineering problem.
And &lt;em&gt;most&lt;/em&gt; of the engineering challenges remain unsolved.&lt;/li&gt;
  &lt;li&gt;A lot of the excitement seems misplaced given that inertial confinement reactors are unlikely to produce economically viable fusion. 
Most experts consider magnetic confinement devices (e.g., tokamaks or stellarators) much more promising for attaining self-sustaining fusion. 
I doubt the technological lessons learned at NIF will help improve magnetic confinement designs.&lt;/li&gt;
  &lt;li&gt;Some people say public excitement about these advances is a good thing, since it will result in increased funding for fusion research.
That may be true. 
But if we still don’t have commercial fusion reactors in 10 or 20 years, tax-payers and investors may become resentful.
That funding could quickly disappear if people feel that the researchers oversold and underdelivered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I voice these concerns as somebody who is a big fan of fusion research.
I wish it had more funding.
But I think the discussion around recent events—by journalists and politicians—has been confused or dishonest.&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Mon, 19 Dec 2022 05:00:00 +0000</pubDate>
        <link>/news/2022/12/19/fusion-confusion.html</link>
        <guid isPermaLink="true">/news/2022/12/19/fusion-confusion.html</guid>
        
        <category>science</category>
        
        <category>physics</category>
        
        <category>fusion</category>
        
        
        <category>news</category>
        
      </item>
    
      <item>
        <title>Some amateur utility theory about gift-giving</title>
        <description>&lt;p&gt;I remember taking a microeconomics class in college.
It covered standard introductory material about utility theory.
Preferences, utility functions, and constrained optimization.&lt;/p&gt;

&lt;p&gt;At one point the professor made an observation about gift-giving:
that cash is the gift of maximal utility for the receiver.
The reason is simple. 
Cash imposes no constraint on the receiver, so the receiver is free to exchange the cash for whatever maximizes their own utility.&lt;/p&gt;

&lt;p&gt;I was very receptive to this idea.
It made sense to me, since I usually enjoyed receiving cash as a birthday or Christmas present (or gift cards, which are a slightly constrained version of cash).
The insight also gave me some solace as a gift giver: I could justify the lazy choice of cash or gift certificates from &lt;em&gt;very sophisticated&lt;/em&gt; economic principles.&lt;/p&gt;

&lt;p&gt;However, my feelings on cash gifts have changed over the years.
I doubt I’ve arrived at any novel insights—I’m guessing there’s a pile of academic literature on the subject, but I don’t know any of it.
Here are some of my thoughts anyways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nobody truly knows their own utility function.
Even if we assume (a) my utility function exists and (b) it remains constant over my lifetime, the reality is that I will never fully explore it.
Since I’m still young, there are many goods I haven’t experienced yet.
And since life is finite, there are many goods I will never experience.
Many (most?) dimensions of my utility function will remain unknown to me.&lt;/li&gt;
  &lt;li&gt;If someone gives me cash, it enables me to take a utility-increasing step &lt;em&gt;within my known preferences&lt;/em&gt;.
This serves as a useful baseline for gift-giving: can you do better than giving simple cash?&lt;/li&gt;
  &lt;li&gt;The interesting thing—the point my professor made—is that you can &lt;em&gt;not&lt;/em&gt; do better than cash &lt;em&gt;if you confine yourself to the receiver’s known preferences&lt;/em&gt;.
This implies that the only way to beat a cash gift is to provide a good that the receiver is not familiar with.&lt;/li&gt;
  &lt;li&gt;This seems like a tall order.
How do I
    &lt;ol&gt;
      &lt;li&gt;identify the &lt;em&gt;unknown unknowns&lt;/em&gt; in another person’s life; and&lt;/li&gt;
      &lt;li&gt;choose one that they would appreciate?&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;A gift that succeeds at these tasks could be called a &lt;em&gt;thoughtful gift&lt;/em&gt;.
I have known people who are skilled at giving gifts.
I think it is a real skill, and has something to do with competence at tasks 1 and 2.&lt;/li&gt;
  &lt;li&gt;An additional human reality may make it easier to beat cash gifts: people have limited attention and memory.
So there may be preferences that they &lt;em&gt;have&lt;/em&gt; explored in the past, but that they’ve forgotten or lost sight of for whatever reason.
A gift that brings those preferences back to the receiver’s attention could also beat a cash gift.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There you have it: some theories of gift-giving. 
Like most theorists, I’m a lousy practitioner.&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Sun, 18 Dec 2022 05:00:00 +0000</pubDate>
        <link>/misc/2022/12/18/gifts-utility.html</link>
        <guid isPermaLink="true">/misc/2022/12/18/gifts-utility.html</guid>
        
        <category>economics</category>
        
        <category>misc</category>
        
        
        <category>misc</category>
        
      </item>
    
      <item>
        <title>Thinking about startup stock options</title>
        <description>&lt;p&gt;I’ve been reading up on how equity compensation works at biotech startups.&lt;/p&gt;

&lt;p&gt;Some of the more helpful sources I found:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://rapport.bio/all-stories/value-of-equity&quot;&gt;Rapport&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://biobuzz.io/before-you-accept-the-job-understand-the-basics-of-stock-options-and-long-term-incentives/&quot;&gt;BioBuzz&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.reddit.com/r/biotech/comments/m1mezy/startup_equity_offer_vs_number_of_employees_vs/&quot;&gt;Reddit&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Wellfound/AngelList
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://angel.co/blog/9-terms-youll-see-in-your-equity-offer-and-what-they-actually-mean&quot;&gt;This blog post&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://angel.co/salaries&quot;&gt;This interactive tool&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;(I would guess Wellfound’s numbers are more typical of software startups, which are much less capital-intensive than biotechs.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;GPT-3:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/equity-gpt3.jpg&quot; alt=&quot;gpt-3 response&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;With enough reading I was able to arrive at coarse-grained mental model of the decision-landscape presented by equity compensation.&lt;/p&gt;

&lt;p&gt;When I consider working for a startup, I expect to (a) take a somewhat lower salary than I would at a more mature company, in exchange for (b) exposure to potential upside contingent on the company’s success.
The company will probably not succeed; but if it does, then I would hope it yields life-changing wealth.
I would also expect the risk and reward to be higher for employee 10 than for employee 100.&lt;/p&gt;

&lt;p&gt;Suppose a startup offers 10,000 shares of stock options. Some things to think about:&lt;/p&gt;

\[\text{your stake} = \frac{\text{your shares}}{\text{total shares outstanding}}\]

&lt;ul&gt;
  &lt;li&gt;What fraction of the company do those shares represent? Equivalently: what is the total number of shares outstanding?&lt;/li&gt;
  &lt;li&gt;Is the total number of shares likely to increase? If the startup is very young then the answer is “yes—by a lot”. If this is the case, then your fraction will shrink. This is called “dilution.”&lt;/li&gt;
  &lt;li&gt;This fraction of ownership (your “stake”) gives an idea of the potential value of your shares.
    &lt;ul&gt;
      &lt;li&gt;Suppose the 10,000 shares represent 0.1% of the startup. Then imagine all of your dreams come true, and the startup reaches a $1B valuation.&lt;/li&gt;
      &lt;li&gt;In that case, your stake would be worth 0.001 x $1B = $1M. Which is great!&lt;/li&gt;
      &lt;li&gt;However, suppose there is significant dilution. Then the stake would be worth much less than that.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Some other salient things to be aware of:
    &lt;ul&gt;
      &lt;li&gt;Vesting schedule. You will be given the stock options on a gradual basis. And this usually only begins to happen after you’ve been an employee for a whole year.
The typical arrangement is “four year vesting with a one year cliff.” This means you’ll receive 0 options during the first year, and ~3,333 options the following three years (usually on a monthly basis). This schedule ends if you quit or get fired.&lt;/li&gt;
      &lt;li&gt;Liquidity. An early stage startup is usually a private company. It can be very difficult to sell the stock of a private company; you typically can’t sell your stock until the company goes public or gets acquired (in which case the acquiring company may buy out your equity, though it’s not guaranteed).&lt;/li&gt;
      &lt;li&gt;Strike price. It will cost money to exercise your options and get actual stock. For example, suppose we’re back in the dream scenario and the strike price is $1 per share.
Then you would have to pay $10K to obtain all of your stock (which you could then resell for $1M, netting $990K). The strike price may vary over the vesting schedule as the valuation of the company changes.&lt;/li&gt;
      &lt;li&gt;Taxes. You will have to pay taxes (a) when you exercise the options and (b) when you sell the stock. In the dream scenario, you will end up with much less than $990K post-tax.&lt;/li&gt;
      &lt;li&gt;If you quit or get fired, then you will be given a strict time limit to exercise your options—usually no more than 90 days. Otherwise you forfeit your options. This is a difficult situation if the shares are still illiquid! You either pay taxes and the strike price up front for illiquid stocks, waiting with the hope of a liquidity event in the future; or you throw away the options that you earned over years of employment.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the offer is accepted, the value of your stock options is a random quantity that depends on (a) the startup’s success; (b) your employment status in the startup and (c) certain choices you make.
It seemed natural to think of the situation as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Markov_decision_process&quot;&gt;Markov decision process&lt;/a&gt;.
I went through the trouble of sketching it out in Inkscape:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/equity-compensation-mdp.svg&quot; alt=&quot;title text&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You begin at the top of the image. Time flows downward and out, roughly speaking. 
This doesn’t show every possible state or action. My goal was to capture some of the more salient parts of the decision landscape.
Perhaps the most important part of this picture is the large probability of the company failing and the stock price going to zero.&lt;/p&gt;

&lt;p&gt;I should emphasize that compensation is one of many criteria for taking a job.
The other criteria belong in different blog posts, though.&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Wed, 07 Dec 2022 05:00:00 +0000</pubDate>
        <link>/finance/2022/12/07/equity-compensation.html</link>
        <guid isPermaLink="true">/finance/2022/12/07/equity-compensation.html</guid>
        
        <category>finance</category>
        
        <category>stock</category>
        
        <category>options</category>
        
        <category>startups</category>
        
        <category>life-choices</category>
        
        
        <category>finance</category>
        
      </item>
    
      <item>
        <title>A genealogy of probability distributions</title>
        <description>&lt;p&gt;Some of the Wikipedia pages I visit the most belong to probability distributions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Multivariate_normal_distribution]&quot;&gt;Multivariate normal&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Poisson_distribution&quot;&gt;Poisson&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_distribution&quot;&gt;Gamma&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Negative_binomial_distribution&quot;&gt;Negative binomial&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Beta_distribution&quot;&gt;Beta&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My favorite parts of these pages are the “Related distributions” and “Random variate generation” sections.
Those sections describe (i) sometimes-surprising mathematical relationships between probability distributions and (ii) algorithmic strategies for generating samples from them.&lt;/p&gt;

&lt;p&gt;This paints an interesting picture in my head: a family tree of probability distributions.
It’s not actually a tree, but it is a directed graph that suggests some distributions are more ancestor-like while others are more descendant-like.&lt;/p&gt;

&lt;p&gt;I’ve sketched it out in the SVG below.
Making this diagram required many choices regarding (a) which information to include and (b) how to display it in space.
You’re free to disagree with my choices.&lt;/p&gt;

&lt;p&gt;I really wanted to capture some of the &lt;em&gt;generative stories&lt;/em&gt; underlying these distributions.
The diagram contains a combination of exact, approximate, asymptotic, and algorithmic relationships.
Various other relationships are excluded: conjugate priors, for example.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/distribution-genealogy.svg&quot; alt=&quot;title text&quot; width=&quot;600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Try opening the image in a new tab and zooming in for a closer look.&lt;/p&gt;

&lt;p&gt;In this picture, randomness begins with nearly-physical representations of uncertainty: fair coins and urns.
The central limit theorem gives the normal distribution a “sink-like” quality in the directed graph (though Cauchy and some Pareto or t-distributions evade capture).&lt;/p&gt;

&lt;p&gt;The relationship between e.g., Binomial and Poisson—marked “flips \( \rightarrow \infty\)”—glosses over a beautiful mathematical process that I might describe in a future post.&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit 2022-12-15:&lt;/strong&gt; Yesterday I came across &lt;a href=&quot;http://www.math.wm.edu/~leemis/chart/UDR/UDR.html&quot;&gt;Larry Leemis’s website&lt;/a&gt; that does something similar, but in much greater detail. &lt;a href=&quot;http://www.math.wm.edu/~leemis/&quot;&gt;Larry Leemis&lt;/a&gt; is a professor at William and Mary.&lt;/p&gt;

</description>
        <pubDate>Sun, 27 Nov 2022 05:00:00 +0000</pubDate>
        <link>/technical/2022/11/27/distribution-genealogy.html</link>
        <guid isPermaLink="true">/technical/2022/11/27/distribution-genealogy.html</guid>
        
        <category>probability</category>
        
        <category>statistics</category>
        
        
        <category>technical</category>
        
      </item>
    
      <item>
        <title>If you&apos;re not writing, you&apos;re not thinking</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;If you’re not writing, you’re not thinking.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My lazy Google search didn’t immediately yield an attribution for this quote, so I gave up.
I’m pretty sure I first heard it years ago on the Tim Ferriss podcast.&lt;/p&gt;

&lt;p&gt;Similar quotes &lt;em&gt;do&lt;/em&gt; have attributions:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you’re thinking without writing, you only think you’re thinking.&lt;/p&gt;

  &lt;p&gt;—Leslie Lamport&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(The fact that this comes from &lt;a href=&quot;https://en.wikipedia.org/wiki/Leslie_Lamport&quot;&gt;Leslie Lamport&lt;/a&gt; makes me like it more.)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you can’t write clearly, you probably don’t think nearly as well as you think you do.&lt;/p&gt;

  &lt;p&gt;—Kurt Vonnegut&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Regardless of who says it, the concept resonates with my experience.&lt;/p&gt;

&lt;p&gt;Most of my writing doesn’t end up on this website. 
It exists as emails, messages, notes, or journal entries.
In each case writing forces me to confront the ideas, intuitions, and feelings bouncing around in my head and impose order on them.
Literally impose &lt;em&gt;order&lt;/em&gt;, as in, arrange them in a &lt;em&gt;sequence&lt;/em&gt; that has some logic to it.&lt;/p&gt;

&lt;p&gt;It’s a healthy exercise.
Once again, I mean that literally.
Cognitive behavioral therapy is based on the idea that thinking dispassionately about our feelings can help us gain control over them and become more mentally healthy.
I don’t deal with an unusual amount of negative emotion, but I find that when I do a good journaling session helps me process it.
I write down what’s bothering me and the potential causes.
I evaluate their plausibilities and consider solutions.
Writing about problems helps me think clearly about them, which in turn asserts my agency over them.&lt;/p&gt;

&lt;p&gt;Writing’s usefulness translates to my work life as well.
I spend a lot of my time in a problem-solving loop where (1) I’m confronted by some problem, (2) I have to think of possible solutions and (3) I try those solutions and see what happens. 
Writing aids each of these steps.&lt;/p&gt;

&lt;p&gt;I can tell when I’ve gone several days without any thoughtful writing.
My brain feels noticeably more sluggish.
Thoughts, words, and ideas come to me much more slowly.&lt;/p&gt;

&lt;p&gt;TBH the whole reason I’m writing this post is that I haven’t done enough writing recently, and the sluggish feeling was returning.
This has been a good session… Thanks for humoring me!&lt;/p&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Thu, 10 Nov 2022 05:00:00 +0000</pubDate>
        <link>/personal/2022/11/10/writing-thinking.html</link>
        <guid isPermaLink="true">/personal/2022/11/10/writing-thinking.html</guid>
        
        <category>{&quot;comma-separatedstrings&quot;=&gt;nil}</category>
        
        
        <category>personal</category>
        
      </item>
    
      <item>
        <title>Themes from ICML 2022</title>
        <description>&lt;p&gt;I had the fortune of attending &lt;a href=&quot;https://icml.cc/Conferences/2022&quot;&gt;ICML 2022&lt;/a&gt; in Baltimore, MD last week.&lt;/p&gt;

&lt;p&gt;I didn’t present any of my work there—I went because &lt;a href=&quot;https://www.biostat.wisc.edu/~gitter/&quot;&gt;my advisor&lt;/a&gt; was invited to give a talk in the &lt;a href=&quot;http://www.ai4science.net/icml22/&quot;&gt;AI for Science&lt;/a&gt; workshop. 
Tony said I could attend the conference, and I was happy to oblige!&lt;/p&gt;

&lt;p&gt;It was refreshing to go back to a big machine learning conference, post-pandemic.
Apparently ~6,000 people registered for the conference.
They had 10 sessions running in parallel for three days, and two more days of workshops after that.&lt;/p&gt;

&lt;p&gt;It was a deluge of information; I could only catch a small fraction of the content.
I paid attention and &lt;a href=&quot;/notes/icml-notes.html&quot;&gt;took some notes&lt;/a&gt;, though.&lt;/p&gt;

&lt;p&gt;Some themes stood out to me.
I’ll list them here in no particular order:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Biological and chemical applications. The conference had 3 keynote talks, and 2 of them focused on biological applications. There was a computational biology workshop on Friday, and an AI for science workshop on Saturday—biology and chemistry took center stage in the AI for science workshop.&lt;/li&gt;
  &lt;li&gt;Graph neural networks; transformers.
There were several sessions devoted to GNNs and attention mechanisms.&lt;/li&gt;
  &lt;li&gt;Robustness; distributional shift; out-of-distribution (OOD) detection.
There were sessions and workshops devoted to these topics.
I didn’t attend them, but I saw many of their posters.
UW-Madison was well-represented in this area.
&lt;a href=&quot;https://pages.cs.wisc.edu/~sharonli/&quot;&gt;Sharon Li’s group&lt;/a&gt; presented half a dozen or so papers.&lt;/li&gt;
  &lt;li&gt;Self-supervised learning and contrastive learning.
These have become dominant learning paradigms in recent years—the “general purpose self-supervised training followed by application-specific fine tuning” strategy seems to work great for images and natural language.
On a somewhat related note: a surprising number of talks focused on data augmentation.&lt;/li&gt;
  &lt;li&gt;Multi-modal tasks and representations.
Most often learning unified representations from images and natural language.
(I can imagine this extending to, e.g., multiomic data).&lt;/li&gt;
  &lt;li&gt;Certain kinds of mathematical sophistication.
SE(3) layers; invariant and equivariant features.
Connections between ODEs/PDEs and neural networks.
Using neural nets to solve differential equations; using differential equations as a form of prior knowledge; using neural networks to solve ill-posed inverse problems.
These use concepts that I recognize from physics, but haven’t noticed in ML until now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I want to flesh out the first bullet point a bit more; the emphasis on biological and chemical applications.
The two relevant keynotes were given by Regina Barzilay (MIT) and Aviv Regev (Genentech).
Additionally, I’ll mention workshop talks by Daphne Koller (Insitro) and Chris Langmead (Amgen).
All of these talks seemed to emphasize that &lt;em&gt;data is the bottleneck in biological and chemical applications&lt;/em&gt;. 
Several of them seemed to propose closed loops between ML models and laboratories—an active learning framework.&lt;/p&gt;

&lt;p&gt;I won’t claim that these themes give an objective picture of ICML.
Think of it as an opinionated summary.
I’d be interested to hear other people’s observations.&lt;/p&gt;

&lt;!-- Internal link
[Link to asset](/assets/myfile.pdf)
--&gt;

&lt;!-- Include an image
![title text](/assets/images/your-image.jpg){:height=&quot;200px&quot; :width=&quot;300px&quot;} 
--&gt;

&lt;p&gt;\( \blacksquare\)&lt;/p&gt;

</description>
        <pubDate>Tue, 26 Jul 2022 05:00:00 +0000</pubDate>
        <link>/personal/2022/07/26/icml-themes.html</link>
        <guid isPermaLink="true">/personal/2022/07/26/icml-themes.html</guid>
        
        <category>machine-learning</category>
        
        <category>conference</category>
        
        <category>ml</category>
        
        <category>ai</category>
        
        
        <category>personal</category>
        
      </item>
    
  </channel>
</rss>
