Coder Social home page Coder Social logo

Test problem about nnsum HOT 8 OPEN

CrystalWLH avatar CrystalWLH commented on July 20, 2024
Test problem

from nnsum.

Comments (8)

kedz avatar kedz commented on July 20, 2024

from nnsum.

CrystalWLH avatar CrystalWLH commented on July 20, 2024

My training command is
python script_bin/train_model.py \ --trainer --train-inputs 'data/inputs/train/' \ --train-labels 'data/labels/train/' \ --valid-inputs 'data/inputs/valid/' \ --valid-labels 'data/labels/valid/' \ --valid-refs 'data/human/valid/' \ --weight \ --epochs 50 \ --gpu 3 \ --model 'result/model' \ --results 'result/valid_score' \ --seed 12345678 \ --emb --embedding-size 200 \ --enc cnn \ --ext s2s --bidirectional
My testing command is
python script_bin/eval_model.py \ --inputs 'data/inputs/test/' \ --refs 'data/human/test/' \ --model 'result/model.pth' \ --results 'result/exp1/test_score' \ --summary-length 100 \ --batch-size 32

The error message is
Loading model...Traceback (most recent call last): File "script_bin/eval_model.py", line 92, in <module> main() File "script_bin/eval_model.py", line 41, in main vocab = model.embeddings.vocab AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings'

from nnsum.

kedz avatar kedz commented on July 20, 2024

Thanks! Can you run the following commands and send me the output:

import torch
model = torch.load("result/model.pth", map_location=lambda storage, loc: storage)
print(model)

from nnsum.

markusdr avatar markusdr commented on July 20, 2024

The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here).

To fix, change the nnsum code here from:

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name)

to

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name, 
                                 save_as_state_dict=False)

from nnsum.

tlifcen avatar tlifcen commented on July 20, 2024

Hello,
I used AMI dataset to test the code without GPU, and I met this problem:

INFO:root: Model parameter initialization finished.

INFO:ignite.engine.engine.Engine:Engine run starting with max_epochs=50.
INFO:ignite.engine.engine.Engine:Epoch[1] Complete. Time taken: 00:00:00
ERROR:ignite.engine.engine.Engine:Engine run is terminating due to exception: Loss must have at least one example before it can be computed.
Traceback (most recent call last):
  File "script_bin/train_model.py", line 79, in <module>
    main()
  File "script_bin/train_model.py", line 76, in main
    results_path=args["trainer"]["results"])
  File "/home/constant/anaconda3/lib/python3.7/site-packages/nnsum-1.0-py3.7.egg/nnsum/trainer/labels_mle_trainer.py", line 164, in labels_mle_trainer
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 359, in run
    self._handle_exception(e)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 324, in _handle_exception
    raise e
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 350, in run
    self._fire_event(Events.EPOCH_COMPLETED)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 259, in _fire_event
    func(self, *(event_args + args), **kwargs)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/metrics/metric.py", line 68, in completed
    result = self.compute()
  File "/home/constant/anaconda3/lib/python3.7/site-packages/nnsum-1.0-py3.7.egg/nnsum/metrics/loss.py", line 21, in compute
ignite.exceptions.NotComputableError: Loss must have at least one example before it can be computed

Is it the problem caused by not using GPU? Thanks for your help!

from nnsum.

tlifcen avatar tlifcen commented on July 20, 2024

The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here).

To fix, change the nnsum code here from:

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name)

to

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name, 
                                 save_as_state_dict=False)

I changed the code as your suggestion, but the code does not work, either. There is still the following error:
AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings'
Do you have other methods to solve the problem? Thanks for your reply!

from nnsum.

kedz avatar kedz commented on July 20, 2024

from nnsum.

tlifcen avatar tlifcen commented on July 20, 2024

Can you give me the versions of python, torch, and ignite that you are using, along with the commandline arguments you are using? I can't reproduce this error. Thanks! Chris

On Tue, Sep 3, 2019 at 1:06 AM tlifcen @.***> wrote: The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here <pytorch/ignite@79e5233#diff-18cd1a3c06de70b0e34b8fcf32940b30> ). To fix, change the nnsum code here https://github.com/kedz/nnsum/blob/master/nnsum/trainer/labels_mle_trainer.py#L244 from: checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func, require_empty=False, score_name=metric_name) to checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func, require_empty=False, score_name=metric_name, save_as_state_dict=False) I changed the code as your suggestion, but the code does not work, either. There is still the following error: AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings' Do you have other methods to solve the problem? Thanks for your reply! — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#7?email_source=notifications&email_token=ABAZOM4PUXUSAJT4QUFUQH3QHXWDNA5CNFSM4HJIHGK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5XAVXQ#issuecomment-527305438>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZOMZKVFULGHZTOLS3NPLQHXWDNANCNFSM4HJIHGKQ .
-- Chris Kedzie PhD Student, Dept. of Computer Science Columbia University email: [email protected] web: www.cs.columbia.edu/~kedzie

I used python3.6.9, torch0.4.1 and ignite0.2.0. And the environment is Ubuntu 16.04 LTS. I used the following command to test the code:

python script_bin/eval_model.py \
  --inputs /home/constant/data/Constant-TL/dataset/summarization/nnsum/reddit/reddit/inputs/test \
  --refs /home/constant/data/Constant-TL/dataset/summarization/nnsum/reddit/reddit/human-extracts/test \
  --model ../dataset/summarization/nnsum/reddit_model_95_rouge-2=0.65826.pth \
  --results ../dataset/summarization/nnsum/reddit/test_score \
  --summary-length 100 

Thanks for your reply!

from nnsum.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.