Skip to content
Back to skills

Sqrt Mse Loss

ASecurity

Uses square root of MSE as training loss to directly optimize for RMSE evaluation metric alignment.

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
developmentpython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill sqrt-mse-loss --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sqrt Mse Loss?

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

Security grade badge for Sqrt Mse Loss
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-sqrt-mse-loss/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-sqrt-mse-loss)

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-sqrt-mse-loss
description: >
  Uses square root of MSE as training loss to directly optimize for RMSE evaluation metric alignment.
---
# Sqrt MSE Loss

## Overview

When the competition metric is RMSE, training with standard MSE can misalign gradients because MSE squares the errors. Using `sqrt(MSE)` as the loss directly optimizes the metric you're evaluated on. This often improves final scores by 0.01-0.03 RMSE compared to plain MSE, especially when error magnitudes vary.

## Quick Start

```python
import torch
import torch.nn as nn

class RMSELoss(nn.Module):
    def __init__(self, eps=1e-8):
        super().__init__()
        self.mse = nn.MSELoss()
        self.eps = eps

    def forward(self, preds, targets):
        return torch.sqrt(self.mse(preds, targets) + self.eps)

# Usage
criterion = RMSELoss()
loss = criterion(model_output.view(-1), labels.view(-1))
loss.backward()
```

## Workflow

1. Replace `nn.MSELoss()` with `RMSELoss()` in training loop
2. Add small epsilon inside sqrt for numerical stability
3. Train as usual — gradients are automatically adjusted

## Key Decisions

- **Epsilon**: 1e-8 prevents NaN when loss approaches zero
- **When to use**: Whenever the evaluation metric is RMSE
- **Gradient behavior**: Sqrt amplifies gradients for small errors, dampens for large — acts as implicit focus on hard examples
- **Alternatives**: Huber loss if you want robustness to outliers instead

## References

- CommonLit Readability Prize (Kaggle)
- Source: [commonlit-readability-prize-roberta-torch-infer-3](https://www.kaggle.com/code/rhtsingh/commonlit-readability-prize-roberta-torch-infer-3)

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…