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

How to train and use models? #2

Open
jackrobson opened this issue Jan 4, 2019 · 3 comments
Open

How to train and use models? #2

jackrobson opened this issue Jan 4, 2019 · 3 comments

Comments

@jackrobson
Copy link

jackrobson commented Jan 4, 2019

Hi

I've managed to setup and compile your project.

The script main.py runs without errors [see bottom for script output].

However, I can't figure out how to save a trained model and then use it.

I.e. let's say I have an input text file with one line

"Wasted so much money on previous laptops - why did I not buy this from the start.... Extremely happy with this product!"

How do I train the model, i.e. using the 14semeval_laptop dataset, and then use the model on my input text file?

Encase you need to send me something, my email is [email protected]

This is what I get when I run the main.py:
$ python3 main.py -n_epoch 1
[dynet] random seed: 1314159
[dynet] allocating memory: 4096MB
[dynet] memory allocation done.
N opinion: 3041
N dataset: 3041
N opinion: 800
N dataset: 800
Use the saved word embeddings
Embeddings shape: (5302, 300)
Use case-insensitive word embeddings
Parameters: Namespace(attention_type='bilinear', dim_asp=100, dim_opi=30, dim_w=300, dropout=0.5, dropout_asp=0.5, dropout_opi=0.5, ds_name='14semeval_rest', dynet_seed=1314159, flag='glove_840B', model_name='full', n_asp_tags=3, n_epoch=1, n_opi_tags=2, n_steps=5, optimizer='sgd', random_seed=1234, rnn_type='LSTM', running_mode='train-test', sgd_lr=0.07, win=3)
Use pretrained word embeddings
In Epoch 1 / 1:
The dy.parameter(...) call is now DEPRECATED.
There is no longer need to explicitly add parameters to the computation graph.
Any used parameter will be added automatically.
train loss: 18462.82, train precision: 67.54, train recall: 59.55, train f1: 63.29
Current results: precision: 81.03, recall: 77.60, f1: 79.27
$

@jackrobson jackrobson changed the title How do you use the trained models? How to train and use models? Jan 4, 2019
@lixin4ever
Copy link
Owner

eval.py is for model evaluation.

For you question, you need to save the trained model first. Then, load the saved model into the memory and call the instance function (i.e., call) of the class MODEL. Note that you should set "is_train" as False and the size of the current dataset as 1 (containing your input sentence).

@jackrobson
Copy link
Author

jackrobson commented Jan 8, 2019

How do I save the trained model?

How do I load the saved model?

@lixin4ever
Copy link
Owner

https://dynet.readthedocs.io/en/latest/python_saving_tutorial.html

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

No branches or pull requests

2 participants