Skip to content

Dynet api tutorial#1312

Merged
neubig merged 8 commits into
clab:masterfrom
woozyan:dynet_API_tutorial
Jun 15, 2018
Merged

Dynet api tutorial#1312
neubig merged 8 commits into
clab:masterfrom
woozyan:dynet_API_tutorial

Conversation

@woozyan

@woozyan woozyan commented Mar 16, 2018

Copy link
Copy Markdown
Contributor

Rewritten the API tutorial (#1302) so that user can have a better idea on how to use DyNet masterfully.

This includes:

  1. Create Expressions
  2. Create Parameters/LookupParameters
  3. Basic Expression Manipulations
  4. Neural Networks Related Manipulations
  5. How to use what you leaned above to create Neural Networks yourself.

@woozyan

woozyan commented Mar 16, 2018

Copy link
Copy Markdown
Contributor Author

@xunzhang Please take a look of what has been modified so far. I think I will continue working on part 4 and 5 later this week.

@xunzhang xunzhang changed the title Dynet api tutorial [WIP] Dynet api tutorial Mar 16, 2018
@xunzhang

Copy link
Copy Markdown
Collaborator

Sure. This is great!

@pmichel31415

Copy link
Copy Markdown
Collaborator

This is very cool.

I have one remark: the API for parameters was changed recently (you don't need to call dy.parameter anymore and doing so prints an error message. Should we do a mini-release including these changes and incorporate them in the tutorials/examples from now on (starting with this one). This would also simplify the examples a bit. thoughts?

@xunzhang

xunzhang commented Mar 16, 2018

Copy link
Copy Markdown
Collaborator

@pmichel31415 Agree, I think this can be finished before early next week, let's make a release when we finish this. And refactor existing models with the new interface. Further implementations should base on new interfaces.

FYI, @zhechenyan please apple changes from #1233 to your API.ipynb. I'll probably fix #1306 during weekends. I'll also try to add all interface changes after v2.0.3 later. This pull request should include all those(use latest one instead of deprecated ones).

"from __future__ import division\n",
"from __future__ import absolute_import\n",
"\n",
"import dynet_config\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add a comment that says please import dynet_config before import dynet, this is important to know.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"metadata": {},
"source": [
"#### Create Parameters\n",
"Parameters are things that are optimized. in contrast to a system like Torch where computational modules may have their own parameters, in DyNet parameters are just parameters."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in -> In. systems like Tensorflow and Torch.

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"b = dy.parameter(pb)\n",
"\n",
"m = dy.ParameterCollection() \n",
"W = m.add_parameters((8,8)) # an 8x8 matrix\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a comment that says add_parameters return an expr.

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"p = m.add_parameters((3,5), init=dy.PyInitializer()) # Any parameter initializer\n",
"scale = 1\n",
"mean = 0\n",
"stddev = 1\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

merge these three into one line please.

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"p = m.add_parameters((3,5), init='he')\n",
"# Creates 3x5 matrix from a numpy array (size is inferred)\n",
"p = m.add_parameters((3,5), np.ones((3,5)))\n",
"# Creates 3x5 matrix from a numpy array (size is inferred)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove this line please.

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"# initialize LookupParameters.\n",
"scale = 1\n",
"mean = 0\n",
"stddev = 1\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment thread examples/jupyter-tutorials/API.ipynb Outdated
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Expression Manipulation\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

rename as More Expression Manipulation?

@xunzhang

Copy link
Copy Markdown
Collaborator

Just finished review above the Expression Manipulation section.

@woozyan woozyan changed the title [WIP] Dynet api tutorial Dynet api tutorial Mar 22, 2018
@neubig

neubig commented Apr 6, 2018

Copy link
Copy Markdown
Contributor

@zhechenyan @xunzhang Is this ready for a final check?

@xunzhang

xunzhang commented Apr 6, 2018

Copy link
Copy Markdown
Collaborator

@neubig not yet. I'll let you know when it's ready for a final look. Probably this weekend.

@xunzhang xunzhang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@xunzhang

xunzhang commented Apr 9, 2018

Copy link
Copy Markdown
Collaborator

cc @neubig , please take a final review and do merge please.

@neubig neubig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall, looks good! I have a few comments, and also think this needs a spell check. Once that's done I think we can merge.

"outputs": [],
"source": [
"# create a vector/matrix expression of special values\n",
"# Different from TensorFlow, DyNet treats batch as the last dim\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not exactly correct. DyNet has a special "batch" dimension, so that you don't need to think about the batch dimension most of the time other than during input and output. Could we make this a little more accurate, following the explanation here?:
http://dynet.readthedocs.io/en/latest/minibatch.html

"dim = 5\n",
"batch_size = 3\n",
"e = dy.zeros(dim, batch_size=batch_size)\n",
"print('zeors of dim {} and batch_size {}:\\n{}'.format(dim, batch_size, e.npvalue()))\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

zeors -> zeros

"cell_type": "markdown",
"metadata": {},
"source": [
"It should be noticed that in DyNet 2.0+ and later version, the dy.parameters() is depecated so explicitly adding parameters to the computation graph is no longer necessary. Any used parameter will be added automatically."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be noticed that in DyNet 2.0+ and later version, the dy.parameters() is depecated
->
Previously, it was necessary to add parameters to the computation graph using "dy.parameters()", but this is now deprecated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also it should probably be 2.0.4+ or ">2.0.3"so that people don't get confused

"metadata": {},
"outputs": [],
"source": [
"# Ceate expressions from lookup parameters.\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ceate -> Create

(There may be other spelling errors, so I'd try to spell-check the text)

"metadata": {},
"source": [
"#### More Expression Manipulation\n",
"DyNet provides hundreds of operations on Expression. User can manipulate Expressions, build complex Expression easily."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

operations on Expression -> operations that can be applied to Expressions

User -> The user

build complex Expression -> and build complex Expressions

@neubig

neubig commented May 11, 2018

Copy link
Copy Markdown
Contributor

Hi! There are a few small comments here, but I think this is largely good. Do you think you could finish this up?

@xunzhang

Copy link
Copy Markdown
Collaborator

cc @zhechenyan

@woozyan

woozyan commented May 11, 2018

Copy link
Copy Markdown
Contributor Author

Sure I will finish this by the end of the weekend.

@neubig

neubig commented Jun 11, 2018

Copy link
Copy Markdown
Contributor

Ping?

@xunzhang

Copy link
Copy Markdown
Collaborator

Ping x2

@neubig neubig merged commit ec0d1f4 into clab:master Jun 15, 2018
@neubig

neubig commented Jun 15, 2018

Copy link
Copy Markdown
Contributor

Made a few changes and merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants