Which statement best describes multi-label classification?
Think about whether an example can belong to more than one category at the same time.
Multi-label classification means each example can have multiple labels at once, unlike single-label classification where only one label is assigned.
You want to build a multi-label classifier. Which model architecture is most suitable?
Consider how the output layer should handle multiple labels independently.
Multi-label classification requires independent probabilities for each label, so sigmoid activation on multiple outputs is appropriate.
Which metric is best suited to evaluate a multi-label classification model?
Think about a metric that counts label-wise errors in multi-label settings.
Hamming Loss counts how many labels are incorrectly predicted per instance, making it suitable for multi-label tasks.
What is the output of the following Python code snippet?
import numpy as np from sklearn.preprocessing import MultiLabelBinarizer labels = [['cat', 'dog'], ['dog'], ['mouse', 'cat'], []] mlb = MultiLabelBinarizer(classes=['cat', 'dog', 'mouse']) encoded = mlb.fit_transform(labels) print(encoded.tolist())
Check the order of classes and how MultiLabelBinarizer encodes labels.
MultiLabelBinarizer encodes each label as a binary vector in the order of classes given.
Given this training code snippet for a multi-label classifier, what is the main cause of the error?
import torch
import torch.nn as nn
model = nn.Sequential(
nn.Linear(10, 3),
nn.Softmax(dim=1)
)
criterion = nn.BCEWithLogitsLoss()
inputs = torch.randn(5, 10)
targets = torch.randint(0, 2, (5, 3)).float()
outputs = model(inputs)
loss = criterion(outputs, targets)
Consider what BCEWithLogitsLoss expects as input and what Softmax outputs.
BCEWithLogitsLoss expects raw logits, so applying Softmax before it is incorrect and causes training issues.