Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust] Compute people memories in ente-photos

laurenspriem18aecd4655ad
diff --git a/rust/crates/ml/examples/memories_text_embeddings.rs b/rust/crates/ml/examples/memories_text_embeddings.rs
index 0555449f87..a569d15a94 100644
--- a/rust/crates/ml/examples/memories_text_embeddings.rs
+++ b/rust/crates/ml/examples/memories_text_embeddings.rs
@@ -174,6 +174,37 @@ const CLIP_MEMORY_TYPES: [(&str, &str); 48] = [
),
];
+const PEOPLE_ACTIVITIES: [(&str, &str); 10] = [
+ (
+ "Admiring",
+ "Photo of two people admiring or looking at each other in a loving but non-intimate and non-physical way",
+ ),
+ (
+ "Embracing",
+ "Photo of people hugging or embracing each other lovingly, without inappropriately kissing or other intimate actions",
+ ),
+ ("Party", "Photo of people celebrating together"),
+ (
+ "Hiking",
+ "Photo of people hiking or walking together in nature",
+ ),
+ ("Feast", "Photo of people having a big feast together"),
+ (
+ "Selfies",
+ "Happy and nostalgic selfie with people, clearly taken from the front camera of a phone",
+ ),
+ (
+ "Posing",
+ "Photo of people posing together in a funny manner for the camera",
+ ),
+ (
+ "Background",
+ "Photo of people with an absolutely stunning or interesting background",
+ ),
+ ("Sports", "Photo of people joyfully playing sports together"),
+ ("Roadtrip", "Photo of people on a road trip together"),
+];
+
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
std::env::var_os("ORT_DYLIB_PATH").context("set ORT_DYLIB_PATH to an ONNX Runtime library")?;
@@ -190,14 +221,18 @@ async fn main() -> Result<()> {
quantize(&result.embedding).with_context(|| format!("quantize {text:?}"))
};
let nostalgia = embed(NOSTALGIA)?;
- let mut clip_memory_types = Vec::with_capacity(CLIP_MEMORY_TYPES.len());
- for (name, query) in CLIP_MEMORY_TYPES {
- clip_memory_types.push((name, embed(query)?));
- }
+ let embed_all = |queries: &[(&'static str, &str)]| -> Result<Vec<(&'static str, Vec<i8>)>> {
+ queries
+ .iter()
+ .map(|(name, query)| Ok((*name, embed(query)?)))
+ .collect()
+ };
+ let clip_memory_types = embed_all(&CLIP_MEMORY_TYPES)?;
+ let people_activities = embed_all(&PEOPLE_ACTIVITIES)?;
let path = manifest_dir.join(OUTPUT);
- std::fs::write(&path, render(&nostalgia, &clip_memory_types)?)
- .with_context(|| format!("write {}", path.display()))?;
+ let source = render(&nostalgia, &clip_memory_types, &people_activities)?;
+ std::fs::write(&path, source).with_context(|| format!("write {}", path.display()))?;
let rustfmt = Command::new("rustfmt")
.args(["--edition", "2024"])
.arg(&path)
@@ -227,9 +262,13 @@ fn quantize(embedding: &[f32]) -> Result<Vec<i8>> {
.collect())
}
-fn render(nostalgia: &[i8], clip_memory_types: &[(&str, Vec<i8>)]) -> Result<String> {
+fn render(
+ nostalgia: &[i8],
+ clip_memory_types: &[(&str, Vec<i8>)],
+ people_activities: &[(&str, Vec<i8>)],
+) -> Result<String> {
let mut source = String::from(
- "use super::output::ClipMemoryType;\n\
+ "use super::output::{ClipMemoryType, PeopleActivity};\n\
use crate::ml_db::CLIP_EMBEDDING_DIMENSIONS;\n\n\
pub(super) type TextEmbedding = [i8; CLIP_EMBEDDING_DIMENSIONS];\n\n",
);
@@ -238,14 +277,10 @@ fn render(nostalgia: &[i8], clip_memory_types: &[(&str, Vec<i8>)]) -> Result<Str
"pub(super) static NOSTALGIA: TextEmbedding = {};\n",
array(nostalgia)
)?;
- source.push_str(
- "impl ClipMemoryType {\n pub(super) fn embedding(self) -> &'static TextEmbedding {\n match self {\n",
- );
- for (name, _) in clip_memory_types {
- writeln!(source, "Self::{name} => &{},", static_name(name))?;
- }
- source.push_str("}\n}\n}\n");
- for (name, embedding) in clip_memory_types {
+ render_embedding_lookup(&mut source, "ClipMemoryType", clip_memory_types)?;
+ source.push('\n');
+ render_embedding_lookup(&mut source, "PeopleActivity", people_activities)?;
+ for (name, embedding) in clip_memory_types.iter().chain(people_activities) {
writeln!(
source,
"\nstatic {}: TextEmbedding = {};",
@@ -256,6 +291,22 @@ fn render(nostalgia: &[i8], clip_memory_types: &[(&str, Vec<i8>)]) -> Result<Str
Ok(source)
}
+fn render_embedding_lookup(
+ source: &mut String,
+ type_name: &str,
+ embeddings: &[(&str, Vec<i8>)],
+) -> Result<()> {
+ writeln!(
+ source,
+ "impl {type_name} {{\n pub(super) fn embedding(self) -> &'static TextEmbedding {{\n match self {{"
+ )?;
+ for (name, _) in embeddings {
+ writeln!(source, "Self::{name} => &{},", static_name(name))?;
+ }
+ source.push_str("}\n}\n}\n");
+ Ok(())
+}
+
fn array(values: &[i8]) -> String {
let values: Vec<String> = values.iter().map(i8::to_string).collect();
format!("[{}]", values.join(", "))
diff --git a/rust/crates/photos/src/memories/clip.rs b/rust/crates/photos/src/memories/clip.rs
index e7da40b6e9..3137a7ed4d 100644
--- a/rust/crates/photos/src/memories/clip.rs
+++ b/rust/crates/photos/src/memories/clip.rs
@@ -80,7 +80,7 @@ mod tests {
use crate::memories::calendar::MICROS_PER_DAY;
use crate::memories::tests::{files_on, micros, period};
use crate::memories::{
- ClipMemoryType, ClipVectors, MemoriesRequest, Memory, MemoryKind, MlInputs,
+ ClipMemoryType, ClipVectors, MemoriesRequest, Memory, MemoryKind, MlInputs, PeopleInputs,
ShownClipMemory, compute_smart_memories,
};
use crate::ml_store::Result;
@@ -136,6 +136,7 @@ mod tests {
let ml = MlInputs {
clip,
face_weights: HashMap::new(),
+ people: PeopleInputs::default(),
};
compute_smart_memories(request, &[period(NOW)], Some(&ml), None)
.unwrap()
diff --git a/rust/crates/photos/src/memories/input.rs b/rust/crates/photos/src/memories/input.rs
index 2cbca7f34e..fef186682f 100644
--- a/rust/crates/photos/src/memories/input.rs
+++ b/rust/crates/photos/src/memories/input.rs
@@ -1,9 +1,9 @@
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use ente_location::{CityMatch, Coordinate};
use super::calendar::{LocalDate, MICROS_PER_DAY, MICROS_PER_SECOND};
-use super::output::ClipMemoryType;
+use super::output::{ClipMemoryType, PeopleMemoryType};
use crate::location::LocationIndex;
use crate::ml_store::Result;
@@ -21,6 +21,10 @@ pub struct MemoryFile {
pub struct MemoriesRequest {
pub files: Vec<MemoryFile>,
pub excluded_collection_ids: Vec<i64>,
+ pub people: Vec<MemoryPerson>,
+ pub me_person_id: Option<String>,
+ pub shows_unnamed_people: bool,
+ pub shown_people: Vec<ShownPerson>,
pub shown_trips: Vec<ShownTrip>,
pub cached_trips: Vec<CachedTrip>,
pub shown_clip_memories: Vec<ShownClipMemory>,
@@ -29,6 +33,20 @@ pub struct MemoriesRequest {
pub seed: u64,
}
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct MemoryPerson {
+ pub id: String,
+ pub is_ignored: bool,
+ pub birth_date: Option<LocalDate>,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct ShownPerson {
+ pub person_id: String,
+ pub memory_type: PeopleMemoryType,
+ pub last_time_shown: i64,
+}
+
#[derive(Clone, Debug, PartialEq)]
pub struct ShownTrip {
pub key: Option<String>,
@@ -76,6 +94,21 @@ impl Period {
pub struct MlInputs<'m> {
pub clip: &'m dyn ClipVectors,
pub face_weights: HashMap<i64, u32>,
+ pub people: PeopleInputs,
+}
+
+#[derive(Clone, Debug, Default, PartialEq, Eq)]
+pub struct PeopleInputs {
+ pub face_counts: HashMap<i64, u32>,
+ pub person_file_ids: HashMap<String, HashSet<i64>>,
+ pub unnamed_clusters: Vec<UnnamedCluster>,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct UnnamedCluster {
+ pub id: String,
+ pub face_count: u32,
+ pub file_ids: HashSet<i64>,
}
pub trait ClipVectors {
diff --git a/rust/crates/photos/src/memories/mod.rs b/rust/crates/photos/src/memories/mod.rs
index 962e2dcb5b..6ca1f09b4f 100644
--- a/rust/crates/photos/src/memories/mod.rs
+++ b/rust/crates/photos/src/memories/mod.rs
@@ -5,6 +5,7 @@ mod geo;
mod input;
mod on_this_day;
mod output;
+mod people;
mod photo;
mod places;
mod rng;
@@ -19,15 +20,16 @@ use std::collections::HashSet;
pub use calendar::LocalDate;
pub use input::{
- CachedTrip, CityLookup, ClipVectors, MemoriesRequest, MemoryFile, MlInputs, Period,
- ShownClipMemory, ShownTrip,
+ CachedTrip, CityLookup, ClipVectors, MemoriesRequest, MemoryFile, MemoryPerson, MlInputs,
+ PeopleInputs, Period, ShownClipMemory, ShownPerson, ShownTrip, UnnamedCluster,
};
pub use output::{
- BaseLocation, BaseMemory, ClipMemoryType, Memory, MemoryKind, SmartMemories, TimeMemory,
- TripMemory,
+ BaseLocation, BaseMemory, Birthday, ClipMemoryType, Memory, MemoryKind, PeopleActivity,
+ PeopleMemory, PeopleMemoryType, SmartMemories, TimeMemory, TripMemory,
};
use input::PhotoSignals;
+use people::People;
use photo::Photo;
use places::Places;
use selector::Selector;
@@ -56,6 +58,10 @@ pub fn compute_smart_memories(
.map(|period| trips::analyze(&located, period.now, &places));
let mut trip_history = TripHistory::new(&request.shown_trips, &request.cached_trips);
let signals = ml.map(Signals::load).transpose()?;
+ let people = ml
+ .zip(signals.as_ref())
+ .map(|(ml, signals)| People::new(&photos, request, &ml.people, signals))
+ .transpose()?;
let mut selector = Selector::new(
signals.as_ref().map(|signals| signals as &dyn PhotoSignals),
request.seed,
@@ -64,6 +70,9 @@ pub fn compute_smart_memories(
for &period in periods {
let mut memories =
on_this_day::memories(&photos, period, &excluded_collection_ids, &mut selector);
+ if let Some(people) = &people {
+ memories.extend(people.memories(period, &mut selector)?);
+ }
if let Some(analysis) = &analysis {
let trip_memories = trips::memories(
analysis,
diff --git a/rust/crates/photos/src/memories/output.rs b/rust/crates/photos/src/memories/output.rs
index 80c57252ce..a71f3710b5 100644
--- a/rust/crates/photos/src/memories/output.rs
+++ b/rust/crates/photos/src/memories/output.rs
@@ -28,6 +28,7 @@ pub struct Memory {
#[derive(Clone, Debug, PartialEq)]
pub enum MemoryKind {
OnThisDay,
+ People(PeopleMemory),
Trip(TripMemory),
Base(BaseMemory),
Clip(ClipMemoryType),
@@ -35,6 +36,58 @@ pub enum MemoryKind {
Filler { years_ago: i32 },
}
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct PeopleMemory {
+ pub person_id: String,
+ pub is_unnamed_cluster: bool,
+ pub memory_type: PeopleMemoryType,
+ pub activity: Option<PeopleActivity>,
+ pub birthday: Option<Birthday>,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum PeopleMemoryType {
+ YouAndThem,
+ DoingSomethingTogether,
+ Spotlight,
+ LastTimeYouSawThem,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum PeopleActivity {
+ Admiring,
+ Embracing,
+ Party,
+ Hiking,
+ Feast,
+ Selfies,
+ Posing,
+ Background,
+ Sports,
+ Roadtrip,
+}
+
+impl PeopleActivity {
+ pub const ALL: [Self; 10] = [
+ Self::Admiring,
+ Self::Embracing,
+ Self::Party,
+ Self::Hiking,
+ Self::Feast,
+ Self::Selfies,
+ Self::Posing,
+ Self::Background,
+ Self::Sports,
+ Self::Roadtrip,
+ ];
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct Birthday {
+ pub is_upcoming: bool,
+ pub new_age: i32,
+}
+
#[derive(Clone, Debug, PartialEq)]
pub struct TripMemory {
pub location: Coordinate,
diff --git a/rust/crates/photos/src/memories/people.rs b/rust/crates/photos/src/memories/people.rs
new file mode 100644
index 0000000000..c32d9702f7
--- /dev/null
+++ b/rust/crates/photos/src/memories/people.rs
@@ -0,0 +1,1020 @@
+use std::cmp::Reverse;
+use std::collections::{BTreeSet, HashMap, HashSet};
+
+use super::calendar::{Anniversary, LocalDate, MICROS_PER_DAY, upcoming_anniversary};
+use super::input::{
+ MemoriesRequest, MemoryPerson, PeopleInputs, Period, PhotoSignals, ShownPerson, UnnamedCluster,
+};
+use super::output::{Birthday, Memory, MemoryKind, PeopleActivity, PeopleMemory, PeopleMemoryType};
+use super::photo::{Photo, sort_chronologically};
+use super::selector::{Selector, best_for_person, first_distinct_and_spaced};
+use super::signals::Signals;
+use super::{MAX_MEMORY_ITEMS, MINIMUM_MEMORY_LENGTH, UPDATE_FREQUENCY_DAYS};
+use crate::ml_store::Result;
+
+const ACTIVITY_SIMILARITY: f32 = 0.20;
+const PERSON_SHOW_TIMEOUT_DAYS: i64 = 16 * UPDATE_FREQUENCY_DAYS;
+const LONG_AGO_DAYS: i64 = 365;
+const MINIMUM_LAST_SEEN_PHOTOS: usize = 2;
+const LAST_MET_WINDOW_DAYS: i64 = 7;
+const BIRTHDAY_WINDOW_DAYS: i64 = 7;
+const UPCOMING_BIRTHDAY_LEAD_DAYS: i64 = 5;
+const ROTATION_MEMORIES_PER_PERSON: usize = 2;
+const FEW_MEMORY_TYPES: usize = 2;
+const NAMED_PEOPLE_DISABLING_UNNAMED_FALLBACK: usize = 5;
+const MAXIMUM_UNNAMED_PEOPLE: usize = 10;
+const MAXIMUM_UNNAMED_GROUP_SIZE: u32 = 6;
+const MINIMUM_UNNAMED_NON_CONSECUTIVE_DAYS: usize = 4;
+const UNNAMED_PERSON_ID_PREFIX: &str = "cluster:";
+
+pub(super) struct People<'a> {
+ persons: Vec<Person<'a>>,
+ unnamed_people: Vec<UnnamedPerson<'a>>,
+ uses_unnamed_fallback: bool,
+ surface_all: bool,
+ show_timeout_days: i64,
+ shown: &'a [ShownPerson],
+ face_counts: &'a HashMap<i64, u32>,
+ signals: &'a dyn PhotoSignals,
+}
+
+struct Person<'a> {
+ id: &'a str,
+ is_me: bool,
+ birth_date: Option<LocalDate>,
+ photos: Vec<&'a Photo>,
+ spotlight: Option<Vec<&'a Photo>>,
+ you_and_them: Option<Vec<&'a Photo>>,
+ activities: Vec<(PeopleActivity, Vec<&'a Photo>)>,
+}
+
+struct UnnamedPerson<'a> {
+ id: String,
+ photos: Vec<&'a Photo>,
+}
+
+#[derive(Clone, Copy)]
+struct Me<'a> {
+ id: &'a str,
+ file_ids: &'a HashSet<i64>,
+}
+
+#[derive(Clone, Copy)]
+struct Candidate<'c, 'a> {
+ person_id: &'c str,
+ is_unnamed_cluster: bool,
+ memory_type: PeopleMemoryType,
+ activity: Option<PeopleActivity>,
+ photos: &'c [&'a Photo],
+}
+
+impl<'a> People<'a> {
+ pub(super) fn new(
+ photos: &'a [Photo],
+ request: &'a MemoriesRequest,
+ inputs: &'a PeopleInputs,
+ signals: &'a Signals<'_>,
+ ) -> Result<Self> {
+ let photos_by_id: HashMap<i64, &Photo> =
+ photos.iter().map(|photo| (photo.id, photo)).collect();
+ let no_file_ids = HashSet::new();
+ let me = request.me_person_id.as_deref().map(|id| Me {
+ id,
+ file_ids: inputs.person_file_ids.get(id).unwrap_or(&no_file_ids),
+ });
+ let mut important: Vec<&MemoryPerson> = request
+ .people
+ .iter()
+ .filter(|person| !request.local_gallery_mode && !person.is_ignored)
+ .collect();
+ important.sort_by_key(|&person| &person.id);
+ let activity_file_ids = match me {
+ Some(me) if important.iter().any(|person| person.id != me.id) => {
+ activity_file_ids(signals)?
+ }
+ _ => Vec::new(),
+ };
+ let uses_unnamed_fallback = request.shows_unnamed_people
+ && (request.local_gallery_mode
+ || important.len() < NAMED_PEOPLE_DISABLING_UNNAMED_FALLBACK);
+ let unnamed_people =
+ if uses_unnamed_fallback || (request.shows_unnamed_people && request.surface_all) {
+ unnamed_people(inputs, &photos_by_id, me)
+ } else {
+ Vec::new()
+ };
+ Ok(Self {
+ show_timeout_days: PERSON_SHOW_TIMEOUT_DAYS
+ .min(important.len().max(1) as i64 * UPDATE_FREQUENCY_DAYS),
+ persons: important
+ .into_iter()
+ .map(|person| Person::new(person, inputs, &photos_by_id, me, &activity_file_ids))
+ .collect(),
+ unnamed_people,
+ uses_unnamed_fallback,
+ surface_all: request.surface_all,
+ shown: &request.shown_people,
+ face_counts: &inputs.face_counts,
+ signals,
+ })
+ }
+
+ pub(super) fn memories(&self, period: Period, selector: &mut Selector) -> Result<Vec<Memory>> {
+ let mut persons: Vec<&Person> = self.persons.iter().collect();
+ selector.shuffle(&mut persons);
+ if self.surface_all {
+ return self.all_memories(&persons, period);
+ }
+ let mut memories = Vec::new();
+ let mut rotation_pool = Vec::with_capacity(persons.len());
+ for person in persons {
+ let relevant = self.relevant_memories(person, period)?;
+ if relevant.is_empty() {
+ rotation_pool.push(person);
+ }
+ memories.extend(relevant);
+ }
+ let rotation = self.rotation_memories(&rotation_pool, period, selector)?;
+ let needs_fallback = rotation.is_empty() && self.uses_unnamed_fallback;
+ memories.extend(rotation);
+ if needs_fallback {
+ memories.extend(self.unnamed_memory(period, selector)?);
+ }
+ Ok(memories)
+ }
+
+ fn all_memories(&self, persons: &[&Person], period: Period) -> Result<Vec<Memory>> {
+ let today = period.today();
+ persons
+ .iter()
+ .flat_map(|person| person.candidates_by_type(today))
+ .flatten()
+ .chain(self.unnamed_people.iter().map(UnnamedPerson::candidate))
+ .map(|candidate| self.memory(candidate, period))
+ .collect()
+ }
+
+ fn relevant_memories(&self, person: &Person, period: Period) -> Result<Vec<Memory>> {
+ let today = period.today();
+ let mut memories = Vec::new();
+ if let Some(last_seen) = person.last_seen(today)
+ && is_last_met_anniversary_near(last_seen, today)
+ {
+ memories.push(self.memory(last_seen, period)?);
+ }
+ let birthday = person
+ .birth_date
+ .and_then(|date| upcoming_anniversary(date, today, BIRTHDAY_WINDOW_DAYS));
+ if let Some(birthday) = birthday {
+ let spotlight = person.spotlight().filter(|_| !person.is_me);
+ for candidate in spotlight.into_iter().chain(person.you_and_them()) {
+ memories.extend(self.birthday_memories(candidate, &birthday, period)?);
+ }
+ }
+ Ok(memories)
+ }
+
+ fn rotation_memories(
+ &self,
+ persons: &[&Person],
+ period: Period,
+ selector: &mut Selector,
+ ) -> Result<Vec<Memory>> {
+ let today = period.today();
+ for person in persons {
+ if self.was_shown_within(self.show_timeout_days, period, person.id, None) {
+ continue;
+ }
+ let types = person.candidates_by_type(today);
+ let mut memories = Vec::with_capacity(ROTATION_MEMORIES_PER_PERSON);
+ for candidates in &types {
+ let candidate = candidates[selector.below(candidates.len())];
+ let type_is_cooling_down = types.len() > FEW_MEMORY_TYPES
+ && self.was_shown_within(
+ self.show_timeout_days * 2,
+ period,
+ person.id,
+ Some(candidate.memory_type),
+ );
+ if !type_is_cooling_down {
+ memories.push(self.memory(candidate, period)?);
+ }
+ if memories.len() == ROTATION_MEMORIES_PER_PERSON {
+ break;
+ }
+ }
+ if !memories.is_empty() {
+ return Ok(memories);
+ }
+ }
+ Ok(Vec::new())
+ }
+
+ fn unnamed_memory(&self, period: Period, selector: &mut Selector) -> Result<Option<Memory>> {
+ let eligible: Vec<&UnnamedPerson> = self
+ .unnamed_people
+ .iter()
+ .filter(|person| {
+ !self.was_shown_within(self.show_timeout_days, period, &person.id, None)
+ })
+ .collect();
+ let weights: Vec<i64> = eligible
+ .iter()
+ .map(|person| self.unnamed_weight(person, period))
+ .collect();
+ let mut remaining = selector.below(weights.iter().sum::<i64>() as usize) as i64;
+ let chosen = weights.iter().position(|weight| {
+ remaining -= weight;
+ remaining < 0
+ });
+ chosen
+ .map(|index| self.memory(eligible[index].candidate(), period))
+ .transpose()
+ }
+
+ fn unnamed_weight(&self, person: &UnnamedPerson, period: Period) -> i64 {
+ self.shown
+ .iter()
+ .filter(|shown| shown.person_id == person.id)
+ .map(|shown| shown.last_time_shown)
+ .max()
+ .map_or(self.show_timeout_days * 2, |last_time_shown| {
+ ((period.now - last_time_shown) / MICROS_PER_DAY).max(1)
+ })
+ }
+
+ fn was_shown_within(
+ &self,
+ days: i64,
+ period: Period,
+ person_id: &str,
+ memory_type: Option<PeopleMemoryType>,
+ ) -> bool {
+ let cutoff = period.now - days * MICROS_PER_DAY;
+ self.shown
+ .iter()
+ .filter(|shown| shown.person_id == person_id)
+ .filter(|shown| memory_type.is_none_or(|memory_type| memory_type == shown.memory_type))
+ .any(|shown| shown.last_time_shown > cutoff)
+ }
+
+ fn memory(&self, candidate: Candidate, period: Period) -> Result<Memory> {
+ Ok(Memory::new(
+ candidate.kind(None),
+ &self.photos(candidate)?,
+ period.now,
+ period.now + UPDATE_FREQUENCY_DAYS * MICROS_PER_DAY,
+ ))
+ }
+
+ fn birthday_memories(
+ &self,
+ candidate: Candidate,
+ birthday: &Anniversary,
+ period: Period,
+ ) -> Result<[Memory; 2]> {
+ let date = period.today().plus_days(birthday.days_from_today);
+ let starts_at = period.start_of(date);
+ let photos = self.photos(candidate)?;
+ let memory = |is_upcoming, first_date_to_show, last_date_to_show| {
+ let birthday = Birthday {
+ is_upcoming,
+ new_age: birthday.years_ago,
+ };
+ Memory::new(
+ candidate.kind(Some(birthday)),
+ &photos,
+ first_date_to_show,
+ last_date_to_show,
+ )
+ };
+ Ok([
+ memory(
+ true,
+ period.start_of(date.plus_days(-UPCOMING_BIRTHDAY_LEAD_DAYS)),
+ starts_at,
+ ),
+ memory(false, starts_at, period.start_of(date.plus_days(1))),
+ ])
+ }
+
+ fn photos<'c>(&self, candidate: Candidate<'c, 'a>) -> Result<Vec<&'a Photo>> {
+ if candidate.memory_type == PeopleMemoryType::LastTimeYouSawThem {
+ return first_distinct_and_spaced(
+ candidate.photos,
+ MINIMUM_LAST_SEEN_PHOTOS,
+ MAX_MEMORY_ITEMS,
+ self.signals,
+ );
+ }
+ let mut photos = best_for_person(candidate.photos.to_vec(), self.signals)?;
+ if candidate.is_unnamed_cluster {
+ self.move_fewest_faces_to_front(&mut photos);
+ }
+ Ok(photos)
+ }
+
+ fn move_fewest_faces_to_front(&self, photos: &mut [&Photo]) {
+ let fewest_faces = photos
+ .iter()
+ .enumerate()
+ .min_by_key(|(_, photo)| self.face_counts.get(&photo.id).copied().unwrap_or(u32::MAX));
+ if let Some((index, _)) = fewest_faces {
+ photos[..=index].rotate_right(1);
+ }
+ }
+}
+
+impl<'a> Person<'a> {
+ fn new(
+ person: &'a MemoryPerson,
+ inputs: &PeopleInputs,
+ photos_by_id: &HashMap<i64, &'a Photo>,
+ me: Option<Me>,
+ activity_file_ids: &[(PeopleActivity, HashSet<i64>)],
+ ) -> Self {
+ let mut photos: Vec<&Photo> = inputs
+ .person_file_ids
+ .get(&person.id)
+ .into_iter()
+ .flatten()
+ .filter_map(|file_id| photos_by_id.get(file_id).copied())
+ .collect();
+ sort_chronologically(&mut photos);
+ let face_count = |photo: &Photo| inputs.face_counts.get(&photo.id).copied();
+ let enough_matching = |matches: &dyn Fn(&Photo) -> bool| {
+ let matching: Vec<&Photo> = photos
+ .iter()
+ .copied()
+ .filter(|photo| matches(photo))
+ .collect();
+ (matching.len() > MINIMUM_MEMORY_LENGTH).then_some(matching)
+ };
+ let other_than_me = me.filter(|me| me.id != person.id);
+ Self {
+ id: &person.id,
+ is_me: me.is_some_and(|me| me.id == person.id),
+ birth_date: person.birth_date,
+ spotlight: enough_matching(&|photo| face_count(photo).is_some_and(|count| count <= 1)),
+ you_and_them: other_than_me.and_then(|me| {
+ enough_matching(&|photo| {
+ me.file_ids.contains(&photo.id) && face_count(photo) == Some(2)
+ })
+ }),
+ activities: other_than_me
+ .iter()
+ .flat_map(|_| activity_file_ids)
+ .filter_map(|(activity, file_ids)| {
+ let photos = enough_matching(&|photo| file_ids.contains(&photo.id))?;
+ Some((*activity, photos))
+ })
+ .collect(),
+ photos,
+ }
+ }
+
+ fn candidate<'c>(
+ &'c self,
+ memory_type: PeopleMemoryType,
+ activity: Option<PeopleActivity>,
+ photos: &'c [&'a Photo],
+ ) -> Candidate<'c, 'a> {
+ Candidate {
+ person_id: self.id,
+ is_unnamed_cluster: false,
+ memory_type,
+ activity,
+ photos,
+ }
+ }
+
+ fn spotlight(&self) -> Option<Candidate<'_, 'a>> {
+ let photos = self.spotlight.as_deref()?;
+ Some(self.candidate(PeopleMemoryType::Spotlight, None, photos))
+ }
+
+ fn you_and_them(&self) -> Option<Candidate<'_, 'a>> {
+ let photos = self.you_and_them.as_deref()?;
+ Some(self.candidate(PeopleMemoryType::YouAndThem, None, photos))
+ }
+
+ fn last_seen(&self, today: LocalDate) -> Option<Candidate<'_, 'a>> {
+ let is_long_ago = self
+ .photos
+ .iter()
+ .all(|photo| photo.date.days_until(today) >= LONG_AGO_DAYS);
+ if self.is_me || !is_long_ago {
+ return None;
+ }
+ let last_day_start = self
+ .photos
+ .windows(2)
+ .rposition(|pair| pair[1].creation_time - pair[0].creation_time > MICROS_PER_DAY)
+ .map_or(0, |gap| gap + 1);
+ let last_day = &self.photos[last_day_start..];
+ (last_day.len() >= MINIMUM_LAST_SEEN_PHOTOS)
+ .then(|| self.candidate(PeopleMemoryType::LastTimeYouSawThem, None, last_day))
+ }
+
+ fn candidates_by_type(&self, today: LocalDate) -> Vec<Vec<Candidate<'_, 'a>>> {
+ let activities: Vec<Candidate> = self
+ .activities
+ .iter()
+ .map(|(activity, photos)| {
+ self.candidate(
+ PeopleMemoryType::DoingSomethingTogether,
+ Some(*activity),
+ photos,
+ )
+ })
+ .collect();
+ [
+ self.spotlight().into_iter().collect(),
+ self.you_and_them().into_iter().collect(),
+ activities,
+ self.last_seen(today).into_iter().collect(),
+ ]
+ .into_iter()
+ .filter(|candidates: &Vec<Candidate>| !candidates.is_empty())
+ .collect()
+ }
+}
+
+impl<'a> UnnamedPerson<'a> {
+ fn candidate(&self) -> Candidate<'_, 'a> {
+ Candidate {
+ person_id: &self.id,
+ is_unnamed_cluster: true,
+ memory_type: PeopleMemoryType::Spotlight,
+ activity: None,
+ photos: &self.photos,
+ }
+ }
+}
+
+impl Candidate<'_, '_> {
+ fn kind(&self, birthday: Option<Birthday>) -> MemoryKind {
+ MemoryKind::People(PeopleMemory {
+ person_id: self.person_id.to_owned(),
+ is_unnamed_cluster: self.is_unnamed_cluster,
+ memory_type: self.memory_type,
+ activity: self.activity,
+ birthday,
+ })
+ }
+}
+
+fn activity_file_ids(signals: &Signals) -> Result<Vec<(PeopleActivity, HashSet<i64>)>> {
+ PeopleActivity::ALL
+ .into_iter()
+ .map(|activity| {
+ let file_ids = signals
+ .matches(activity.embedding(), ACTIVITY_SIMILARITY)?
+ .into_iter()
+ .filter(|&(_, similarity)| similarity > ACTIVITY_SIMILARITY)
+ .map(|(file_id, _)| file_id)
+ .collect();
+ Ok((activity, file_ids))
+ })
+ .collect()
+}
+
+fn is_last_met_anniversary_near(last_seen: Candidate, today: LocalDate) -> bool {
+ last_seen.photos.last().is_some_and(|photo| {
+ let anniversary = LocalDate::new(today.year, photo.date.month, photo.date.day);
+ (0..LAST_MET_WINDOW_DAYS).contains(&today.days_until(anniversary))
+ })
+}
+
+fn unnamed_people<'a>(
+ inputs: &'a PeopleInputs,
+ photos_by_id: &HashMap<i64, &'a Photo>,
+ me: Option<Me>,
+) -> Vec<UnnamedPerson<'a>> {
+ if me.is_some_and(|me| me.file_ids.is_empty()) {
+ return Vec::new();
+ }
+ let mut clusters: Vec<&UnnamedCluster> = inputs.unnamed_clusters.iter().collect();
+ clusters.sort_by_key(|&cluster| (Reverse(cluster.face_count), &cluster.id));
+ clusters
+ .into_iter()
+ .filter_map(|cluster| unnamed_person(cluster, inputs, photos_by_id, me))
+ .take(MAXIMUM_UNNAMED_PEOPLE)
+ .collect()
+}
+
+fn unnamed_person<'a>(
+ cluster: &UnnamedCluster,
+ inputs: &PeopleInputs,
+ photos_by_id: &HashMap<i64, &'a Photo>,
+ me: Option<Me>,
+) -> Option<UnnamedPerson<'a>> {
+ let is_in_small_group = |file_id: &&i64| {
+ inputs
+ .face_counts
+ .get(*file_id)
+ .is_some_and(|count| (1..=MAXIMUM_UNNAMED_GROUP_SIZE).contains(count))
+ };
+ let photos: Vec<&Photo> = cluster
+ .file_ids
+ .iter()
+ .filter(is_in_small_group)
+ .filter_map(|file_id| photos_by_id.get(file_id).copied())
+ .collect();
+ let enough_with_me = me.is_none_or(|me| {
+ photos
+ .iter()
+ .filter(|photo| me.file_ids.contains(&photo.id))
+ .count()
+ >= MINIMUM_MEMORY_LENGTH
+ });
+ let qualifies = enough_with_me
+ && photos.len() >= MINIMUM_MEMORY_LENGTH
+ && non_consecutive_days(&photos) >= MINIMUM_UNNAMED_NON_CONSECUTIVE_DAYS;
+ qualifies.then(|| UnnamedPerson {
+ id: format!("{UNNAMED_PERSON_ID_PREFIX}{}", cluster.id),
+ photos,
+ })
+}
+
+fn non_consecutive_days(photos: &[&Photo]) -> usize {
+ let days: BTreeSet<i64> = photos
+ .iter()
+ .map(|photo| photo.date.days_since_epoch())
+ .collect();
+ let gaps = days
+ .iter()
+ .zip(days.iter().skip(1))
+ .filter(|(day, next_day)| *next_day - *day > 1)
+ .count();
+ gaps + 1
+}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::{HashMap, HashSet};
+
+ use crate::memories::calendar::MICROS_PER_DAY;
+ use crate::memories::tests::{files_on, micros, period};
+ use crate::memories::{
+ Birthday, ClipVectors, LocalDate, MemoriesRequest, Memory, MemoryKind, MemoryPerson,
+ MlInputs, PeopleActivity, PeopleInputs, PeopleMemory, PeopleMemoryType, ShownPerson,
+ UnnamedCluster, compute_smart_memories,
+ };
+ use crate::ml_store::Result;
+
+ const NOW: &str = "2026-10-30T09:00:00";
+
+ type Summary = (String, PeopleMemoryType, Option<PeopleActivity>);
+
+ #[derive(Default)]
+ struct Library {
+ request: MemoriesRequest,
+ inputs: PeopleInputs,
+ activities: HashMap<PeopleActivity, Vec<i64>>,
+ }
+
+ impl ClipVectors for Library {
+ fn matches(&self, query: &[f32], _: f32) -> Result<Vec<(i64, f32)>> {
+ let activity = PeopleActivity::ALL.into_iter().find(|activity| {
+ activity
+ .embedding()
+ .iter()
+ .copied()
+ .map(f32::from)
+ .eq(query.iter().copied())
+ });
+ Ok(activity
+ .and_then(|activity| self.activities.get(&activity))
+ .into_iter()
+ .flatten()
+ .map(|&file_id| (file_id, 0.3))
+ .collect())
+ }
+
+ fn vector(&self, _: i64) -> Result<Option<Vec<f32>>> {
+ Ok(None)
+ }
+ }
+
+ impl Library {
+ fn new(person_ids: &[&str]) -> Self {
+ let people = person_ids
+ .iter()
+ .map(|id| MemoryPerson {
+ id: (*id).to_owned(),
+ is_ignored: false,
+ birth_date: None,
+ })
+ .collect();
+ Self {
+ request: MemoriesRequest {
+ people,
+ ..MemoriesRequest::default()
+ },
+ ..Self::default()
+ }
+ }
+
+ fn with_me(person_ids: &[&str]) -> Self {
+ let mut library = Self::new(person_ids);
+ library.request.me_person_id = Some("me".to_owned());
+ library
+ }
+
+ fn add_photos(
+ &mut self,
+ person_ids: &[&str],
+ first_id: i64,
+ date: &str,
+ count: i64,
+ faces: u32,
+ ) {
+ self.request.files.extend(files_on(first_id, date, count));
+ for file_id in first_id..first_id + count {
+ self.inputs.face_counts.insert(file_id, faces);
+ for person_id in person_ids {
+ self.inputs
+ .person_file_ids
+ .entry((*person_id).to_owned())
+ .or_default()
+ .insert(file_id);
+ }
+ }
+ }
+
+ fn memories(&self) -> Vec<Memory> {
+ let ml = MlInputs {
+ clip: self,
+ face_weights: HashMap::new(),
+ people: self.inputs.clone(),
+ };
+ compute_smart_memories(&self.request, &[period(NOW)], Some(&ml), None)
+ .unwrap()
+ .periods
+ .remove(0)
+ }
+
+ fn people_memories(&self) -> Vec<(PeopleMemory, Memory)> {
+ self.memories()
+ .into_iter()
+ .filter_map(|memory| match &memory.kind {
+ MemoryKind::People(people) => Some((people.clone(), memory)),
+ _ => None,
+ })
+ .collect()
+ }
+
+ fn summaries(&self) -> Vec<Summary> {
+ self.people_memories()
+ .into_iter()
+ .map(|(people, _)| (people.person_id, people.memory_type, people.activity))
+ .collect()
+ }
+
+ fn summaries_for_seed(&mut self, seed: u64) -> Vec<Summary> {
+ self.request.seed = seed;
+ self.summaries()
+ }
+ }
+
+ fn summary(
+ person_id: &str,
+ memory_type: PeopleMemoryType,
+ activity: Option<PeopleActivity>,
+ ) -> Summary {
+ (person_id.to_owned(), memory_type, activity)
+ }
+
+ fn shown(person_id: &str, memory_type: PeopleMemoryType, days_ago: i64) -> ShownPerson {
+ ShownPerson {
+ person_id: person_id.to_owned(),
+ memory_type,
+ last_time_shown: micros(NOW) - days_ago * MICROS_PER_DAY,
+ }
+ }
+
+ fn cluster(
+ id: &str,
+ face_count: u32,
+ file_ids: impl IntoIterator<Item = i64>,
+ ) -> UnnamedCluster {
+ UnnamedCluster {
+ id: id.to_owned(),
+ face_count,
+ file_ids: file_ids.into_iter().collect(),
+ }
+ }
+
+ #[test]
+ fn surfacing_everything_lists_each_type_with_more_than_five_photos() {
+ let mut library = Library::with_me(&["me", "alice", "bob", "ignored"]);
+ library.request.people[3].is_ignored = true;
+ library.request.surface_all = true;
+ library.add_photos(&["me"], 1, "2026-05-01", 6, 1);
+ library.add_photos(&["alice"], 11, "2026-05-02", 6, 1);
+ library.add_photos(&["bob"], 21, "2026-05-03", 5, 1);
+ library.add_photos(&["me", "alice"], 31, "2026-05-04", 6, 2);
+ library.add_photos(&["me", "bob"], 41, "2026-05-05", 6, 3);
+ library.add_photos(&["ignored"], 51, "2026-05-06", 6, 1);
+ library.activities = HashMap::from([
+ (PeopleActivity::Party, (1..=6).chain(11..=16).collect()),
+ (PeopleActivity::Hiking, (11..=15).collect()),
+ ]);
+
+ let summaries = library.summaries();
+
+ let of = |person_id: &str| -> Vec<Summary> {
+ summaries
+ .iter()
+ .filter(|summary| summary.0 == person_id)
+ .cloned()
+ .collect()
+ };
+ assert_eq!(summaries.len(), 4);
+ assert_eq!(
+ of("alice"),
+ [
+ summary("alice", PeopleMemoryType::Spotlight, None),
+ summary("alice", PeopleMemoryType::YouAndThem, None),
+ summary(
+ "alice",
+ PeopleMemoryType::DoingSomethingTogether,
+ Some(PeopleActivity::Party)
+ ),
+ ]
+ );
+ assert_eq!(of("me"), [summary("me", PeopleMemoryType::Spotlight, None)]);
+ }
+
+ #[test]
+ fn someone_not_seen_for_a_year_returns_in_the_week_before_their_last_day_comes_round() {
+ let mut library = Library::new(&["alice", "bob", "carol"]);
+ library.add_photos(&["alice"], 1, "2023-03-01", 3, 1);
+ library.add_photos(&["alice"], 11, "2024-11-02", 3, 1);
+ library.add_photos(&["bob"], 21, "2024-11-06", 3, 1);
+ library.add_photos(&["carol"], 31, "2024-11-02", 3, 1);
+ library.add_photos(&["carol"], 41, "2025-10-31", 1, 1);
+ library.request.shown_people = ["alice", "bob", "carol"]
+ .map(|id| shown(id, PeopleMemoryType::Spotlight, 1))
+ .into();
+
+ let memories = library.people_memories();
+
+ assert_eq!(memories.len(), 1);
+ let (people, memory) = &memories[0];
+ assert_eq!(people.person_id, "alice");
+ assert_eq!(people.memory_type, PeopleMemoryType::LastTimeYouSawThem);
+ assert_eq!(memory.file_ids, [11, 12, 13]);
+ assert_eq!(
+ (memory.first_date_to_show, memory.last_date_to_show),
+ (micros(NOW), micros(NOW) + 3 * MICROS_PER_DAY)
+ );
+ }
+
+ #[test]
+ fn birthdays_show_a_lead_up_and_a_day_of_memory_for_spotlight_and_you_and_them() {
+ let birthday = |day| LocalDate {
+ year: 1990,
+ month: 11,
+ day,
+ };
+ let mut library = Library::with_me(&["me", "alice", "bob"]);
+ library.request.people[0].birth_date = Some(birthday(2));
+ library.request.people[1].birth_date = Some(birthday(2));
+ library.request.people[2].birth_date = Some(birthday(6));
+ library.add_photos(&["me"], 1, "2026-05-01", 6, 1);
+ library.add_photos(&["alice"], 11, "2026-05-02", 6, 1);
+ library.add_photos(&["me", "alice"], 21, "2026-05-03", 6, 2);
+ library.add_photos(&["bob"], 31, "2026-05-04", 6, 1);
+
+ let birthdays: Vec<_> = library
+ .people_memories()
+ .into_iter()
+ .filter_map(|(people, memory)| {
+ Some((
+ people.person_id,
+ people.memory_type,
+ people.birthday?,
+ memory.first_date_to_show,
+ memory.last_date_to_show,
+ ))
+ })
+ .collect();
+
+ let (lead_up, day_of, day_after) = (
+ micros("2026-10-28T00:00:00"),
+ micros("2026-11-02T00:00:00"),
+ micros("2026-11-03T00:00:00"),
+ );
+ let entry = |memory_type, is_upcoming, first, last| {
+ let birthday = Birthday {
+ is_upcoming,
+ new_age: 36,
+ };
+ ("alice".to_owned(), memory_type, birthday, first, last)
+ };
+ assert_eq!(
+ birthdays,
+ [
+ entry(PeopleMemoryType::Spotlight, true, lead_up, day_of),
+ entry(PeopleMemoryType::Spotlight, false, day_of, day_after),
+ entry(PeopleMemoryType::YouAndThem, true, lead_up, day_of),
+ entry(PeopleMemoryType::YouAndThem, false, day_of, day_after),
+ ]
+ );
+ }
+
+ #[test]
+ fn rotation_gives_one_rested_person_their_first_two_rested_types() {
+ let mut library = Library::with_me(&["me", "alice", "bob"]);
+ library.add_photos(&["alice"], 1, "2026-05-01", 6, 1);
+ library.add_photos(&["me", "alice"], 11, "2026-05-02", 6, 2);
+ library.add_photos(&["bob"], 21, "2026-05-03", 6, 1);
+ library.activities = HashMap::from([(PeopleActivity::Party, (1..=6).collect())]);
+ library.request.shown_people = vec![
+ shown("alice", PeopleMemoryType::Spotlight, 12),
+ shown("bob", PeopleMemoryType::YouAndThem, 8),
+ ];
+
+ for seed in 0..20 {
+ assert_eq!(
+ library.summaries_for_seed(seed),
+ [
+ summary("alice", PeopleMemoryType::YouAndThem, None),
+ summary(
+ "alice",
+ PeopleMemoryType::DoingSomethingTogether,
+ Some(PeopleActivity::Party)
+ ),
+ ]
+ );
+ }
+
+ library.activities.clear();
+ assert_eq!(
+ library.summaries_for_seed(0),
+ [
+ summary("alice", PeopleMemoryType::Spotlight, None),
+ summary("alice", PeopleMemoryType::YouAndThem, None),
+ ]
+ );
+
+ library.request.shown_people.clear();
+ let chosen_people: HashSet<String> = (0..20)
+ .flat_map(|seed| library.summaries_for_seed(seed))
+ .map(|summary| summary.0)
+ .collect();
+ assert_eq!(
+ chosen_people,
+ HashSet::from(["alice".to_owned(), "bob".to_owned()])
+ );
+ }
+
+ fn unnamed_library(person_ids: &[&str]) -> Library {
+ let mut library = Library::new(person_ids);
+ library.request.shows_unnamed_people = true;
+ for (index, (date, faces)) in [
+ ("2025-01-01", 3),
+ ("2025-01-03", 2),
+ ("2025-01-05", 1),
+ ("2025-01-07", 2),
+ ("2025-01-09", 3),
+ ]
+ .into_iter()
+ .enumerate()
+ {
+ library.add_photos(&[], index as i64 + 1, date, 1, faces);
+ }
+ library.add_photos(&[], 11, "2025-02-01", 5, 2);
+ library.add_photos(&[], 21, "2025-02-03", 5, 7);
+ library.inputs.unnamed_clusters = vec![
+ cluster("same_day", 9, 11..=15),
+ cluster("crowded", 8, 21..=25),
+ cluster("spread_out", 5, 1..=5),
+ ];
+ library
+ }
+
+ #[test]
+ fn unnamed_clusters_fill_in_for_rotation_with_the_clearest_photo_first() {
+ let memories = unnamed_library(&[]).people_memories();
+
+ assert_eq!(memories.len(), 1);
+ let (people, memory) = &memories[0];
+ assert_eq!(people.person_id, "cluster:spread_out");
+ assert!(people.is_unnamed_cluster);
+ assert_eq!(people.memory_type, PeopleMemoryType::Spotlight);
+ assert_eq!(memory.file_ids, [3, 5, 4, 2, 1]);
+ }
+
+ #[test]
+ fn unnamed_clusters_stay_away_when_hidden_cooling_down_or_replaced_by_named_people() {
+ let spotlight =
+ |days_ago| shown("cluster:spread_out", PeopleMemoryType::Spotlight, days_ago);
+ let named_people = ["a", "b", "c", "d", "e"];
+
+ let mut hidden = unnamed_library(&[]);
+ hidden.request.shows_unnamed_people = false;
+ assert!(hidden.people_memories().is_empty());
+
+ let mut cooling_down = unnamed_library(&[]);
+ cooling_down.request.shown_people = vec![spotlight(2)];
+ assert!(cooling_down.people_memories().is_empty());
+
+ let mut rested = unnamed_library(&[]);
+ rested.request.shown_people = vec![spotlight(3)];
+ assert_eq!(rested.people_memories().len(), 1);
+
+ let mut replaced = unnamed_library(&named_people);
+ assert!(replaced.people_memories().is_empty());
+ replaced.request.surface_all = true;
+ assert_eq!(replaced.people_memories().len(), 1);
+
+ let mut local_gallery = unnamed_library(&named_people);
+ local_gallery.add_photos(&["a"], 41, "2026-05-01", 6, 1);
+ local_gallery.request.local_gallery_mode = true;
+ assert_eq!(
+ local_gallery.summaries(),
+ [summary(
+ "cluster:spread_out",
+ PeopleMemoryType::Spotlight,
+ None
+ )]
+ );
+ }
+
+ #[test]
+ fn unnamed_clusters_need_five_photos_with_me_once_i_am_known() {
+ let mut library = unnamed_library(&[]);
+ library.request.me_person_id = Some("me".to_owned());
+ assert!(library.people_memories().is_empty());
+
+ library
+ .inputs
+ .person_file_ids
+ .insert("me".to_owned(), (1..=4).collect());
+ assert!(library.people_memories().is_empty());
+
+ library
+ .inputs
+ .person_file_ids
+ .insert("me".to_owned(), (1..=5).collect());
+ assert_eq!(library.people_memories().len(), 1);
+ }
+
+ #[test]
+ fn unnamed_picks_lean_towards_clusters_not_seen_for_longest() {
+ let mut library = unnamed_library(&[]);
+ for (index, date) in [
+ "2025-03-01",
+ "2025-03-03",
+ "2025-03-05",
+ "2025-03-07",
+ "2025-03-09",
+ ]
+ .into_iter()
+ .enumerate()
+ {
+ library.add_photos(&[], index as i64 + 31, date, 1, 1);
+ }
+ library
+ .inputs
+ .unnamed_clusters
+ .push(cluster("seen_before", 4, 31..=35));
+ library.request.shown_people =
+ vec![shown("cluster:seen_before", PeopleMemoryType::Spotlight, 3)];
+
+ let picks: Vec<String> = (0..300)
+ .flat_map(|seed| library.summaries_for_seed(seed))
+ .map(|summary| summary.0)
+ .collect();
+
+ let seen_before = picks
+ .iter()
+ .filter(|person_id| *person_id == "cluster:seen_before")
+ .count();
+ assert_eq!(picks.len(), 300);
+ assert!((70..130).contains(&seen_before), "{seen_before}");
+ }
+
+ #[test]
+ fn people_memories_follow_on_this_day_and_later_memories_skip_their_photos() {
+ let mut library = Library::new(&["alice"]);
+ library.add_photos(&["alice"], 1, "2024-11-01", 6, 1);
+ library.add_photos(&[], 11, "2023-10-31", 1, 1);
+ library.add_photos(&[], 21, "2024-10-30", 3, 1);
+ library.add_photos(&[], 31, "2023-10-30", 3, 1);
+
+ let memories = library.memories();
+
+ assert!(matches!(memories[0].kind, MemoryKind::OnThisDay));
+ assert!(matches!(memories[1].kind, MemoryKind::People(_)));
+ assert_eq!(memories[1].file_ids, [1, 2, 3, 4, 5, 6]);
+ let later_photos: HashSet<i64> = memories[2..]
+ .iter()
+ .flat_map(|memory| memory.file_ids.iter().copied())
+ .collect();
+ assert_eq!(later_photos, HashSet::from([11]));
+ }
+}
diff --git a/rust/crates/photos/src/memories/rng.rs b/rust/crates/photos/src/memories/rng.rs
index 492cd91178..0b7f32af70 100644
--- a/rust/crates/photos/src/memories/rng.rs
+++ b/rust/crates/photos/src/memories/rng.rs
@@ -13,7 +13,7 @@ impl Rng {
}
}
- fn below(&mut self, bound: usize) -> usize {
+ pub(super) fn below(&mut self, bound: usize) -> usize {
((u128::from(self.next_u64()) * bound as u128) >> 64) as usize
}
diff --git a/rust/crates/photos/src/memories/selector.rs b/rust/crates/photos/src/memories/selector.rs
index a7746ef0b8..e88e9dd73e 100644
--- a/rust/crates/photos/src/memories/selector.rs
+++ b/rust/crates/photos/src/memories/selector.rs
@@ -2,7 +2,10 @@ use std::cmp::Ordering;
use std::collections::{BTreeMap, HashSet};
use std::convert::Infallible;
+use ente_location::Coordinate;
+
use super::calendar::MICROS_PER_MINUTE;
+use super::geo::distance_km;
use super::input::PhotoSignals;
use super::photo::{Photo, sort_chronologically};
use super::rng::Rng;
@@ -10,6 +13,7 @@ use crate::ml_store::Result;
const DEFAULT_SELECTION_SIZE: usize = 10;
const TOP_MATCHES: usize = 50;
+const TOP_SCORES_PERCENT: usize = 30;
const MINIMUM_TIME_GAP: i64 = 10 * MICROS_PER_MINUTE;
const NEAR_DUPLICATE_SIMILARITY: f32 = 0.80;
const FACE_WEIGHT_SCORE: f64 = 1000.0;
@@ -26,6 +30,12 @@ enum Spread {
AcrossYears,
}
+#[derive(Clone, Copy, PartialEq, Eq)]
+enum BucketPick {
+ Best,
+ FarthestOfTheBest,
+}
+
#[derive(Clone, Copy)]
struct Candidate<'p> {
photo: &'p Photo,
@@ -91,6 +101,10 @@ impl<'s> Selector<'s> {
self.rng.shuffle(items);
}
+ pub(super) fn below(&mut self, bound: usize) -> usize {
+ self.rng.below(bound)
+ }
+
pub(super) fn sample_across_years<'p>(
&mut self,
mut photos: Vec<&'p Photo>,
@@ -198,6 +212,58 @@ impl<'s> Selector<'s> {
}
}
+pub(super) fn best_for_person<'p>(
+ mut photos: Vec<&'p Photo>,
+ signals: &dyn PhotoSignals,
+) -> Result<Vec<&'p Photo>> {
+ sort_chronologically(&mut photos);
+ if photos.len() > DEFAULT_SELECTION_SIZE {
+ let candidates = photos
+ .iter()
+ .map(|&photo| Candidate {
+ photo,
+ score: signals.nostalgia(photo.id).map_or(0.0, f64::from),
+ })
+ .collect();
+ photos = ranked_over_time(
+ candidates,
+ DEFAULT_SELECTION_SIZE,
+ BucketPick::FarthestOfTheBest,
+ signals,
+ )?;
+ sort_chronologically(&mut photos);
+ }
+ photos.reverse();
+ Ok(photos)
+}
+
+pub(super) fn first_distinct_and_spaced<'p>(
+ photos: &[&'p Photo],
+ minimum_distinct: usize,
+ limit: usize,
+ signals: &dyn PhotoSignals,
+) -> Result<Vec<&'p Photo>> {
+ let mut distinct = Vec::new();
+ let mut spaced = Vec::with_capacity(limit);
+ let mut skipped = 0;
+ for &photo in photos {
+ if spaced.len() == limit {
+ break;
+ }
+ if photos.len() - skipped > minimum_distinct
+ && is_near_duplicate(photo, &distinct, signals)?
+ {
+ skipped += 1;
+ continue;
+ }
+ distinct.push(photo);
+ if !is_too_close(photo, &spaced) {
+ spaced.push(photo);
+ }
+ }
+ Ok(spaced)
+}
+
fn ranked<'p>(
photos: &[&'p Photo],
size: usize,
@@ -214,7 +280,7 @@ fn ranked<'p>(
.collect();
match spread {
Spread::None => ranked_flat(candidates, size, signals),
- Spread::OverTime => ranked_over_time(candidates, size, signals),
+ Spread::OverTime => ranked_over_time(candidates, size, BucketPick::Best, signals),
Spread::AcrossYears => ranked_across_years(candidates, size, signals),
}
}
@@ -248,6 +314,7 @@ fn ranked_flat<'p>(
fn ranked_over_time<'p>(
candidates: Vec<Candidate<'p>>,
size: usize,
+ pick: BucketPick,
signals: &dyn PhotoSignals,
) -> Result<Vec<&'p Photo>> {
if is_single_moment(&candidates, |candidate| candidate.photo.creation_time) {
@@ -256,6 +323,9 @@ fn ranked_over_time<'p>(
let mut selected: Vec<&Photo> = Vec::with_capacity(size);
for mut bucket in time_buckets(&candidates, size, |candidate| candidate.photo.creation_time) {
sort_by_score(&mut bucket);
+ if pick == BucketPick::FarthestOfTheBest {
+ keep_top_scores(&mut bucket, signals);
+ }
let mut distinct: Vec<Candidate> = Vec::new();
for &candidate in &bucket {
if !is_near_duplicate(candidate.photo, &selected, signals)? {
@@ -267,10 +337,15 @@ fn ranked_over_time<'p>(
} else {
distinct
};
- if let Some(winner) = pool
+ let spaced: Vec<Candidate> = pool
.into_iter()
- .find(|candidate| !is_too_close(candidate.photo, &selected))
- {
+ .filter(|candidate| !is_too_close(candidate.photo, &selected))
+ .collect();
+ let winner = match pick {
+ BucketPick::Best => spaced.first(),
+ BucketPick::FarthestOfTheBest => farthest_from(&spaced, &selected),
+ };
+ if let Some(winner) = winner {
selected.push(winner.photo);
}
}
@@ -295,6 +370,43 @@ fn ranked_over_time<'p>(
Ok(selected)
}
+fn keep_top_scores(bucket: &mut Vec<Candidate>, signals: &dyn PhotoSignals) {
+ let scored = bucket
+ .iter()
+ .filter(|candidate| signals.nostalgia(candidate.photo.id).is_some())
+ .count();
+ if scored * 2 >= bucket.len() {
+ bucket.truncate((bucket.len() * TOP_SCORES_PERCENT / 100).max(1));
+ }
+}
+
+fn farthest_from<'c, 'p>(
+ candidates: &'c [Candidate<'p>],
+ selected: &[&Photo],
+) -> Option<&'c Candidate<'p>> {
+ let selected_locations: Vec<Coordinate> =
+ selected.iter().filter_map(|photo| photo.location).collect();
+ if selected_locations.is_empty() {
+ return candidates.first();
+ }
+ let mut farthest = candidates.first();
+ let mut farthest_distance = -1.0;
+ for candidate in candidates {
+ let Some(location) = candidate.photo.location else {
+ continue;
+ };
+ let distance = selected_locations
+ .iter()
+ .map(|&selected_location| distance_km(location, selected_location))
+ .fold(f64::INFINITY, f64::min);
+ if distance > farthest_distance {
+ farthest = Some(candidate);
+ farthest_distance = distance;
+ }
+ }
+ farthest
+}
+
fn ranked_across_years<'p>(
candidates: Vec<Candidate<'p>>,
size: usize,
@@ -415,7 +527,9 @@ fn is_near_duplicate(
mod tests {
use std::collections::{HashMap, HashSet};
- use super::Selector;
+ use ente_location::Coordinate;
+
+ use super::{Selector, best_for_person, first_distinct_and_spaced};
use crate::memories::input::{MemoryFile, PhotoSignals};
use crate::memories::photo::{Photo, prepare};
use crate::memories::tests::{file, micros};
@@ -559,6 +673,85 @@ mod tests {
assert_ne!(selected, pick(6));
}
+ fn hundred_days_with_a_few_locations() -> Vec<MemoryFile> {
+ let mut files = daily(1, "2024-01-01T12:00:00", 100);
+ for (id, latitude) in [(10, 1.0), (15, 80.0), (18, 40.0), (19, 1.0), (20, 1.0)] {
+ files[id - 1].location = Some(Coordinate::new(latitude, 10.0));
+ }
+ files
+ }
+
+ #[test]
+ fn person_picks_favour_new_places_among_the_top_scores_of_each_period_newest_first() {
+ let photos = prepare(&hundred_days_with_a_few_locations());
+ let signals = Signals {
+ nostalgia: (1..=100).map(|id| (id, id as f32 / 1000.0)).collect(),
+ ..Signals::default()
+ };
+
+ let selected = best_for_person(photos.iter().collect(), &signals).unwrap();
+
+ assert_eq!(ids(&selected), [100, 90, 80, 70, 60, 50, 40, 30, 18, 10]);
+ }
+
+ #[test]
+ fn person_picks_consider_a_whole_period_when_most_of_it_has_no_score() {
+ let photos = prepare(&hundred_days_with_a_few_locations());
+ let signals = Signals {
+ nostalgia: (1..=100)
+ .filter(|id| !(15..=20).contains(id))
+ .map(|id| (id, id as f32 / 1000.0))
+ .collect(),
+ ..Signals::default()
+ };
+
+ let selected = best_for_person(photos.iter().collect(), &signals).unwrap();
+
+ assert_eq!(ids(&selected), [100, 90, 80, 70, 60, 50, 40, 30, 15, 10]);
+ }
+
+ #[test]
+ fn small_person_sets_are_kept_whole_newest_first() {
+ let photos = prepare(&daily(1, "2024-01-01T12:00:00", 3));
+
+ let selected = best_for_person(photos.iter().collect(), &Signals::default()).unwrap();
+
+ assert_eq!(ids(&selected), [3, 2, 1]);
+ }
+
+ #[test]
+ fn near_duplicates_go_until_only_the_minimum_remains() {
+ let photos = prepare(&daily(1, "2024-01-01T12:00:00", 4));
+ let photos: Vec<&Photo> = photos.iter().collect();
+ let signals = Signals {
+ near_duplicates: HashSet::from([(1, 2), (1, 3), (1, 4)]),
+ ..Signals::default()
+ };
+
+ let kept = first_distinct_and_spaced(&photos, 2, 10, &signals).unwrap();
+
+ assert_eq!(ids(&kept), [1, 4]);
+ }
+
+ #[test]
+ fn photos_within_ten_minutes_of_a_kept_one_go_and_the_limit_ends_the_pass() {
+ let start = micros("2024-01-01T12:00:00");
+ let files: Vec<MemoryFile> = [0, 5, 10, 12, 20, 30]
+ .into_iter()
+ .map(|minutes| MemoryFile {
+ creation_time: start + minutes * 60_000_000,
+ ..file(minutes, "1970-01-01T00:00:00")
+ })
+ .collect();
+ let photos = prepare(&files);
+ let photos: Vec<&Photo> = photos.iter().collect();
+ let signals = Signals::default();
+
+ let kept = first_distinct_and_spaced(&photos, 2, 3, &signals).unwrap();
+
+ assert_eq!(ids(&kept), [0, 10, 20]);
+ }
+
#[test]
fn small_sets_are_kept_whole_in_chronological_order() {
let photos = prepare(&daily(0, "2024-01-01T12:00:00", 5));
diff --git a/rust/crates/photos/src/memories/signals.rs b/rust/crates/photos/src/memories/signals.rs
index 725b3e606c..f05063a14c 100644
--- a/rust/crates/photos/src/memories/signals.rs
+++ b/rust/crates/photos/src/memories/signals.rs
@@ -88,7 +88,7 @@ mod tests {
use std::collections::HashMap;
use super::Signals;
- use crate::memories::input::{ClipVectors, MlInputs, PhotoSignals};
+ use crate::memories::input::{ClipVectors, MlInputs, PeopleInputs, PhotoSignals};
use crate::ml_store::Result;
struct Clip;
@@ -113,6 +113,7 @@ mod tests {
let ml = MlInputs {
clip: &Clip,
face_weights: HashMap::from([(1, 12)]),
+ people: PeopleInputs::default(),
};
let signals = Signals::load(&ml).unwrap();
diff --git a/rust/crates/photos/src/memories/text_embeddings.rs b/rust/crates/photos/src/memories/text_embeddings.rs
index a2e6ca2d00..54c724c2c7 100644
--- a/rust/crates/photos/src/memories/text_embeddings.rs
+++ b/rust/crates/photos/src/memories/text_embeddings.rs
@@ -1,4 +1,4 @@
-use super::output::ClipMemoryType;
+use super::output::{ClipMemoryType, PeopleActivity};
use crate::ml_db::CLIP_EMBEDDING_DIMENSIONS;
pub(super) type TextEmbedding = [i8; CLIP_EMBEDDING_DIMENSIONS];
@@ -81,6 +81,23 @@ impl ClipMemoryType {
}
}
+impl PeopleActivity {
+ pub(super) fn embedding(self) -> &'static TextEmbedding {
+ match self {
+ Self::Admiring => &ADMIRING,
+ Self::Embracing => &EMBRACING,
+ Self::Party => &PARTY,
+ Self::Hiking => &HIKING,
+ Self::Feast => &FEAST,
+ Self::Selfies => &SELFIES,
+ Self::Posing => &POSING,
+ Self::Background => &BACKGROUND,
+ Self::Sports => &SPORTS,
+ Self::Roadtrip => &ROADTRIP,
+ }
+ }
+}
+
static SUNRISE: TextEmbedding = [
4, 3, 5, -5, 3, 1, -4, 9, 21, 3, 0, -8, -9, -3, -3, 126, -6, -6, 4, -2, -2, -3, -1, 6, 3, -11,
9, 2, 2, -7, 0, -3, -3, 3, -9, 8, 2, 0, -10, 7, 9, -4, 2, -5, -1, -8, 2, 10, -2, 5, 3, 10, -11,
@@ -1199,3 +1216,234 @@ static BABY_SMILES: TextEmbedding = [
-1, -4, -10, -12, 2, 0, 9, 3, -8, -6, 3, -6, 4, 2, 0, 2, 9, -1, 8, -2, -3, -5, -10, -12, -4,
-1, 2, 0, 2, 1, 6, 3, 0, -8, 1, 4, 1, 4, 3, -3, -1, 1, 2, 2, 1, 10, -1, 2, -16,
];
+
+static ADMIRING: TextEmbedding = [
+ -7, -4, -5, 14, 2, 6, 3, 2, -12, -12, 7, -4, -3, -4, 8, 126, 4, 5, -4, -3, 2, -2, -1, -1, -1,
+ 0, 2, -3, -6, 9, 0, 2, 7, -11, -6, 0, -11, 7, -3, -9, 3, -1, -3, 7, -3, -7, 0, -14, -2, 11, 3,
+ 7, 0, 4, 4, 0, 8, 0, -8, 0, -2, 2, 0, 12, -2, 9, 0, 1, 0, 19, -5, 9, 5, 6, 0, -4, -28, 8, 5,
+ -9, -7, -5, 1, -5, 3, 0, -1, -3, 0, 10, 1, 3, -6, 10, -6, 14, 4, -1, 1, 6, 1, -6, 0, -9, 9, 15,
+ -16, 8, 2, -1, 2, -3, 31, 4, 2, -10, 1, -1, -1, 8, 1, -7, -2, -1, 2, 1, 2, -3, 2, -7, 3, 2, -2,
+ 2, 12, 0, -2, 7, 10, 0, 3, -3, -5, -2, -2, -7, -8, 6, -13, -8, -5, 8, -12, 8, 5, 2, 6, 3, 4,
+ -6, -2, 2, -12, 6, -8, 5, 2, -127, 0, -5, -4, 19, 0, 3, -1, 1, 4, -5, 8, -5, 0, 2, -5, -7, 3,
+ -1, -7, -3, 2, -1, -4, -2, 9, -3, -5, -7, 2, 13, -12, 4, -1, 6, 0, 6, 0, -4, 2, -6, -5, 3, 6,
+ -7, -11, 1, -1, -16, 0, -6, -2, -2, -3, -6, -3, 16, -4, -5, 6, -6, -2, -2, -10, -6, 1, -10, -1,
+ 10, -1, -8, -9, -4, 5, 2, -8, 7, 3, 3, -7, 2, -19, -8, 2, -9, 8, 1, 3, -3, -4, 14, -5, 7, -6,
+ -4, 9, 13, -4, -7, 6, 5, 1, -2, 1, -3, -8, -6, 9, 4, -4, -2, 3, -6, 12, 12, -6, 5, 11, 9, -3,
+ 5, -16, -5, 2, -2, -12, -2, 4, 4, -6, 3, 9, 3, 1, 0, 1, 5, 1, -6, -4, 0, -1, 10, 8, 1, -5, -3,
+ -1, 0, -15, 5, -17, -7, 8, 13, 5, 11, -7, -3, -4, 9, -2, 2, 4, -6, 11, 9, -9, 0, 2, -5, -10,
+ -4, -3, 0, 10, 4, -3, -4, 0, 2, -12, 2, -6, 9, 0, -14, 5, 14, -11, -10, 4, 6, -7, -7, -1, 4, 8,
+ -7, 1, -10, 8, 0, -4, -9, -7, -2, 9, 1, 4, -9, -16, 1, -9, -4, -4, 4, 7, 1, -1, -1, 8, -11,
+ -20, 0, 7, -1, -5, 1, -1, -8, -8, -24, -7, -9, -5, -4, -5, -3, 3, 2, 3, -7, -9, 4, 5, -1, 9, 9,
+ 4, -7, 1, 5, 13, -10, -4, 0, -2, -4, 1, -7, 8, -5, -7, -6, 1, -2, -11, 8, 8, 0, -4, 0, -1, -5,
+ 7, 3, -3, 8, -3, 8, -3, -14, -9, -3, 1, -4, 0, 0, 6, 8, 4, 7, -2, 4, -7, -8, 1, 13, -5, 8, 0,
+ 6, -5, 4, -7, 4, -2, -2, 0, 2, -4, 3, 4, 24, 8, -3, 5, -10, -26, -6, -1, 1, 5, 8, 6, 0, 4, 3,
+ 5, -7, 4, 3, -3, 2, 7, 0, 5, 6, -2, 4, 5, 2, 3, -3,
+];
+
+static EMBRACING: TextEmbedding = [
+ 7, 2, -5, 5, 7, -1, 5, 9, -18, -10, 3, -3, 5, 5, 15, 126, -2, -1, -10, -4, -8, -6, -16, 2, 2,
+ 3, -10, 0, -3, 11, -10, -4, 2, -15, -6, 0, -9, 10, 4, -6, 7, -1, -5, 11, -1, -14, -6, -14, -3,
+ 3, -6, 20, 0, 0, -6, -4, 8, 6, 0, -3, -6, 2, 2, 4, -8, 6, -1, 4, 0, 13, -5, 7, 11, 3, 1, -6,
+ -22, 9, 5, -3, -13, -7, -2, -8, -1, -1, -3, -1, 5, 0, -6, -1, -5, 10, 10, 13, 6, -5, 2, 1, 3,
+ -4, -7, -9, 8, -1, -15, 9, -1, -2, -5, -3, 27, -8, -3, -11, 5, -4, 1, 6, 9, -2, -11, -4, 6, 3,
+ 5, -7, 7, 3, -3, -3, 1, 4, 23, -10, -9, 5, 8, -6, -3, -7, 0, -10, -12, -5, -7, 1, -9, -2, -11,
+ 0, -12, 7, 1, -6, 2, -2, 0, -1, -4, -8, -12, 3, -6, 5, 8, -127, 1, 4, -16, 19, 0, 1, -3, 3, 7,
+ 2, 1, -4, 0, 2, -2, -5, 5, 0, -4, -6, 3, -3, 6, -6, -5, -8, -8, 1, -2, 9, -1, 7, 1, 3, -2, 6,
+ 3, 6, -2, 2, -8, -5, 3, -10, -2, 4, -7, -1, 12, -1, -4, 1, -9, -2, -1, 8, -7, 3, 4, 4, 1, 3,
+ -14, -6, 13, -21, -2, 2, 2, -4, -7, -4, 5, 0, -12, 2, 11, 0, -7, 5, -11, -19, -1, -12, 0, -10,
+ -6, 1, -8, 14, -3, 3, -10, -8, 22, 12, -7, -10, 6, 14, -6, -6, -6, 2, -4, -12, 1, 9, 0, -2, -3,
+ -2, 12, 8, -9, -2, 11, 7, 2, 6, -7, -12, 3, -5, -12, -1, 2, 3, 0, 8, 6, -6, -1, 1, 2, 1, 4, -2,
+ 5, -3, 4, 3, 11, 2, 0, 4, 0, 14, -15, -1, -8, 2, 10, 5, -1, 12, -5, -5, 3, 1, -6, 6, -11, 2,
+ 11, 16, -6, -1, 8, -11, 2, 2, 0, -3, 10, 1, 12, 8, -5, 2, -13, 10, 7, 5, 0, -9, 3, 11, -8, -5,
+ 3, 1, 1, -3, -5, 4, 8, 3, 5, -3, 0, 6, -1, 6, -6, 0, -4, 2, 5, -7, -17, 3, -7, -3, -13, -4, 7,
+ -5, -15, -6, 3, -7, -26, -13, 4, 2, -10, -1, 1, -11, -8, -26, 3, -12, -3, -10, -2, -1, 1, -1,
+ 6, -10, -12, -4, 5, -1, 12, 5, -2, -3, -5, 7, 28, -1, 0, 3, 5, 7, 6, -16, -2, -8, -1, -1, 4,
+ -7, -1, 12, 1, 0, 8, 6, -8, 9, 1, 1, 0, 8, -5, 3, -13, -18, -6, 0, 4, -5, -1, -4, 5, 6, -1, -3,
+ 0, -1, -4, -1, -3, 7, -4, 3, 0, 3, 1, 3, 3, 0, -6, -4, 0, 3, 3, 6, -1, 20, 6, 3, -2, -15, -20,
+ 3, -2, 3, 5, -3, 3, -7, 4, 4, -1, -2, 5, 1, -12, 1, 2, 1, 5, -3, -2, 13, 11, 6, 10, -12,
+];
+
+static PARTY: TextEmbedding = [
+ 4, 5, -7, -11, 1, 0, -8, 5, -4, -8, 4, -7, -4, 7, 5, 126, 4, 2, 2, -7, 3, -6, -4, 2, -1, 2, -4,
+ 4, 0, 1, 2, -4, 3, -8, 6, 2, -2, -1, 7, 6, 12, -5, 0, 8, -3, -8, -9, -6, 2, 5, 0, 10, 8, 7, -2,
+ 0, -2, 1, -2, 1, -7, -5, -1, -16, -13, 4, 4, 5, 0, 8, 6, 6, -5, 0, 8, 0, -13, 9, 9, 2, -4, -4,
+ -6, 8, -7, 0, 4, -3, 0, 0, -17, -1, -4, 0, 9, 10, -15, 6, -5, 1, -5, 4, 0, -9, 3, 4, -13, 4, 2,
+ 0, 2, -10, 15, 0, -1, -16, 5, -6, 0, 4, 10, -5, 2, -3, 1, -2, 1, -13, 6, 0, -5, 7, -1, 3, 2, 1,
+ -2, -2, 3, 1, -6, 1, 2, -12, -1, 7, -6, 1, -2, -1, -5, -5, -16, 7, -5, -2, -2, 1, 6, -5, -5,
+ -6, -3, -1, 2, -5, 6, -127, 3, -6, -1, 13, -3, 4, 1, 2, 7, 0, -3, -1, 1, 2, 7, 3, 8, -2, -2,
+ -1, 8, -2, 9, 3, -1, -5, 1, -6, 0, 5, -5, 13, -2, 7, -3, -4, 5, 7, -8, -2, 4, 1, -2, 0, 10,
+ -11, -4, -4, 5, -6, -9, -4, -7, 10, 1, 12, 2, 6, 2, 4, 1, -1, 0, -2, 1, -3, -3, -7, -5, 0, -6,
+ -1, -5, -2, -6, 4, -5, 11, -2, 5, -9, -1, 0, -5, -9, 4, 1, -1, -6, 1, -3, 5, -7, -7, 4, 10, 6,
+ -6, 5, 4, 1, -5, -3, 1, -4, -8, 9, -4, 3, -3, 0, 1, -2, 4, 5, 1, 1, 10, -5, 5, -7, 4, -7, -9,
+ -8, 0, 6, -1, 0, 1, 5, -3, 2, 1, 5, -4, 5, 1, 3, 4, 5, 2, -4, 4, -2, 3, -6, 0, -12, 1, -5, 2,
+ 11, 1, -7, 3, -3, 2, -2, 11, -2, 3, 7, -1, 7, 21, -2, 0, 4, -7, 1, 1, 1, -4, 20, 1, -2, 1, -1,
+ -3, -26, -2, 0, 4, -3, -14, 3, 4, -28, 3, 3, -15, 9, -2, -11, -4, 9, 7, 7, 0, 2, 6, 6, 7, -2,
+ 3, -2, 3, 3, -3, -24, 1, -10, 0, -10, -3, 8, -6, -8, -6, 8, 4, -20, -11, 2, -1, 1, 3, 1, -18,
+ 5, -28, 10, 0, -12, -8, 1, 6, 3, 7, 3, -11, 2, 2, -2, 2, 6, 4, -2, 0, 4, 1, 12, -12, -4, 2, 18,
+ 1, 1, -1, -2, -7, -3, -8, 1, 2, -7, 13, 3, 2, -6, 1, -5, 2, -14, 5, 9, 2, 3, 1, 0, -5, -7, 1,
+ 0, 3, -5, 3, 0, 6, -4, -2, 0, -3, -1, -3, -4, 13, -1, -3, -8, -5, 4, -10, 8, 2, -1, 6, 1, 5, 3,
+ 4, 4, -2, 7, -6, -7, -11, -27, 12, -2, 9, 5, 2, 3, 1, 2, 1, -2, -1, 2, 3, 2, 2, -9, 4, -2, -6,
+ -2, 5, 14, -1, -2, -17,
+];
+
+static HIKING: TextEmbedding = [
+ 1, 0, -4, -1, 6, 1, -7, 1, 5, -2, -2, -2, 0, 6, 12, 126, 3, 1, 3, -6, 4, -1, -6, -2, 4, 1, -8,
+ -2, 4, 2, 6, 0, 3, -4, 8, -3, 1, -9, 2, 10, 0, -1, 0, -3, -13, -4, 9, -11, 0, 5, 5, 0, -2, 6,
+ -5, -3, -2, -9, -1, -1, -10, -2, -6, 6, -7, 4, -5, 1, 9, 4, 1, 4, 1, -7, -8, 2, -19, 1, 16, 7,
+ -5, -3, -1, -1, 5, 4, -7, -1, 3, 8, 2, -4, 2, -4, 0, 5, -19, 9, -3, 5, -7, -3, -4, -16, 2, 4,
+ -13, 4, 2, -9, -2, 1, -10, -1, -5, -3, 2, -3, 8, 0, 9, -2, 1, -4, -3, 2, 6, -11, 0, 0, 1, 7, 3,
+ 5, 16, 0, -3, -2, -1, -1, 2, 0, -1, 5, -2, -1, 1, 6, -5, 3, -11, 4, -1, 13, -2, 7, 5, 0, 1, -5,
+ 0, 4, 3, 2, -18, 11, 4, -127, 5, -7, -7, 13, 0, -7, -8, 0, -1, -5, 6, 10, 0, 9, -1, -2, 10, -4,
+ -6, -4, 3, -3, -1, 7, 9, -12, -7, -2, 6, -23, 0, 4, 11, 23, 11, 4, 9, -2, 4, 1, -3, 5, 6, 0, 0,
+ -2, -2, -3, 14, -6, -1, -6, -6, 2, 2, 12, 6, 2, 2, -6, -6, -22, -4, -8, 2, -7, 2, -9, -5, 6,
+ -1, -8, -1, 0, -8, 0, 3, 17, -7, 3, -20, -4, -2, -9, -13, -7, -2, 1, 0, -15, 0, 1, -11, 1, 4,
+ 3, -6, -4, 2, 5, -2, -3, 0, 0, -1, 5, 6, 2, 2, 0, 6, 1, 3, 2, 2, -4, -10, 2, 2, 2, -1, 2, -1,
+ 0, 10, -1, 1, 6, -8, -25, 4, -1, -8, 3, 4, 4, 6, -3, -2, 4, 2, 10, 13, -1, -4, -1, 2, 14, -8,
+ 3, -11, -7, 10, 2, 8, -2, 1, -3, -9, 2, -1, 5, 6, 2, -7, 13, 0, -1, 6, -6, -4, -16, 2, 1, 7,
+ -2, 1, -4, 2, 1, 2, 4, -2, 0, 5, -19, 4, 2, -4, 5, 0, -1, 4, -5, -7, -3, -2, 0, -7, -5, 5, 4,
+ -2, 4, -10, 1, 2, -4, 5, -3, -14, -3, 0, -2, -5, -2, 14, -4, 4, -4, 5, 1, 4, 8, 0, 11, 3, -4,
+ -2, -4, 7, -27, 4, 10, 2, 3, -6, -2, -1, 14, -2, 2, -9, -3, 2, 0, 3, 1, -1, 1, 5, 7, 28, -20,
+ -16, 6, 4, -5, -1, 4, 8, -1, -1, 2, 1, -7, -14, 3, 5, 8, -4, -2, -1, 2, 3, -6, 0, 5, -5, 5, 1,
+ -2, -14, 4, -10, 5, -4, -4, -6, 1, -3, -3, 2, -6, -2, 9, 3, 14, 0, 2, 5, 5, 4, 0, 2, 3, -15, 4,
+ -5, 3, 7, -3, 0, 8, 5, -4, 0, -12, -15, 1, 5, 4, 6, 8, 5, -9, 10, 2, 0, -13, -4, 0, -5, -2, -2,
+ 4, -4, -5, -5, 3, 16, -2, 3, -11,
+];
+
+static FEAST: TextEmbedding = [
+ -7, 1, -5, -12, 4, -2, -5, 1, -7, -18, -3, 5, -2, 6, 5, 126, -4, -1, -4, -4, -2, -9, 5, 1, -1,
+ 0, -2, -3, 7, 8, -2, -8, 4, 3, -1, 11, -2, -2, -7, 4, 17, -5, -1, 5, -8, -12, -6, -10, -1, 3,
+ 2, 2, 8, -2, -5, -3, -5, 1, -8, 2, -7, 3, -4, -17, -10, 2, -1, -12, 1, 2, 0, -6, -3, 6, 7, -2,
+ -14, 2, 22, 4, 0, -8, -4, -3, 4, 11, 1, -1, 1, -1, -5, 3, -7, 0, -3, 5, -31, 8, -5, 3, 0, 6,
+ -3, 11, 5, 2, -12, 3, 8, -2, 2, -7, 13, -6, 1, -23, 10, -8, 3, 7, -3, -1, -5, -11, 1, -1, 12,
+ -8, 11, 2, -4, 7, -2, 1, -3, -3, -2, -2, 3, 8, -2, 6, -1, -11, 1, -4, 1, 7, -5, 4, -4, 1, -15,
+ 5, 3, 9, 7, -4, 0, -5, -11, -4, -3, 1, 12, -11, 3, -127, 1, 1, -2, 12, -6, 7, 2, -1, 11, -3,
+ -2, -2, 6, 3, 3, 2, 11, -2, 3, -6, -2, -5, 5, 0, -10, -4, -4, -7, -6, 6, -6, 13, -1, 1, 0, -5,
+ -2, -1, 0, -7, 6, -2, 3, 0, 0, -2, 6, 5, -22, -3, -8, 2, -2, 13, 3, 5, 2, -3, 0, -4, 0, 0, 5,
+ 10, -2, -5, -6, 13, 2, -2, -15, -1, 0, 3, -5, 3, -17, 7, 2, -2, -8, 0, -5, -10, -14, 6, -5, -1,
+ -7, -6, 2, 7, -5, -7, 5, 5, 3, -3, 11, -4, -3, 2, 3, 8, 1, 1, 1, -6, -1, 1, 4, 7, 3, 7, 7, 1,
+ 4, 6, 5, 1, -8, -2, -10, -4, -5, -10, 2, 1, -3, -10, 3, 4, 8, -3, 5, -1, 9, -3, 6, 4, -1, -2,
+ -12, -4, -8, 0, 3, 14, -10, 2, -11, 1, 5, 4, -2, 12, 0, 0, -6, 1, 3, 3, 2, 0, 3, 21, -5, -1, 3,
+ -5, -5, -6, -9, 7, 14, -5, 1, -7, 5, -1, -15, 5, -2, -1, 4, -18, 5, 5, -28, 3, 1, -15, 10, -1,
+ -1, 6, 14, 2, 5, 0, 6, -10, -3, -7, 4, -4, 0, 4, 11, -5, -29, -3, -8, -6, -5, 1, 3, 1, 2, 1,
+ 12, 4, -22, -1, -5, 4, 0, 15, 2, 4, -3, -16, 6, 6, -4, -9, -4, 1, 9, 11, 3, -14, -2, 7, 2, 7,
+ 3, 3, 1, 5, 2, -2, 9, -7, 3, -3, 12, 5, -2, 0, 5, -9, 1, -3, -2, -3, 0, 5, 6, -1, -1, 4, -6, 0,
+ -8, -10, 3, 7, 1, 12, -1, -1, -14, 1, -2, 1, -6, -6, 1, 4, 6, -1, 0, -2, 1, 2, 3, 7, -7, 5,
+ -13, -1, -3, -1, 11, 6, 5, -6, -5, -2, 2, 2, 0, -1, 1, -10, -16, -2, -22, 8, 8, -2, 5, -5, -5,
+ -11, -3, 1, -2, 0, 5, -2, 3, 0, 1, 1, 5, -3, -3, 4, 12, 3, 6, -34,
+];
+
+static SELFIES: TextEmbedding = [
+ 4, 13, -6, -24, 8, 0, -1, 0, 9, 2, 0, -2, -10, 0, -1, 126, 7, -4, 18, -14, -3, -7, 8, -2, 4, 4,
+ -2, -4, 18, 5, 6, -12, 0, 4, 4, -11, 1, 0, 2, -12, -11, 2, -12, 13, 12, -14, 0, -7, 8, -2, -16,
+ 19, 4, -7, -14, -11, 3, 10, -10, 2, -4, 1, -8, 0, -23, 3, 5, 3, 7, 13, 4, 15, -13, 4, -2, -1,
+ -18, -2, 19, 3, 13, -12, 4, 6, 4, 13, 0, 5, 10, 2, 1, 7, 7, 2, -5, 3, -1, 10, -11, -4, -3, 4,
+ -12, -5, 1, 2, -12, 11, -5, 2, -4, -6, 6, -15, 2, 7, 3, -14, -4, 1, 6, -3, 4, -2, 6, -1, 13,
+ -14, -5, -4, -5, 4, -6, -3, 1, 9, 1, 3, 10, -21, -6, -2, 2, -6, -1, -2, -10, -6, 8, -22, 3, 9,
+ -4, 0, 5, -2, -1, -4, -15, -11, 8, 8, -9, 3, 10, -4, 5, -127, 14, 5, 0, 16, 8, -5, 2, -13, 8,
+ 0, 7, 36, -4, -3, 6, -5, 12, 16, 1, -8, 0, -16, 6, -6, 9, -12, 1, -6, 1, -4, -11, 0, 7, 13,
+ -15, -6, -7, -2, -8, 9, 14, 12, -3, -2, 2, -4, -5, 0, 10, 9, 7, -1, 5, 4, 4, 5, 7, 2, -4, 5, 4,
+ -4, -7, -1, 1, -20, 2, 7, 4, -10, 0, -6, -3, 2, -3, 7, -9, 14, 4, -14, -7, -10, 4, -22, 3, 2,
+ -6, -8, -8, -16, -11, 4, -21, -3, 4, 2, 11, -8, -7, -11, 4, 1, -9, 6, 4, -8, -7, 6, 0, 3, -2,
+ 1, 6, -8, 0, -17, -4, 9, -7, 5, -6, 1, -10, -9, -6, 10, 0, 4, -8, 25, 8, -1, 1, -4, -8, 8, -2,
+ 0, 2, 4, -5, -10, -12, -4, -3, 1, 3, 12, -14, 20, -7, 1, 2, -18, -6, 9, 22, -7, 3, 16, -7, 1,
+ 8, 0, 8, 9, 3, -10, -2, 4, -10, 4, -5, -6, 8, -10, 3, -10, -6, -4, -35, 6, 0, -4, 2, -8, 7, 5,
+ -24, 6, -10, 4, -6, 6, -2, 2, 5, 4, 17, 13, -1, -2, 8, -7, 5, -10, 4, -7, 20, -9, 14, 0, -6, 0,
+ 2, -8, 7, -9, -5, -2, 15, -27, -17, -22, -1, 6, 3, 7, -9, -7, 0, -22, 0, -19, 0, -1, 12, 1, 4,
+ 10, -2, 6, -12, 8, -5, -3, -3, 12, -10, 5, -7, -9, 11, -20, -10, 8, 9, 3, 2, 7, 6, 2, 4, -8,
+ -11, 1, 6, 3, -1, 1, 3, -6, -9, -17, -23, -7, 0, -9, -13, -5, -3, -6, -6, -3, 17, -9, -4, 1, 9,
+ -5, 6, 4, -3, -5, 3, 2, -19, 10, -11, -6, -7, -12, -7, -7, -1, 0, 1, -5, 7, 13, -6, 13, -9, -1,
+ 14, 6, 1, 8, -21, 6, -1, 5, 11, 7, -6, 2, -8, 3, -1, -3, 0, 1, 1, -4, 3, -6, 0, -1, -1, 13, 11,
+ -4, -7, -14,
+];
+
+static POSING: TextEmbedding = [
+ 1, 0, -3, -6, 2, -5, 1, 6, 6, -11, 4, -10, 6, 2, -2, 126, 4, -12, 3, -8, -1, -4, -5, -3, 2, 3,
+ 0, -2, -1, -1, 1, -3, -2, 7, 4, -2, -1, 1, -1, 7, 6, 1, -1, -1, 3, -4, -5, -5, 9, -2, -7, 10,
+ 2, 0, -4, -9, 2, 0, 0, 1, -2, 1, -9, -2, 1, 0, -3, 0, 0, 16, 2, 3, -4, 3, -2, 3, -14, -1, 7, 6,
+ -3, -5, 1, -2, -5, -2, 0, -1, -2, 0, 1, -3, 5, -4, 5, 5, -7, -1, 0, 1, -5, 0, -5, 3, 0, 6, -9,
+ -3, 1, 0, -4, -5, 19, -1, 2, -11, 3, -3, -1, 0, 12, -1, 3, -1, -4, -4, 3, -3, 5, -3, -3, 0, -8,
+ 3, 14, 0, -5, 1, 1, -7, -5, 6, 1, -3, 5, 6, 2, -3, 0, -12, -2, 6, -9, 0, -7, -2, -2, -1, -7,
+ -7, -6, 4, -6, 1, -4, 10, -4, -127, 5, 4, -7, 12, 4, 0, 4, -3, 4, 0, 0, 8, 0, 8, 5, -6, 4, 2,
+ -5, -5, 6, 1, 4, -4, 12, -9, -1, 2, -4, 1, 0, 1, 13, 9, -11, -3, 0, -1, -6, -2, 5, 8, -1, 0, 4,
+ -7, -4, 10, -4, 5, 4, 3, 0, 9, -1, 5, 4, 1, -2, 1, -3, -9, -5, -8, 2, -4, -5, 2, -2, 2, -3, 0,
+ 0, 0, -15, 3, -12, 4, -6, -2, -6, -4, 5, -11, 2, 5, -4, -1, -8, 3, -11, -2, -4, 0, 0, 3, 8, 8,
+ 0, 3, 4, 1, -3, -2, -3, -6, 1, -3, 7, 2, -4, -11, 4, -4, -2, -16, -4, 3, 0, 3, -10, 5, 1, -7,
+ 1, 5, 3, -3, -3, 11, 3, -3, 2, -1, 1, 3, -1, -2, -2, -1, 3, -1, -1, -4, -1, 5, 8, 11, -9, 4,
+ -10, -4, 11, -3, -8, 5, 1, -1, -9, 10, 6, 3, 0, -2, 5, 32, -3, 0, -1, -6, 0, -3, 3, -4, 10, -5,
+ 3, 2, -2, -3, -13, 1, -2, 2, -8, -13, 4, 4, -21, 0, 2, 2, 3, 2, -2, 1, 8, 9, 1, 13, -1, -5, 10,
+ 6, 3, -2, 3, -1, 8, -1, -6, -6, -5, -2, -4, 0, 5, -4, -3, -10, 8, -1, -21, -2, 3, 6, -1, 0, -3,
+ -4, 5, -23, -4, 0, 1, -1, 8, 0, 1, 6, -7, 1, -12, 4, 5, -5, -1, 3, -5, 3, 0, -4, 16, -14, 0, 4,
+ 9, 3, -9, 7, 2, 3, -5, 2, 1, -1, 2, 3, 2, 5, -4, 0, -7, 1, -6, 4, -4, -3, -5, 7, -11, -5, -6,
+ -1, 0, -2, -12, -4, -9, 5, 0, 1, 2, -4, 1, 2, 1, 18, -5, 0, -4, -4, -5, -2, 4, -1, 2, 2, 1, -6,
+ 4, 0, 2, 1, 9, 3, 11, -6, -28, 1, -2, 6, 6, 4, 2, -2, 3, 4, -3, 0, 11, 3, -1, 0, -1, -6, -3,
+ -4, -2, 10, 12, 5, 3, -16,
+];
+
+static BACKGROUND: TextEmbedding = [
+ -4, -1, 2, 2, -1, -2, 7, -2, 6, 9, 1, 6, 5, 0, 2, 126, -3, -3, 0, -5, 0, -7, 0, -2, 2, 3, -1,
+ 2, 10, 8, -7, 0, 5, 2, -1, 0, -5, 4, -1, -5, 0, -3, 6, -6, -2, -4, 5, -5, 6, 2, 3, 9, 6, 2, -4,
+ -5, 17, -2, -6, 2, 13, -3, -9, 6, -6, 6, 2, -10, 1, 14, -2, 6, -5, 6, -6, 2, -19, 1, 25, 12,
+ -4, -18, 1, 0, 6, 7, 0, 1, -10, -2, -5, 3, -4, -2, -2, 5, 5, 2, 5, -5, 2, -7, -8, 14, 8, 9,
+ -14, -3, -2, 4, 1, -4, 24, -13, -1, 5, -1, 2, -1, 5, 0, -7, 10, 2, 5, 4, 22, -6, -1, -3, -3, 4,
+ -4, 7, 7, 1, -7, 6, -1, -4, 3, -5, -1, 2, 3, 0, -4, -4, -8, -8, 2, -3, -12, -3, -11, 2, -2, -1,
+ 5, -2, -12, 5, 2, 2, -7, 3, 2, -127, -4, 1, -4, 17, 10, -7, 4, 3, -1, -5, 0, 13, -1, 6, -3, -3,
+ 1, -1, -3, -6, 0, 4, -8, -7, 11, -25, 0, -9, 6, 0, -3, -6, 6, 3, -2, -1, 6, -2, 1, -5, -1, -4,
+ 2, 6, -4, 0, 1, 12, -1, -9, 2, -4, 5, 6, 6, 8, -4, -5, 3, 2, -1, -1, 1, 5, -2, 8, -5, 3, -6,
+ -2, -2, -6, -8, 1, -24, -2, -18, -1, -9, -15, -10, -4, 0, -8, 1, 3, -7, -6, -2, -10, -8, 2, -3,
+ -1, 2, 0, -3, 4, -2, 2, -4, 5, 7, -2, -6, -5, -2, 5, -1, -1, -6, -8, -10, 0, 0, -14, 4, -2, 1,
+ 2, -4, -4, 4, -1, -3, 1, 1, -3, -10, 17, 3, 3, 2, 0, -1, 1, -2, 2, 1, 3, 1, 2, 15, 3, -6, -1,
+ 4, 16, -13, -6, -10, 0, 8, 2, 1, 9, 6, 4, -6, 12, 2, -6, 1, 1, 3, 22, 6, 1, -9, -4, -5, -8, -1,
+ 6, 1, -2, 4, -6, -6, -5, -17, -3, 1, -4, -2, -19, 8, 7, -2, 0, -4, -4, 1, -4, 9, 1, 6, 2, -4,
+ -3, -2, 2, -4, 0, -2, -6, 12, -9, 4, -4, -15, 0, -3, -11, -5, 1, 5, 3, -1, -13, 5, -7, -25, -9,
+ 8, 0, 1, -1, -3, -16, 4, -29, -5, 0, 5, -1, -8, 2, 0, 11, -3, -12, 1, -1, 6, -1, 2, 1, -3, 8,
+ -3, -4, 23, -19, -9, 4, -5, 1, -3, 8, 3, -4, -2, 1, -7, 1, -3, 1, 2, 6, -5, 4, -7, -11, -8, 10,
+ 9, -2, -2, 12, -3, -2, -5, 1, -4, -2, -10, 6, -2, 7, 5, 4, 1, -11, 4, -3, 6, 32, -5, 2, 3, -8,
+ 0, 1, 1, -6, -12, 3, -9, -2, -1, 1, -2, -3, 10, -5, 17, -7, -46, 6, 4, 10, 5, -8, 0, 1, 3, 1,
+ -8, -6, 5, -8, 4, -1, 2, -5, -4, 0, -5, 6, 4, 0, -5, -4,
+];
+
+static SPORTS: TextEmbedding = [
+ 0, 3, 0, -14, -4, 4, -4, 1, -7, -7, -3, -3, 2, 6, 5, 126, 3, 4, 6, -14, 3, -7, 4, -6, 5, -8,
+ -6, 1, -7, 7, 9, -1, 6, -1, 3, 1, 3, -2, 2, 7, 4, -4, 0, 4, -4, -5, 1, -2, -1, 5, 3, 10, 1, 1,
+ 2, -1, 3, -3, 1, 5, -9, 1, -8, -7, -3, 3, 2, 4, 3, 5, 6, 8, -2, -7, -4, 2, -14, 16, 11, 7, -4,
+ -5, -2, 5, -4, 10, -4, 6, 7, 3, -13, -1, -4, -2, 5, 10, -23, 0, -3, 6, 0, 8, 3, -7, 9, 9, -11,
+ 10, 0, 1, 1, 0, 16, 0, 3, -18, -2, -4, 2, 10, 17, -8, 1, -5, -1, -2, 9, -2, 8, 6, -13, 1, -1,
+ -4, 3, -1, -1, -2, 5, 6, 5, 5, -1, -12, 3, 2, -3, 4, -5, -1, 1, 3, -9, 14, -3, 6, 7, -2, 5, -6,
+ -7, -5, -8, 9, -6, 2, 4, -127, -3, -6, -3, 13, 9, 7, -3, 3, 0, 7, -10, 3, 3, 1, 5, 1, -3, -3,
+ -9, -8, 5, 1, 4, 2, 14, -3, -6, -1, 0, 5, -8, 14, 5, 4, -2, 3, 5, 4, -2, -6, 4, 3, -5, 4, -2,
+ -2, -2, 0, -1, 1, 2, 2, 0, 14, -7, 1, -5, 0, 3, 1, -3, -15, 0, -7, 3, -12, 3, -17, -8, 0, -2,
+ -7, -3, -3, -4, 3, -10, 3, 1, -2, -7, -1, 2, -15, -1, -5, -3, -5, 3, -3, -7, 4, -1, 0, -3, 3,
+ 4, -4, 2, -5, 4, 1, -6, 6, 0, -4, 2, 3, 7, 5, -2, -1, -1, 1, 4, -2, 1, -1, 1, 7, -9, -1, -3,
+ -12, -8, 5, 2, 4, 0, -6, 10, 0, -6, 7, 3, 9, 7, -4, 8, 6, 2, 0, 4, 3, -7, 0, 2, 2, -9, -1, -7,
+ -5, 2, -1, -12, 14, -6, 5, 0, 15, 3, 0, -6, -3, 14, 20, -6, 0, 0, 1, -5, -8, -2, -4, 9, 5, 2,
+ -7, -3, -6, -12, 3, -3, -2, -2, -19, 0, 9, -12, -1, 5, -5, 0, -5, -8, 4, 7, 0, 4, -4, 3, 4, 8,
+ -8, 1, 0, 0, -8, 7, -3, -15, 4, -9, -4, -7, 0, 2, -3, 2, -9, 5, 16, -8, 3, 2, -4, 0, -2, -6,
+ -22, 20, -31, 0, -8, -2, -2, 9, -4, 3, 3, 3, 2, -4, 4, -2, -2, 0, -5, -3, 8, 6, -1, 12, -7, 1,
+ 3, 14, 5, 0, -2, 2, -3, -3, -5, -2, -5, -8, 8, -1, 9, -2, -1, -14, 6, -8, -7, 4, 1, 2, 2, -4,
+ -5, 0, 1, 2, 6, -5, -1, -12, -2, 1, -11, -4, -6, -5, 3, -3, 4, -2, 1, -6, 3, -7, -3, 12, 4, -7,
+ 6, 5, -2, -2, -7, 2, -1, 8, 2, 18, -3, -10, -4, 3, 1, 4, 2, 2, 7, -2, -4, 4, 1, -1, 1, 0, 1,
+ -1, 4, -4, -5, -2, 7, 8, 0, 2, -26,
+];
+
+static ROADTRIP: TextEmbedding = [
+ -2, 0, 0, 6, 3, -7, 0, 3, -5, -3, -9, -7, -3, 6, 0, 126, -2, 2, 4, 0, 8, -3, -4, 0, 5, 2, -1,
+ 5, 6, 8, 0, 2, -5, -1, 2, -2, -6, -1, -2, -5, 8, 3, -4, 5, -11, -12, -10, -2, 3, 8, 2, -2, 3,
+ 3, -1, -10, -7, 0, -3, -3, 0, 12, -7, 12, -22, 5, -5, 1, 8, 10, -4, 6, -5, -2, -13, 5, -14, 0,
+ 25, 16, -3, -2, 7, 3, 10, 11, -5, 1, -4, 6, -4, -5, 6, -7, 1, 8, -15, 10, 4, 13, -8, 0, -1,
+ -21, -2, 7, -14, -2, -2, 4, 5, -2, 12, -6, -7, -9, 1, -11, 0, 2, 11, -14, -3, -6, -7, -9, 10,
+ -7, -1, -6, -4, 7, 1, 11, 9, 1, -6, -7, -2, -2, 5, 18, 10, -10, -7, -9, -2, 1, -12, -11, -3,
+ 10, 5, 1, 10, 7, -12, 4, 1, -2, -7, -4, 1, 1, 13, -8, 4, -127, 0, 8, 5, 11, -2, 2, 8, -5, -4,
+ 4, 2, 6, 6, -2, 8, -5, 16, -1, 8, 0, -2, -2, 4, -10, 4, 10, 4, -4, 3, -23, -4, 5, 5, 6, -4, -5,
+ 1, -1, -7, 3, 5, -2, -8, -4, 6, -4, 0, -2, 1, -5, 7, -1, -1, 0, -8, 12, 7, 1, 1, 1, -4, -11,
+ -5, -7, -1, -12, 0, 0, -5, 7, 2, 1, -7, 3, -6, 1, -12, 14, -5, 11, -8, 5, -10, -10, -9, 15, 0,
+ -1, -10, -15, 3, 0, 1, -8, -2, 4, 7, 0, 4, -2, 4, -7, -8, 3, -8, -14, -3, -3, -1, -4, 5, -2, 1,
+ 4, 13, -12, 0, -1, -1, 1, -6, -2, -3, -6, -6, 1, 6, 4, -4, -26, 1, 4, -3, -7, 6, 5, 4, -4, 1,
+ -1, 8, 1, 9, 2, -5, -5, -5, 11, -11, 4, -10, -13, 4, 16, -2, -1, 3, -5, -8, 21, 0, -1, 6, -3,
+ 2, 12, -1, 6, 5, -9, -9, 3, -5, 4, 18, -2, 3, -9, -3, -4, 1, 1, -6, 3, 9, -18, -4, 3, -12, -4,
+ 1, 5, 0, -8, -3, -3, 1, 2, 6, 2, 0, -3, 1, 1, -10, 4, 4, -4, 5, -3, -19, 6, -3, -8, 1, -6, 8,
+ -4, 2, -9, 6, -11, -12, 3, -4, 5, -2, 5, -3, -2, 17, -19, 8, 1, -8, 0, 6, 0, 9, 21, -8, 3, -7,
+ 0, -1, 2, 6, 10, -2, 3, -3, 7, 25, -17, -7, 0, 2, -11, -9, 11, 1, -2, -1, 0, 3, 7, -8, 2, -2,
+ 5, -5, 2, -4, 4, -3, 3, 4, 1, 4, 0, -1, -5, -17, 2, -6, -2, 0, 0, -1, 8, 3, 1, 10, -4, 0, 1, 8,
+ 6, 5, 2, -9, -14, 4, 4, 10, 7, -2, 2, -1, 4, 0, -1, 0, 2, 12, -3, 3, -4, -18, -5, 2, 1, 3, 11,
+ 9, 2, 2, -3, 3, -5, 2, -1, -2, 5, -2, -4, -10, 0, 10, 2, 12, -3, 6, -15,
+];