Skip to content

Latest commit

 

History

History
132 lines (76 loc) · 3.65 KB

File metadata and controls

132 lines (76 loc) · 3.65 KB

tfra.dynamic_embedding.RestrictPolicy

View source on GitHub




Class RestrictPolicy

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__

View source

__init__(var)

Create a new RestrictPolicy.

Args:

Properties

status

Get status variable which save information about properties of features.

Methods

apply_restriction

View source

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.

Args:

  • num_reserved: number of remained keys after restriction.
  • **kwargs: (Optional) reserved keyword arguments.

Returns:

An operation to restrict the sizes of variable and variables in slots.

apply_update

View source

apply_update(ids)

Define the rule to update status, with tracking the changes in variable and slots.

Args:

  • ids: A Tensor. Keys appear in training. These keys in status variable will be updated if needed.

Returns:

An operation to update status.