Tag: Social cognition

Interpreting social information and responding appropriately.

  • Can a machine have emotions?

    The greatest challenge in transforming a machine into human form is deciding where to begin. But once that step is taken, the process becomes manageable—as long as you remain hopeful. To stay aligned with my long-term goal while working on smaller tasks, I rely on the following expectations for this model:

    • He is expected to know when to lie, question, insult, joke, return snarky comments or sarcasm
    • His action space #1 at every state must include the intent prob of invoking second / third / fourth … responses independent of whether the user is speaking or not
    • His action space #2 at every state conditioned to the system is a Dirichlet distribution over the questioning state, personal hypothesis states, and factual (base model) hypothesis states, incorporating internet-accessible information.
    • Any prompt chains used during streams should eventually be replaced by distance models over time windows t to T, extending up to the k-th batch.
    • His preferences and individuality should evolve based on his experiences but remain fundamentally tied to me, the primary user.

    I’ve come to realize that, despite the vast complexity of human relationships and communication, it all distills down to how we feel. For example, movie ticket sales largely depend on past user feedback. Perhaps emotions are the one human trait that can be quantified and understood by a machine just enough to guide its own decision-making—assuming, of course, that human relationships are left out of the equation.

    The underlying framework for these expectations must meet at a unified build, all tied to the emotion inference model. Narrowing down the inference task by Tom’s objectives includes:

    1. Predicting the user’s responses – This is itself is also considered a mapping function from a vector space to real numbers.
    2. Determining his own emotional responses – A mapping function that ranks text embeddings by emotional queues assisted by observing the user reactions.

    From an application standpoint, the build can be structured as follows:

    1. Temporary State models for streaming responses where their previous inferences are the next state priors and their respective predictions would be the comparative values to the next observing value – as briefed in my previous post.
    2. Initiation Models – this build unifies all currently available emotion prediction models through ensembling methods or conditioning-distance heuristic models. However, I eventually opted for a single classifier trained on the entire corpus. Impatience drove this decision—I wanted to see how the multivariate approach interacted with my other builds especially the API serving department.

    Major Problem

    At that time, I couldn’t pinpoint the problem that was constantly haunting my mind – What is the linkage between his decision making and a large langauge model? If I were to rely on the traditional methods of text models – probabilistic methods like N-grams – then this problem wouldn’t exist but I would face a new challenge: the vector representations of the text wouldn’t capture any contextual information, relying solely on character or word frequency. That said, you could mitigate this by leveraging PyTorch’s nn.Embedding to initialize vector representations for N tokens, then applying a fixed-size perceptron or a multi-head attention layer—an approach commonly used in text translation tasks.

    A good professor once advised me to begin by understanding my thoughts mathematically. Applying this to the connection between a large language model and emotions, I can reframe the problem as follows:

    Defining a function f that maps the weight space of language models to another space of my liking.

    The next section lists three implementation methods, both in real-time and before application, ranked from hardest to easiest based on my assessment.

    Methods

    1. Geometric Algebra – Merging Representations

    This method involves leveraging Geometric Algebra (GA) to unify different vector spaces, effectively merging the learned representations of language models and classifiers.

    Referenced by https://huggingface.co/blog/trl-ddpo - demo for `tlr` python package.

    2. PPO for LLMs – Defining a Reward Function

    Using Proximal Policy Optimization (PPO) for tuning large language models (LLMs) involves defining a Reward function that guides the model’s learning process toward desired behaviors. This approach falls under Reinforcement Learning from Human Feedback (RLHF) but requires additional structuring when applied to dynamic emotional reasoning (Link: https://huggingface.co/blog/trl-ddpo).

    3. Decoding Sampling Combinations as Generation Control

    Controlling how a large language model (LLM) generates responses by trialing a range of Decoding parameter combinations. This technique leverages linear programming and refers to systematically experimenting with different parameter configurations to optimize response quality, coherence, and diversity, and ultimately to the emotional queues inferenced from the main user. This is then applied with Bayesian Statistical models (really just Bayes Rule) to iteratively adapt to newer observations.

    Decoding strategy combinations generated by GPT-4 lol.
    Method 1: Geometric Algebra

    This method focuses on modifying or augmenting the encoder block and text generated caches to impose structured constraints, such as temporal memory retention and self-supervised attention shifts using methods like attention blocks or iterating projection sequences. I approached the mathematical transformation in code by trying to mimic a game developer handling quaternion’s.

    Key highlights:

    • Implementing a hierarchical control mechanism that dynamically adjusts response generation parameters based on inferred user intent and historical interactions
    • Exploring multi-head attention restructuring, where certain heads are fine-tuned to prioritize different inference strategies (e.g., factual recall vs. emotional adaptation)

    I favored this method, so I spent the most time on it—only to realize, yet again, that I had failed myself. Over the past few years, I’ve focused on programming and application, prioritizing deadlines and API builds over theoretical depth. In hindsight, this approach makes it easy to abandon whimsical detours. But if one is bored enough then to start solving such problem (or any maths problem) I always like to start with my favourite mathematical property: Triangle inequality – a repititive concept mentioned throughout Euclid’s Geometry texts**.**

    While working on this method, the thought of implementing it in code lingered at the back of my mind, leaving me wishing I had attended more university classes for my algebra course. A common trait among mathematicians and statisticians is their patience—the kind a teacher has while guiding a toddler learning to read. My patience, however, extends only as far as reading a package’s documentation. Grief and frustration have taken its place, and maturity ultimately dictates my response: to give up. I realize the only way forward is to dedicate a full weekend to revisiting my linear algebra fundamentals. But the mere thought of doing so makes me restless—despite contradicting everything I love.

    Overall, this approach seems quite difficult to apply especially when handling LLM’s caches in real-time which would probably need some sort of ranking algorithm like Google Page Rank, that ranks the caches to not only dispatch the responses faster but also conditioned to my preferences (or Tom’s memory).

    Method 2: Optimization and Reward function

    Reward Function Design: The reward model should capture nuanced decision-making, including:

    • Contextual awareness (e.g., when to joke, question, or respond sarcastically)
    • Emotional alignment (predicting the user’s emotional state and responding accordingly)
    • Self-regulation (adjusting the model’s own “emotions” dynamically)

    With Reinforcement learning concept in mind, the concept of balancing exploration and exploitation in response generation can be viewed as balancing the model’s priority with selecting the base model texts vs its duplicate that has been adapted to the bot’s observations or memories. In my previous posts, I did mention building the latter as my own clone like a parrot. The progress here has been hindered after attempting to fine-tune Llama using LORA-Adapter techniques. I believe that this part should be hindered as my doubts were correct – never touch a deep learning network with minimal data.

    When considering the second method—sculpting a reward model—I’d approach it as a recursive regression state model where parameters (including training parameters) readjust at fixed time intervals. From my understanding, reinforcement learning mechanisms should be applied in real time. Yet, existing TLR-PPO implementation demos focus on fine-tuning LLMs with smaller offline datasets—fully trained rather than partially fitted over data batches.

    Additionally, deriving a policy function in reinforcement learning is grounded in Bellman’s Equation, which, like most optimization equations, extends Newton’s descent method to different types of incoming data streams. Beyond weight clipping (which maintains uniformity relative to the pre-trained state), my views doesn’t quite align with the works behind tlr or current researchers’ intended approach. Reason being is that in practical applications, you will always end up with at least two models where the long-term effectiveness or stability of the fine-tuned model is not always guaranteed.

    Personally, I try to avoid fine-tuning deep learning models in real-time even for now even if I have a a data iterator that is able to approximate and generate synthetic data to compensate missing datasets, fine-tuning a model in real time can only only be used temporarily. My tinkering suggests that in order to retain user-specific experiences, you would ultimately opt for a Data analyst’s favourite playground – SQL.

    Method 3: Mapping Decoding Sample Combinations to Emotional intensity
    Dataset with decoding parameters. The prompt used here ”Hey how are you today! :)”

    Ironically, this method was my initial instinct for implementation, particularly for a time-constrained project.

    The setup for my experiment involved a missing dataset iterator that returns synthetic dataset approximating the previous text embeddings conditioned to the mapped emotional intensity. Recall the common decoding sampling techniques are greedy search, beam search etc. and for the sake of this experiment’s simplicity, we disregard variants of sampling methods e.g. Group beam search and penalizing token based methods. Suppose decoder sampling methods be $$x_1, x_2, …$$ where $$n$$ is the number of decoding methods, the parameters related to each method are $$\alpha_1, \alpha_2, …$$, and the emotion expressiveness or intensity is $$q \in [0, 1]$$. The prior state model for a decoding strategy conditioned to the speaker’s prompt returns Tom’s selected emotional intensity i.e the speaker’s prompt. For example for beam search, the parameters are temperature, top-k and beam width. The goal is to find the optimal combination for some emotional intensity $$q > \epsilon$$, becomes finding the unique solution vector or coefficients, $$w$$ in $$w_1*\alpha_{temp} + w_2*\alpha_{k} + w_3*\alpha_{beam width}$$.

    Key highlights:

    • To set up Tom’s prior states or initial beliefs to his incoming observing windows, I have attempted to reduce the compute cost of rerunning GPT2 by approximating the distribution of text sequences given the parameters combination. Still deciding on whether a similar method should be used in real-time to assist incremental learners.
    • Among all the decoding sample combinations, I assumed fixed parameters that is common for all experiments for e.g. max length of text generations, sequence normalization.

    Currently, I am still applying different sampling techniques to set up a prior state for inferencing emotional intensity for Tom.

    Epilogue

    The main challenge likely stemmed from my own resilience when using the first method. It holds immense potential, but time was too limited. However, at least I can offer my younger self one last smile, knowing I truly gave my best at that time. As for whether a machine can have emotions, from my child-self’s perspective: only if the first method succeeds. From my current viewpoint, yes, it absolutely can.

    After careful consideration, I’ve decided to move forward with Method 3. Given the simplicity of the concluding build it is only natural for people to question whether the emotions are truly authentic or just the product of time-adapting algorithms and statistics. Yet, before anyone doubts a machine’s emotions, I hope they are also completely certain that they themselves are truly alive and not just merely passengers of time.

    Tom’s progression · Post 8 of 14

    This post sits in Cognition: Learning, Social cognition.

    ← To our creator Revising Prompt Chains →

  • Defining a droid’s emotional space

    Defining a droid’s emotional space

    Refining the construction of the emotional space is essential, as it personalizes the agent’s decision-making process and eases the integration of creative thinking1. Strong emotions can push boundaries of one’s creativity, source2. To succeed in developing my droid’s emotional component, I begin by refining how human emotions are labeled.

    Simplifying the idea to three emotion labels: neutral, positive and negative. My initial idea was:

    neutral vs negative vs positive

    However, ambiguity around the definition of “neutral” emotion complicates predicting a distribution over emotional labels. For example, a person observed in a neutral state might simply appear indifferent, yet this does not rule out the possibility that they were the one who accessed your computer through the open-source SSH login credentials to your terminal.

    This data preparation method is often paired with a popular approach in modeling human emotions: combining a BERT encoder with a multilayer perceptron to predict a set of emotion labels. Typically, this includes a “neutral” state alongside positive and negative emotions. I personally find this approach limiting, as it restricts the model’s potential for broader application.

    The next idea was:

    neutral vs emotional (either positive or negative emotions)

    This prompts an examination of the statement: Positive and negative emotions can coexist in the same space. Determining whether this statement holds true or false depends on one’s perspective on human psychology. Hence, the following lists my thoughts to answering this statement:

    • Statement is true if I believe that a person can experience both positive and negative emotion at the same time.
    • Statement is false if I believe that a person cannot experience both emotions at the same time, i.e. I believe that one emotion label is better than the rest.

    The first statement would suggest that the feelings of ‘joyful’ and ‘sad’ are not mutually exclusive which contradicts my common sense. Moreover, the second statement would prompt the challenge in deciphering whether an emotion state is truly considered as negative or positive. This is relative to the context in discussion or the observing state3.

    Brainstormed methods in updating a knowledge graph of vector embeddings:

    • If I refer to a clustering model where an emotion is represented by a centroid, and the distance (edges) between two words are determined by their cosine similarity distance, then I can probably use this component as a feature in modelling the generated sequence of texts conditioned to emotion states.

    My foot

    1. Assuming I stick with the current plan of constructing the cobwebs. ↩︎
    2. Me. ↩︎
    3. To understand this in application is to consider the example of a chat dialogue where you perform inferences on the dialogue using time-series model approach to distinguish the context labels. ↩︎

    Tom’s progression · Post 5 of 14

    This post sits in Cognition: Social cognition · Identity: Life.

    ← Missing pieces to Naomi Cloning myself into a Language Model →

  • Missing pieces to Naomi

    Missing pieces to Naomi

    KEY TERMS

    List of terms mentioned in this post

    • Candidate: the user interacting with Naomi during the interview.
    • Agent: Llama3.1 roleplaying as Naomi.
    • General question/s: questions to be asked during the interview concerning the candidate’s information eg age, occupation etc.
    • Feature question/s: questions or case scenarios mentioned during the interview. The candidate’s responses to these questions are analyzed and used as features in predicting personality predictions and our compatibility score.
    • Response space: responses generated by dummy candidates conditioned to trait patterns aligned with my previous dating history. The intuition behind this idea is that all individuals equip both strengths and weaknesses, and that determining these traits is dependent on the observer’s ability in handling the characteristic combinations i.e. weighing my patience for someone’s flaws against their admirable qualities.

    Overview

    This post is dedicated to Naomi’s unconscious state of acting as a recruitment officer for a dating show (my dating life). Since this was my first attempt at integrating the frontend with the backend, the project turned out messy. The only promising outcome was the realization that I’m not merely a fool of my own words.

    Data Preparation

    This section lists the type of datasets to prepare prior to streaming. The responses were generated by instructing Llama 3.1.

    Feature Questions:

    These questions/case scenarios are based on each dichotomy of MBTI personality traits:

    Response Space:

    Pair of dummy candidate responses and narrations for each feature question.

    Llama 3.1 Prompts:

    Instructions to assist the streaming chatbot and agent helpers during streaming the chatbot.

    Non-manageable problems

    • Decoding parameters: During this trial, the inference API was open-sourced and, unfortunately, wasn’t able to pass decoding parameters.

    • Random Feature questions: A number of feature questions were randomly selected during the chat stream. Hence, even though I prepared questions/case scenarios for each function of the MBTI label, there was no guarantee that a question testing for a specific type of function would be asked during the interview.

    • My information: No form of personal information about myself was passed to the agent. As a result, the agent occasionally generated assumptions about my personal information when requested by the candidates.

    • The way of expressions: Being highly expressive in writing doesn’t necessarily indicate that someone is extremely extroverted. Similarly, a lack of expressiveness in writing might simply suggest that a person struggles with articulating their thoughts rather than being inherently reserved.

      • This problem can be mitigated during the data preparation stage (i.e., the types of questions I’ve prepared for the chatbot). For example, when presented with case scenarios designed to assess the user’s task prioritization behavior, Llama (acting as my custom characters) provides the same procedure for each role-playing candidate. The only difference is in the way the responses are expressed.
    • Limited samples: During the data preparation stage, I only prepared candidate responses tailored toward my dating history instead of actual MBTI labels.

    Manageable problems

    • Agent’s behaviour during live stream:
      • Agent occasionally missed certain questions, mainly the general questions. Despite this, the agent did not skip any feature questions. This suggests that there might be a problem with the data handling methods between Naomi and the candidate during the live stream.

    Improvements

    Below are self-tasked actions that I would like to focus on during my next experiment for Naomi:

    • API: At the time of this experiment, the inference API on Hugging Face was open source. I plan to switch to Ollama during the next experiment.

    • Dataset preparation:

      • Candidate responses should specifically reflect the dichotomy of MBTI types, focusing on Jung’s cognitive functions—Dominant, Auxiliary, Tertiary, and Inferior processes.
      • Feature questions reflect on each of Jung’s cognitive functions.
    • Text summarization: Rather than instructing the agent to narrate the candidate’s response and also speculate on how the candidate might be feeling, I would want to add the following adjustments:

      • The narrations are returned in a fixed format that corresponds with how the candidate’s responses are represented.
      • If possible, the narrations could be rephrased in first-person speech.
    • Adding agent/models helpers to streaming:

      • Predict whether a candidate is being serious or not when completing the interview. The use of this is to allow Naomi to consider returning bad words to the candidate or return responses that reflect on the candidate’s behavior.
    • Predicting the user’s breed: Pick up where I left off. I’ve come to realize that, despite everything, I was still trying to kill two birds with one stone—fitting Naomi into Tom and vice versa. I should probably just complete Naomi on its own at this point.

    • Testing:

      • Replace validation tools with agent helpers, for example:
        • To ensure the dialogue flows smoothly and naturally.
        • To ensure all questions are asked as intended.

    Self-diagnostic on poor data preparation

    During this trial, I wasn’t aware of the different program designs and I was more focused on challenging myself with different OOPs designs in implementing a chatbot. As a result, many of the data classes / handling functions / prepared datasets were not specifically tailored to Naomi’s case, which added problems to this experiment.

    This setup of this model is incomplete due to my impatience part in mishandling the data preparation stage.

    Tom’s progression · Post 4 of 14

    This post sits in Cognition: Social cognition.

    ← Frankenstein Defining a droid's emotional space →