Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/IBM/activation-steering
/ functions
Functions
52 in github.com/IBM/activation-steering
⨍
Functions
52
◇
Types & classes
8
↓ 50 callers
Function
log
Log a message to the console and/or file based on the current configuration. Args: message (str): The message to log. style
activation_steering/config.py:129
↓ 6 callers
Method
clean_text
Clean the input text by replacing special tokens. Args: text: The input text to be cleaned. Returns:
activation_steering/steering_dataset.py:103
↓ 6 callers
Function
get_model_layer_list
Get the list of layers from a model. This function handles different model architectures to retrieve their layers. Args: model:
activation_steering/malleable_model.py:664
↓ 5 callers
Function
custom_progress
Create a custom progress bar for iterating over items. Args: iterable: The iterable to process. description: A string descri
activation_steering/utils.py:50
↓ 3 callers
Method
_check_single_condition
Check if a single condition is met. Args: condition: The condition to check. Returns: Boolean indic
activation_steering/leash_layer.py:281
↓ 3 callers
Method
initialize_log_files
Initialize log files for all configured classes.
activation_steering/config.py:53
↓ 2 callers
Method
compute_similarity
Compute the cosine similarity between two tensors. Args: x: First tensor. y: Second tensor. Returns
activation_steering/leash_layer.py:299
↓ 2 callers
Method
respond
Generate a response to a given prompt using the underlying language model. Args: prompt: The input prompt to generate a
activation_steering/malleable_model.py:419
↓ 2 callers
Method
use_explained_variance
Apply explained variance scaling to a steering vector. This method scales the steering vector based on its explained variance,
activation_steering/malleable_model.py:144
↓ 1 callers
Method
_apply_multi_behaviors
Apply multiple behavior vectors to the hidden states based on rules. Args: hidden_states: The hidden states to modify.
activation_steering/leash_layer.py:232
↓ 1 callers
Method
_apply_ooi_normalization
Apply out-of-input (OOI) preventive normalization to hidden states. Args: hidden_states: The hidden states to normalize.
activation_steering/leash_layer.py:312
↓ 1 callers
Method
_apply_single_behavior
Apply a single behavior vector to the hidden states. Args: hidden_states: The hidden states to modify.
activation_steering/leash_layer.py:210
↓ 1 callers
Method
_evaluate_rule
Evaluate a steering rule. Args: rule: The rule to evaluate. Returns: Boolean indicating whether the
activation_steering/leash_layer.py:257
↓ 1 callers
Method
_process_multi_conditions
Process multiple conditions for multi-steering. Args: hidden_state: The hidden state to process.
activation_steering/leash_layer.py:179
↓ 1 callers
Method
_process_single_condition
Process a single condition for steering. Args: hidden_state: The hidden state to process.
activation_steering/leash_layer.py:151
↓ 1 callers
Method
_save_analysis_results
Save the analysis results from find_best_condition_point to a file. Args: analysis_results: Dictionary containing the an
activation_steering/malleable_model.py:596
↓ 1 callers
Function
batched_get_hiddens
Retrieve the hidden states from the specified layers of the language model for the given input strings. Args: model: The model to ge
activation_steering/steering_vector.py:254
↓ 1 callers
Method
default
Return a default instance of LayerControlParams. Returns: A LayerControlParams instance with default values.
activation_steering/utils.py:27
↓ 1 callers
Method
generate
Generate output using the underlying model. This method is a pass-through to the generate method of the wrapped model. It al
activation_steering/malleable_model.py:391
↓ 1 callers
Method
get_file_path
Get the log file path for a specific class. Args: class_name (str): The class name to get the file path for. Re
activation_steering/config.py:116
↓ 1 callers
Method
is_verbose
Check if verbose logging is enabled for a specific class. Args: class_name (str): The class name to check. Defaults to "
activation_steering/config.py:77
↓ 1 callers
Function
project_onto_direction
Project a matrix H onto a direction vector. Args: H: The matrix to project. direction: The direction vector to project onto.
activation_steering/steering_vector.py:321
↓ 1 callers
Function
read_representations
Extract representations from the language model based on the contrast dataset. Args: model: The model to extract representations fro
activation_steering/steering_vector.py:121
↓ 1 callers
Method
reset_class
Reset the class-level attributes of LeashLayer.
activation_steering/leash_layer.py:346
↓ 1 callers
Method
reset_instance
Reset this instance of LeashLayer to its default state.
activation_steering/leash_layer.py:335
↓ 1 callers
Method
reset_leash_to_default
Reset the model's steering configuration to its default state. This method removes all applied steering configurations, including
activation_steering/malleable_model.py:364
↓ 1 callers
Function
return_default_suffixes
Return a list of default suffixes used in the CAIS representation engineering paper. Returns: A list of string suffixes.
activation_steering/utils.py:84
↓ 1 callers
Function
save_pca_figures
Save PCA analysis figures for each hidden layer and create a macroscopic x-axis layer analysis plot. Args: layer_hiddens: A dictiona
activation_steering/steering_vector.py:343
↓ 1 callers
Method
should_log_to_file
Check if logging to a file is enabled for a specific class. Args: class_name (str): The class name to check. Re
activation_steering/config.py:103
↓ 1 callers
Method
steer
Apply (conditional) activation steering to the model. This method configures the model to apply behavior modifications based on
activation_steering/malleable_model.py:172
Method
__call__
Make the MalleableModel instance callable. This method allows the MalleableModel to be used like a function, delegating to the under
activation_steering/malleable_model.py:648
Method
__init__
Initialize a LogConfig instance. Args: enabled (bool): Initial enabled state for logging.
activation_steering/config.py:14
Method
__init__
Initialize the SteeringDataset. Args: tokenizer: The tokenizer used to tokenize and format the examples. exa
activation_steering/steering_dataset.py:16
Method
__init__
Initialize a LeashLayer. Args: layer: The underlying layer to be wrapped. layer_id: The ID of this layer in
activation_steering/leash_layer.py:28
Method
__init__
Initialize a MalleableModel instance. This constructor wraps a pre-trained language model and its associated tokenizer, prep
activation_steering/malleable_model.py:42
Method
__new__
(cls)
activation_steering/config.py:46
Method
config
Get the configuration of the underlying model. This property provides access to the configuration object of the wrapped pre-
activation_steering/malleable_model.py:82
Method
device
Get the device on which the underlying model is located. This property returns the device (CPU or GPU) where the model tensors
activation_steering/malleable_model.py:100
Method
find_best_condition_point
Find the optimal condition point for steering. Args: positive_strings: List of strings that should trigger the condition
activation_steering/malleable_model.py:488
Method
forward
Perform a forward pass through this layer, applying steering if configured. Args: hidden_states: The input hidden states
activation_steering/leash_layer.py:96
Method
forward
Perform a forward pass through the model. This method delegates to the underlying model's forward method. Args:
activation_steering/malleable_model.py:632
Method
insert_vline
(token: str)
activation_steering/steering_dataset.py:116
Method
load
Load a SteeringVector from a file. Args: file_path: The path to load the file from. If it doesn't end with '.svec',
activation_steering/steering_vector.py:92
Method
multisteer
Configure multi-steering for this layer. Args: behavior_vectors: List of behavior vectors to apply. conditio
activation_steering/leash_layer.py:69
Method
multisteer
Apply multiple conditional steering rules to the model. This method configures the model to apply multiple behavior modifications
activation_steering/malleable_model.py:263
Method
respond_batch_sequential
(self, prompts, settings=None, use_chat_template=True)
activation_steering/malleable_model.py:467
Method
save
Save the SteeringVector to a file. Args: file_path: The path to save the file to. If it doesn't end with '.svec',
activation_steering/steering_vector.py:64
Method
set_file_output
Set whether to output logs to a file for a specific class or globally. Args: enabled (bool): Whether to enable file outp
activation_steering/config.py:90
Method
set_verbose
Set the verbose state for a specific class or globally. Args: verbose (bool): Whether to enable verbose logging.
activation_steering/config.py:65
Method
steer
Configure steering for this layer. Args: behavior_vector: The behavior vector to apply. condition_projector:
activation_steering/leash_layer.py:44
Method
train
Train a SteeringVector for a given model and tokenizer using the provided dataset. Args: model: The model to train the s
activation_steering/steering_vector.py:35
Method
unwrap
Remove steering modifications and return the original model. This method removes the LeashLayer wrappers applied to the model during
activation_steering/malleable_model.py:119