<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.5">Jekyll</generator><link href="https://jdiwa.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jdiwa.github.io/" rel="alternate" type="text/html" /><updated>2024-07-22T17:51:42+00:00</updated><id>https://jdiwa.github.io/feed.xml</id><title type="html">Jason Noah Diwa</title><subtitle>Jason Noah Diwa's personal website.</subtitle><author><name>Jason Noah Diwa</name></author><entry><title type="html">Neural Network</title><link href="https://jdiwa.github.io/project/neural-network/" rel="alternate" type="text/html" title="Neural Network" /><published>2023-10-18T04:00:00+00:00</published><updated>2023-10-18T04:00:00+00:00</updated><id>https://jdiwa.github.io/project/neural-network</id><content type="html" xml:base="https://jdiwa.github.io/project/neural-network/"><![CDATA[<p>In this project from UC Berkeley’s CS189 (Introduction to Machine Learning), I built a neural network from the ground up. I first a base-level understanding of the math (and biology) behind how neural networks operate and then building increasingly complex models.</p>

<p>Neural networks, like brains, are made up of small constituent units called neurons. These neurons build connections that allow them to communicate with each other; this process . In the human brain, these connections are called synapses, while in the neural network they are represented by a constantly shifting array of weights where each value in the array corresponds to a synapse. In order to “learn”, like all machine learning models, a neural network relies on optimizing a constraint called loss – the less loss, the better your model performs. In order to reduce loss, we do a “forward pass” where training data is passed into the neural network. The network makes its predictions take the gradient (essentially a derivative) of the loss function and adjust our model accordingly, repeating this process over and over to train the neural network. However, this process might need to happen hundreds or thousands of times before our model becomes sufficiently predictive.</p>

<p>In order to reduce this high computational workload, neural networks use a mathematical technique called backpropagation:</p>

<table>
  <thead>
    <tr>
      <th style="text-align: center"><img src="/assets/images/posts/neural-network/derivation.png" alt="Math" /></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: center"><em>Similar to the chain rule from calculus, we can optimize this process by taking the gradient of each layer’s input with respect to its output and “backpropagate” by starting at the last layer and working backwards, caching and reusing our results as we go.</em></td>
    </tr>
  </tbody>
</table>

<p>To further optimize the process, we can take advantage of parallelism by “batching” training points (each of which is represented by a vector) and performing operations on mini-batches (each of which is represented by a matrix) instead of individual training points:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">backward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dLdY</span><span class="p">:</span> <span class="n">np</span><span class="p">.</span><span class="n">ndarray</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="p">.</span><span class="n">ndarray</span><span class="p">:</span>
        <span class="s">"""Backward pass for fully connected layer.
        Parameters
        ----------
        dLdY  derivative of the loss with respect to the output of this layer
              shape (batch_size, output_dim)

        Returns
        -------
        derivative of the loss with respect to the input of this layer
        shape (batch_size, input_dim)
        """</span>

        <span class="c1"># unpack the cache
</span>        <span class="n">X</span> <span class="o">=</span> <span class="bp">self</span><span class="p">.</span><span class="n">cache</span><span class="p">[</span><span class="s">"X"</span><span class="p">]</span>
        <span class="n">Z</span> <span class="o">=</span> <span class="bp">self</span><span class="p">.</span><span class="n">cache</span><span class="p">[</span><span class="s">"Z"</span><span class="p">]</span>
        
        <span class="c1"># compute the gradients of the loss w.r.t. all parameters as well as the
