MCPcopy Create free account

hub / github.com/IBM/activation-steering / functions

Functions52 in github.com/IBM/activation-steering

↓ 50 callersFunctionlog
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 callersMethodclean_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 callersFunctionget_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 callersFunctioncustom_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 callersMethod_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 callersMethodinitialize_log_files
Initialize log files for all configured classes.
activation_steering/config.py:53
↓ 2 callersMethodcompute_similarity
Compute the cosine similarity between two tensors. Args: x: First tensor. y: Second tensor. Returns
activation_steering/leash_layer.py:299
↓ 2 callersMethodrespond
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 callersMethoduse_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 callersMethod_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 callersMethod_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 callersMethod_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 callersMethod_evaluate_rule
Evaluate a steering rule. Args: rule: The rule to evaluate. Returns: Boolean indicating whether the
activation_steering/leash_layer.py:257
↓ 1 callersMethod_process_multi_conditions
Process multiple conditions for multi-steering. Args: hidden_state: The hidden state to process.
activation_steering/leash_layer.py:179
↓ 1 callersMethod_process_single_condition
Process a single condition for steering. Args: hidden_state: The hidden state to process.
activation_steering/leash_layer.py:151
↓ 1 callersMethod_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 callersFunctionbatched_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 callersMethoddefault
Return a default instance of LayerControlParams. Returns: A LayerControlParams instance with default values.
activation_steering/utils.py:27
↓ 1 callersMethodgenerate
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 callersMethodget_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 callersMethodis_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 callersFunctionproject_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 callersFunctionread_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 callersMethodreset_class
Reset the class-level attributes of LeashLayer.
activation_steering/leash_layer.py:346
↓ 1 callersMethodreset_instance
Reset this instance of LeashLayer to its default state.
activation_steering/leash_layer.py:335
↓ 1 callersMethodreset_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 callersFunctionreturn_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 callersFunctionsave_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 callersMethodshould_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 callersMethodsteer
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
Methodconfig
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
Methoddevice
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
Methodfind_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
Methodforward
Perform a forward pass through this layer, applying steering if configured. Args: hidden_states: The input hidden states
activation_steering/leash_layer.py:96
Methodforward
Perform a forward pass through the model. This method delegates to the underlying model's forward method. Args:
activation_steering/malleable_model.py:632
Methodinsert_vline
(token: str)
activation_steering/steering_dataset.py:116
Methodload
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
Methodmultisteer
Configure multi-steering for this layer. Args: behavior_vectors: List of behavior vectors to apply. conditio
activation_steering/leash_layer.py:69
Methodmultisteer
Apply multiple conditional steering rules to the model. This method configures the model to apply multiple behavior modifications
activation_steering/malleable_model.py:263
Methodrespond_batch_sequential
(self, prompts, settings=None, use_chat_template=True)
activation_steering/malleable_model.py:467
Methodsave
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
Methodset_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
Methodset_verbose
Set the verbose state for a specific class or globally. Args: verbose (bool): Whether to enable verbose logging.
activation_steering/config.py:65
Methodsteer
Configure steering for this layer. Args: behavior_vector: The behavior vector to apply. condition_projector:
activation_steering/leash_layer.py:44
Methodtrain
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
Methodunwrap
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