Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new linear regression tutorial #2016

Merged
merged 24 commits into from
Nov 22, 2022
Merged

Conversation

Saransh-cpp
Copy link
Member

This PR -

  • Adds a new "Getting Started" section in the docs which I will be working on for the next couple of weeks
  • Moves basics.md and overview.md to the "Getting Started" section. Currently, there are no changes in the files, but they will be changed soon.
  • Adds a Linear Regression example to the "Getting Started" section

For the linear regression guide -

  • Should I add the backpropagation step in the first half, or should I leave it to the Flux.Optimise.update! step?
  • This guide overlaps with a lot of other textual information present but scattered in Flux's docs. These other texts will also be updated or moved to a better place soon. Basics.md, for example, does something very similar with dummy data, and the current "Getting Started" guide does something similar but with pre-defined weights.

PR Checklist

  • Tests are added
  • Entry in NEWS.md
  • Documentation, if applicable

@Saransh-cpp Saransh-cpp marked this pull request as draft July 5, 2022 20:23
@DhairyaLGandhi
Copy link
Member

DhairyaLGandhi commented Jul 5, 2022 via email

@Saransh-cpp
Copy link
Member Author

The first thought I had was to add a hyperlink on the website's Getting Started page, which would redirect the user to the docs' Getting Started page (similar to the Ecosystem page).

Should I also add the same tutorial (once approved) to the website, or should we link the section?

@Saransh-cpp Saransh-cpp marked this pull request as ready for review July 6, 2022 11:37
@avik-pal
Copy link
Member

avik-pal commented Jul 7, 2022

I think there is a consensus to not use Flux.params API any longer. We should not introduce it into new tutorials being written.

@Saransh-cpp
Copy link
Member Author

Thank you for the suggestion! I took some time to go through Optimisers.jl, and I am assuming that the traditional Flux training method should be replaced with Optimisers.jl?

@mcabbott
Copy link
Member

Agree we should move away from the whole weird Params story.

But perhaps this linear regression example should delay introducing Optimisers.jl as long as possible. For simple gradient descent, just writing out something like this:

dLdW, _, _ = gradient(loss, W, x, y)
W .= W .- 0.1 .* dLdW

might be a better level than immediately introducing optimiser state etc. It's unfortunate that this has quite a few moving parts, unlike train!'s apparent simplicity (although really train! hides a lot & this is also confusing). Maybe Optimisers.jl ought to be introduced along with an explanation that adding momentum helps, so that you know why there is a state?

Even something like this seems OK to me, pretty explicit, and makes you understand why you are about to see a tool for walking over the arrays:

m = Dense(1 => 1)
for step in 1:10
  dLdm, _, _ = gradient(loss, m, x, y)
  
  m.weight .= m.weight .- 0.1 .* dLdm.weight
  m.bias .= m.bias .- 0.1 .* dLdm.bias
end

One more comment. In such tutorials, things like params = Flux.params(W, b) seem super-confusing. It would be nice to choose variable names which are very clearly things you've chosen, not features of Flux. flux_model is good.

