Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[BB3] Memory Heuristics #4770

Merged
merged 5 commits into from
Sep 9, 2022
Merged

[BB3] Memory Heuristics #4770

merged 5 commits into from
Sep 9, 2022

Conversation

klshuster
Copy link
Contributor

Patch description
Implement the following memory heuristics when selecting what memories to show the bot when crafting a response:

  1. memory_overlap_threshold --> if set to > 0, we block any memories that do not have this F1 overlap with the incoming text
  2. memory_hard_block_for_n_turns --> if set to > 0, we block memories that have been used in the last n turns
  3. memory_soft_block_decay_factor --> if set to > 0, we block memories according the following probability: pr(block) = random.random() < decay_factor ** n_turns_since_used

This required an overhaul of how memories are stored in the agent; rather than a list of memories, we now use a dictionary mapping memory: n_turns_since_use

Testing steps
Several more tests added

# we need at least one memory to open with...
memories_to_use = random.sample(list(prefixed_memories.keys()), 1)

new_obs.force_set('text', self._check_and_limit_len('\n'.join(memories_to_use)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we setting text here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're rebuilding the observation for the opening model; 'text' is what the model is seeing

observations = super().observe(observation)
for m in Module.dialogue_modules():
ag_obs = copy.deepcopy(observation)
observations[m] = self.agents[m].observe(ag_obs)
if is_opener(observation['text'], opening_memories):
assert opening_memories
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: having no memory does it make it generate an opening message anyway? I mean, if it doesn't crash the model, it may be a legitimate case to have here (?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_opener checks that opening_memories is non-empty, so this assertion is not necessarily required

@@ -701,7 +725,15 @@ def _failed_messages(replies):
retries += 1
n_mems = [min(1, len(obs['memories']) // 3) for obs in opening_obs]
for i, o in enumerate(opening_obs):
o.force_set('memories', random.sample(o['memories'], n_mems[i]))
mem_indices = random.sample(range(len(o['memories'])), n_mems[i])
o.force_set(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this purge the existing memories if the current item in the batch doesn't have memory access this round?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we're just playing around with the memories sent in the opening message. This is legacy logic for if the opening message is not meaningful (back when our models couldn't handle the opener)

)
non_stopword_text = ' '.join(normal_tokenizer(text, include_pronouns=True))
if (
F1Metric.compute(non_stopword_memory, [non_stopword_text]).value()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe only checking if memory_overlap_threshold > 0? Just saving a bit on F1 compute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good idea

< memory_overlap_threshold
):
continue
if memory_overlap_threshold > 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@klshuster klshuster merged commit 58b6977 into main Sep 9, 2022
@klshuster klshuster deleted the memory_blocking branch September 9, 2022 14:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants