-
Notifications
You must be signed in to change notification settings - Fork 5.9k
add word2vec test for the new API #10303
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maybe have something like fluid.params.load() (since we have trainer.params.save() above) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking about it! If we aim for symmetry, params.save is a method of a params instance, in the same time fluid.params.load is a static method, which is not very symmetric?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry didn't catch this before, but place is not used, it should be passed into fluid.Inferencer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
| next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64') | ||
| predict_word = inference_network() | ||
| cost = fluid.layers.cross_entropy(input=predict_word, label=next_word) | ||
| avg_cost = fluid.layers.mean(cost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metrics, like error rate, auc, are not defined in this demo. How do we define a error rate in our new designed API?
By just adding fluid.layers.accury(input=predict_word, label=label) ? Should we fetch metrics by default?
|
|
||
| trainer = fluid.Trainer( | ||
| partial(inference_network, is_sparse), | ||
| fluid.optimizer.SGD(learning_rate=0.001), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we passing the optimizer instance to a trainer, we cannot use learning rate schedule since the learning_rate is a variable of learning rate schedule method, which is designed by @jacquesqiao
Perhaps, we can pass a lambda here or an instance here.
lambda could be
trainer = fluid.Trainer(optimizer=lambda: fluid.optimizer.SGD(learning_rate=fluid.layers.fill_constant(1e-3)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I realized that we may need to freeze parameter when reading your GAN example.
Another possibility is we pass in a optimize function?
def optimize(loss):
opt = fluid.optimizer.SGD(learning_rate=fluid.layers.fill_constant(1e-3)))
return opt.minimize(
loss=loss,
parameter_list=[
p.name for p in g_program.global_block().all_parameters()
])
trainer = fluid.Trainer(..., optimize=optimize)EDIT: never mind, I just realized that the user would not have access to p.name for p in g_program.global_block().all_parameters().
| sys.exit("got NaN loss, training failed.") | ||
|
|
||
| trainer = fluid.Trainer( | ||
| partial(inference_network, is_sparse), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partial(train_network, is_sparse) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fluid.Trainer's first argument should be a function without any arguments. partial(train_network, is_sparse) binds is_sparse to train_network, creating a function without any argument.
No description provided.