graph4ai / graph4nlp_demo

This repo is to present various code demos on how to use our Graph4NLP library.
Apache License 2.0
152 stars 31 forks source link

UnpicklingError when trying KDD2021_demo's semantic_parsing in jupyter notebook #6

Closed chris-opendata closed 3 years ago

chris-opendata commented 3 years ago

🐛 Bug

When trying KDD2021_demo semantic_parsing in jupyter notebook, I got the following error upon "Run the model"

[ Using CUDA ]
Loading pre-built vocab model stored in ../data/jobs\processed\node_emb_graph\vocab.pt
---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
<ipython-input-7-8ce32756f002> in <module>
      1 # run the model
----> 2 runner = Jobs(opt)
      3 max_score = runner.train()
      4 print("Train finish, best val score: {:.3f}".format(max_score))
      5 runner.load_checkpoint("best.pth")

<ipython-input-2-a40dcc751a5f> in __init__(self, opt)
      6         self.use_coverage = self.opt["decoder_args"]["rnn_decoder_share"]["use_coverage"]
      7         self._build_device(self.opt)
----> 8         self._build_dataloader()
      9         self._build_model()
     10         self._build_loss_function()

<ipython-input-2-a40dcc751a5f> in _build_dataloader(self)
     58 
     59         # Call the TREC dataset API
---> 60         dataset = JobsDataset(root_dir=self.opt["graph_construction_args"]["graph_construction_share"]["root_dir"],
     61                               pretrained_word_emb_name=self.opt["pretrained_word_emb_name"],
     62                               pretrained_word_emb_cache_dir=self.opt["pretrained_word_emb_cache_dir"],

c:\users\chris\dev\pyvenv_gnn\lib\site-packages\graph4nlp_cu111-0.4.0-py3.8.egg\graph4nlp\pytorch\datasets\jobs.py in __init__(self, root_dir, topology_builder, topology_subdir, pretrained_word_emb_name, pretrained_word_emb_url, pretrained_word_emb_cache_dir, graph_type, merge_strategy, edge_strategy, seed, word_emb_size, share_vocab, lower_case, thread_number, port, dynamic_graph_type, dynamic_init_topology_builder, dynamic_init_topology_aux_args)
     68         """
     69         # Initialize the dataset. If the preprocessed files are not found, then do the preprocessing and save them.
---> 70         super(JobsDataset, self).__init__(root_dir=root_dir, topology_builder=topology_builder,
     71                                           topology_subdir=topology_subdir, graph_type=graph_type,
     72                                           edge_strategy=edge_strategy, merge_strategy=merge_strategy,

c:\users\chris\dev\pyvenv_gnn\lib\site-packages\graph4nlp_cu111-0.4.0-py3.8.egg\graph4nlp\pytorch\data\dataset.py in __init__(self, root_dir, topology_builder, topology_subdir, share_vocab, **kwargs)
    692         self.data_item_type = Text2TextDataItem
    693         self.share_vocab = share_vocab
--> 694         super(Text2TextDataset, self).__init__(root_dir, topology_builder, topology_subdir, **kwargs)
    695 
    696     def parse_file(self, file_path) -> list:

c:\users\chris\dev\pyvenv_gnn\lib\site-packages\graph4nlp_cu111-0.4.0-py3.8.egg\graph4nlp\pytorch\data\dataset.py in __init__(self, root, topology_builder, topology_subdir, tokenizer, lower_case, pretrained_word_emb_name, pretrained_word_emb_url, target_pretrained_word_emb_name, target_pretrained_word_emb_url, pretrained_word_emb_cache_dir, max_word_vocab_size, min_word_vocab_freq, use_val_for_vocab, seed, thread_number, port, timeout, **kwargs)
    370             self.val = data['val']
    371 
--> 372         self.build_vocab()
    373 
    374     @property

c:\users\chris\dev\pyvenv_gnn\lib\site-packages\graph4nlp_cu111-0.4.0-py3.8.egg\graph4nlp\pytorch\data\dataset.py in build_vocab(self)
    640             data_for_vocab = self.val + data_for_vocab
    641 
--> 642         vocab_model = VocabModel.build(saved_vocab_file=self.processed_file_paths['vocab'],
    643                                        data_set=data_for_vocab,
    644                                        tokenizer=self.tokenizer,

c:\users\chris\dev\pyvenv_gnn\lib\site-packages\graph4nlp_cu111-0.4.0-py3.8.egg\graph4nlp\pytorch\modules\utils\vocab_utils.py in build(cls, saved_vocab_file, data_set, tokenizer, lower_case, max_word_vocab_size, min_word_vocab_freq, pretrained_word_emb_name, pretrained_word_emb_url, target_pretrained_word_emb_name, target_pretrained_word_emb_url, pretrained_word_emb_cache_dir, word_emb_size, share_vocab)
    184             print('Loading pre-built vocab model stored in {}'.format(saved_vocab_file))
    185             with open(saved_vocab_file, 'rb') as f:
--> 186                 vocab_model = pickle.load(f)
    187 
    188         else:

UnpicklingError: A load persistent id instruction was encountered,
but no persistent_load function was specified.

To Reproduce

Steps to reproduce the behavior:

  1. Following the instructions by the site to open semantic_parsing.
  2. Running through code segments.
  3. The error occurred when running "Run the model" code segment.

Expected behavior

Don't expect the error.

Environment

Additional context

  1. Started jupyter notebook in python virtual environment.
  2. Also tried setting config_file (in Set up the config segment) to the absolute path.
  3. text_classification example faced the same issue.
chris-opendata commented 3 years ago

Worked out the problem. It was due to the pre-existing vocab.pt in data\jobs\processed\node_emb_graph when it tried to build vocab. After deleting the existing vocab.pt, it should by-pass the error.

chris-opendata commented 3 years ago

There are other problems worked out. List here for anyone's reference

  1. One may need to reduce thread number in the config file in case facing the following error

    Exception has occurred: OSError       (note: full exception trace is shown but execution is paused at: <module>)
    [WinError 1455] The paging file is too small for this operation to complete. Error loading "...\lib\site-packages\torch\lib\cudnn_adv_infer64_8.dll" or one of its dependencies.
  2. One also needs to download nltk's 'punkt' if facing the error like

    Exception has occurred: LookupError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
    **********************************************************************
    Resource punkt not found.
    Please use the NLTK Downloader to obtain the resource:
    >>> import nltk
    >>> nltk.download('punkt')