question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bulding multiclass classification model

See original GitHub issue

Hi,

I’m opening this issue as a continuation of #1001. I understand now how SoftmaxLikelihood works (thanks a lot!) but I haven’t been able to perform multiclass classification because I’m encountering the following error during a call to the marginal log likelihood:

Traceback (most recent call last):
  File "multiclass_classifier_for_issue.py", line 91, in <module>
    log_lik, kl_div, log_prior = mll(output, y_batch,combine_terms=False)
  File "/home/mgarort/housekeeping/virtualenv/ml2/lib/python3.6/site-packages/torch/tensor.py", line 421, in __iter__
    raise TypeError('iteration over a 0-d tensor')
TypeError: iteration over a 0-d tensor

I think I’m using SoftmaxLikelihood correctly. I’ve created a short clean script that reproduces the error. multiclass_classifier_for_issue.zip

For convenience, I have created a Colab notebook where you can execute the code directly https://colab.research.google.com/drive/1Sg8kiqWajy6fyeu5G0sgZhR1Pqdkj8tS

Do you think you could take a look at it and let me know what the problem might be? In the hyperparameters section, you can set mixing_weights to be True or False depending on whether a mixing matrix is desired in the softmax likelihood or not. If True, the GP model’s number of tasks is 100, and if False, it is the number of classes (10 in this case, for MNIST). In both cases I obtain the same error.

Thanks a lot in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
gpleisscommented, Dec 23, 2019

Thanks for the Colab notebook! It looks like you might have some code that’s from an older version of the tutorial. The output of the mll by default is a scalar. If you pass the combine_terms=False to the mll object, then you can get the different components of the variational elbo - log_lik, kl_div, log_prior - on their own. (This is mostly useful for debugging purposes.)

To fix this, you should either pass the combine_terms=False argument to the mll - e.g.

mll = VariationalELBO(likelihood, model, train_y.numel(), combine_terms=False)
# ...
for i in range(num_epochs):
    # ...
    log_lik, kl_div, log_prior = mll(output, y_batch)
    loss = -(log_lik - kl_div + log_prior)

or use the following lines in the training loop:

mll = VariationalELBO(likelihood, model, train_y.numel())
# ...
for i in range(num_epochs):
    # ...
    loss = -mll(output, y_batch)

The tutorial has a correct training loop.

0reactions
gaoxiaoyaocommented, Jun 17, 2020

@KeAWang 谢谢你的指教,明白了

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to building Multiclass Text Classification Model
Learn how to build a multiclass text classification model from opensource dataset in Python from scratch with this end-to-end guide.
Read more >
Build multi-class classification models with Amazon Redshift ML
This post specifically focuses on creating models in Amazon Redshift using the multi-class classification problem type, which consists on ...
Read more >
A Step-By-Step Guide to Building A Multiclass Classifier for ...
This post contains a step-by-step guide for building and training a simple multi-class classification model for classifying breast tissue.
Read more >
A Wide Variety of Models for Multi-class Classification - Medium
A Wide Variety of Models for Multi-class Classification · Multinomial/Multi-class Logistic Classification, · Decision Tree, · Random Forest, · Naïve Bayes (NB), ...
Read more >
How to Solve a Multi Class Classification Problem with Python?
For training the model, the training data is expected to have sufficient examples belonging to each class so that the machine learning model...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found