Skip to content
Back to skills

Transformer Lgbm Stacking

ASecurity

Two-stage stacking: transformer predictions plus hand-crafted features feed into a LightGBM meta-learner.

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

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill transformer-lgbm-stacking --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Transformer Lgbm Stacking?

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

Security grade badge for Transformer Lgbm Stacking
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-transformer-lgbm-stacking/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-transformer-lgbm-stacking)

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-transformer-lgbm-stacking
description: >
  Two-stage stacking: transformer predictions plus hand-crafted features feed into a LightGBM meta-learner.
---
# Transformer + LightGBM Stacking

## Overview

Fine-tune a transformer (e.g., DeBERTa) for initial predictions, then use those predictions alongside hand-crafted features (text statistics, overlap metrics) as inputs to a LightGBM meta-learner. This captures both deep semantic understanding and surface-level patterns that transformers miss.

## Quick Start

```python
import lightgbm as lgb

# Stage 1: Get transformer OOF predictions per fold
for fold in range(n_folds):
    model = train_transformer(train[train.fold != fold])
    train.loc[train.fold == fold, "pred"] = predict(model, train[train.fold == fold])

# Stage 2: Stack with hand-crafted features
features = ["pred", "word_count", "overlap_ratio", "ner_overlap", "misspelling_count"]
for fold in range(n_folds):
    dtrain = lgb.Dataset(train[train.fold != fold][features], label=y_train)
    dval = lgb.Dataset(train[train.fold == fold][features], label=y_val)
    model = lgb.train(params, dtrain, valid_sets=[dval],
                      callbacks=[lgb.early_stopping(30)])
```

## Workflow

1. Fine-tune transformer with K-fold CV, save OOF predictions
2. Engineer hand-crafted features (text stats, overlaps, spelling)
3. Combine transformer predictions + features as LightGBM input
4. Train LightGBM per fold with early stopping
5. Average fold predictions for final output

## Key Decisions

- **Why stack**: Transformers miss surface features; GBDT captures them well
- **OOF predictions**: Use out-of-fold predictions to avoid leakage in stacking
- **Early stopping**: 30 rounds patience on validation RMSE prevents overfitting
- **Per-target models**: Train separate LightGBM for each target variable

## References

- CommonLit - Evaluate Student Summaries (Kaggle)
- Source: [tuned-debertav3-lgbm-autocorrect](https://www.kaggle.com/code/cody11null/tuned-debertav3-lgbm-autocorrect)

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.