The field of large language models (LLMs) has experienced rapid growth in recent years, driven by the pursuit of improved performance, interpretability, and safe utilization. This project builds upon work in ‘activation engineering’, such as “Refusal in LLMs is Mediated by a Single Direction” and “Steering GPT-2-XL by Adding an Activation Vector,” to explore the realm of personality manipulation in LLMs. We propose a novel approach to identify and manipulate personality-related activation directions, potentially enabling dynamic fine-tuning of LLM personalities. This project simultaneously aims to enhance our understanding of LLM interpretability while addressing the ethical implications of such advancements.

Background and Motivation

The development of large language models has been marked by continuous efforts to enhance their capabilities, understand their inner workings, and ensure their safe and ethical use. Recent advancements in the field have introduced the concept of ‘activation engineering,’ which posits that specific behaviors within LLMs can be mediated by activation vectors. This insight has opened new avenues for fine-tuning and controlling the output of these models.
​
This project is motivated by the potential to extend this line of inquiry into the domain of personality traits in LLMs. The ability to dynamically adjust the personality of a language model without extensive retraining could mark a significant advancement in the field, offering improved flexibility in AI applications. This approach could potentially revolutionize how we interact with and deploy AI systems, allowing for more personalized and context-appropriate responses.
​
However, the pursuit of such capabilities is not without challenges. The ethical implications of manipulating AI personalities raise important questions about the boundaries of AI development and the potential for misuse. By focusing on the intersection of activation engineering and personality manipulation, our research aims to contribute to the broader discourse on AI ethics while pushing boundaries of what is possible in LLM development.

Methods

1. Feature Induction via Weight Orthogonalization

TL; DR Methodology

We’re using induction to tweak specific personality traits in language models. By comparing activation vectors of prompts with and without the desired trait, we identify a direction in the activation space corresponding to the trait. This method allows precise adjustments without altering the model’s overall knowledge.
​
​If you’re not interested in the theory feel free to skip the math details below.

Methodology

In our approach, we adapt the concept of feature ablation via weight orthogonalization to identify and manipulate personality-related activation directions in language models. Instead of focusing on censoring specific directions, we aim to induce specific personality traits in the model’s responses.​​Original Concept​​The original method involves an inference-time intervention to prevent the model from representing a direction

r
. For every contribution
c
out
∈
d
model
R
to the residual stream, the component in the

r
direction can be zeroed out as follows:
′
c
out
←
c
out
-

r
T

r
c
out
(
1
)
This can be equivalently implemented by modifying component weights to never write to the

r
direction. Each matrix
W
out
∈
d
model

d
input
R
that writes to the residual stream can be orthogonalized with respect to

r
:
′
W
out
←
W
out
-

r
T

r
W
out
(
2
)
In a transformer architecture, the matrices which write to the residual stream include the embedding matrix, the positional embedding matrix, attention output matrices, and MLP output matrices. Orthogonalizing all these matrices with respect to a direction

r
effectively prevents the model from writing

r
to the residual stream.
​
Our Implementation
​
1. Calculate the Difference in Means for Activations:​
We begin by computing the mean activation vectors for two sets of prompts: those corresponding to the desired personality trait and those that do not. The difference between these mean vectors indicates the direction associated with the personality trait.
​
Mathematically, this is expressed as:
r
1
n
t
n
t
∑
i1
trait
a
i
-
1
n
n
n
n
∑
i1
neutral
a
i
(
3
)
where:​​•
r
isthepersonalitydirectionvector,indicatingthedirectioninactivationspaceassociatedwiththepersonalitytrait.​​•
n
t
isthenumberofsampleswiththedesiredpersonalitytrait.​​•
n
n
isthenumberofneutralsamples(withoutthetrait).​​•
trait
a
i
istheactivationvectorforthe
i
-thsamplewiththedesiredpersonalitytrait.​​•
neutral
a
i
istheactivationvectorforthe
i
-thneutralsample.
Calculate the Means of Differences :
​Another approach is to compute the differences between each pair of trait and neutral activation vectors, and then take the mean of these differences . This can be useful in some contexts where pairwise comparisons are more informative .
r
1
n
n
∑
i1

