View source on GitHub |
Base class of restrict policies. Never use this class directly, but
instead of of its derived class.
This class defines the rules for tracking and restricting the size of the
dynamic_embedding.Variable
. If the variable joins training via stateful
optimizer, the policy also manage the slots of the optimizer. It could own
a status to keep tracking the state of affairs of the features presented
in sparse dynamic_embedding.Variable
.
RestrictPolicy
requires a set of methods to be override, in its derived
policies: apply_update
, apply_restriction
, status
.
- apply_update: keep tracking on the status of the sparse variable, specifically the attributes of each key in sparse variable.
- apply_restriction: eliminate the features which are not legitimate.
__init__(var)
Create a new RestrictPolicy.
var
: Adynamic_embedding.Variable
object to be restricted.
Get status variable which save information about properties of features.
apply_restriction(
num_reserved,
**kwargs
)
Define the rule to restrict the size of the target variable. There are
three kinds of variables are token into consideration: variable, status
variable, and variables in slots. Number of num_reserved
features will
be kept in variable.
num_reserved
: number of remained keys after restriction.**kwargs
: (Optional) reserved keyword arguments.
An operation to restrict the sizes of variable and variables in slots.
apply_update(ids)
Define the rule to update status, with tracking the changes in variable and slots.
ids
: A Tensor. Keys appear in training. These keys in status variable will be updated if needed.
An operation to update status.