product
Product
Bases: Potential
Combine two potential instances via element-wise multiplication (sum in log space).
This class creates a new potential that is the element-wise product of two potentials:
prefix(xs) = p1.prefix(xs) + p2.prefix(xs)
complete(xs) = p1.complete(xs) + p2.complete(xs)
logw_next(x | xs) = p1.logw_next(x | xs) + p2.logw_next(x | xs)
The new potential's vocabulary is the intersection of the two potentials' vocabularies.
This class inherits all methods from Potential,
see there for method documentation.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Potential
|
The first potential instance. |
p2 |
Potential
|
The second potential instance. |
token_type |
str
|
The type of tokens that this product potential operates on. |
vocab |
list
|
The common vocabulary shared between the two potentials. |
Warning
Be careful when taking products of potentials with minimal vocabulary overlap. The resulting potential will only operate on tokens present in both vocabularies.
Source code in genlm/control/potential/product.py
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 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 | |
__init__(p1, p2)
Initialize a Product potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Potential
|
First potential |
required |
p2
|
Potential
|
Second potential |
required |