Transformers: bert summarizer module import error

Created on 21 Apr 2020  路  3Comments  路  Source: huggingface/transformers

馃悰

Running bert summarizer (run_summarization.py) gives the following error

Traceback (most recent call last):
  File "run_summarization.py", line 15, in <module>
    from .utils_summarization import (
ModuleNotFoundError: No module named '__main__.utils_summarization'; '__main__' is not a package

Information

I've managed to fix this issue personally by changing "from .utils_summarization import" to "from utils_summarization import", though I don't know if this is due to a convention change in python module imports.

The problem arises when using:

  • [x] the official example scripts: (give details below)

Running the following command yields the error
python3 run_summarization.py --documents_dir ".../bertabs/dataset/input" --summaries_output_dir ".../bertabs/dataset/output" --no_cuda false --batch_size 4 --min_length 50 --max_length 200 --beam_size 5 --alpha 0.95 --block_trigram true

To reproduce

Steps to reproduce the behavior:

  1. Followed the steps here https://github.com/huggingface/transformers/blob/5b396457e5035a8b16ddee14b205c098598fe6bb/examples/summarization/bertabs/README.md
    Though I skipped the 'Reproduce the authors' ROUGE score' section, that should not have any effect on usage for different inputs.
  2. Created custom data paths for testing a single input article.
  3. Run the command given above.
Traceback (most recent call last):
  File "run_summarization.py", line 15, in <module>
    from .utils_summarization import (
ModuleNotFoundError: No module named '__main__.utils_summarization'; '__main__' is not a package

Expected behavior

It should import the module utils_summarization

Environment info

  • transformers version: 2.8.0
  • Platform: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic
  • Python version: 3.6.9
  • PyTorch version (GPU?): 1.4.0 (False)
  • Tensorflow version (GPU?): not installed (NA)
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No
wontfix

Most helpful comment

Hi!
Change: from .utils_summarization import ( CNNDMDataset, build_mask, compute_token_type_ids, encode_for_summarization, truncate_or_pad, )
To: from utils_summarization import ( CNNDMDataset, build_mask, compute_token_type_ids, encode_for_summarization, truncate_or_pad, )

All 3 comments

HELLO eeegnu, I'm also facing the same issue.
issue
Environment Info :
Platform: Windows 10 64bit
Python version: 3.6.10
PyTorch version (GPU?): 1.4.0
Tensorflow version (GPU?): not installed (NA)

Hi!
Change: from .utils_summarization import ( CNNDMDataset, build_mask, compute_token_type_ids, encode_for_summarization, truncate_or_pad, )
To: from utils_summarization import ( CNNDMDataset, build_mask, compute_token_type_ids, encode_for_summarization, truncate_or_pad, )

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guanlongtianzi picture guanlongtianzi  路  3Comments

siddsach picture siddsach  路  3Comments

hsajjad picture hsajjad  路  3Comments

rsanjaykamath picture rsanjaykamath  路  3Comments

fabiocapsouza picture fabiocapsouza  路  3Comments