![]() |
Gaussian process layer with random feature approximation [1].
tfm.nlp.layers.RandomFeatureGaussianProcess(
units,
num_inducing=1024,
gp_kernel_type='gaussian',
gp_kernel_scale=1.0,
gp_output_bias=0.0,
normalize_input=False,
gp_kernel_scale_trainable=False,
gp_output_bias_trainable=False,
gp_cov_momentum=0.999,
gp_cov_ridge_penalty=1.0,
scale_random_features=True,
use_custom_random_features=True,
custom_random_features_initializer=None,
custom_random_features_activation=None,
l2_regularization=1e-06,
gp_cov_likelihood='gaussian',
return_gp_cov=True,
return_random_features=False,
dtype=None,
name='random_feature_gaussian_process',
**gp_output_kwargs
)
During training, the model updates the maximum a posteriori (MAP) logits estimates and posterior precision matrix using minibatch statistics. During inference, the model divides the MAP logit estimates by the predictive standard deviation, which is equivalent to approximating the posterior mean of the predictive probability via the mean-field approximation.
User can specify different types of random features by setting
use_custom_random_features=True
, and change the initializer and activations
of the custom random features. For example:
MLP Kernel: initializer='random_normal', activation=tf.nn.relu RBF Kernel: initializer='random_normal', activation=tf.math.cos
A linear kernel can also be specified by setting gp_kernel_type='linear' and
use_custom_random_features=True
.
[1]: Ali Rahimi and Benjamin Recht. Random Features for Large-Scale Kernel Machines. In Neural Information Processing Systems, 2007. https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf
Methods
call
call(
inputs, global_step=None, training=None
)
This is where the layer's logic lives.
The call()
method may not create state (except in its first
invocation, wrapping the creation of variables or other resources in
tf.init_scope()
). It is recommended to create state, including
tf.Variable
instances and nested Layer
instances,
in __init__()
, or in the build()
method that is
called automatically before call()
executes for the first time.
Args | |
---|---|
inputs
|
Input tensor, or dict/list/tuple of input tensors.
The first positional inputs argument is subject to special rules:
|
*args
|
Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above. |
**kwargs
|
Additional keyword arguments. May contain tensors, although
this is not recommended, for the reasons above.
The following optional keyword arguments are reserved:
training : Boolean scalar tensor of Python boolean indicating
whether the call is meant for training or inference.mask : Boolean input mask. If the layer's call() method takes a
mask argument, its default value will be set to the mask
generated for inputs by the previous layer (if input did come
from a layer that generated a corresponding mask, i.e. if it came
from a Keras layer with masking support).
|
Returns | |
---|---|
A tensor or list/tuple of tensors. |
reset_covariance_matrix
reset_covariance_matrix()
Resets covariance matrix of the GP layer.
This function is useful for reseting the model's covariance matrix at the beginning of a new epoch.