foley.index.taxonomy.resolver#
Resolve free tags/caption/labels to a UCS CatID (the EnvSound-UCS pipeline).
Staged precedence, highest wins (report 04 §5.3, [11 §3.1] — normalize heterogeneous labels onto UCS via mapping/synonym tables):
filename-parse > declared CatID > keyword/synonym > audioset-map > none
A declared CatID is one the file states about itself (the iXML CATID of a pro
pack, foley.embedded_metadata); like a filename’s, it counts only when the
table knows it. A keyword match weaker than an AudioSet-map hit (its band is below
MatchPolicy.audioset_confidence) yields to one.
The keyword stage, in three pure steps over the table’s
TermIndex (built once per table):
collect — each term (subcategory, category name, synonym) found in one field of the input, word-boundary aware and across function words, becomes a
Hit; the hits of one CatID fold into itsEvidence;pick — the highest score wins (one word counts once, whatever it hits); on a tie, the stronger evidence, with a category name as strong as a subcategory, then the category’s generic (
GENERAL/MISC) row, then table order;band — the confidence says how much evidence there is (
MatchPolicy.band()), not which row won.
Everything tunable is one frozen MatchPolicy (policy=). The
always-available default is this stdlib KeywordResolver; a richer CLAP
zero-shot resolver (embed once, argmax over UCS label prompts, report 03 Part 2) can
be dropped in behind the same TaxonomyResolver protocol.
Module Attributes
the sound says what it is. |
|
English function words, dropped from both sides before matching, so a phrase matches across them ( |
|
Common narration words that the UCS master also lists as a subcategory or synonym ( |
|
Base weight of a matched term, by where it came from. |
|
Evidence strengths, strongest first (indices into |
|
Evidence strengths, strongest first (indices into |
|
Evidence strengths, strongest first (indices into |
|
an AudioSet-map hit's. |
Functions
|
A synonym weighs its BM25 IDF over the |
|
A synonym listed by |
|
The keyword stage alone: the best row for |
|
Resolve inputs to a best UCS CatID by the staged precedence. |
|
The |
Classes
|
Everything the input says for one CatID: the folded |
|
One term of a row found in the input. |
|
The default stdlib resolver — staged keyword/synonym/AudioSet resolution. |
|
How the keyword stage matches, ranks and bands (one strategy object). |
|
Resolve a |
- foley.index.taxonomy.resolver.DEFAULT_AMBIGUOUS_WORDS: frozenset = frozenset({'arc', 'bang', 'beat', 'big', 'blue', 'break', 'catch', 'day', 'down', 'drop', 'fall', 'general', 'handle', 'heavy', 'hit', 'hold', 'large', 'light', 'little', 'long', 'meeting', 'misc', 'night', 'off', 'open', 'out', 'over', 'part', 'person', 'piece', 'place', 'quiet', 'release', 'run', 'set', 'shot', 'side', 'small', 'sound', 'thing', 'time', 'tone', 'up', 'way', 'work'})#
Common narration words that the UCS master also lists as a subcategory or synonym (
quietisCRWDQuiet,releaseanAIRsynonym): they count inside a multi-word term ("glass break","wind up"), never alone ("take a break","the price went up").
- foley.index.taxonomy.resolver.DEFAULT_KIND_WEIGHTS: Mapping[str, float] = mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0})#
Base weight of a matched term, by where it came from. A category name is its rows’ own name, as strong as a subcategory.
- foley.index.taxonomy.resolver.DEFAULT_STOP_WORDS: frozenset = frozenset({'a', 'about', 'all', 'also', 'am', 'an', 'and', 'any', 'are', 'as', 'at', 'be', 'been', 'being', 'but', 'by', 'can', 'could', 'did', 'do', 'does', 'each', 'every', 'few', 'for', 'from', 'had', 'has', 'have', 'he', 'her', 'here', 'him', 'his', 'how', 'i', 'if', 'in', 'into', 'is', 'it', 'its', 'just', 'may', 'me', 'might', 'more', 'most', 'must', 'my', 'no', 'nor', 'not', 'of', 'on', 'only', 'onto', 'or', 'other', 'our', 'own', 'same', 'she', 'should', 'so', 'some', 'such', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'to', 'too', 'under', 'us', 'very', 'was', 'we', 'were', 'what', 'when', 'where', 'which', 'who', 'why', 'will', 'with', 'without', 'would', 'you', 'your'})#
English function words, dropped from both sides before matching, so a phrase matches across them (
"rain on window"in “rain on a window”). Particles that carry sound meaning (up,down,out,off,over: “wind up” is a toy, “the wind picked up” is weather) are not here but in the ambiguous words.
- class foley.index.taxonomy.resolver.Evidence(catid, score, matched, words, kinds, phrase, unique_synonym)[source]#
Bases:
objectEverything the input says for one CatID: the folded
Hits.
- class foley.index.taxonomy.resolver.Hit(catid, kind, text, words, weight, shared_by)[source]#
Bases:
objectOne term of a row found in the input.
wordsare the term’s content lemmas (stop words dropped);shared_byis how many rows list the term.
- class foley.index.taxonomy.resolver.KeywordResolver(*, table=None, audioset_map=None, policy=MatchPolicy(stop_words=frozenset({'your', 'me', 'into', 'those', 'on', 'very', 'just', 'then', 'am', 'been', 'more', 'without', 'nor', 'has', 'why', 'that', 'how', 'own', 'at', 'in', 'is', 'were', 'under', 'any', 'will', 'most', 'should', 'such', 'their', 'a', 'us', 'not', 'can', 'if', 'these', 'had', 'where', 'may', 'each', 'its', 'could', 'he', 'of', 'my', 'our', 'the', 'who', 'does', 'as', 'must', 'it', 'what', 'this', 'she', 'might', 'other', 'also', 'they', 'some', 'all', 'him', 'same', 'from', 'with', 'to', 'so', 'for', 'there', 'his', 'we', 'no', 'and', 'here', 'being', 'which', 'about', 'are', 'i', 'have', 'an', 'you', 'onto', 'be', 'or', 'too', 'them', 'but', 'was', 'when', 'her', 'only', 'did', 'than', 'by', 'do', 'would', 'every', 'few'}), ambiguous_words=frozenset({'over', 'small', 'down', 'tone', 'release', 'part', 'thing', 'break', 'sound', 'night', 'off', 'work', 'up', 'meeting', 'long', 'little', 'bang', 'light', 'large', 'misc', 'shot', 'hold', 'day', 'person', 'heavy', 'general', 'hit', 'set', 'out', 'way', 'beat', 'quiet', 'drop', 'blue', 'time', 'fall', 'run', 'handle', 'big', 'place', 'side', 'arc', 'piece', 'open', 'catch'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5))[source]#
Bases:
objectThe default stdlib resolver — staged keyword/synonym/AudioSet resolution.
Zero heavy dependencies. Bind a different
TaxonomyResolver(e.g. a future CLAP zero-shot resolver) by keyword injection to upgrade quality.- resolve(record)[source]#
Resolve a
SoundRecord’s tags/caption/labels/uri.- Return type:
- class foley.index.taxonomy.resolver.MatchPolicy(stop_words=frozenset({'a', 'about', 'all', 'also', 'am', 'an', 'and', 'any', 'are', 'as', 'at', 'be', 'been', 'being', 'but', 'by', 'can', 'could', 'did', 'do', 'does', 'each', 'every', 'few', 'for', 'from', 'had', 'has', 'have', 'he', 'her', 'here', 'him', 'his', 'how', 'i', 'if', 'in', 'into', 'is', 'it', 'its', 'just', 'may', 'me', 'might', 'more', 'most', 'must', 'my', 'no', 'nor', 'not', 'of', 'on', 'only', 'onto', 'or', 'other', 'our', 'own', 'same', 'she', 'should', 'so', 'some', 'such', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'to', 'too', 'under', 'us', 'very', 'was', 'we', 'were', 'what', 'when', 'where', 'which', 'who', 'why', 'will', 'with', 'without', 'would', 'you', 'your'}), ambiguous_words=frozenset({'arc', 'bang', 'beat', 'big', 'blue', 'break', 'catch', 'day', 'down', 'drop', 'fall', 'general', 'handle', 'heavy', 'hit', 'hold', 'large', 'light', 'little', 'long', 'meeting', 'misc', 'night', 'off', 'open', 'out', 'over', 'part', 'person', 'piece', 'place', 'quiet', 'release', 'run', 'set', 'shot', 'side', 'small', 'sound', 'thing', 'time', 'tone', 'up', 'way', 'work'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5)[source]#
Bases:
objectHow the keyword stage matches, ranks and bands (one strategy object).
- skip_categories#
UCS categories the keyword stage never picks (a filename or declared CatID still may).
- Type:
- kind_weights#
Base weight of a hit by term kind (
subcategory,category,synonym).
- synonym_weight#
(rows listing the synonym, rows in the table) -> factoron a synonym hit’s weight:inverse_sqrt_share()(default) oridf_share()(foley#290).
- strong_confidence#
Band of strong evidence: a subcategory hit, a multi-word phrase, or two distinct content words on the row (a category name plus another word counts).
- Type:
- weak_confidence#
Band of a brush: a category name alone, or a synonym many rows share. A
confident=Falserow drops one band (floored here).- Type:
- foley.index.taxonomy.resolver.RECORD_MIN_CONFIDENCE: float = 0.5#
an AudioSet-map hit’s. A weak keyword brush (a category name alone, a synonym many rows share) is below it.
- Type:
The least confidence worth writing onto a record
- foley.index.taxonomy.resolver.SINGLE = 1#
Evidence strengths, strongest first (indices into
MatchPolicy.bands).
- foley.index.taxonomy.resolver.STATED_CONFIDENCE: float = 1.0#
the sound says what it is.
- Type:
A filename’s or the file’s own metadata’s CatID
- foley.index.taxonomy.resolver.STRONG = 0#
Evidence strengths, strongest first (indices into
MatchPolicy.bands).
- class foley.index.taxonomy.resolver.TaxonomyResolver(*args, **kwargs)[source]#
Bases:
ProtocolResolve a
SoundRecordto a UCS CatID.
- foley.index.taxonomy.resolver.WEAK = 2#
Evidence strengths, strongest first (indices into
MatchPolicy.bands).
A synonym weighs its BM25 IDF over the
n_rowsUCS rows (each row a document), relative to a synonym only one row lists (foley.index.indexes.bm25_idf(), the IDFMemoryIndexranks with). Gentler on shared words thaninverse_sqrt_share(): “car” (32 of 753 rows) keeps about half its weight.- Return type:
A synonym listed by
shared_byrows weighs1/sqrt(shared_by)of its kind’s weight: “car” (32 rows) a sixth, “doorknob” (one row) all of it.- Return type:
- foley.index.taxonomy.resolver.keyword_resolution(tags=(), caption=None, *, table=None, policy=MatchPolicy(stop_words=frozenset({'your', 'me', 'into', 'those', 'on', 'very', 'just', 'then', 'am', 'been', 'more', 'without', 'nor', 'has', 'why', 'that', 'how', 'own', 'at', 'in', 'is', 'were', 'under', 'any', 'will', 'most', 'should', 'such', 'their', 'a', 'us', 'not', 'can', 'if', 'these', 'had', 'where', 'may', 'each', 'its', 'could', 'he', 'of', 'my', 'our', 'the', 'who', 'does', 'as', 'must', 'it', 'what', 'this', 'she', 'might', 'other', 'also', 'they', 'some', 'all', 'him', 'same', 'from', 'with', 'to', 'so', 'for', 'there', 'his', 'we', 'no', 'and', 'here', 'being', 'which', 'about', 'are', 'i', 'have', 'an', 'you', 'onto', 'be', 'or', 'too', 'them', 'but', 'was', 'when', 'her', 'only', 'did', 'than', 'by', 'do', 'would', 'every', 'few'}), ambiguous_words=frozenset({'over', 'small', 'down', 'tone', 'release', 'part', 'thing', 'break', 'sound', 'night', 'off', 'work', 'up', 'meeting', 'long', 'little', 'bang', 'light', 'large', 'misc', 'shot', 'hold', 'day', 'person', 'heavy', 'general', 'hit', 'set', 'out', 'way', 'beat', 'quiet', 'drop', 'blue', 'time', 'fall', 'run', 'handle', 'big', 'place', 'side', 'arc', 'piece', 'open', 'catch'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5))[source]#
The keyword stage alone: the best row for
tags/caption, banded.>>> keyword_resolution(caption="a heavy wooden door creaks open").catid 'DOORWood' >>> r = keyword_resolution(caption="the wind picked up") >>> r.catid, r.confidence ('WIND', 0.4)
- Return type:
- foley.index.taxonomy.resolver.resolve_catid(*, tags=(), caption=None, audioset_labels=(), filename=None, catid=None, table=None, audioset_map=None, policy=MatchPolicy(stop_words=frozenset({'your', 'me', 'into', 'those', 'on', 'very', 'just', 'then', 'am', 'been', 'more', 'without', 'nor', 'has', 'why', 'that', 'how', 'own', 'at', 'in', 'is', 'were', 'under', 'any', 'will', 'most', 'should', 'such', 'their', 'a', 'us', 'not', 'can', 'if', 'these', 'had', 'where', 'may', 'each', 'its', 'could', 'he', 'of', 'my', 'our', 'the', 'who', 'does', 'as', 'must', 'it', 'what', 'this', 'she', 'might', 'other', 'also', 'they', 'some', 'all', 'him', 'same', 'from', 'with', 'to', 'so', 'for', 'there', 'his', 'we', 'no', 'and', 'here', 'being', 'which', 'about', 'are', 'i', 'have', 'an', 'you', 'onto', 'be', 'or', 'too', 'them', 'but', 'was', 'when', 'her', 'only', 'did', 'than', 'by', 'do', 'would', 'every', 'few'}), ambiguous_words=frozenset({'over', 'small', 'down', 'tone', 'release', 'part', 'thing', 'break', 'sound', 'night', 'off', 'work', 'up', 'meeting', 'long', 'little', 'bang', 'light', 'large', 'misc', 'shot', 'hold', 'day', 'person', 'heavy', 'general', 'hit', 'set', 'out', 'way', 'beat', 'quiet', 'drop', 'blue', 'time', 'fall', 'run', 'handle', 'big', 'place', 'side', 'arc', 'piece', 'open', 'catch'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5))[source]#
Resolve inputs to a best UCS CatID by the staged precedence.
- Parameters:
audioset_labels (
Sequence[str]) – AudioSet MIDs or names (e.g. from PANNs).filename (
Optional[str]) – Optional UCS-style filename/path (its token-0 CatID wins if recognized).catid (
Optional[str]) – Optional CatID the sound declares (e.g. its iXMLCATID); wins over keywords when the table knows it, else it is ignored.table (
Optional[UcsTable]) – UCS table (defaults todefault_ucs_table()).audioset_map (
Optional[AudioSetUcsMap]) – AudioSet->UCS map (defaults todefault_audioset_ucs_map()).policy (
MatchPolicy) – How keywords match and band (defaultDEFAULT_MATCH_POLICY; vary it withdataclasses.replace).
- Return type:
- Returns:
A
CatIdResolution(falsy when nothing resolved).