pub struct AttentionVisualizer<F: Float + Debug> {
pub num_heads: usize,
pub sequence_length: usize,
pub aggregation: AttentionAggregation,
pub attention_cache: HashMap<String, ArrayD<F>>,
pub target_layers: Vec<String>,
}
Expand description
Attention visualizer for transformer models
Fields§
§num_heads: usize
Number of attention heads
sequence_length: usize
Sequence length
aggregation: AttentionAggregation
Aggregation strategy
attention_cache: HashMap<String, ArrayD<F>>
Cached attention weights
target_layers: Vec<String>
Layer names to visualize
Implementations§
Source§impl<F> AttentionVisualizer<F>
impl<F> AttentionVisualizer<F>
Sourcepub fn new(
num_heads: usize,
sequence_length: usize,
aggregation: AttentionAggregation,
target_layers: Vec<String>,
) -> Self
pub fn new( num_heads: usize, sequence_length: usize, aggregation: AttentionAggregation, target_layers: Vec<String>, ) -> Self
Create a new attention visualizer
Sourcepub fn cache_attention_weights(
&mut self,
layer_name: String,
attention_weights: ArrayD<F>,
)
pub fn cache_attention_weights( &mut self, layer_name: String, attention_weights: ArrayD<F>, )
Cache attention weights for a layer
Sourcepub fn visualize_attention(&self, layer_name: &str) -> Result<ArrayD<F>>
pub fn visualize_attention(&self, layer_name: &str) -> Result<ArrayD<F>>
Visualize attention patterns
Sourcepub fn aggregate_attention_heads(
&self,
attention_weights: &ArrayD<F>,
) -> Result<ArrayD<F>>
pub fn aggregate_attention_heads( &self, attention_weights: &ArrayD<F>, ) -> Result<ArrayD<F>>
Aggregate attention across multiple heads
Sourcepub fn attention_rollout(&self) -> Result<ArrayD<F>>
pub fn attention_rollout(&self) -> Result<ArrayD<F>>
Generate attention rollout visualization
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for AttentionVisualizer<F>
impl<F> RefUnwindSafe for AttentionVisualizer<F>where
F: RefUnwindSafe,
impl<F> Send for AttentionVisualizer<F>where
F: Send,
impl<F> Sync for AttentionVisualizer<F>where
F: Sync,
impl<F> Unpin for AttentionVisualizer<F>
impl<F> UnwindSafe for AttentionVisualizer<F>where
F: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more