geno_lewm.encoder.pooling¶
pooling
¶
Pooling strategies for Carbon hidden states.
Defined by encoder contract This module is intentionally independent of torch so the pooling contract, cache metadata, and downstream schema behavior can be validated before the Carbon runtime wrapper lands.
PoolingResult
dataclass
¶
PoolingResult(vector: tuple[float, ...], pool_type: Literal['centered_mean', 'global_mean'], pool_radius: int, untargeted: bool, center_token: int | None, token_count: int)
Pooled state vector plus cache-key metadata.
as_cache_fields
¶
Return fields shared with the window-cache schema.
global_mean
¶
Mean-pool every token vector in hidden_states.
centered_mean
¶
centered_mean(hidden_states: Sequence[Sequence[float]], *, center_token: int, pool_radius: int = DEFAULT_POOL_RADIUS_TOKENS) -> tuple[float, ...]
Mean-pool the inclusive token span center_token ± pool_radius.
Source code in geno_lewm/encoder/pooling.py
pool_hidden_states
¶
pool_hidden_states(hidden_states: Sequence[Sequence[float]], *, edit_locus: int | None = None, center_token: int | None = None, content_token_bounds: tuple[int, int] | None = None, pool_type: Literal['centered_mean', 'global_mean'] = POOL_CENTERED_MEAN, pool_radius: int = DEFAULT_POOL_RADIUS_TOKENS) -> PoolingResult
Pool token-level hidden states into a state vector.
center_token is the actual hidden-state index resolved from the
tokenizer's DNA/control-token layout. edit_locus only records whether
the state is targeted; this function deliberately does not approximate a
token index from base-pair arithmetic. When the locus is absent, the
encoder contract requires a global-mean fallback tagged as untargeted.
Source code in geno_lewm/encoder/pooling.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |