Language models often overuse recognizable phrases, sentence shapes, and stylistic tics. Simple token banning can suppress some phrases, but it damages fluency when the banned token is useful in other contexts. Sequence-aware repetition suppression intervenes only when an unwanted phrase or pattern is actually being formed, then backtracks and resamples from alternatives.
The Antislop work combines three pieces: a sampler that detects unwanted strings during generation and backtracks to the first token of the match, a profiling pipeline that compares model output to human baselines to identify overrepresented n-grams, and Final Token Preference Optimization (FTPO), a fine-tuning method that updates the model at the exact continuation token where a banned pattern would have appeared.
The key engineering idea is narrow intervention. Instead of deleting a word from the vocabulary or training on whole rejected completions, the system targets the first token of a problematic continuation under the context where it occurs. That preserves more of the model’s general distribution while reducing repetitive phraseology.
A pattern can be an n-gram, phrase, or regular expression. The sampler watches the generated text stream, not just the next-token distribution. This matters because a token may be harmless alone but undesirable as part of a longer sequence.
When a banned pattern is detected, generation rewinds to the first token that started the matched continuation. The sampler lowers or removes that continuation and samples again from the same context. The intervention happens locally, so earlier valid text remains intact.
FTPO turns sampler events into preference examples. The rejected item is the next token that would have begun the banned pattern; chosen items are coherent alternatives sampled for the same position. The loss pushes chosen logits above the rejected logit while regularizing the rest of the vocabulary toward the reference model.
Sequence-aware suppression distinguishes a bad continuation from a globally bad token. It changes the model or sampler only at the point where the unwanted pattern is being formed.
The sampler keeps a rolling text buffer and evaluates configured phrase or regex bans. If the buffer matches a pattern, the sampler identifies the first token in the match, rewinds to that position, applies a penalty or ban for the rejected continuation, and resumes generation.
def sample_with_pattern_backtracking(model, prompt, bans):
tokens = tokenize(prompt)
penalties = {}
while len(tokens) < max_length:
next_token = sample_next(model, tokens, penalties)
tokens.append(next_token)
match = find_banned_match(detokenize(tokens), bans)
if match:
start = token_index_for_char(tokens, match.start)
rejected = tokens[start]
tokens = tokens[:start]
penalties[(tuple(tokens), rejected)] = float("-inf")
return detokenize(tokens)
The automated pipeline generates baseline outputs, computes n-gram and phrase frequencies, and compares them with a human-writing profile. Overrepresented patterns become candidates for the ban list. User-supplied phrases and regex patterns can be merged when the application has domain-specific style constraints.
During antislop generation, each ban event can produce a training row: shared context, one rejected token, and several chosen tokens that pass a probability filter and do not trigger the pattern. FTPO optimizes the logit gap at that final token while applying MSE regularization to avoid broad distribution drift.
def ftpo_loss(logits, reference_logits, rejected_id, chosen_ids):
gap = mean(logits[chosen_ids] - logits[rejected_id])
preference = softplus(-beta * gap)
target_ids = chosen_ids + [rejected_id]
non_target = all_vocab_except(target_ids)
tether = mse(logits[non_target], reference_logits[non_target])
target_tether = mse(logits[target_ids], reference_logits[target_ids])
return preference + lambda_mse * tether + lambda_target * target_tether
Applications that generate user-facing prose often need to avoid repetitive phrasing without making the model terse or mechanical. Pattern-level suppression lets teams encode a house style as banned continuations and then fine-tune the model toward better alternatives.
Backtracking samplers can generate cleaner synthetic data by rejecting overused phrases as they appear. Those same rejection events become fine-grained preference examples for later training, creating a feedback loop between decoding and fine-tuning.
Small open-weight models can be adapted away from distinctive repetitive phrases with LoRA or late-layer training. Because FTPO focuses on final-token choices, it can be less disruptive than broad preference optimization over entire completions.
Store phrase, n-gram, and regex bans as versioned artifacts. Each entry should have a source, creation date, and evaluation status. Automatically mined patterns should be reviewed before production use because frequency alone does not prove a phrase is bad.
{
"phrase": "example repeated phrase",
"match_type": "string",
"source": "ngram_profile",
"enabled": true,
"min_context_tokens": 8
}
Chosen alternatives should be plausible continuations, not arbitrary tokens that merely avoid the ban. Filtering by minimum probability mass helps ensure FTPO teaches coherent substitutions rather than flattening the model’s local distribution.
Most vocabulary logits should stay close to the original model. FTPO’s non-target logit regularization is important because the goal is local phrase suppression, not a broad rewrite of voice, reasoning behavior, or domain knowledge.