Part 1, online study group

Lesson 5

I shared the below image in our previous meetup. This is an updated version along with annotated code and notes.

Building a minimal Neural Network (Logistic Regression with no hidden layer) from scratch

Let’s walk through step by step and also refer how we code each blocks from the below image


Source: Natural Language Processing with PyTorch by Delip Rao et al.

  • Predictions: y_hat = model(x) , here we are using own model.
  • Loss function: loss_func(y_hat, y). In addition to that we are also adding it with w2*wd
  • Gradients: parameter.sub_(learning_rate * gradient), performing an inplace subtraction on parameters with product(learning_rate, gradient). But since our model has multiple parameters (weights, biases), we are looping through them using PyTorch parameters.
  • Extras:
    • Weight Decay:
      • a) w2: using each parameter, we are calculating the sum of squared weights, w2 , for p in model.parameters(): w2 += (p**2).sum()
      • b) wd: a constant (1e-5)
      • multiply w2 and wd & add to regular loss_func
  • Combined
    • We are going to calculate the loss for each minibatch by calling update(x,y,lr) on them. losses = [update(x,y,lr) for x,y in data.train_dl]
    • .item() turns into a python number in order to plot & see them visually.
def update(x, y, learning_rate):
  wd = 1e-5
  #prediction
  y_hat = model(x)
  w2 = 0.
  #sum of squared weights
  for p in model.parameters():
    w2 = w2 + (p**2).sum()
  # regular loss
  loss = loss_func(y_hat, y) + w2*wd
  # updates the gradients in the model ie parameters
  loss.backward()
  # instruct pytorch not to record these actions for the next gradient calculation
  with torch.no_grad():
    for p in model.parameters():
      #gradients
      p.sub_(learning_rate * p.grad)
      p.grad.zero_()
  return loss.item()

Resources

Feedback is welcome.

5 Likes

Hi msivanes hope your having a splendid day.
Thanks for a great post.

Cheers mrfabulous1 :smiley::smiley:

1 Like

Just a reminder, there is a meetup tomorrow at 2pm GMT, dedicated to Lesson 3 :slightly_smiling_face:

1 Like

The meetup starts in about an hour. Link (Always the same): zoom.us/j/226775879 .

The meetup is on :slight_smile:

Meeting Notes 18-01-2020

  • Multilabel classification review by @gagan
  • Segmentation classification notebook walk-through by @gagan
  • Image Regression notebook walk-through by @Shahnoza

Advice

Discussion

  • Class Imbalance : Doesn’t appear to be valid for images. Research suggests that it might be valid for tabular data. Further exploration required.
  • Partial functions : Concept review by @gagan (Used in multi-class classification)

Resources

4 Likes

We are deciding timing for the next meetup, please write your suggestions in the comments or vote in the slack :slight_smile: The meetup will be dedicated to Lesson 4

Curious general question: how do you guys keep track of changes in your model. For instance, when you change parameters or change resnet#. Do you guys save the graph in word document, use a software to compare different runs or what do you guys do?

Personally, i had been trying to use Wandb to compare different models but still trying to learn how to use different features. For instance, if i wanted for it to grab a graph of a certain run and the others to compare how its changing.

1 Like

Highly interested. expecting an invitation. Thanks

You can join our open slack group. Link is in the first post of this thread. The timings of the next meetup will be updated soon. :slight_smile:

Hi hi, just a reminder, the meetup is today at 4PM GMT ( 8AM PST = 9:30PM IST = 11AM EST) :slight_smile: It is dedicated to NLP and based on Lesson 4. Click to the Zoom link when it is a time.

1 Like

The meetup is starting in ~11mins, zoom link is on!

This worked when I tried few months back, not sure if this still works but you can try this hack to automatically reconnect colab notebook. https://stackoverflow.com/a/58275370/5951165

2 Likes

Meeting Minutes for 01/26/2020

Presentation on Lesson 4

Questions

  • What does np.random.seed(2) do?
    This post & this one addresses them

The ImageDataBunch creates a validation set randomly each time the code block is run. To maintain a certain degree of reproducibility the np.random.seed() method is built-in within the fastai library.

  • How to stop Google Colab from disconnecting?
    @vijayabhaskar shared this in the previous comment

Challenges

  • Many participants shared the common challenges that they face. This deserves a separate post (will summarize this & possible options soon)

Misc

  • Organizational stuff

Resources

2 Likes

I wrote my first post using the fast_template shared by Jeremy, which uses Github pages and Jekyll. I hope it can be helpful to people.

5 Likes

Hi gagan hope you’re having a wonderful day!

I found your first post informative and a real joy to read.

Cheers mrfabulous1 :smiley: :smiley:

1 Like

Thanks @mrfabulous1!! I’m glad you found it useful. !!

Hi people!!! As part of this study group, we are starting an algorithms meetup to hone our expertise in using data structures and algorithms, which can be useful for interviews as well.

Preparing for Leet-code styled coding interviews can be a very challenging task because the material is scattered and finding the perfect explanation for the problem can take time. I, along with a friend prepared for these interviews and I intend to cover some patterns that we learnt, (related to data-structures and algorithms) that were useful to us. We both got a new job after weeks of preparation and iteratively figuring out how not to fail. Please note that I will be just sharing my experience and by no means am I an expert (yet ). I hope my experience will help others in solving such coding problems and nailing that interview!!!

People who are interested can join the slack for our study-group using the link in the first post of this thread. (We would be using the #coding_interview_prep channel for this specific purpose)

3 Likes

Just a reminder, there is a meetup today, at 4PM GMT :wink: We will focus on Lesson 4!

1 Like

Hello all! first time in this meetup… just started lesson 4 today :slight_smile:

4 Likes