(Link to rendered version: https://github.com/Saransh-cpp/Flux.jl/blob/linear-regression/docs/src/getting_started/linear_regression.md )

@Saransh-cpp
Copy link
Member Author

Agreed, we should keep the linear regression example simple. I will update the tutorial to show the gradient descent algorithm in action.

I have been working on the logistic regression example locally and will update that with the same.

@Saransh-cpp
Copy link
Member Author

I'll update this with the new train! definition once #2029 is merged. Right now this PR does not use train! in any way.

@Saransh-cpp
Copy link
Member Author

Test: @ModelZookeeper commands

Copy link
Member

@mcabbott mcabbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some comments on an earlier version... perhaps useful but not a full review.

docs/src/getting_started/linear_regression.md Outdated Show resolved Hide resolved
docs/src/getting_started/linear_regression.md Outdated Show resolved Hide resolved
docs/src/getting_started/linear_regression.md Outdated Show resolved Hide resolved
docs/src/getting_started/linear_regression.md Outdated Show resolved Hide resolved
## Copy-pastable code
### Dummy dataset
```julia
using Flux
using Plots

# data
x = hcat(collect(Float32, -3:0.1:3)...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to encourage people to try this out. I fear that nobody will find this section until they have done plenty of copying pieces above.

And that they will tend to drift out of sync. (Maybe this section should at least run as a smoke-test.)

Should we consider making these pages with Pluto, so that they are just a static version of something you can download and run?

@Saransh-cpp
Copy link
Member Author

Saransh-cpp commented Aug 15, 2022

Thanks for the review, @mcabbott! Pluto sounds good! We can get rid of the copy-paste section if this is converted to a Pluto notebook (or file, not sure, will go through it in detail).

(SciML uses this copy-paste section at the top, but this code was too lengthy to be placed at the top)

Edit: A discussion about the documentation of Metalhead is going on at FluxML/Metalhead.jl#199, which could result in a uniform template for these getting started/quickstart guides.

@Saransh-cpp
Copy link
Member Author

@mcabbott, JuliaManifolds/Manopt.jl renders Pluto notebooks in the Documenter documentation using the following make.jl contents - https://github.com/JuliaManifolds/Manopt.jl/blob/master/docs/make.jl#L1-L106.

This does look a bit hacky, and it also distorts the documentation when a user opens one of the rendered Pluto notebooks -

Sidebar

Normal page

image

Rendered Pluto notebook

image

Settings

Normal page

image

Rendered Pluto notebook

image

Is there a legitimate way to render Pluto notebooks in Documenter's documentation? This hack does not look good to me. Alternatively, we could keep the section as it is and at the top link a Pluto notebook that can be downloaded for following along.

Here is how the converted Pluto notebook looks like - https://saransh-cpp.github.io/assets/pluto/linear_regression.jl.html

Note: I am just redirecting users to the html page generated by Pluto from here - https://saransh-cpp.github.io/blog/ (this will be removed once this PR is merged to avoid duplicate pages on the web).

@Saransh-cpp
Copy link
Member Author

Currently, https://fluxml.ai/Flux.jl/stable/models/overview/ does something similar but is not as extensive as this guide. Should it be removed, or should it also be put under the "Getting Started" guide with a better title?

@ToucheSir
Copy link
Member

What if anything do we lose if it's removed? I think it would be nice to do so, but any material in it which isn't covered elsewhere would need a new home.

@Saransh-cpp
Copy link
Member Author

I think the following text can be used at the top of this guide. The rest of this page is definitely a subset of this guide.


Flux is a pure Julia ML stack that allows you to build predictive models. Here are the steps for a typical Flux program:

  • Provide training and test data
  • Build a model with configurable parameters to make predictions
  • Iteratively train the model by tweaking the parameters to improve predictions
  • Verify your model

Under the hood, Flux uses a technique called automatic differentiation to take gradients that help improve predictions. Flux is also fully written in Julia so you can easily replace any layer of Flux with your own code to improve your understanding or satisfy special requirements.

Here's how you'd use Flux to build and train the most basic of models, step by step.

@Saransh-cpp Saransh-cpp force-pushed the linear-regression branch 2 times, most recently from da20b62 to 2c9cdd1 Compare August 23, 2022 15:02
@mcabbott
Copy link
Member

Currently, https://fluxml.ai/Flux.jl/stable/models/overview/ does something similar but is not as extensive as this guide. Should it be removed, or

One virtue of that page is that it's much shorter.

I like this PR's story, it's a nice ground-up explanation. But if you have met some of this before, and want a faster path to seeing how to write it in Julia's syntax and using Flux's pieces, then perhaps you prefer the older one.

Not sure what the ideal way to organise this material is...

@Saransh-cpp
Copy link
Member Author

But if you have met some of this before, and want a faster path to seeing how to write it in Julia's syntax and using Flux's pieces, then perhaps you prefer the older one.

Yes, this makes sense. Maybe converting it into a "Quickstart" page under the "Getting Started" section?

@mcabbott
Copy link
Member

In addition to the main manual

https://fluxml.ai/Flux.jl/stable/models/overview/

we also have some quite nice tutorials here:

https://fluxml.ai/tutorials.html

How do we make these all findable, and where does this new page go?

The main docs also seem a slightly awkward combination of introduction and reference. It's possible that the "Building models" heading should be split in two? Not sure.

Screenshot 2022-08-29 at 15 12 58

@Saransh-cpp
Copy link
Member Author

In addition to the main manual

https://fluxml.ai/Flux.jl/stable/models/overview/

we also have some quite nice tutorials here:

https://fluxml.ai/tutorials.html

How do we make these all findable, and where does this new page go?

While drafting the "Getting Started" section, I wanted to include only the guides that will get a user started with flux. The website tutorials should be the ones introducing something that a user doesn't find themselves engaged with when they begin with ML/DL or an ML/DL package, for example, GANs and Transfer Learning. I think the DataLoader tutorial should be moved to the MLUtils page and the Deep Learning with Flux - A 60 Minute Blitz (September 2020) can be added to the "Getting Started" section.

Ideally, there should be a "Tutorials" heading on the docs' sidebar which should redirect users to the website's tutorials page. Similarly, the website's getting started page should redirect users to the docs' getting started section.

A nice infographic -

image

IMO, the DataLoader example is a "How-To Guide", the "Getting Started" guides are more inclined towards "Explanations", and the website tutorials are "Tutorials".

docs/make.jl Outdated
"Gradients and Layers" => "models/basics.md",
"Quick Start" => "getting_started/quickstart.md",
"Fitting a Line" => "getting_started/overview.md",
"Gradients and Layers" => "getting_started/basics.md",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I suggest leaving files where they are, until sure? I think moving them may break some links elsewhere. And we may re-organise this into Guide / Reference.

(Adding id & linking by that, not heading name nor file name, seems like the right solution.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the references associated with these pages now use ids! I have also reverted back the structural changes.

@Saransh-cpp Saransh-cpp changed the title A new linear regression tutorial + restructure docs directory A new linear regression tutorial Oct 27, 2022
Copy link
Member

@mcabbott mcabbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it. Tutorials is the right section, IMO.

@ToucheSir ToucheSir merged commit da8ce81 into FluxML:master Nov 22, 2022
@Saransh-cpp Saransh-cpp deleted the linear-regression branch November 22, 2022 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants