no-repeat n-gram
**No-repeat n-gram** is the **hard decoding constraint that blocks generation of any n-gram already produced earlier in the output** - it is a strict safeguard against repeated phrase loops.
**What Is No-repeat n-gram?**
- **Definition**: Constraint rule that forbids duplicate n-token sequences during generation.
- **Mechanism**: At each step, candidate tokens that would recreate an existing n-gram are masked out.
- **Parameter**: The n value controls strictness, with larger n allowing more flexibility.
- **Applicability**: Works with beam search and sampling-based decoding flows.
**Why No-repeat n-gram Matters**
- **Degeneration Control**: Prevents common repetitive loops in long-form generation.
- **Readability**: Reduces duplicated clauses and improves narrative flow.
- **Deterministic Safety**: Provides hard guarantees where soft penalties are insufficient.
- **Production Reliability**: Useful for public-facing assistants where repetition is highly visible.
- **Quality Consistency**: Stabilizes output under high-entropy sampling settings.
**How It Is Used in Practice**
- **Choose N Carefully**: Start with moderate n values and validate against fluency regression.
- **Domain Testing**: Check technical tasks where exact phrase reuse may be necessary.
- **Combined Policies**: Use with light penalties instead of excessive hard blocking where possible.
No-repeat n-gram is **a strong structural guardrail for repetitive generation failures** - it is highly effective but must be tuned to avoid over-constraining valid output.