Skip to content
Back to skills

Fill Mask Entity Classification

ASecurity

Uses a fine-tuned masked language model to classify candidate entity spans by comparing fill-mask probabilities for positive vs negative marker tokens.

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

Works with

  • api

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill fill-mask-entity-classification --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fill Mask Entity Classification?

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

Security grade badge for Fill Mask Entity Classification
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-fill-mask-entity-classification/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-fill-mask-entity-classification)

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-fill-mask-entity-classification
description: >
  Uses a fine-tuned masked language model to classify candidate entity spans by comparing fill-mask probabilities for positive vs negative marker tokens.
---
# Fill-Mask Entity Classification

## Overview

Instead of training a separate classifier for entity type detection, leverage masked language modeling: replace a candidate entity span with a [MASK] token, then compare the model's fill-mask probabilities for a positive marker (e.g., "$") vs a negative marker (e.g., "#"). If the positive marker is more likely, the span is classified as an entity. Fine-tune the MLM on domain text where markers replace known entities vs non-entities.

## Quick Start

```python
from transformers import pipeline

ENTITY_SYMBOL = "$"
NON_ENTITY_SYMBOL = "#"

mlm = pipeline("fill-mask", model="fine-tuned-mlm-model", device=0)

def classify_candidates(sentences_with_mask):
    results = mlm(sentences_with_mask, targets=[f" {ENTITY_SYMBOL}", f" {NON_ENTITY_SYMBOL}"])
    predictions = []
    for (pos_result, neg_result), phrase in zip(results, candidate_phrases):
        if pos_result["score"] > neg_result["score"] * 2:
            predictions.append(phrase)
    return predictions
```

## Workflow

1. Fine-tune an MLM where "$" replaces entity mentions and "#" replaces non-entity noun phrases
2. At inference, extract candidate noun phrases from text (capitalization heuristics, NP chunking)
3. Replace each candidate with [MASK] in its sentence context
4. Run fill-mask and compare probabilities of "$" vs "#"
5. Accept candidates where entity marker probability dominates (e.g., 2x threshold)

## Key Decisions

- **Marker tokens**: Use single special tokens added to vocabulary; avoid common words
- **Threshold ratio**: 2x is typical; higher = more precision, lower = more recall
- **Candidate extraction**: Capitalized noun phrases, regex patterns, or NP chunker
- **Batching**: Process multiple masked sentences in batch for GPU efficiency

## References

- [External_Datasets_Matching + MLM](https://www.kaggle.com/code/chienhsianghung/external-datasets-matching-mlm)

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.