<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aladdin Persson on Medium]]></title>
        <description><![CDATA[Stories by Aladdin Persson on Medium]]></description>
        <link>https://medium.com/@aladdinpersson?source=rss-66cfbb5f28e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BBIa1Z1nmHXo4v4bq2p55g.jpeg</url>
            <title>Stories by Aladdin Persson on Medium</title>
            <link>https://medium.com/@aladdinpersson?source=rss-66cfbb5f28e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:50:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aladdinpersson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Is Machine Learning by Andrew Ng on Coursera worth it in 2021? [Course Review]]]></title>
            <link>https://aladdinpersson.medium.com/is-machine-learning-by-andrew-ng-on-coursera-worth-it-in-2021-course-review-b4d8348dbcdc?source=rss-66cfbb5f28e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4d8348dbcdc</guid>
            <category><![CDATA[machine-learning-andrew]]></category>
            <category><![CDATA[machine-learning-stanford]]></category>
            <category><![CDATA[machine-learning-course]]></category>
            <category><![CDATA[coursera-machine-learning]]></category>
            <dc:creator><![CDATA[Aladdin Persson]]></dc:creator>
            <pubDate>Sat, 30 Jan 2021 11:40:51 GMT</pubDate>
            <atom:updated>2021-01-30T14:28:29.313Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLMja0isVs3E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLMja0isVs3E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLMja0isVs3E%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/879f8aa2d24cd249349e033f600bce00/href">https://medium.com/media/879f8aa2d24cd249349e033f600bce00/href</a></iframe><p>The infamous machine learning course by Andrew Ng has been the introduction to the machine learning field for so many people. This year it will be 10 years old. I took this course approximately three years ago, and recently took a look at it again and thought I could share my thoughts on if it is worth your time in 2021. I should start by saying that the course is completely free and it only costs money if you want to buy a certificate. <a href="https://bit.ly/2EPoPwV">Here</a> is a link to the course.</p><p><strong><em>TLDR:</em></strong><em> Yes it’s still worth it in 2021. I still rate it 5/5.</em></p><p>Let me go into a bit more depth of the course. First let us talk about who the course is aimed for, what the structure of the course is like, what you will learn and lastly mention some of the cons of the course.</p><h3>Who it’s aimed for</h3><p>The course is mainly directed towards people who are complete beginners in machine learning (ML). So if you’re curious and interested in getting into ML this is absolutely the course for you! Andrew Ng (the teacher of the course) makes very few assumptions on your previous mathematical ability and concretely I think you need high school math and you’re pretty much good to go. It turns out that a lot of people have done and understood most parts of the course without any university level math, but if you have taken a calculus or linear algebra (or watched 3Blue1Brown) the course might be a bit easier for you and you’ll have better intuitions.</p><h3>The course structure</h3><p>The structure of the course is pretty standard with video lectures, quizzes and programming assignments. I think one thing that is also really great is that there are pop up questions during the lectures which makes you think about the material and I felt it improved my retention. Generally I would say the lectures are easy to follow. I feel Andrew really is on the of best teachers I have ever come across, and I think you will too. Personally I felt the programming assignments were the ones that could be challenging. For a typical week he would go through some machine learning algorithm or concept like linear regression and in the subsequent assignment you get instructions on how to implement it in code. The assignments are in the MatLab/Octave (either of the two) programming language which in an ideal would be in Python and NumPy but more on the cons later. I really don’t think this is a big issue honestly and still <strong>highly</strong> recommend the course. Just trust me, the time you waste learning about the language is going to be very minimal.</p><h3>What you will learn</h3><p>I guess going into too much detail of what you will learn wouldn’t be too interesting because you probably don’t know what any of the words mean yet. Let’s do it anyways, lol. After you have completed the course you won’t be some machine learning master who knows how to solve all of humanity’s problems. However you will be someone who has a solid foundation to ML and a good understanding of many common algorithms like linear regression, logistic regression, neural networks, support vector machines, principal component analysis but additionally you will know very important concepts like supervised vs unsupervised learning, gradient descent, overfitting, cost functions, regularization, backpropogation, bias vs variance, and much more. Yeah sorry if none of that made sense, all you have to know is that you’ll be at least 50% more badass by knowing these topics, in my opinion. Not sure if that says more about me than the course, anyways let’s move on to the final part of the review.</p><h3>Cons of the course</h3><p>Finding flaws in this course is basically NP-Complete, meaning the following analysis took a lot of compute. Personally I’d say the biggest cons are these:</p><ul><li>Relatively bad video and audio quality (yes I am being picky)</li><li>Programming assignments in MatLab or Octave, should preferably be in Python (<strong>this is the biggest con imo</strong>)</li><li>The Neural Network part is slightly outdated (but not to the point of being a waste of time).</li></ul><p>And that’s it for this course review, if you do decide to take it do let me know what you think of it! Also if you do decide to buy a fancy certificate which you could share on Linkedin etc (I didn’t) then please use the link at the top which gives me a referral fee, or don’t, it’s completely up to you :) <a href="https://www.coursera.org/learn/machine-learning">Here</a> is a link to the course with no referral.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4d8348dbcdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get a progress bar in PyTorch]]></title>
            <link>https://aladdinpersson.medium.com/how-to-get-a-progress-bar-in-pytorch-72bdbf19b35c?source=rss-66cfbb5f28e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/72bdbf19b35c</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[pytorch-progress-bar]]></category>
            <dc:creator><![CDATA[Aladdin Persson]]></dc:creator>
            <pubDate>Fri, 29 Jan 2021 19:12:23 GMT</pubDate>
            <atom:updated>2021-01-30T10:14:58.009Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRKHopFfbPao%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRKHopFfbPao&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRKHopFfbPao%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ccc936361c3cedcb7979c687d00f60e/href">https://medium.com/media/4ccc936361c3cedcb7979c687d00f60e/href</a></iframe><p>Let us start with the basic imports where we will be using tqdm for our progress bar:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbf64c3f1ece062af3a40cb49c68fe9e/href">https://medium.com/media/fbf64c3f1ece062af3a40cb49c68fe9e/href</a></iframe><p>Let’s create a simple toy dataset example using <strong>TensorDataset</strong> that we imported above. This is just to make a simple example, so for our dataset we will just generate random numbers. Replace the cell below loading the dataset (doesn’t matter which) of your choice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c8a77eeee804cc4b45d65948549804a/href">https://medium.com/media/6c8a77eeee804cc4b45d65948549804a/href</a></iframe><p>Let’s create a very simple model and training loops:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe1ab917ec7533bad180e1af05854900/href">https://medium.com/media/fe1ab917ec7533bad180e1af05854900/href</a></iframe><p>Here we set loss and acc to a random value but here you would set important information you previously computed. This is what it will look like after it’s finished:</p><p>Epoch [0/3]: 100%|██████████████████████████████████| 125/125 [00:02&lt;00:00, 42.25it/s, acc=0.776, loss=0.0617]<br>Epoch [1/3]: 100%|██████████████████████████████████| 125/125 [00:02&lt;00:00, 41.70it/s, acc=0.0216, loss=0.668]<br>Epoch [2/3]: 100%|██████████████████████████████████| 125/125 [00:03&lt;00:00, 41.23it/s, acc=0.0701, loss=0.912]</p><p>Alright so it basically looks identical to how we normally set up our loops in PyTorch. The only difference is that we instead set <em>loop = tqdm(loader)</em> and then we can also add additional information to the progress bar like current (running) accuracy as well as loss for the current batch. Personally I always like to use a progress bar to know how long things will take and I recommend you to do it too! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72bdbf19b35c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pytorch Neural Network Tutorial]]></title>
            <link>https://aladdinpersson.medium.com/pytorch-neural-network-tutorial-7e871d6be7c4?source=rss-66cfbb5f28e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e871d6be7c4</guid>
            <category><![CDATA[pytorch-neural-network]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Aladdin Persson]]></dc:creator>
            <pubDate>Sat, 12 Sep 2020 00:00:00 GMT</pubDate>
            <atom:updated>2021-01-29T19:32:16.051Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJy4wM2X21u0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJy4wM2X21u0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJy4wM2X21u0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/da14a16af456f4684d73603b36a23328/href">https://medium.com/media/da14a16af456f4684d73603b36a23328/href</a></iframe><blockquote>Note: There is a video based tutorial on YouTube which covers the same material as this blogpost, and if you prefer to watch rather than read, then you can check out the video <a href="https://www.youtube.com/watch?v=Jy4wM2X21u0">here</a>.</blockquote><p>In this post we will learn how to build a simple neural network in PyTorch and also how to train it to classify images of handwritten digits in a very common dataset called MNIST.</p><p>Specifically in this tutorial we will:</p><ul><li>Load the MNIST dataset</li><li>Build a simple fully connected neural network in PyTorch</li><li>See how to train this network</li><li>Check the accuracy of our network on training data and testing data</li></ul><h3>Imports</h3><p>First we need will need a couple of different packages</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e8ccf86875f7c18ada274843d128079/href">https://medium.com/media/8e8ccf86875f7c18ada274843d128079/href</a></iframe><p>For loading the classical dataset <a href="https://pytorch.org/docs/stable/torchvision/datasets.html#mnist">MNIST</a> we need the following packages from PyTorch we can do this using torchvision as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3a64e3f4f2f3b418f17c1f779517698/href">https://medium.com/media/f3a64e3f4f2f3b418f17c1f779517698/href</a></iframe><p>Note that torchvision.datasets contains many more &quot;standard datasets&quot; that you may want to play around with as well, such as <a href="https://pytorch.org/docs/stable/torchvision/datasets.html#cifar">CIFAR-10</a> and <a href="https://pytorch.org/docs/stable/torchvision/datasets.html#svhn">SVHN</a> which can easily be loaded into PyTorch.</p><p>In this tutorial we use torchvision.datasets to load the data and if you are starting out learning deep learning they provide several datasets you can start working with before you dive into custom datasets. The following lines are all that&#39;s needed to load the MNIST train and test data. Here we are also setting a batch size which will be the amount of examples our network will see at a time when performing update steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabc81cc2c95f07ecbfbdc4fe130a7c5/href">https://medium.com/media/fabc81cc2c95f07ecbfbdc4fe130a7c5/href</a></iframe><p>The train_dataset and test_dataset are Torchvision dataset objects and in this example the only transform we apply to the images and labels is to convert them to PyTorch tensors with transforms.ToTensor() and this is a necessary step to train our network. The DataLoader() returns an iterator which will generate batches of the selected batch_size as tuples of (data, labels). We will therefor obtain 64 images at the same time from a batch with the associated correct label digit with those images. The argument shuffle determines whether these batches will be shuffled and you can default to setting it to True unless you are working with inherent sequential data. New batches will then be randomly selected each epoch which makes sure that the 64 examples inside a batch will be different from epoch to epoch.</p><h3>Building the model</h3><p>In PyTorch the general way of building a model is to create a class where the neural network modules you want to use are defined in the __init__() function. These modules can for example be a fully connected layer initialized by nn.Linear(input_features, output_features). We then define a function forward() in which the forward propagation of the model is performed by calling the defined modules and applying activation functions from nn.functional onto the input. When building the model you don&#39;t have to think about back-propagation as this will be taken care of automatically by PyTorch autograd.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74b99cc90040f442aa9cd8639c490c05/href">https://medium.com/media/74b99cc90040f442aa9cd8639c490c05/href</a></iframe><p>In this network we use the rectified nonlinear unit (ReLU) activation function and apply it in the forward propagation using F.relu() and the fully connected network has one input layer, one hidden layer and one output layer with 10 nodes, one for each digit 0-9.</p><h3>Setting up the training loop</h3><p>We have now arrived to the point where we are ready to put it all together and train the model. First we will define some hyperparameters that are required for the training of the network. If you are using a GPU for the training and have cuda enabled the code will make sure all training is run on the GPU by transferring the model and data .to(device).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8e001dc2aa5a89636c6d431b1cc3b47/href">https://medium.com/media/b8e001dc2aa5a89636c6d431b1cc3b47/href</a></iframe><p>Then, we initialize an instance of the model NN, the optimizer and the loss function. When we initialize the model the weights and biases of the model will be initialized under the hood of PyTorch to random small numbers and if you want a customized weight initialization it can be added in the NN class.</p><p>In this tutorial we will use the Adam optimizer which is a good default in most applications. The standard loss function for classifications tasks in PyTorch is the CrossEntropyLoss() which applies the softmax function and negative log likelihood given the predictions of the model and data labels. This is also the reason why we do not apply softmax to the outputs from our neural network, because it is already included in CrossEntropyLoss and we do not want to apply it twice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0a6dd3c98cc775dd704de8c61c85ed2/href">https://medium.com/media/b0a6dd3c98cc775dd704de8c61c85ed2/href</a></iframe><p>Now, we are ready to start training the model. We will loop through the epochs and then the train loader. For each batch we will perform forward propagation, compute the loss, calculate the gradients in back-propagation and update the weights with the optimizer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b15d1866a3cce96cbab40f74aa5b618b/href">https://medium.com/media/b15d1866a3cce96cbab40f74aa5b618b/href</a></iframe><p>Lastly, we want to make sure our model is learning by computing the accuracy on the training and test set. We will therefore code a function which checks the accuracy given the model and dataloader. In PyTorch a model can either be in the train or eval state which determines the behaviour of certain modules such as dropout or batch normalization that should act differently during training and testing time (don&#39;t bother too much if you don&#39;t know what those are). The default mode is train and when you evaluate a model you should toggle the model to eval. If you then want to continue training you would have to toggle it back to train. The attentive reader will realize that in this example, however, no module has different behaviour on train and test time. During evaluation you do not either want to spend valuable time on computing the gradients and all computations should therefore be under with torch.no_grad(). To check the accuracy of the model we will perform a forward pass on all batches in the dataloader, compute the predictions and then count how many predictions that correspond to the correct labels.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77ee9ac222751dcf779b2639c54266d2/href">https://medium.com/media/77ee9ac222751dcf779b2639c54266d2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3832737dd8e0b918cd1865ddcc60cfa7/href">https://medium.com/media/3832737dd8e0b918cd1865ddcc60cfa7/href</a></iframe><p>If you follow this tutorial you should expect to see a test accuracy of over 95% after 3 epochs of training. So after following this tutorial you learned how to setup a neural network in PyTorch, how to load data, train the network and finally see how well it performs on training and test data!</p><p>Leave a comment preferably on the <a href="https://www.youtube.com/watch?v=Jy4wM2X21u0">YouTube video</a> if you have any thoughts or questions! <a href="https://github.com/AladdinPersson/machine-learning-collection">Here</a> is a link to the Github repository where you can find this code, and many more similar to this!</p><p><em>Originally published at </em><a href="https://aladdinpersson.com/2020/09/12/pytorch-neural-network-tutorial/"><em>https://aladdinpersson.com</em></a><em> on September 12, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e871d6be7c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>