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

Dex Tutorial #443

Merged
merged 17 commits into from
Jan 20, 2021
Merged

Dex Tutorial #443

merged 17 commits into from
Jan 20, 2021

Conversation

srush
Copy link
Contributor

@srush srush commented Jan 9, 2021

An attempt at writing a Dex starter tutorial.

Goal was to start and focus on the that makes Dex unique (for / indices / type system) as opposed to starting with the syntax. Also assumes that the user is coming from python.

Open questions:

  • What are the standard names for things. Arrays? Tables? Tensors?
  • Is plotting / html stable? Probably would look better with plots and things like that as a running example.

For #425

@google-cla
Copy link

google-cla bot commented Jan 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Jan 9, 2021
Copy link
Collaborator

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Excellent language introduction and persuasive literate programming, thank you!

No surprise given your history of great notebook essays:

Would you mind if I pushed a copy-editing commit to your branch? I thought that might be more efficient than leaving a bunch of small comments.


Edited: I created a PR srush#1 to your srush:tutorial branch with some tutorial edits, in addition to merging google-research:main into the branch. The current srush:tutorial branch seems ~5 months outdated.

@srush: please take a look! I wanted to share as early as possible to prevent conflicting/duplicate edits.

examples/tutorial.dx Outdated Show resolved Hide resolved
examples/tutorial.dx Outdated Show resolved Hide resolved
@srush
Copy link
Contributor Author

srush commented Jan 9, 2021

Thanks so much Dan! I will update right away.

Definitely a first draft, so I very much appreciate all the edits. Happy for any feedback.

@dan-zheng
Copy link
Collaborator

Sure thing! It also looks like you need to sign the Contributor License Agreement (CLA).

@google-cla
Copy link

google-cla bot commented Jan 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@srush
Copy link
Contributor Author

srush commented Jan 9, 2021

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Jan 9, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@dan-zheng
Copy link
Collaborator

dan-zheng commented Jan 9, 2021

ℹ️ Googlers: Go here for more info.

The internal link says that the email address [email protected] is missing a signed CLA. I think there are two ways to resolve it:

  • Signing a CLA with that email address. I think that involves linking the email address to your GitHub account.
  • Amending the commit 3bcda85 to use a different email instead.

@google-cla
Copy link

google-cla bot commented Jan 9, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@srush
Copy link
Contributor Author

srush commented Jan 9, 2021

@dan-zheng Errors fixed.

I do want to note though that this is still a draft. I want to make most of these example run on images (maybe mnist?) to make it a bit more engaging.

@dan-zheng
Copy link
Collaborator

dan-zheng commented Jan 9, 2021

Visualization via images sounds great!
I didn't mean to dominate, sorry. I'd like to read your tutorial again when it's ready!

examples/tutorial.dx Outdated Show resolved Hide resolved

' Next: `\`. This symbol is the lambda sigil in Dex. It is analogous to the
`lambda` keyword in Python, and starts the definition of a function value
(i.e. closure). In `arrSum` above: the lambda takes an argument named `acc`
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically speaking it may or may not be a closure.
Idk if that kind of pedantry is useful in the tutorial though.

It might be nice to mention in this section that this can also be used to define functions, like the def keword above.

It also might be nice to mention the symmetry between for i. and \i.;
though I thing that might be awkard so maybe not worth interupting flow that much.

Copy link
Collaborator

@dan-zheng dan-zheng Jan 9, 2021

Choose a reason for hiding this comment

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

Technically speaking it may or may not be a closure.
Idk if that kind of pedantry is useful in the tutorial though.

Good note. From my Swift background, I use "closure" as a generic name for "function values", including both function references (trivial closures, capturing no context) and closure expressions (\x. blah x, possibly capturing values).

It might be nice to mention in this section that this can also be used to define functions, like the def keword above.

I think omitting this (explanation of first-class functions, lambdas can be assigned to variables) is reasonable, given that Python programmers are familiar with it (Python also has first-class function values).

It also might be nice to mention the symmetry between for i. and \i.;
though I thing that might be awkard so maybe not worth interupting flow that much.

I agree, expanding a bit on "arrays are like functions" would be neat.

We discussed a bit more about "arrays as functions" in a different thread. Sasha pointed out that "for as a list comprehension" is more user-friendly than "arrays as function types/lambdas" (which is more programming-language-theoretic) - and this tutorial seems catered to folks coming from Python.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with closure. This is not supposed to be a super formal introduction, and in most informal settings lambda ≈ closure.

@oxinabox
Copy link
Contributor

oxinabox commented Jan 9, 2021

What are the standard names for things. Arrays? Tables? Tensors?

Tables I think. That was what the old tutorial used; iirc.
When introducing them it might also be worth saying something like "Traditional arrays are the common special case of a Table where the index is Fin _, but dex tables can (as we will later see) be more exotic"
(We could probably implement some thing that a physicist would be happy to call a Tensor with up and down indexes etc. That would be cool)

Is plotting / html stable? Probably would look better with plots and things like that as a running example.

Nothing is stable, e.g. #370 like completely changed the way type classes are used and constructed.
But we should totally use plotting and html in this tuitorial and should just maintain the tutorial when/if they change.

Copy link
Collaborator

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

This is amazing, thanks for writing that!

examples/tutorial.dx Outdated Show resolved Hide resolved
examples/tutorial.dx Outdated Show resolved Hide resolved

