Skip to content
Back to skills

In Task Pretraining

ASecurity

Further pretrains a transformer with masked language modeling on the target task's own text before fine-tuning.

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

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill in-task-pretraining --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of In Task Pretraining?

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

Security grade badge for In Task Pretraining
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-in-task-pretraining/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-in-task-pretraining)

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-in-task-pretraining
description: >
  Further pretrains a transformer with masked language modeling on the target task's own text before fine-tuning.
---
# In-Task Pre-Training (ITPT)

## Overview

Before fine-tuning a pretrained transformer on your target task, run additional masked language modeling (MLM) on the task's own text corpus. This adapts the model's language understanding to the domain and vocabulary of your specific data, often improving downstream performance by 0.5-2% RMSE.

## Quick Start

```python
from transformers import (
    AutoModelForMaskedLM, AutoTokenizer,
    DataCollatorForLanguageModeling, TrainingArguments, Trainer
)

tokenizer = AutoTokenizer.from_pretrained("roberta-base")
model = AutoModelForMaskedLM.from_pretrained("roberta-base")

# Tokenize task text
def tokenize(examples):
    return tokenizer(examples["text"], truncation=True, max_length=256)

dataset = dataset.map(tokenize, batched=True)
collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm_probability=0.15)

args = TrainingArguments(
    output_dir="./itpt", num_train_epochs=5,
    per_device_train_batch_size=16, learning_rate=5e-5,
)
trainer = Trainer(model=model, args=args, train_dataset=dataset, data_collator=collator)
trainer.train()
model.save_pretrained("./itpt-roberta")
```

## Workflow

1. Collect all text from train + test (no labels needed)
2. Run MLM pre-training for 3-10 epochs with 15% masking
3. Save the adapted checkpoint
4. Fine-tune from the adapted checkpoint on the labeled task

## Key Decisions

- **Epochs**: 3-10; watch perplexity on held-out text, stop when it plateaus
- **Include test text**: Yes — MLM is unsupervised, no leakage
- **MLM probability**: 0.15 is standard; 0.20 for very domain-specific text
- **Learning rate**: Same as pre-training (5e-5), not fine-tuning rate

## References

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

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.