Skip to content
Back to skills

Label Smoothing Binary

ASecurity

Applies label smoothing to binary cross-entropy loss to reduce overconfidence and improve generalization in text classification.

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
datapythongoawsgit

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill label-smoothing-binary --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Label Smoothing Binary?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Label Smoothing Binary
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-label-smoothing-binary/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-label-smoothing-binary)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nlp-label-smoothing-binary
description: >
  Applies label smoothing to binary cross-entropy loss to reduce overconfidence and improve generalization in text classification.
---
# Label Smoothing (Binary)

## Overview

Replace hard labels (0/1) with softened labels (ε, 1-ε) during training. This prevents the model from becoming overconfident on training examples, acts as implicit regularization, and improves calibration of predicted probabilities. Especially useful in text classification where boundary examples are ambiguous.

## Quick Start

```python
# Keras / TensorFlow
import tensorflow as tf

loss = tf.keras.losses.BinaryCrossentropy(label_smoothing=0.02)
model.compile(optimizer='adam', loss=loss, metrics=['accuracy'])

# PyTorch (manual)
import torch
import torch.nn.functional as F

def smooth_bce(preds, targets, smoothing=0.02):
    """Binary cross-entropy with label smoothing."""
    targets = targets * (1 - smoothing) + 0.5 * smoothing
    return F.binary_cross_entropy_with_logits(preds, targets)

# Usage in training loop
loss = smooth_bce(logits, labels, smoothing=0.02)
loss.backward()
```

## Workflow

1. Choose smoothing factor ε (typically 0.01-0.1)
2. Replace loss function with smoothed version
3. Train as usual — no other changes needed
4. At inference, predictions are naturally better calibrated

## Key Decisions

- **Smoothing value**: 0.02 for clean labels, 0.1 for noisy labels
- **Effect**: Label 1→0.99, label 0→0.01 (with ε=0.02) — tiny change, significant regularization
- **vs dropout**: Complementary — use both for best results
- **When to avoid**: Very small datasets where every label is precious and verified correct
- **Calibration**: Smoothed models output more calibrated probabilities — good for ensembling

## References

- LLM - Detect AI Generated Text (Kaggle)
- Source: [detect-fake-text-kerasnlp-tf-torch-jax-train](https://www.kaggle.com/code/awsaf49/detect-fake-text-kerasnlp-tf-torch-jax-train)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.