' Next: `\`. This symbol is the lambda sigil in Dex. It is analogous to the
`lambda` keyword in Python, and starts the definition of a function value
(i.e. closure). In `arrSum` above: the lambda takes an argument named `acc`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with closure. This is not supposed to be a super formal introduction, and in most informal settings lambda ≈ closure.

examples/tutorial.dx Show resolved Hide resolved
examples/tutorial.dx Outdated Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Jan 10, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 10, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@srush
Copy link
Contributor Author

srush commented Jan 10, 2021

Did another pass today to remove some sections and added some visual examples.

Here's the running version: https://srush.github.io/dex-lang/tutorial.html

@dougalm I love this multiple image function!

image

@dan-zheng feel free to take over, your changes were great. I probably don't have too much more time to work on this in the next couple days.

todo

  • @apaszke comments
  • conclusion - (point people to read prelude / examples)
  • something about laziness. (I need to test it out to understand when that is okay to assume)

I think I will defer advanced topics to a second doc. These include:

  • Randomness
  • Records / lenses
  • List

@dan-zheng
Copy link
Collaborator

Thanks @srush! I'm happy to continue editing the tutorial today, making progress towards the todos you listed above.

@google-cla
Copy link

google-cla bot commented Jan 10, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

srush and others added 7 commits January 10, 2021 17:47
…h#445)

The bottom padding adds unnecessary empty bottom scrolling,
which slightly hurts UX.
…#444)

This involves only web frontend changes via KaTeX CSS and JS: https://katex.org.
I chose KaTeX over MathJax because KaTeX seems more modern, performant, and prettier.
Remove `-threaded` option to fix warning:
```
Warning: 'ghc-options: -threaded' has no effect for libraries. It should only
be used for executables.
```
- Rebase on top of main branch.
  - Some code snippets do not yet compile due to syntax changes.
    This should be straightforward to fix.
- Stylistic edits: use consistent terminology and voice.
  - Remove some second person "you" references.
  - Use consistent Dex and programming languages terminology and spellings.
   - Consistently use "array" everywhere: no mentions of "table"
   - Consistently use "`for` comprehension"
  - Consistent formatting, punctuation, heading casing (first word uppercase).
Copy link
Collaborator

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

This is awesome thanks! I left a few general comments, but it looks good.

One big blocker for merging though might be the MNIST binary file. I'd be kind of reluctant to include this because of licensing issues, and git also being really bad when it comes to handling binary files in the history. Can we just include a line such as "oh btw line wget <url> if you want to continue with the tutorial"?

examples/tutorial.dx Outdated Show resolved Hide resolved
examples/tutorial.dx Outdated Show resolved Hide resolved
examples/tutorial.dx Outdated Show resolved Hide resolved
@srush
Copy link
Contributor Author

srush commented Jan 14, 2021

Sure @apaszke I will do that and your other changes.

@dan-zheng
Copy link
Collaborator

dan-zheng commented Jan 14, 2021

Can we just include a line such as "oh btw line wget <url> if you want to continue with the tutorial"?

Could dataset downloading be a Dex command too, via IO effect and shell command support by @dougalm? "wget to ~/.dex/datasets/mnist if it does not already exist"

Shouldn't be much work to create a basic datasets library.

I filed a feature issue for a Dex datasets library, hope that's not controversial: #458

@srush srush requested a review from apaszke January 14, 2021 20:34
@srush
Copy link
Contributor Author

srush commented Jan 14, 2021

Okay, think this mostly complete.

Should I send a PR to the GitHub Pages branch as well or is that automated?

@dan-zheng dan-zheng force-pushed the tutorial branch 2 times, most recently from da92945 to 13d9651 Compare January 15, 2021 07:47
@srush srush changed the title [Preliminary] Dex Tutorial Dex Tutorial Jan 15, 2021
@dan-zheng
Copy link
Collaborator

dan-zheng commented Jan 19, 2021

Should I send a PR to the GitHub Pages branch as well or is that automated?

My opinion: I think we're happy to handle the GitHub Pages branch regeneration!

Perhaps the tutorial is in a ready state for final review and merging. I'll take my final pass now.

static/dynamic.js Outdated Show resolved Hide resolved
examples/latex.dx Outdated Show resolved Hide resolved
srush and others added 5 commits January 19, 2021 17:21
- Consistent space: no triple newline.
- Spell out `tabXX` function names to `tableXX`.
- Rename dummy `Add`` and `VSpace`` interface requirements.
  - Prevents clash with Prelude interfaces and requirements of the same name.
- Rename title: "Dex Tutorial" → "Introduction to Dex"
- Fix English typos.
@google-cla
Copy link

google-cla bot commented Jan 19, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Jan 19, 2021
@srush
Copy link
Contributor Author

srush commented Jan 19, 2021

Thanks @dan-zheng . Think everything checks from my side.

Copy link
Collaborator

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

Sorry for the delays. It's a busy week, and for some reason the email notifications still had the "[Preliminary]" prefix in your PR title, so that didn't help.

Anyway, this looks good, so I'll go ahead and merge!

rewrite all operations in terms of batched tensor interactions, but
allows for a range of interactions. Put more simply, when learning
MATLAB students are told repeatedly to "avoid for loops". *Dex gives
for loops back*.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I love this pitch!

@apaszke apaszke merged commit 8aeaf90 into google-research:main Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants