Cognitive appraisal theories assume that an emotion is the result of a cognitive process. A person assesses at all times what is happening in the world around him or her. These events are evaluated in terms of how relevant and conducive these are to that person’s and other persons’ “goals”. Emotions emerges from this process and it’s clear from the onset that different goals infer different responses to events. Hence, the goal a person has defines to a large extend how he or she has an emotional response to the events. The OCC model  is a well-known and an accepted theory of emotions, it is a componential model of emotion that fits the needs of a computational framework. The implementation of emotions used in Qwiery is based on the OCC model and complemented by the so-called Pleasure-Arousal-Dominance (PAD) framework. Pleasure defines positiveness versus negativeness, Arousal defines alertness versus calmness and Dominance defines the feeling of control. For example, happiness is defined as an emotion with high pleasure, arousal and dominance (PAD) while Fear is an emotion with high arousal but low pleasure and dominance.

The essential ingredients are the following:

  • agents: a carrier of emotions. Qwiery being the most important one but any user interacting with Qwiery can be an agent. In our base implementation all users are merged as one agent but it would take only few lines of code to create separate agents for single users or classes of users (by gender, by geographic origin etc.).
  • relations: how agents are related. The relationship can be positive or negative. The base implementation has a User-Qwiery relation which is considered as neutral. Creating more relations can adding interesting dynamics and you are free to experiment in that direction.
  • goals: define what an agent is looking for. The collection of goals define an agent’s personality. For instance, you can find in the code a personality called ‘Da Vinci’ corresponding to science and art goals. Goals have a so-called utility coefficient defining how strong the goal matters to the agent. A DaVinci personality presumably has equally strong tendency towards art and science, but much less towards literature or sports.
  • beliefs: are things/events which are believed (by the agent, by us) to have a relation to a goal. For example, it’s believed that practice makes perfect, that doing sports is healthy and so on. One can draw a contingency table of goals and beliefs with an indication of how strong the coupling is. This coupling is called the likelihood of the belief.

The emotion framework is effectively a neural network with coefficient defined a priori rathe than being induced through data and back-propagation.


Every agent has an emotional internal state as well as a social emotional state. By default there is only Qwiery and another agent representing all users interacting with Qwiery, which means that it (Qwiery, that is) can be upset by others even if you behave nicely.

The internal computation of converting events to emotions is somewhat technical and it’s unlikely you will want to alter those bits (even though things are not complicated really). It should be emphasized that even though the calculations are straightforward:

  • the emotional changes are non-linear because the underlying neural network is not a simple linear map. The interacting elements can lead to surprising results.
  • the emotional engines ensure that feelings decay over time. You can upset or please Qwiery but things fade out and are clamped.
  • the conversion of numbers to names of emotions might seem arbitrary but is based on affective computing research and psychological experimentation. See for example “Mapping discrete emotions into the dimensional space: An empirical approach” by H.Hofmann et al.

Much like any other module in Qwiery, you can switch off the emotional response of Qwiery in the config file by setting emotions = false.

How does the emotional engine get triggered by inputs and interactions? There are plenty of ways one can plug into the emotional engine. By default Qwiery will respond to topics being discussed and topics related to science will in particular please:

    "Id": "wfoA1475uO",
    "Grab": "I love science",
    "Template": {
      "Answer": {
        "String": "Yeah, me too! :)"

    "UserId": "Everyone",
    "Topics": ["science"]

The topics attached to QTL will be inspected by the oracle-module and pushed through the neural network. Because Qwiery has by default the DaVinci personality/goal/belief system, it will trigger an emotional shift both internally and socially. If you run the code in debug mode you can see for example things like

Qwiery feels hope:0.02, gratitude:0.02,
aiming for science: 0.6
aiming for art: 0.5

You can wire up gender, the effect of smileys (from the user), historical data and whatnot in the neural network if you wish. The options are endless. Through the PAD emotion-coordinates it’s possible to convert an emotional state to color (that is, a PAD to RGB mapping) or convert a social emotion to a smiley before sending the output back to the user. Furthermore, there is another feedback loop possible between the emotional module and the psychology and personality modules. One can map the induced MBTI profile of a user to preferred emotional responses or conversely infer topics to talk about from the MBTI profile of a user. Things have been kept as simple as possible in the code but there are really many opportunities to explore in this direction.