@@ -58,7 +58,7 @@ labels = [
5858
5959## Two Approaches to Multilabel
6060
61- ### Approach 1: Ragged Lists (Recommended)
61+ ### Approach 1: Ragged Lists
6262
6363Each sample has a ** list of label indices** :
6464
@@ -72,14 +72,14 @@ labels = [
7272
7373** Pros:**
7474- Natural representation
75- - Saves memory
7675- Easy to construct
7776
7877** Cons:**
7978- Can't directly convert to numpy array
8079- Variable-length lists
80+ - Forward pass a bit slower (we convert to one-hot encodings behind the scene, on the fly for each batch)
8181
82- ### Approach 2: One-Hot Encoding
82+ ### Approach 2: One-Hot Encoding (Recommended)
8383
8484Each sample has a ** binary vector** (1 = label present, 0 = absent):
8585
@@ -96,8 +96,7 @@ labels = [
9696- Can store probabilities (not just 0/1)
9797
9898** Cons:**
99- - Memory-intensive for many labels
100- - Sparse representation
99+ - _ Might_ require a bit more work on your end to have this format
101100
102101## Complete Example: Ragged Lists
103102
@@ -247,14 +246,12 @@ predictions = result["prediction"]
247246### 1. Choose Your Approach
248247
249248** Use Ragged Lists if:**
250- - You have variable numbers of labels per sample
251- - Memory is a concern
252- - Data is naturally in list format
249+ - Data is naturally in list format...
250+ - ... and it wouldbe too costly to one-hot encode them
253251
254252** Use One-Hot if:**
255- - You need fixed-size arrays
253+ - You want more efficiency
256254- You want to store probabilities
257- - You're integrating with systems expecting one-hot
258255
259256### 2. Prepare Labels
260257
@@ -263,9 +260,6 @@ predictions = result["prediction"]
263260``` python
264261# List of lists (variable length)
265262labels = [[0 , 1 ], [1 , 2 , 3 ], [0 ]]
266-
267- # Convert to numpy array with dtype=object
268- y = np.array(labels, dtype = object )
269263```
270264
271265#### One-Hot Encoding
@@ -288,7 +282,7 @@ one_hot_labels = mlb.fit_transform(ragged_labels)
288282
289283### 3. Configure Loss Function
290284
291- ** Always use ` BCEWithLogitsLoss ` for multilabel:**
285+ ** We recommend to use ` BCEWithLogitsLoss ` for multilabel:**
292286
293287``` python
294288import torch
@@ -640,3 +634,4 @@ Ready to combine everything? Try adding categorical features to multilabel class
640634- ** Mixed features** : Combine multilabel with categorical features
641635- ** Explainability** : Understand which words trigger which labels
642636- ** API Reference** : See {doc}` ../api/index ` for detailed documentation
637+
0 commit comments