Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Custom data file for classification seems to be failing #154

Closed
zippeurfou opened this issue Apr 23, 2021 · 7 comments
Closed

Custom data file for classification seems to be failing #154

zippeurfou opened this issue Apr 23, 2021 · 7 comments
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed wontfix This will not be worked on

Comments

@zippeurfou
Copy link
Contributor

馃悰 Bug

When training a classification model on custom data file, the training fails because it expect num_classes

To Reproduce

Use this collab:
https://colab.research.google.com/drive/1uamw6SNaOr_4ch24JNxAj2yfgLUKfJqO?usp=sharing
Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/lightning_transformers/cli/train.py", line 84, in hydra_entry
    main(cfg)
  File "/usr/local/lib/python3.7/dist-packages/lightning_transformers/cli/train.py", line 78, in main
    logger=logger,
  File "/usr/local/lib/python3.7/dist-packages/lightning_transformers/cli/train.py", line 61, in run
    trainer.fit(model, datamodule=data_module)
  File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py", line 458, in fit
    self.call_setup_hook(model)
  File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py", line 1066, in call_setup_hook
    model.setup(stage_name)
  File "/usr/local/lib/python3.7/dist-packages/lightning_transformers/core/model.py", line 88, in setup
    self.configure_metrics(stage)
  File "/usr/local/lib/python3.7/dist-packages/lightning_transformers/task/nlp/text_classification/model.py", line 61, in configure_metrics
    self.prec = Precision(num_classes=self.num_classes)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 948, in __getattr__
    type(self).__name__, name))
AttributeError: 'TextClassificationTransformer' object has no attribute 'num_classes'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Expected behavior

It should start training.

Environment

check the notebook

@zippeurfou zippeurfou added the help wanted Extra attention is needed label Apr 23, 2021
@dsindex
Copy link

dsindex commented Apr 26, 2021

same here~

$ python train.py task=nlp/text_classification dataset=nlp/text_classification/emotion
...
torch.nn.modules.module.ModuleAttributeError: 'TextClassificationTransformer' object has no attribute 'num_classes'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

@edenlightning edenlightning added the bug / fix Something isn't working label Apr 26, 2021
@SeanNaren
Copy link
Contributor

Thanks guys! This makes sense, I think the right approach to fix this would be to either infer the number of classes from the data (by collecting all unique labels, which I think HF Datasets supports) or to allow the user to pass this in.

@vvssttkk
Copy link

this error only for cli
when u fixed this, or how I can do this myself?

@vvssttkk
Copy link

but, when run predict accept next error
image

@RaedShabbir
Copy link

RaedShabbir commented May 28, 2021

am running into the same issue, is there any workarounds?
'''
TextClassificationTransformer' object has no attribute 'num_classes'
'''

@stale
Copy link

stale bot commented Jul 27, 2021

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.

@stale stale bot added the wontfix This will not be worked on label Jul 27, 2021
@stale stale bot closed this as completed Aug 5, 2021
@jmwoloso
Copy link

see #216 and #215

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug / fix Something isn't working help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

7 participants