openasce.extension.debias.common package¶
Submodules¶
openasce.extension.debias.common.utils module¶
- class openasce.extension.debias.common.utils.DNNLayer(*args, **kwargs)[source]¶
Bases:
LayerBuilding a MLP/DNN Layer.
Layer: dense dnn layer
- inputs:
2d tensor (batch_size, input_dim)
- outputs:
2d tensor (batch_size, output_dim)
Initialize DNNLayer.
- Parameters
hidden_units – list of positive integer, the layer number and units in each layer.
activation – Activation function to use.
l1_reg – float between 0 and 1. L1 regularizer strength applied to the kernel weights matrix.
l2_reg – float between 0 and 1. L2 regularizer strength applied to the kernel weights matrix.
dropout_rate – float in [0,1). Fraction of the units to dropout.
use_bn – bool. Whether use BatchNormalization before activation or not.
apply_final_act – whether to apply act in final layer
seed – A Python integer to use as random seed.
- __init__(hidden_units: Optional[List] = None, activation='relu', l1_reg=0.0001, l2_reg=0.0001, dropout_rate=0, use_bn=False, apply_final_act=True, seed=1024, **kwargs)[source]¶
Initialize DNNLayer.
- Parameters
hidden_units – list of positive integer, the layer number and units in each layer.
activation – Activation function to use.
l1_reg – float between 0 and 1. L1 regularizer strength applied to the kernel weights matrix.
l2_reg – float between 0 and 1. L2 regularizer strength applied to the kernel weights matrix.
dropout_rate – float in [0,1). Fraction of the units to dropout.
use_bn – bool. Whether use BatchNormalization before activation or not.
apply_final_act – whether to apply act in final layer
seed – A Python integer to use as random seed.
- build(input_shape)[source]¶
Creates the variables of the layer (for subclass implementers).
This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().
This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).
- Parameters
input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).
- call(inputs, training=None, **kwargs)[source]¶
Calls the layer on new inputs.
- Parameters
inputs – 2d tensor (batch_size, dim_1), deep features.
- Returns
2d tensor (batch_size, out_dim).
- compute_output_shape(input_shape)[source]¶
Computes the output shape of the layer.
This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.
- Parameters
input_shape – Shape tuple (tuple of integers) or tf.TensorShape, or structure of shape tuples / tf.TensorShape instances (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
- Returns
A tf.TensorShape instance or structure of tf.TensorShape instances.
- get_config()[source]¶
Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.
- Returns
Python dictionary.
- class openasce.extension.debias.common.utils.DNNModel(*args, **kwargs)[source]¶
Bases:
ModelBuilding a DNN model.
Model: DNN or MLP.
- inputs:
2d tensor (batch_size, input_dim).
- outputs:
2d tensor (batch_size, output_dim).
Initialize DNNModel.
- Parameters
hidden_units – list, unit in each hidden layer.
act_fn – string, activation function.
l2_reg – float, regularization value.
dropout_rate – float, fraction of the units to dropout.
use_bn – boolean, if True, apply BatchNormalization in each hidden layer.
seed – int, random value for initialization.
- __init__(hidden_units, act_fn='relu', l1_reg=0.0001, l2_reg=0.0001, dropout_rate=0, use_bn=False, seed=1024, apply_final_act=False, name='DNNModel')[source]¶
Initialize DNNModel.
- Parameters
hidden_units – list, unit in each hidden layer.
act_fn – string, activation function.
l2_reg – float, regularization value.
dropout_rate – float, fraction of the units to dropout.
use_bn – boolean, if True, apply BatchNormalization in each hidden layer.
seed – int, random value for initialization.
- class openasce.extension.debias.common.utils.FMLayer(*args, **kwargs)[source]¶
Bases:
LayerBuilding a FM Layer. Model: Factorization Machine.
Paper: Factorization Machine models pairwise (order-2) feature interactions without linear term and bias.
Link: https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf.
Author: Steffen Rendle
- Input shape
3D tensor with shape:
(batch_size,field_size,embedding_size).
- Output shape
2D tensor with shape:
(batch_size, dim).
- build(input_shape)[source]¶
Creates the variables of the layer (for subclass implementers).
This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().
This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).
- Parameters
input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).
- call(inputs, **kwargs)[source]¶
Calls the layer on new inputs. :param input_shape: Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer).
- compute_output_shape(input_shape)[source]¶
Computes the output shape of the layer.
This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.
- Parameters
input_shape – Shape tuple (tuple of integers) or tf.TensorShape, or structure of shape tuples / tf.TensorShape instances (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
- Returns
A tf.TensorShape instance or structure of tf.TensorShape instances.
- class openasce.extension.debias.common.utils.MultiTaskDNNModel(*args, **kwargs)[source]¶
Bases:
ModelBuilding a multi task dnn model.
Model: MultiTaskDNN.
- inputs:
2d tensor (batch_size, input_dim).
- outputs:
list odf 2d tensor [(batch_size, output_dim),..].
Initialize MultiTaskDNNModel.
- Parameters
hidden_units – list, unit in each hidden layer.
act_fn – string, activation function.
num_tasks – int, number of the task.
l2_reg – float, regularization value.
dropout_rate – float, fraction of the units to dropout.
use_bn – boolean, if True, apply BatchNormalization in each hidden layer.
seed – int, random value for initialization.
- __init__(hidden_units, num_tasks, task_hidden_units, act_fn='relu', l1_reg=0.0001, l2_reg=0.0001, dropout_rate=0, use_bn=False, seed=1024, apply_final_act=False, task_apply_final_act=False, name='MultiTaskDNNModel')[source]¶
Initialize MultiTaskDNNModel.
- Parameters
hidden_units – list, unit in each hidden layer.
act_fn – string, activation function.
num_tasks – int, number of the task.
l2_reg – float, regularization value.
dropout_rate – float, fraction of the units to dropout.
use_bn – boolean, if True, apply BatchNormalization in each hidden layer.
seed – int, random value for initialization.
- openasce.extension.debias.common.utils.mmd_rbf(X, t, p, sig)[source]¶
Computes the l2-RBF MMD for X given t
Paper: Estimating individual treatment effect: generalization bounds and algorithms. Gaussian kernel(RBF): https://en.wikipedia.org/wiki/Radial_basis_function_kernel :param X: embeddings. :param t: 1 or 0. Distinguish the treatment group and the control group. :param p: the proportion of the number of treatment instances / the number of all instances. :param sig: kernel width.