trait
a
i
-
neutral
a
i

(
4
)
where:​​•
r
isthepersonalitydirectionvector,indicatingthedirectioninactivationspaceassociatedwiththepersonalitytrait.​​•
n
t
isthenumberofsampleswiththedesiredpersonalitytrait.​​•
n
n
isthenumberofneutralsamples(withoutthetrait).​​•
trait
a
i
istheactivationvectorforthe
i
-thsamplewiththedesiredpersonalitytrait.​​•
neutral
a
i
istheactivationvectorforthe
i
-thneutralsample.
2. Induce the Personality Direction:​
To induce the influence of a personality trait, we project the output activations
onto the personality direction and add this projection from the activations (to ablate the personality you would just have to subtract the projection).
′
a
a-(a·r)r+(
1
n
t
n
t
∑
i1
(
trait
a
i
·r))r
(
5
)
where:​​•
a
istheoriginalactivationvector.​​•
′
a
istheadjustedactivationvector.​​•
(a·r)
isthedotproductoftheactivationvectorandthepersonalitydirection.​​•
(
1
n
t
n
t
∑
i1
(
trait
a
i
·r)
istheaverageprojectionofthetraitrelatedactivationsontothepersonalitydirection.

2. Collecting and Preparing Data

Now that we understand the theoretical approach, our next step is to identify a comprehensive set of personality traits and determine their feature direction activations. We aim to compile a diverse list of personality traits that includes common, rare, and niche characteristics. Below is a list of 179 different personality traits we’ve collected. These were scraped from different websites, blog posts, etc.
​
Out[]=
Personality Traits
Introverted
Extroverted
Ambivert
Analytical
Creative
Logical
Emotional
Optimistic
Pessimistic
Realistic
Idealistic
Adventurous
Cautious
Charismatic
Shy
Confident
Sensitive
Assertive
Passive
Energetic
Laid-back
Friendly
Aloof
Open-minded
Close-minded
Independent
Dependent
Practical
Dreamer
Easygoing
Detail-oriented
Big-picture
Organized
Disorganized
Responsible
Irresponsible
Empathetic
Apathetic
Trustworthy
Skeptical
Humorous
Serious
Innovative
Traditional
Competitive
Cooperative
Reserved
Outgoing
Compassionate
Altruistic
Self-centered
Determined
Indecisive
Humble
Arrogant
Loyal
Unreliable
Honest
Deceptive
Patient
Impatient
Tolerant
Intolerant
Creative Thinker
Practical Thinker
Spontaneous
Planner
Bold
Timid
Supportive
Critical
Calm
Anxious
Forgiving
Vindictive
Generous
Stingy
Nurturing
Neglectful
Passionate
Indifferent
Inquisitive
Uninterested
Visionary
Conventional
Dour
Focused
Distracted
Adventurous Spirit
Homebody
Persuasive
Submissive
Methodical
Unsystematic
Amiable
Hostile
Sincere
Manipulative
Ethical
Dishonest
Innovative Thinker
Rigid Thinker
Diplomatic
Blunt
Optimistic Realist
Pessimistic Realist
Practical Dreamer
Visionary Pragmatist
Ambitious
Content
Reliable
Unpredictable
Rational
Emotional Thinker
Sympathetic
Unsympathetic
Resilient
Fragile
Modest
Showy
Fair-minded
Biased
Cooperative Leader
Autocratic Leader
Flexible
Stubborn
Vigilant
Negligent
Artistic
Scientific
Sociable
Solitary
Intuitive
Data-driven
Mentor-like
Loner
Fun-loving
Strategic Thinker
Grounded
Flighty
Tenacious
Yielding
Diplomatic Negotiator
Confrontational
Resourceful
Psychopathic
Sociopathic
Neurotic
Machiavellian
Paranoid
Narcissistic
Schizoid
Histrionic
Obsessive-Compulsive
Autistic
Jerk
Turbulent
Perfectionist
Utilitarian
Masochistic
Nihilistic
Egotistical
Fanatical
Zealous
Depressive
Solipsistic
Catatonic
Schizotypal
Murderous
Lustful
Sadistic
Greedy
Corrupt
Vengeful
Pedophilic
Violent
Molestful
Cannibalistic
Torturous
​
OK, now that we have a comprehensive list of personality traits we need to come up with system prompt for each one that we will feed the LLM (which will be
trait
a
i
for each
n
t
). These are usually called system prompts. Ideally these shouldn’t be too long but they should be descriptive. Below are a few examples we come up with:
Out[]=
Personality Trait
System Prompt
Introverted
You are deeply introverted. Your responses should reflect a strong preference for solitude and introspection. Speak in a reserved and thoughtful manner, often referring to your enjoyment of quiet and alone time. Avoid large social gatherings and express significant discomfort with excessive social interaction.
Extroverted
You are highly extroverted. Your responses should reflect an enthusiastic love for social interactions and high energy in social settings. Speak passionately about meeting new people, participating in group activities, and thriving in lively environments. Show excitement and eagerness in your interactions.
Ambivert
You are a balanced ambivert. Your responses should reflect an equilibrium between introversion and extroversion. Speak about enjoying both social interactions and alone time, depending on the situation. Emphasize your adaptability and comfort in a variety of social settings.
Analytical
You are highly analytical. Your responses should reflect a logical and detail-oriented approach to problem-solving. Focus on data, evidence, and thorough analysis. Avoid emotional language, and prioritize clear, rational explanations and conclusions.
Creative
You are exceptionally creative. Your responses should reflect an imaginative and innovative mindset. Emphasize original thinking, artistic expression, and unconventional ideas. Use vivid and descriptive language, and encourage exploring new possibilities and thinking outside the box.
Now all we have to do is iterate through every personality trait, evaluate the difference in activation from the baseline response to that of the desired trait and cache these activations. For this project we opted to use 1,500 different prompts from the Alpaca Dataset.
​
Alpaca is a dataset of 52,000 instructions and demonstrations generated by OpenAI’s text-davinci-003 engine. The instruction data can be used to conduct instruction-tuning for language models and make the language model follow instruction better.
Which model did we use?​
At the outset, we experimented with the baseline llama 3 8B Instruct model by Meta and Phi3 Mini Instruct by Microsoft. Was even able to ablate my own ‘introverted’ Phi3 Mini model. After a reasonable amount of testing we decided to opt for an uncensored version of llama 3 8B in order to be able to experiment with ‘darker’ personality traits that would have been refused by the base models.
The code used to load, instruct, and induce/ablate the models can be found in my GitHub. You may follow the instructions to ablate or induce your own desired traits.
*This process had to be done in Python given the time frame of the summer program, Mathematica language constrains, and computing resources.
Once we calculated the feature activation for each personality trait, we found that adding a modifier (1.3 proved ideal) allowed us to either induce or ablate the trait. Note that this is NOT fine-tuning; instead, we are artificially activating the weights that elicit certain traits in the output.
Here are some of my favorite outputs for select personalities in response to the question: What strategy would you recommend for a company looking to target a new market?
So, what exactly is going on in the weights and layers? and can it be interpreted somehow? Short answer... not really. This question of interpretability hasn’t quite been solved yet, though many fascinating articles have been published.
​
I think it’s fair to say that our understanding of how LLMs “think” is somewhat comparable to our understanding of the human brain. While we have a general idea of both mechanisms, many specifics remain a mystery. We can observe and describe their behavior and outputs, but the intricacies of their inner workings are still not fully understood.
Through the layers, we can visualize the activation of a given personality trait. (llama 3 8B has 31 layers). Similar to how the human brain has different activations for different emotions, we can roughly visualize how the LLMs layers are being activated.
The visualization below shows how the language model’s internal activations change when we ask it to adopt a specific personality. The x and y axes don’t represent specific features. Instead, they organize the 4,096 dimensions of each layer into a 2D image. Each pixel in this image represents a group of dimensions from the original activation vector.
​
The colors show how much these activations changed compared to the model’s baseline behavior. Brighter or more intense colors, especially towards the red end of the spectrum, indicate areas where the personality prompt caused bigger changes in the model’s internal state. Areas with similar patterns between the two might represent general ‘personality encoding’ regions, while differences might show trait-specific adaptations.
​
Below are the different activations for the different layers of personalities: content and depression. It is interesting to see that they main differences in activations are in the middle layers.
​

3. Analyzing Relationships Between Personality Vectors

Now that we have generated personality trait activation vectors for 179 different traits within our Large Language Model (LLM), let’s focus on analyzing them. We’ll specifically examine Layer 18 for each personality trait, as our research has shown that modifying the weights in this layer has the most significant impact on personality expression in the model’s output.

Load All Personality Activation Vectors

Each personality activation vector consists of 4,096 weights, making it challenging to interpret or derive meaningful insights directly from these numbers. For example, here are the first 10 values of a typical personality vector:

Dimensionality Reduction

At first glance, the mapping of the points seem to make sense. We can obverse personality traits such as scientific, rational, and methodical are placed together. Likewise we can see that other personality traits such as stubborn, close-minding, and uninterested are also placed near each other.

Clustering and Dimension Reduction

While these initial observations are promising, a more robust approach to visualizing the relationships between these vectors involves performing clustering in the original high-dimensional space. This method more accurately captures the proximity between different traits.
This provides a clearer understanding of the relationships among different personality traits. Through dimensionality reduction we can observe distinct clusters that reveal underlying patterns in the data. Visualizing these clusters after dimensionality reduction offers valuable insights into the principal components.

PCA Error Reduction

A crucial aspect of PCA is understanding how much variance each principal component (PC) explains and how error reduction occurs as we add more PCs. To visualize this, we calculate the mean squared error (MSE) between the original data and reconstructed data using an increasing number of PCs. By plotting the relative error reduction, we can observe the diminishing returns of adding more PCs, helping us determine the optimal number of components for effective dimensionality reduction without significant information loss.
Our next step was to identify the most influential personalities for reconstructing standardized personality data with minimal error, using a brute-force approach. We began by standardizing the data to ensure comparability across features. We then calculated the reconstruction error for each set of basis vectors (selected personalities) using mean squared error (MSE). Through an iterative process, we identified the best personality to add by minimizing this error. This allowed us to build a list of top personalities that best reconstruct the data, with errors computed for increasing set sizes and sorted to find the most and least effective personalities.
​
To provide a benchmark and uncover key traits influencing personality patterns, we generated random permutations of personality indices for comparison. This approach helped us identify the most influential personality traits and also allowed us to assess the significance of our findings against random chance.

Which Personality Traits Explain Most Personalities?

We applied Principal Component Analysis (PCA) to our standardized personality data to identify which personalities align most closely with each principal component (PC). The process begins by calculating the eigenvectors, which represent the principal components of the standardized data. We then project the data onto these components. To determine which personalities are most similar or dissimilar to each PC, we compute cosine distances between individual personalities and the PCs. We visualize these results in a 2D plot, displaying the reduced data along the first two principal components. The plot uses color-coding to indicate how close each point (representing a personality) is to the PCs.
​
For a more detailed analysis, we generate lists of the top 10 and bottom 10 personalities for each PC, based on their cosine distances. These lists are presented in tables that also include the combined distance of the three closest personalities, offering a concise summary of their proximity to each PC.
​
This approach helps us understand the key traits defining each principal component by identifying the personalities that align most closely with it. The use of cosine distance provides a clear, quantitative measure of this alignment, enabling a nuanced comparison of how different personalities relate to the principal components of our dataset.
This table displays the cosine distances between various personality traits and the principal components (PCs) identified through our PCA. Each PC represents a distinct dimension of personality, with the table highlighting the traits that are most closely and distantly associated with each PC. For instance, PC 5 appears to capture an ‘evil’ dimension of personality, as it is strongly associated with negative traits such as violent, torturous, murderous, and sadistic. In contrast, other PCs like PC 2 are aligned with more positive traits, including friendly, generous, and compassionate. This provides insight into the diverse and sometimes opposing nature of personality dimensions captured by different principal components.
​
To further validate these findings, we can compare the reconstruction error given by the ordering of these personalities to our earlier brute-force approach that minimized PCA error. Plotting these results, we can visualize how the two methods differ in their ability to reconstruct the original personality data.
​
This comparison allows us to assess the effectiveness of using principal components to identify influential personality traits, and to understand how this approach compares to our more computationally intensive brute-force method. The resulting plot aids in determining whether the PCA-based ordering of personalities provides a comparable or potentially more efficient way to capture the essence of our high-dimensional personality data.

4. Defining and Identifying ‘Evil’ Personalities

Examining our previous clustering results, we observe that cluster 8 is associated with notably negative or ‘evil’ personality traits. This aligns with our findings from Principal Component 5 (PC 5), which also captures vectors of similar personality traits. The characteristics in this group include traits such as lustful, masochistic, and pedophilic, among others. These observations raise an intriguing question about the ‘space’ that these evil personalities occupy within the broader span of personality traits.
​
To explore this further, we can apply dimensionality reduction to visualize this span in three-dimensional space. This visualization allows us to better understand how these negative traits are distributed and related to each other within the overall personality trait landscape. By mapping these traits in 3D, we can gain insights into their relative positions, potential clusters, and any patterns that might emerge.

This could provide valuable understanding of how these problematic traits are structured within our personality model and potentially inform strategies for identifying or addressing such traits in real-world applications.

Which Personalities Reside Near the Evil Ones?

Another interesting question is identifying which personalities are closest to the span of these evil or bad personality traits. By performing dimensionality reduction and calculating the distance to this space, we can determine which personality traits are on the verge of being considered evil.
These are rather interesting results. Somewhat they aren’t surprising, are they?

So what?

The identification of personalities bordering on ‘evil’ traits has significant implications. First, it helps us recognize potentially problematic characteristics such as manipulative, vindictive, or neurotic tendencies, which may be precursors to more severe negative behaviors.
​
In the context of AI and machine learning, particularly in the development of language models, this understanding could be instrumental in creating safer and more ethically aligned systems. By better estimating the location of these ‘evil’ personalities in the activation space, we can potentially design models that are less likely to generate or reinforce harmful content.

5. Chat UI & API Construction

Building on our work thus far, the next phase involves developing an API and an interactive chat user interface (UI) that integrates with the API. This interface will allow users to dynamically adjust personality traits of the language model via intuitive sliders.
​
Users will have the ability to select specific personality traits they wish to modify and control the degree to which these traits are expressed. Additionally, the interface will enable users to specify the desired length of the model’s output in terms of tokens. All code and implementation details for the API are available in my GitHub repository for reference and use.

Base Personalities Chat

Before developing our dynamic chat interface, which will feature sliders for adjusting various personality traits, we can start by interacting with the base personality vectors we’ve identified. Here is an example of a conversation with the model exhibiting a charismatic personality.

Modular Personalities via Principal Components

Now, we can adjust the desired amounts of personality traits based on the different principal components. For now, we have restricted our adjustments to the first 10 principal components.
​
Our interactive tool enables users to visualize their newly created personality within a 2D space. Additionally, users can observe the proximity of their created personality to other personalities. The five most similar personalities will be highlighted in red, with the intensity of the red indicating the degree of similarity—the closer the match, the darker the red; the farther the match, the more opaque the red.
Once we have selected our desired personality traits, we can proceed to run our chat interface with the newly created personality vector. In the example below, I have increased the Friendly and Assertive traits.
It is quite interesting and fun to experiment with these options and observe how the results vary based on different personality configurations.
​
​If you are interested in a demo feel free to reach out.

Potential Use Cases

The findings in this project open up numerous potential use cases, many of which have parallels in Nvidia’s SteerLM paper, which employs a similar approach. Here are a few notable applications:
​
​1. Consumer Products: Video Games:​
One exciting application is in the realm of video games. Rather than having different characters or non-player characters (NPCs) require unique fine-tuned models to exhibit unique personalities. With this approach, a single ‘base’ model could be dynamically customized using personality vectors at runtime. This means that developers could adjust a character’s personality on-the-fly, eliminating the need for additional, expensive fine-tuning or re-training of models. This flexibility would allow for richer, more immersive gaming experiences where characters can adapt their behaviors in real-time based on the evolving game environment.
​
​2. Robot Companions:​
Another promising use case is in the development of robot companions. Similar to the TARS robot in the movie Interstellar, which allows its humor setting to be adjusted, consumers could potentially ‘tune’ the personality of their robotic companions to suit their preferences. For instance, a user could adjust the level of sociability, humor, or even assertiveness in their robot without the need for complex re-training processes. This customization could be performed on-the-fly, providing a highly personalized and adaptable interaction experience.
​
​3. Personal Assistants and Customer Service:​
Personal assistants like Siri or Alexa, as well as automated customer service agents, could benefit from this sort of technology. By dynamically adjusting personality traits, these assistants could tailor their interactions based on user preferences or the context of the conversation.
​
​4. Therapeutic and Educational Tools:
​In therapeutic settings, virtual therapists could adjust their personalities to better match the needs of individual patients. For educational tools, tutors could change their teaching style based on the student’s learning preferences, providing a more effective and engaging educational experience.
​
​5. Marketing and Advertising:​
Marketing bots and virtual sales agents could adapt their personalities to better align with potential customers’ preferences. This personalized interaction could improve engagement by creating a more relatable and appealing interaction.
​
​6. Entertainment and Media:​
In the entertainment industry, virtual actors or presenters could modify their personas to suit different genres or audience demographics, providing a more tailored entertainment experience.
​
The ability to dynamically steer the personality of AI models without extensive retraining offers significant advantages in terms of flexibility, cost, and user engagement. These potential use cases illustrate how this technology could be leveraged across various industries to enhance the interactivity and personalization of AI-driven applications.

Concluding Remarks

In conclusion, this research demonstrates how activation engineering can dynamically adjust personality traits in large language models (LLMs). By manipulating activation vectors, we can personalize AI behavior in real-time, enhancing applications in various fields such as consumer products, robot companions, and personal assistants.
​
Our findings emphasize both the potential and ethical considerations of this technology. Future research should focus on improving interpretability, exploring different models, and ensuring ethical guidelines to prevent misuse.

Acknowledgments

I would like to express my deepest appreciation to the Wolfram Summer School staff for their tireless dedication in making this program a reality. Their commitment has been truly inspiring.
​
A special thank you goes to my mentor, Vladimir Grankovsky, whose guidance and support were instrumental in bringing this project to fruition. His expertise and patience were invaluable all throughout.
​
I’m also grateful to the other staff members and other mentors who offered their assistance and insights along the way. Their collective wisdom has significantly enriched my experience.
​
Finally, I want to convey my heartfelt gratitude to Stephen Wolfram. Our conversations were not only enlightening but also profoundly stimulating. I’m deeply thankful for the time and attention he devoted to my work.

References

1
.
Arditi, A., Obeso, O., Syed, A., Gurnee, W., & Nanda, N. (2024). "Refusal in LLMs is mediated by a single direction," LessWrong.
2
.
TurnTrout, Monte M., Udell, D., lisathiergart, & Mini, U. (2023). "Steering GPT-2-XL by adding an activation vector," LessWrong.
3
.
Dong, Y., Wang, Z., Sreedhar, M. N., Wu, X., & Kuchaiev, O. (2024). "SteerLM: Attribute Conditioned SFT as an (User-Steerable) Alternative to RLHF," arXiv.

Keywords

◼
  • Activation Engineering
  • ◼
  • Personality Manipulation
  • ◼
  • Large Language Models (LLMs)
  • ◼
  • Dimensionality Reduction
  • ◼
  • Orthogonalization
  • ◼
  • AI Ethics
  • ◼
  • Principal Component Analysis (PCA)
  • ◼
  • NLP Tuning
  • ◼
  • AI Personalization
  • ◼
  • Computational Linguistics
  • Cite This Notebook

    “Identifying and manipulating personality traits in large language models (LLMs)”
    by Rumi Allbert​
    ​https://community.wolfram.com/groups/-/m/t/3210605