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.

Expected more than 1 value per channel when training

See original GitHub issue

I am following the instructions to fit the model. However, I am getting this error: ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 50])

How to resolve this? What does this mean?

from contextualized_topic_models.models.ctm import CTM
from contextualized_topic_models.utils.data_preparation import TextHandler
from contextualized_topic_models.utils.data_preparation import bert_embeddings_from_file
from contextualized_topic_models.datasets.dataset import CTMDataset

handler = TextHandler("topic_tst.txt")
handler.prepare() # create vocabulary and training data

training_bert = bert_embeddings_from_file("topic_tst.txt", "./roberta-large-nli-mean-tokens")


training_dataset = CTMDataset(handler.bow, training_bert, handler.idx2token)

ctm = CTM(input_size=len(handler.vocab), bert_input_size=1024, inference_type="combined", n_components=50)

ctm.fit(training_dataset) # run the model

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vinidcommented, Sep 9, 2020

Yay! That’s great!

I’m closing the issue then 😃

1reaction
rajevvcommented, Sep 9, 2020

Update: Add other lines in the file does solve the problem. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Expected more than 1 value per channel when training
The error is most likely thrown during training and if the current batch only contains a single sample. As you've explained this might...
Read more >
Expected more than 1 value per channel? - Stack Overflow
This stops BatchNorm layers from updating their mean and variance, and allows input of just one sample. Use model.train() to resume training ......
Read more >
Error: Expected more than 1 value per channel when training
It looks like you pass just 1 example during training. I'm guessing you've got a Batch Normalization layer in your network and it...
Read more >
ValueError: Expected more than 1 value per channel when ...
When I run train.py file reported an error, and then modified the drop in the dataloader_ Last is true Running again is the...
Read more >
error Expected more than 1 value per channel when training ...
So, the error occurs either if your batch size equals to 1, or if size of your dataset modulo batch size is equal...
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