smc
SequenceModel
A single SMC particle: one candidate sequence and its weight.
clone copies the mutable state (context, weight, twist_amount,
max_tokens, done) and shares the sampler, critic and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_sampler
|
TokenSampler
|
Draws one unit per step via |
required |
critic
|
Potential
|
Twists and reweights the particle. |
None
|
max_tokens
|
int
|
Token budget; EOS is forced at the boundary. |
float('inf')
|
twist_with_critic
|
bool
|
Whether the critic twists at every step, rather than scoring once at termination. |
True
|
terminate_when
|
callable
|
A |
None
|
verbosity
|
int
|
0 is silent, 1 prints the particle at each step. |
0
|
Source code in genlm/control/sampler/smc.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
clone()
Return a particle with copied state and a shared sampler and critic.
Source code in genlm/control/sampler/smc.py
twist(amt)
start()
async
Score the empty sequence's prefix weight.
Source code in genlm/control/sampler/smc.py
step()
async
Advance the particle by one unit, forcing EOS at the token budget.
Source code in genlm/control/sampler/smc.py
smc_standard(model, n_particles, ess_threshold=0.5, resampling_method='multinomial', json_path=None)
async
Run standard SMC over clones of model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
SequenceModel
|
The particle template, cloned |
required |
n_particles
|
int
|
Number of particles. |
required |
ess_threshold
|
float
|
Resample when ESS falls below this fraction of
|
0.5
|
resampling_method
|
str
|
One of 'multinomial', 'stratified', 'systematic', 'residual'. |
'multinomial'
|
json_path
|
str
|
Path to write the inference record to, for use
with the |
None
|
Returns:
| Type | Description |
|---|---|
list[SequenceModel]
|
The completed particles. |