Package opennlp.tools.depparse
Class ContributionCache
java.lang.Object
opennlp.tools.depparse.ContributionCache
Caches the hidden-layer contribution of each (feature position, embedding row) pair
a
FeedforwardDependencyParser scores, within a byte budget.
Each position has one table sized to the vocabulary block it reads, so a tag or label position never reserves a slot per word. The tables are charged to the budget up front; contribution vectors are charged when they are computed. Pairs that do not fit are scored directly. Contributions keep double precision, so cached and direct scoring return the same values.
- Since:
- 3.0.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longThe bytes charged per contribution vector beyond its values.private final AtomicReferenceArray<double[]>[]The cached contribution vectors, indexed by feature position and row offset.private static final longThe bytes of one double value.private final AtomicLongThe number of contribution vectors published so far.private final longThe bytes one contribution vector costs.private final int[]The first embedding row of the vocabulary block each position reads.private final FeedforwardNetwork(package private) static final longThe bytes charged per table slot.private final AtomicLongThe bytes the cache may still spend. -
Constructor Summary
ConstructorsConstructorDescriptionContributionCache(FeedforwardNetwork network, long budgetBytes) Allocates the tables of a cache. -
Method Summary
Modifier and TypeMethodDescription(package private) double[]contribution(int position, int row) Returns the cached hidden-layer contribution of one pair, computing and publishing it on first sight while the budget lasts.(package private) longentries()(package private) long(package private) longprivate booleanreserve()Reserves the bytes of one contribution vector.
-
Field Details
-
REFERENCE_BYTES
static final long REFERENCE_BYTESThe bytes charged per table slot.- See Also:
-
ARRAY_HEADER_BYTES
static final long ARRAY_HEADER_BYTESThe bytes charged per contribution vector beyond its values.- See Also:
-
DOUBLE_BYTES
private static final long DOUBLE_BYTESThe bytes of one double value.- See Also:
-
network
-
byPosition
The cached contribution vectors, indexed by feature position and row offset. -
firstRow
private final int[] firstRowThe first embedding row of the vocabulary block each position reads. -
entryBytes
private final long entryBytesThe bytes one contribution vector costs. -
remainingBytes
The bytes the cache may still spend. -
entries
The number of contribution vectors published so far.
-
-
Constructor Details
-
ContributionCache
ContributionCache(FeedforwardNetwork network, long budgetBytes) Allocates the tables of a cache.- Parameters:
network- The network whose contributions are cached. Must not benull.budgetBytes- The bytes the tables and the contribution vectors may use together.- Throws:
IllegalArgumentException- Thrown if the tables alone exceedbudgetBytes.
-
-
Method Details
-
contribution
double[] contribution(int position, int row) Returns the cached hidden-layer contribution of one pair, computing and publishing it on first sight while the budget lasts.- Parameters:
position- The feature position.row- The embedding row at that position.- Returns:
- The contribution vector, or
nullif the pair is not cached and the budget is spent.
-
reserve
private boolean reserve()Reserves the bytes of one contribution vector.- Returns:
- Whether the vector fits the remaining budget.
-
entries
long entries()- Returns:
- The number of contribution vectors the cache holds.
-
remainingBytes
long remainingBytes()- Returns:
- The bytes the cache may still spend on contribution vectors.
-
entryBytes
long entryBytes()- Returns:
- The bytes one contribution vector costs.
-