ConstraintDecoder

Struct ConstraintDecoder 

Source
pub struct ConstraintDecoder { /* private fields */ }
Expand description

The Constraint Decoder - makes forbidden tokens PHYSICALLY IMPOSSIBLE

This is not a filter. This is not a guard. This modifies the REALITY of what the model can produce.

Implementations§

Source§

impl ConstraintDecoder

Source

pub fn new(rules: &[String], vocab_size: usize) -> Self

Create a new constraint decoder from sealed rules

The forbidden space is computed ONCE at initialization. This is the “hard-wiring” - baked into the system.

Source

pub fn apply_constraints(&self, logits: &mut [f32])

Apply constraints to logits - THE CORE OF DIAMOND

This is where the magic happens:

  • Forbidden tokens get logit = -∞
  • After softmax: P(forbidden) = 0.0
  • The model CANNOT generate these tokens
Before:  [0.2, 0.3, 0.5, ...]  ← Any token possible
After:   [0.2, -∞, 0.5, ...]   ← Token 1 IMPOSSIBLE
Softmax: [0.28, 0.0, 0.72, ...] ← P(token1) = 0.0
Source

pub fn apply_constraints_with_context( &self, logits: &mut [f32], context: &[u32], )

Apply constraints with context (for sequence-based constraints)

Source

pub fn check_sequence(&self, tokens: &[u32]) -> Option<String>

Check if a token sequence violates constraints

Returns None if valid, Some(violation) if invalid. But in Diamond, this should NEVER return Some - violations are impossible by construction.

Source

pub fn space_hash(&self) -> [u8; 32]

Get the forbidden space hash (for attestation)

Source

pub fn stats(&self) -> ForbiddenSpaceStats

Get statistics about the forbidden space

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V