operators
PotentialOps
Mixin providing operations for potential functions:
-
Product (
*): Take the product of two potentials. -
Coercion (
coerce): Coerce the potential to operate on another potential's vocabulary. -
Auto-batching (
to_autobatched): Create a version that automatically batches concurrent requests to the instance methods. -
Parallelization (
to_multiprocess): Create a version that parallelizes operations over multiple processes.
Source code in genlm/control/potential/operators.py
1 2 3 4 5 6 7 8 9 10 11 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 | |
__mul__(other)
Take the product of two potentials.
See Product for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Potential
|
Another potential instance to take the product with. |
required |
Returns:
| Type | Description |
|---|---|
Product
|
A Product instance representing the unnormalized product of the two potentials. |
Note
Potentials must operate on the same token type and the intersection of their vocabularies must be non-empty.
Source code in genlm/control/potential/operators.py
__pow__(beta)
Scale this potential's log-weights by beta.
See Tempered for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
beta
|
float
|
The exponent, |
required |
Returns:
| Type | Description |
|---|---|
Tempered
|
The unnormalized |
Source code in genlm/control/potential/operators.py
normalize()
Renormalize this potential's next-token rows.
See Normalized for more details.
Returns:
| Type | Description |
|---|---|
Normalized
|
A potential whose |
Source code in genlm/control/potential/operators.py
coerce(other, f, prune=True, homomorphic=None, trie=None, tables=None)
Coerce the current potential to operate on the vocabulary of another potential.
See Coerced for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Potential
|
The potential instance whose vocabulary will be used. |
required |
f
|
callable
|
A function mapping sequences of tokens from self's vocab to sequences of tokens from other's vocab. |
required |
prune
|
bool
|
Whether to prune the coerced potential's vocabulary to only include tokens that can be mapped to the original potential's vocabulary.
If |
True
|
homomorphic
|
bool | None
|
Whether |
None
|
trie
|
dict | None
|
The symbol trie over |
None
|
tables
|
VocabTables | None
|
Prebuilt tables for |
None
|
Returns:
| Type | Description |
|---|---|
Coerced
|
A Potential that operates on the vocabulary of |
Source code in genlm/control/potential/operators.py
to_autobatched()
Return a potential instance that automatically batches concurrent requests to the instance methods.
The wrapper is memoized: repeated calls return the same instance.
See AutoBatchedPotential for more details.
Returns:
| Type | Description |
|---|---|
AutoBatchedPotential
|
A potential instance that wraps the current potential and automatically batches concurrent requests to the instance methods. |
Source code in genlm/control/potential/operators.py
to_multiprocess(num_workers=2, spawn_args=None)
Create a new potential instance that parallelizes operations using multiprocessing.
See MultiProcPotential for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_workers
|
int
|
The number of workers to use in the multiprocessing pool. |
2
|
spawn_args
|
tuple
|
The positional arguments to pass to the potential's |
None
|
Returns:
| Type | Description |
|---|---|
MultiProcPotential
|
A new potential instance that wraps the current potential and uses multiprocessing to parallelize operations. |
Note
For this method to be used, the potential must implement a picklable spawn method.