RoBERTa classification RuntimeError: shape '[-1, 9]' is invalid for input of size 8
    m = MultiLabelBinarizer()

    X = pd.read_csv('data/data.csv', sep=None, engine='python')
    X = X.dropna()

    Y_train = m.fit_transform(X['labels'])
    Y_train2 = [list(i) for i in Y_train]

    data = pd.DataFrame({'text': pd.Series(X[text_col]), 'labels': Y_train2})
    data = data.dropna()

    train_df, eval_df = train_test_split(data, test_size=0.2)

    numLabels = len(pd.unique(X['labels])) # count of the labels

    model = MultiLabelClassificationModel('roberta', 'roberta-base', num_labels=numLabels, use_cuda=False)

    model.train_model(pd.DataFrame(train_df))


My data-structure for the label column is: [[0,1,0,0,0,1,0,0], [0,1,1,0,0,1,0,0], [0,0,0,0,0,0,0,1]....] for every row there is one label-list like [0,1,0,0,0,1,0,0] in the label-column 

And for the texts there is one text (newspaper article) per row.

(got it from that source: https://github.com/ThilinaRajapakse/simpletransformers#minimal-start-for-multilabel-classification)

the model can be trained if i train it with only 4 entries. But when i want to train it with the whole dataset it gives me that: RuntimeError: shape '[-1, 9]' is invalid for input of size 8:

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/simpletransformers/classification/multi_label_classification_model.py", line 121, in train_model
    return super().train_model(train_df, multi_label=multi_label, eval_df=eval_df, output_dir=output_dir, show_running_loss=show_running_loss, args=args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/simpletransformers/classification/classification_model.py", line 208, in train_model
    global_step, tr_loss = self.train(train_dataset, output_dir, multi_label=multi_label, show_running_loss=show_running_loss, eval_df=eval_df, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/simpletransformers/classification/classification_model.py", line 306, in train
    outputs = model(**inputs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/simpletransformers/custom_models/models.py", line 117, in forward
    loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1, self.num_labels))
RuntimeError: shape '[-1, 9]' is invalid for input of size 8


I have no idea where that size 8 comes from and what to do now since it works with very few entries.
Can anyone help?

[0,1,0,0,0,1,0,0] - it is 8 size, but your model expect size 9. 
it means that, your numLabels = 9. If you have 9 classes, then the  label-list in the label-colum should be like this: [0,1,0,0,0,1,0,0,0].
But I think you just need to pass the num_labels as 8
