-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
474 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
env | ||
pages/.obsidian/ | ||
# pages/temp/ | ||
not_so_eff.py | ||
static/404_error.jpg | ||
templates/new.html | ||
templates/new.html | ||
gradients.txt | ||
__pycache__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import numpy as np | ||
|
||
X1 = np.array([0, 0, 1, 1]) | ||
|
||
X2 = np.array([0, 1, 0, 1]) | ||
|
||
Y = np.array([0, 1, 1, 0]) | ||
|
||
np.random.seed(42) | ||
|
||
# Weight Initialization | ||
|
||
W11 = np.random.randn() | ||
|
||
W21 = np.random.randn() | ||
|
||
B1 = np.random.randn() | ||
|
||
W12 = np.random.randn() | ||
|
||
W22 = np.random.randn() | ||
|
||
B2 = np.random.randn() | ||
|
||
W1_out = np.random.randn() | ||
|
||
W2_out = np.random.randn() | ||
|
||
B_out = np.random.randn() | ||
|
||
learning_rate = 0.5 | ||
|
||
def sigmoid(x): | ||
|
||
return 1 / (1 + np.exp(-x)) | ||
|
||
def forward_propagation(X1, X2): | ||
|
||
|
||
|
||
|
||
|
||
H1_input = (X1 * W11) + (X2 * W21) + B1 | ||
|
||
H1_output = sigmoid(H1_input) | ||
|
||
H2_input = (X1 * W12) + (X2 * W22) + B2 | ||
|
||
H2_output = sigmoid(H2_input) | ||
|
||
Y_pred_input = (H1_output * W1_out) + (H2_output * W2_out) + B_out | ||
|
||
Y_pred = sigmoid(Y_pred_input) | ||
|
||
return Y_pred, H1_output, H2_output | ||
|
||
def error_func(Y, Y_pred): | ||
|
||
return (1/2) * np.sum((Y - Y_pred) ** 2) | ||
|
||
def back_propagation(X1, X2, Y_pred, Y, H1_output, H2_output): | ||
|
||
global W11, W21, B1, W12, W22, B2, W1_out, W2_out, B_out | ||
|
||
dY_pred = (Y_pred - Y) * Y_pred * (1 - Y_pred) | ||
|
||
dW1_out = np.sum(H1_output * dY_pred) | ||
|
||
dW2_out = np.sum(H2_output * dY_pred) | ||
|
||
dB_out = np.sum(dY_pred) | ||
|
||
dH2_output = dY_pred * W2_out | ||
|
||
dH2_input = dH2_output * H2_output * (1 - H2_output) | ||
|
||
dW12 = np.sum(X1 * dH2_input) | ||
|
||
dW22 = np.sum(X2 * dH2_input) | ||
|
||
dB2 = np.sum(dH2_input) | ||
|
||
dH1_output = dY_pred * W1_out | ||
|
||
dH1_input = dH1_output * H1_output * (1 - H1_output) | ||
|
||
dW11 = np.sum(X1 * dH1_input) | ||
|
||
dW21 = np.sum(X2 * dH1_input) | ||
|
||
dB1 = np.sum(dH1_input) | ||
|
||
W11 -= learning_rate * dW11 | ||
|
||
W21 -= learning_rate * dW21 | ||
|
||
B1 -= learning_rate * dB1 | ||
|
||
W12 -= learning_rate * dW12 | ||
|
||
W22 -= learning_rate * dW22 | ||
|
||
B2 -= learning_rate * dB2 | ||
|
||
W1_out -= learning_rate * dW1_out | ||
|
||
|
||
|
||
|
||
|
||
W2_out -= learning_rate * dW2_out | ||
|
||
B_out -= learning_rate * dB_out | ||
|
||
for epoch in range(2000): | ||
|
||
Y_pred, H1_output, H2_output = forward_propagation(X1, X2) | ||
|
||
if np.all(np.round(Y_pred) == Y): | ||
|
||
print("Weights are:\n") | ||
|
||
print("Hidden Layer 1: W11 =", W11, " W21 =", W21, " B1 =", B1) | ||
|
||
print("Hidden Layer 2: W12 =", W12, " W22 =", W22, " B2 =", B2) | ||
|
||
print("Output Layer: W1_out =", W1_out, " W2_out =", W2_out, " B_out =", B_out) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="../static/style.css" /> | ||
<link rel="stylesheet" href="../static/default.css" /> | ||
<link | ||
href="https://fonts.googleapis.com/css?family=Fira Code" | ||
rel="stylesheet" | ||
/> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Dosis:wght@300&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Barlow:wght@200;400&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@300&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Jost:ital,wght@0,100..900;1,100..900&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
href="https://iosevka-webfonts.github.io/iosevka/iosevka.css" | ||
rel="stylesheet" | ||
/> | ||
<title></title> | ||
</head> | ||
<body> | ||
<header> | ||
<!-- <a href="/" class="logo">Surya Narayan</a> --> | ||
<a href="/" | ||
><img alt="icon_image" class="logo" src="/static/icon.svg" width="30" | ||
/></a> | ||
<nav class="nav_links"> | ||
<ul> | ||
<li><a href="/blog">blog</a></li> | ||
<li><a href="/about">about</a></li> | ||
</ul> | ||
</nav> | ||
</header> | ||
|
||
|
||
<p class=post_date>1 Apr, 2024</p> | ||
<h1>Testing</h1> | ||
<h2 class="subtitle">None</h2> | ||
<h4 id="sample-title">Sample title</h4> | ||
|
||
<blockquote> | ||
<p>sample text</p> | ||
</blockquote> | ||
|
||
<ul> | ||
<li>sample code block below</li> | ||
</ul> | ||
|
||
<div class="codehilite"><pre><span></span><code><span class="c1"># code </span> | ||
<span class="n">Hello</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> | ||
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Hello World </span><span class="si">{</span><span class="n">Hello</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> | ||
</code></pre></div> | ||
|
||
<footer> | ||
<section class="footer"> | ||
<a href="/blog/feed.xml"> | ||
<img alt="rss feed" src="/static/rss.svg" width="30" /> | ||
</a> | ||
<a href="https://github.com/Surya-29"> | ||
<img alt="git" src="/static/github.svg" width="35" /> | ||
</a> | ||
</section> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,15 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<feed xmlns="http://www.w3.org/2005/Atom"><id>http://127.0.0.1:5000/</id><title>Itnaava</title><updated>2022-09-17T06:48:41.078155+00:00</updated><author><name>Surya</name><email>[email protected]</email></author><link href="http://127.0.0.1:5000/" rel="alternate"/><generator uri="https://lkiesow.github.io/python-feedgen" version="0.9.0">python-feedgen</generator><entry><id>nn_scratch</id><title>Neural Networks from scratch</title><updated>2022-09-17T06:48:41.160785+00:00</updated><link href="http://127.0.0.1:8000/blog/nn_scratch" rel="alternate"/><summary type="html"><h2 id="introduction">Introduction</h2></summary></entry><entry><id>music_gen</id><title>Music Generation</title><updated>2022-09-17T06:48:41.078155+00:00</updated><link href="http://127.0.0.1:8000/blog/music_gen" rel="alternate"/><summary type="html"><h4 id="project-title">Project Title</h4> | ||
<feed xmlns="http://www.w3.org/2005/Atom"><id>http://127.0.0.1:5000/</id><title>Surya Narayan</title><updated>2024-04-01T09:47:46.487438+00:00</updated><author><name>Surya</name><email>[email protected]</email></author><link href="http://127.0.0.1:5000/" rel="alternate"/><generator uri="https://lkiesow.github.io/python-feedgen" version="0.9.0">python-feedgen</generator><entry><id>Temp blog</id><title>Testing</title><updated>2024-04-01T09:47:46.487438+00:00</updated><link href="http://127.0.0.1:8000/blog/Temp blog" rel="alternate"/><summary type="html"><h4 id="sample-title">Sample title</h4> | ||
|
||
<p>Composition of music by training a model on sheet music.</p> | ||
|
||
<h4 id="project-members">Project Members</h4> | ||
|
||
<ul> | ||
<li>Surya Narayan AI&amp;DS B</li> | ||
</ul> | ||
|
||
<h4 id="abstract">Abstract</h4> | ||
|
||
<p>Our goal is to compose music (more like short piece of music) by training various deep learning models on a specific instrument's MIDI dataset.We will be looking into both RNN(principally LSTM networks) based and NLP based model as a music generation system,but our primary focus will be more on the latter.</p> | ||
|
||
<h4 id="introduction">Introduction</h4> | ||
|
||
<p>The art of ordering tones or sound in succession, in combination is music. It is a temporal relationship to produce a composition of notes having continuity and unity.Predicting the likely next few notes can be thought of as a time series problem due to the presence of long-term structural patterns in the music sequence.Also due to its sequential nature ,we can also consider this as an NLP problem.</p> | ||
|
||
<p>Techniques like Recurrent Neural Networks (RNN's) can be used ,which incorporates dependencies across time. Long Short Term Memory is one such variant of RNN, that is capable of capturing long-term temporal dependencies in the given music dataset and it might be a great fit for generating music.</p> | ||
|
||
<p>Transformer archietecture looks really promising not only for NLP problems but also for music generation since it is faster and have really good memory so extracting long-term structural patterns wouldn't be a problem. </p> | ||
|
||
<h4 id="preprocessing-of-musical-instrument-digital-interface-midi-files"><strong>Preprocessing of musical instrument digital interface (MIDI) Files</strong></h4> | ||
|
||
<p>Using the <a href='https://magenta.tensorflow.org/datasets/'>instrument dataset</a> (i.e.,represented as an MIDI files) we have to extract the features required. Python libraries like music21,python-midi,etc,. can be used to perform the necessary operations.MIDI files plays an important role in extracting information about note sequence, note velocity and the time component.</p> | ||
|
||
<h4 id="model-training"><strong>Model Training</strong></h4> | ||
<blockquote> | ||
<p>sample text</p> | ||
</blockquote> | ||
|
||
<ul> | ||
<li><p><u>RNN based approach</u>:</p> | ||
|
||
<p>Long Term Short Memory (LSTM),special type of RNN variant will be used.Since traditional RNN based models will not be able to retain information for long periods of time.</p> | ||
|
||
<p>Image from <a href='https://towardsdatascience.com/neural-networks-for-music-generation-97c983b50204?gi=57ecd2161d78'>article</a> </p> | ||
|
||
<p><a href="https://arxiv.org/pdf/1909.09586.pdf">Link</a>:Brief on LSTM architecture and function. </p></li> | ||
<li><p><u>Language models based approach</u></p> | ||
|
||
<p>GPT is an architecture based on Transformers decoders stacked together.The Transformer is a sequence model that leverage self-attention and that already had impressive results for generation tasks involving long-range dependencies. </p> | ||
|
||
<p>It is essentially the vanilla Transformer model with its encoder block and cross-attention mechanism stripped away — so that it can perform more efficiently on unsupervised tasks. This makes it well suited for music representation.</p> | ||
|
||
<p>Source from <a href='https://towardsdatascience.com/neural-networks-for-music-generation-97c983b50204?gi=57ecd2161d78'>article</a> </p> | ||
|
||
<p>Image form <a href='https://towardsdatascience.com/creating-a-pop-music-generator-with-the-transformer-5867511b382a?gi=d1154441bcd7'>article</a></p> | ||
|
||
<p>Apart from GPT language <code>model</code> we will also try to implement this approach on various other language models like BERT,GPT-2,etc,. </p></li> | ||
<li>sample code block below</li> | ||
</ul> | ||
|
||
<div class="codehilite"><pre><span></span><code><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/blog&quot;</span><span class="p">)</span> | ||
<span class="k">def</span> <span class="nf">blog_page</span><span class="p">():</span> | ||
<span class="k">global</span> <span class="n">d</span><span class="p">;</span> | ||
<span class="n">dir_lis</span> <span class="o">=</span> <span class="n">list_dir</span><span class="p">(</span><span class="s1">&#39;pages/blog&#39;</span><span class="p">)</span> | ||
<span class="n">d</span> <span class="o">=</span> <span class="p">{}</span> | ||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">dir_lis</span><span class="p">:</span> | ||
<span class="n">temp</span><span class="p">,</span><span class="n">article_info</span> <span class="o">=</span> <span class="n">md_to_html</span><span class="p">(</span><span class="s2">&quot;pages/blog/&quot;</span><span class="o">+</span><span class="n">i</span><span class="p">)</span> | ||
<span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">+</span><span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;slug&#39;</span><span class="p">]</span> | ||
<span class="k">if</span> <span class="n">i</span><span class="p">[:</span><span class="o">-</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;slug&#39;</span><span class="p">]:</span> | ||
<span class="n">d</span><span class="p">[</span><span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;title&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[</span> | ||
<span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]]</span><span class="o">+</span><span class="p">[</span><span class="n">article_info</span><span class="p">[</span><span class="s1">&#39;url&#39;</span><span class="p">]]</span> | ||
<span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;blog.html&#39;</span><span class="p">,</span> <span class="n">file_dict</span><span class="o">=</span><span class="n">d</span><span class="p">)</span> | ||
</code></pre></div> | ||
|
||
<h4 id="references">References</h4> | ||
|
||
<ul> | ||
<li><p><strong>Dataset</strong> :</p> | ||
|
||
<ul> | ||
<li><a href="https://magenta.tensorflow.org/datasets/groove">https://magenta.tensorflow.org/datasets/groove</a></li> | ||
<li><a href="https://magenta.tensorflow.org/datasets/maestro">https://magenta.tensorflow.org/datasets/maestro</a></li> | ||
<li><a href="https://magenta.tensorflow.org/datasets/nsynth">https://magenta.tensorflow.org/datasets/nsynth</a></li> | ||
</ul></li> | ||
<li><p><strong>Articles and Research Papers :</strong></p> | ||
|
||
<ul> | ||
<li><a href="https://towardsdatascience.com/creating-a-pop-music-generator-with-the-transformer-5867511b382a?gi=d1154441bcd7">https://towardsdatascience.com/creating-a-pop-music-generator-with-the-transformer-5867511b382a?gi=d1154441bcd7</a></li> | ||
<li>RNN Architecture : <a href="https://karpathy.github.io/2015/05/21/rnn-effectiveness/">https://karpathy.github.io/2015/05/21/rnn-effectiveness/</a></li> | ||
<li><a href="https://arxiv.org/ftp/arxiv/papers/1908/1908.01080.pdf">https://arxiv.org/ftp/arxiv/papers/1908/1908.01080.pdf</a></li> | ||
<li><a href="https://medium.com/artists-and-machine-intelligence/neural-nets-for-generating-music-f46dffac21c0">https://medium.com/artists-and-machine-intelligence/neural-nets-for-generating-music-f46dffac21c0</a></li> | ||
<li>Detailed working on LSTM networks : <a href="http://www.bioinf.jku.at/publications/older/2604.pdf">http://www.bioinf.jku.at/publications/older/2604.pdf</a></li> | ||
<li>Transformer Architecture : <a href="https://jalammar.github.io/illustrated-transformer/">https://jalammar.github.io/illustrated-transformer/</a></li> | ||
<li>Research articles by magenta : <a href="https://magenta.tensorflow.org/research/">https://magenta.tensorflow.org/research/</a></li> | ||
</ul></li> | ||
</ul></summary></entry></feed> | ||
<div class="codehilite"><pre><span></span><code><span class="c1"># code </span> | ||
<span class="n">Hello</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> | ||
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Hello World </span><span class="si">{</span><span class="n">Hello</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span> | ||
</code></pre></div></summary></entry></feed> |
Oops, something went wrong.