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
__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
coerce(other, f, prune=True)
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
|
Returns:
Type | Description |
---|---|
Coerced
|
A Potential that operates on the vocabulary of |
Source code in genlm/control/potential/operators.py
to_autobatched()
Create a new potential instance that automatically batches concurrent requests to the instance methods.
See AutoBatchedPotential
for more details.
Returns:
Type | Description |
---|---|
AutoBatchedPotential
|
A new 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.