</span>        <span class="c1"># input of the layer
</span>
        <span class="n">dLdZ</span> <span class="o">=</span> <span class="bp">self</span><span class="p">.</span><span class="n">activation</span><span class="p">.</span><span class="n">backward</span><span class="p">(</span><span class="n">Z</span><span class="p">,</span> <span class="n">dLdY</span><span class="p">)</span>

        <span class="n">dX</span> <span class="o">=</span> <span class="n">dLdZ</span> <span class="o">@</span> <span class="bp">self</span><span class="p">.</span><span class="n">parameters</span><span class="p">[</span><span class="s">"W"</span><span class="p">].</span><span class="n">T</span>
        <span class="n">dW</span> <span class="o">=</span> <span class="n">X</span><span class="p">.</span><span class="n">T</span> <span class="o">@</span> <span class="n">dLdZ</span>
        <span class="n">dB</span> <span class="o">=</span> <span class="n">np</span><span class="p">.</span><span class="nb">sum</span><span class="p">(</span><span class="n">dLdZ</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

        <span class="c1"># store the gradients in `self.gradients`
</span>        <span class="c1"># the gradient for self.parameters["W"] should be stored in
</span>        <span class="c1"># self.gradients["W"], etc.
</span>        <span class="bp">self</span><span class="p">.</span><span class="n">gradients</span><span class="p">[</span><span class="s">"W"</span><span class="p">]</span> <span class="o">=</span> <span class="n">dW</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">gradients</span><span class="p">[</span><span class="s">"b"</span><span class="p">]</span> <span class="o">=</span> <span class="n">dB</span>

        <span class="k">return</span> <span class="n">dX</span>
</code></pre></div></div>]]></content><author><name>Jason Noah Diwa</name></author><category term="Project" /><category term="Machine Learning" /><category term="Python" /><category term="PyTorch" /><summary type="html"><![CDATA[In this project from UC Berkeley’s CS189 (Introduction to Machine Learning), I built a neural network from the ground up. I first a base-level understanding of the math (and biology) behind how neural networks operate and then building increasingly complex models.]]></summary></entry><entry><title type="html">Nutstradamus - Arcade Game</title><link href="https://jdiwa.github.io/project/nutstradamus/" rel="alternate" type="text/html" title="Nutstradamus - Arcade Game" /><published>2023-10-14T04:00:00+00:00</published><updated>2023-10-14T04:00:00+00:00</updated><id>https://jdiwa.github.io/project/nutstradamus</id><content type="html" xml:base="https://jdiwa.github.io/project/nutstradamus/"><![CDATA[<p>For our final project in UC Berkeley’s CS61B (Data Structures and Algorithms), my friend Evan Pfeifer and I were tasked with building an arcade game essentially from scratch using Java. We were given a free hand for the design and implementation components and provided with only an engine to render tiles.</p>

<p><img src="/assets/images/arcade_map.png" alt="Map" /></p>

<p>In our game, you play as Nutstradamus, a squirrel philosopher who must collect enough acorns to reach enlightenment. However, he must evade a pack of hungry dogs who relentlessly track him down; if you are caught by the dogs before collecting all the acorns, you fail to reach enlightenment and lose the game.</p>]]></content><author><name>Jason Noah Diwa</name></author><category term="Project" /><category term="SWE" /><category term="Design" /><category term="Java" /><summary type="html"><![CDATA[For our final project in UC Berkeley’s CS61B (Data Structures and Algorithms), my friend Evan Pfeifer and I were tasked with building an arcade game essentially from scratch using Java. We were given a free hand for the design and implementation components and provided with only an engine to render tiles.]]></summary></entry><entry><title type="html">Teaching Bitches How To Swim: Death Grips’ “Hacker” and the Age of Digital Conformity</title><link href="https://jdiwa.github.io/article/dg-article/" rel="alternate" type="text/html" title="Teaching Bitches How To Swim: Death Grips’ “Hacker” and the Age of Digital Conformity" /><published>2022-11-03T04:00:00+00:00</published><updated>2022-11-03T04:00:00+00:00</updated><id>https://jdiwa.github.io/article/dg-article</id><content type="html" xml:base="https://jdiwa.github.io/article/dg-article/"><![CDATA[<p>The year is 1979. The US Pioneer 11 space probe has just passed Saturn and the Knack’s “My Sharona” sits comfortably atop the Billboard charts. A little-known trio from Englewood, New Jersey who call themselves The Sugarhill Gang are about to release their new single, based on a freestyle they performed over the instrumental from Chic’s “Good Times”; they decide to title it “Rapper’s Delight”. This is the birth of hip hop.</p>

<p>Hip hop’s roots are firmly embedded in counterculture. Hip hop gained traction early on by serving as a loudspeaker that downtrodden Black Americans could use to amplify their voices and speak out against overwhelming systemic repression. The outright aggression of early acts like N.W.A. and Public Enemy stood in stark contrast to the synth-heavy, dancy sounds of contemporary pop as they spoke truth to power on cuts like “Fuck Tha Police” and “Black Steel in The Hour of Chaos”. As a result, hip hop was and often still is demonized by political commentators who speculate that hip hop “has done more damage to young African Americans than racism in recent years” as well as old-head music fans who opine that it lacks respectability and decry hip hop artists as talentless hacks.</p>

<iframe width="420" height="315" src="https://www.youtube.com/watch?v=SqES8vQE-ZA" frameborder="0" allowfullscreen=""></iframe>

