Similarity-Based Token Filtering for Safe Foundation Model Decoding

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing large language models (LLMs) face high computational costs and are slow for user experiences due to inefficiencies in filtering out toxic, improper, or copyright-infringing content during generation, with existing safeguarding methods being inflexible, computationally expensive, or adversely impacting output quality.

Innovation Solution

Implement a similarity-based filtering method that uses an external validator to compare candidate tokens with demonstration examples of unsafe content, rejecting tokens with high similarity and allowing valid tokens to proceed through decoding, thereby enhancing token-sampling methods like beam search to ensure safety constraints are met without retraining.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If existing safeguarding methods are used to filter toxic and improper content, then safety constraints are met, but computational cost increases and generation speed decreases

Engineering Contradiction:
Improvesafety constraint complianceVSAvoidgeneration speed
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The patent pre-processes demonstration examples of unsafe content before runtime, organizing them into structured formats with embedding vectors. This preliminary organization allows the runtime system to quickly compare candidate tokens against pre-processed examples using similarity search, avoiding the need to process raw demonstration data during generation and thus maintaining high speed while ensuring safety compliance.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent introduces an intermediate validation layer that sits between the foundation model's token generation and the final output. This validator uses similarity comparison against pre-processed demonstration examples to filter unsafe tokens efficiently. The intermediary structure enables safety checking without requiring the foundation model itself to be retrained or modified, preserving generation speed while enforcing safety constraints.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Reliability

If existing safeguarding methods are used to filter toxic and improper content, then safety constraints are met, but computational overhead increases

Engineering Contradiction:
Improvesafety constraint complianceVSAvoidcomputational overhead
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent performs computationally intensive operations in advance: organizing demonstration examples into structured formats, computing embedding vectors for all demonstration tokens, and creating indexed data structures. These pre-processing steps convert expensive runtime operations into cheap lookups and similarity comparisons, dramatically reducing computational overhead during actual content generation while maintaining rigorous safety validation.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent transforms the safety validation problem from exact matching or complex classification into a similarity comparison task using embedding vectors. By changing the parameter space from discrete token categories to continuous vector similarity measurements, the system achieves efficient computation through approximate nearest neighbor search and cosine similarity calculations, reducing computational overhead while improving safety detection accuracy.

Inventive Principle:
Principle #35Parameter changes

3Reliability

If traditional filtering methods are used, then unsafe content is removed, but output quality may be adversely impacted

Engineering Contradiction:
Improvesafe content generationVSAvoidoutput quality
Core Design Contradiction:
ReliabilityVSManufacturing precision

Solution Approach 1:

The patent implements dynamic token validation where the safety check adapts to the specific context of each generation step. Instead of applying static filtering rules, the system dynamically computes similarity between candidate tokens and relevant demonstration examples, allowing nuanced decisions about whether to reject tokens. This dynamic approach preserves output quality by avoiding over-rejection of safe tokens while still blocking unsafe content effectively.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent incorporates feedback mechanisms where the validation results influence subsequent token selection. When unsafe tokens are rejected, the system can adjust the sampling distribution or try alternative tokens while maintaining context coherence. This feedback loop ensures that safety constraints are met without permanently degrading output quality, as the model can recover from rejected tokens and generate high-quality safe alternatives.

Inventive Principle:
Principle #23Feedback

Data Source

PatentUS20260050820A1Systems, apparatuses, methods, and non-transitory computer-readable storage media employing similarity-based filtering for foundation models
Publication Date: 2026.02.19 HUAWEI TECH CO LTD
  • US20260050820A1 patent drawing
  • US20260050820A1 patent drawing
  • US20260050820A1 patent drawing

AI summary

A computerized method has the steps of: at a first timestep: obtaining a first candidate token, the first candidate token being generated by a foundation model based on an input; and based on a similarity comparison between the first candidate token and one or more sample tokens, allowing the foundation model to use the first candidate token for generating an output.