<p>Fast forward to today. Hip hop is the soundtrack to soda commercials featuring pro athletes; Travis Scott has his own McDonalds meal; high schoolers put their raps on Soundcloud, hoping to hit it big; fans congregate in enormous numbers across social media to discuss their rabid anticipation for release dates and drop hot takes. Hip hop has well and truly taken over the mainstream, and its sound has shifted accordingly: the advent of digital tools fundamentally changed hip hop’s approach to production, as early regional styles like boom bap and G-funk gave way to sample-heavy bling era opulence and eventually bombastic trap music with its trademark adlibs and heavy snares. However, as hip hop gained cultural acceptance, it also lost its edge: even though rappers continued telling real stories about gang warfare and life on the streets, their music was readily co-opted by mainstream culture in spite of its subject matter because of its catchy hooks and danceable rhythms. As Andrew Callaghan, one of the original man-on-the-street interview trendsetters and host of Channel 5 puts it, “before you knew it, white America was doing the hokey pokey to murder music”. Hip hop’s seriousness was undercut by the accessible appeal of the proverbial banger, and sociopolitical messaging gave way to the proven songwriting formulas and consistent output of mainstream hip hop’s hit machines like Drake or Migos. However, many modern hip hop artists are still focused on innovation and search for creative ways to use digital tools to create entirely new sounds. The advent of technology has changed the world we live in drastically in the 43 years since the Sugarhill Gang dropped “Rapper’s Delight”, with ever more sinister forms of digital repression alongside exciting new forms of musical expression. Experimental hip hop is one of the newest forms of musical counterculture, and the artist who might best exemplify the genre is Death Grips.</p>

<table>
  <thead>
    <tr>
      <th style="text-align: center"><img src="/assets/images/posts/dg-article/death-grips.jpg" alt="death grips" /></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: center"><em>Death Grips performing. Photo credit: Josh Druding</em></td>
    </tr>
  </tbody>
</table>

<p>Death Grips is anything but mainstream. Among other things, they were dropped from their Epic label deal for leaking their own album (where the cover art was the drummer’s erect penis) over a release date dispute. They are unapologetically and unequivocally confrontational and their music reflects that fact: it is intentionally abrasive, seemingly assembled slipshod from clashing, discordant tones and off-kilter, layered samples. However, their complete disregard for hip hop trends and tendency towards noise, distortion, and open hostility has made them new-age hip hop counterculture icons. “Hacker”, the closing track to their magnum opus The Money Store, is Death Grips’ special form of satire and social critique at its most effective. MC Ride plays the part of a dispassionate hacker, performing digital-age smash-and-grabs behind the anonymity of a computer screen. The chanted chorus reminds the listener that they live under constant threat; regardless of his physical location, the eponymous hacker knows the “first three numbers” of your area code are only a few keystrokes away, and he can be “in your area” anytime and anywhere. The combination of Ride’s uniquely impassioned, shouty delivery and driving, anxious synths adds desperation and urgency to every line, even though his cryptic lyrics are largely inscrutable. Throughout the song, Ride name drops the Apple Store, Lady Gaga and Wikileaks alongside a constant stream of technological jargon and veiled threats of digital violence – “Neo-reality”, “you’ll catch a jpeg to the head”. This esoteric diction interspersed with the occasional pop culture reference works in tandem with Flatlander’s shifting, glitchy production to replicate the information overload we feel on a daily basis, a side effect of the 24-hour news cycle and being permanently online: all meaning is lost in the nonstop verbal barrage and the listener is left confused and disoriented.  “Hacker” depicts the absurdity and paranoia of the modern age from the perspective of an outsider lurking in the shadows: even at ten years of age, Death Grips’ scorching diatribe against an encroaching digital dystopia still resonates deeply with the world we live in today.</p>]]></content><author><name>Jason Noah Diwa</name></author><category term="Article" /><category term="Hip Hop" /><category term="Thinkpiece" /><summary type="html"><![CDATA[The year is 1979. The US Pioneer 11 space probe has just passed Saturn and the Knack’s “My Sharona” sits comfortably atop the Billboard charts. A little-known trio from Englewood, New Jersey who call themselves The Sugarhill Gang are about to release their new single, based on a freestyle they performed over the instrumental from Chic’s “Good Times”; they decide to title it “Rapper’s Delight”. This is the birth of hip hop.]]></summary></entry></feed>