openasce.extension.debias package¶
- class openasce.extension.debias.CFRModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a CFR model.
Model: CFR (CounterFactual Regression).
Paper: Estimating individual treatment effect: generalization bounds and algorithms.
Link: http://proceedings.mlr.press/v70/shalit17a/shalit17a.pdf.
Author: Uri Shalit, Fredrik D. Johansson and David Sontag.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a CFR model.\n\n Model: CFR (CounterFactual Regression).\n\n Paper: Estimating individual treatment effect: generalization bounds and algorithms.\n\n Link: http://proceedings.mlr.press/v70/shalit17a/shalit17a.pdf.\n\n Author: Uri Shalit, Fredrik D. Johansson and David Sontag.\n '¶
- __module__ = 'openasce.extension.debias.cfr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘treatment’: np.ndarray}. feature: train feature. treatment: binary treatment or multiple discrete treatment.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.DICEDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a DICE model.
Model: DICE (Disentangling Interest and Conformity with Causal Embedding).
Link: https://arxiv.org/pdf/2006.11011.pdf.
Author: Yu Zheng, Chen Gao, Xiang Li, Xiangnan He, Depeng Jin, Yong Li.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a DICE model.\n\n Model: DICE (Disentangling Interest and Conformity with Causal Embedding).\n\n Link: https://arxiv.org/pdf/2006.11011.pdf.\n\n Author: Yu Zheng, Chen Gao, Xiang Li, Xiangnan He, Depeng Jin, Yong Li.\n\n '¶
- __module__ = 'openasce.extension.debias.dice'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘mask’: np.ndarray}. feature: train feature. mask: indicate the instance belong to interest or conformity, 1 means interest, 0 means conformity.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding prediction tensors, where logits_interest: model output logits tensor. logits_conformity: model output logits tensor. logits_click: model output logits tensor. conformity_emb: model output conformity_emb tensor. interest_emb: model output interest_emb tensor. mask: indicate the instance belong to interest or conformity, 1 means interest, 0 means conformity.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.DMBRDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a DMBR model.
Model: DMBR (De-Matching Bias Recommendation).
Paper: Alleviating Matching Bias in Marketing Recommendations.
Link: https://dl.acm.org/doi/abs/10.1145/3539618.3591854.
Author: Junpeng Fang, Qing Cui, Gongduo Zhang, Caizhi Tang, Lihong Gu, Longfei Li, Jinjie Gu, Jun Zhou, Fei Wu.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a DMBR model.\n\n Model: DMBR (De-Matching Bias Recommendation).\n\n Paper: Alleviating Matching Bias in Marketing Recommendations.\n\n Link: https://dl.acm.org/doi/abs/10.1145/3539618.3591854.\n\n Author: Junpeng Fang, Qing Cui, Gongduo Zhang, Caizhi Tang, Lihong Gu, Longfei Li, Jinjie Gu, Jun Zhou, Fei Wu.\n\n '¶
- __module__ = 'openasce.extension.debias.dmbr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘confounder’: np.ndarray}. feature: train feature. confounder: confounder feature.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.DRDebiasModel(hidden_units: Dict, min_propensity: float = 0.01, t_is_multi_class: bool = False, t_as_feature: bool = False, lr: float = 0.1, name: str = 'dr_debias')[source]¶
Bases:
CausalDebiasModelDoubly Robust Model for Debiasing Exposure/Post-click.
Model: DR (Doubly robust)
Paper: Doubly robust joint learning for recommendation on data missing not at random[C].
Link: https://proceedings.mlr.press/v97/wang19n.html.
Author: Wang X, Zhang R, Sun Y, et al.
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
t_is_multi_class (bool) – wether the treatment label is multi-class.
t_as_feature (bool) – wether the treatment is observed feature.
lr (float) – learning rate
- __annotations__ = {}¶
- __doc__ = 'Doubly Robust Model for Debiasing Exposure/Post-click.\n\n Model: DR (Doubly robust)\n\n Paper: Doubly robust joint learning for recommendation on data missing not at random[C].\n\n Link: https://proceedings.mlr.press/v97/wang19n.html.\n\n Author: Wang X, Zhang R, Sun Y, et al.\n '¶
- __init__(hidden_units: Dict, min_propensity: float = 0.01, t_is_multi_class: bool = False, t_as_feature: bool = False, lr: float = 0.1, name: str = 'dr_debias') None[source]¶
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
t_is_multi_class (bool) – wether the treatment label is multi-class.
t_as_feature (bool) – wether the treatment is observed feature.
lr (float) – learning rate
- __module__ = 'openasce.extension.debias.doubly_robust'¶
- _call(*, x: Tensor, y: Tensor, c: Dict[str, Tensor], training: bool) Union[None, Dict[str, Tensor]][source]¶
- Parameters
x – one batch of features
y – one batch of labels, shape: [batch_size, 2], including ctr and cvr labels
c – one batch for each concerned columns of the samples, here, {‘treatment’: Iterable[tf.Tensor]}
training – True means training and False for predict
- Returns
None for training and Dict for predict
- property trainable_variables¶
- class openasce.extension.debias.FAIRCODebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a FAIRCO model.
Model: FAIRCO (Inverse Probability Weighting).
Paper: Controlling Fairness and Bias in Dynamic Learning-to-Rank.
Link: https://arxiv.org/pdf/2005.14713.pdf.
Author: Marco Morik, Ashudeep Singh, Jessica Hong, and Thorsten Joachims.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a FAIRCO model.\n\n Model: FAIRCO (Inverse Probability Weighting).\n\n Paper: Controlling Fairness and Bias in Dynamic Learning-to-Rank.\n\n Link: https://arxiv.org/pdf/2005.14713.pdf.\n\n Author: Marco Morik, Ashudeep Singh, Jessica Hong, and Thorsten Joachims.\n '¶
- __module__ = 'openasce.extension.debias.fairco'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘weight’: np.ndarray, ‘group’: np.ndarray}. feature: train feature. weight: indicates the exposure proportion of item perspective. group: indicates the group identity of the item.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.IPSDebiasModel(hidden_units: Dict, min_propensity: float = 0.01, alpha: float = 0.1, lr: float = 0.1, name: str = 'ips_debias')[source]¶
Bases:
CausalDebiasModelInverse Propensity Score Model of the causal debias.
Model: IPS (Inverse Propensity Score)
Paper: Estimating causal effects from large data sets using propensity scores[J].
Author: Rubin, Donald B.
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
alpha (float) – hyperparameters of propensity loss
- __annotations__ = {}¶
- __doc__ = 'Inverse Propensity Score Model of the causal debias.\n\n Model: IPS (Inverse Propensity Score)\n\n Paper: Estimating causal effects from large data sets using propensity scores[J].\n\n Author: Rubin, Donald B.\n '¶
- __init__(hidden_units: Dict, min_propensity: float = 0.01, alpha: float = 0.1, lr: float = 0.1, name: str = 'ips_debias') None[source]¶
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
alpha (float) – hyperparameters of propensity loss
- __module__ = 'openasce.extension.debias.debias_ips'¶
- _call(*, x: Tensor, y: Tensor, c: Dict[str, Tensor], training: bool) Union[None, Dict[str, Tensor]][source]¶
- Parameters
x – one batch of features
y – one batch of labels, shape: [batch_size], outcome labels
c – one batch for each concerned columns of the samples, here, {‘treatment’: Iterable[tf.Tensor]}
training – True means training and False for predict
- Returns
None for training and Dict for predict
- property trainable_variables¶
- class openasce.extension.debias.IPWDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a IPW model.
Model: IPW (Inverse Probability Weighting).
Paper: Inverse probability weighted estimation for general missing data problems.
Link: https://www.econstor.eu/bitstream/10419/79298/1/386079048.pdf.
Author: Jeffrey M. Wooldridge.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a IPW model.\n\n Model: IPW (Inverse Probability Weighting).\n\n Paper: Inverse probability weighted estimation for general missing data problems.\n\n Link: https://www.econstor.eu/bitstream/10419/79298/1/386079048.pdf.\n\n Author: Jeffrey M. Wooldridge.\n '¶
- __module__ = 'openasce.extension.debias.ipw'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘weight’: np.ndarray}. feature: train feature. weight: indicates the exposure proportion of item perspective.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.MACRDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a MACR model.
Model: MACR (Model-Agnostic Counterfactual Reasoning).
Paper: Model-agnostic counterfactual reasoning for eliminating popularity bias in recommender system.
Link: https://arxiv.org/pdf/2010.15363.pdf.
Author: Tianxin Wei, Fuli Feng, Jiawei Chen, Ziwei Wu, Jinfeng Yi and Xiangnan He.
- __annotations__ = {}¶
- __doc__ = 'Building a MACR model.\n\n Model: MACR (Model-Agnostic Counterfactual Reasoning).\n\n Paper: Model-agnostic counterfactual reasoning for eliminating popularity bias in recommender system.\n\n Link: https://arxiv.org/pdf/2010.15363.pdf.\n\n Author: Tianxin Wei, Fuli Feng, Jiawei Chen, Ziwei Wu, Jinfeng Yi and Xiangnan He.\n '¶
- __module__ = 'openasce.extension.debias.macr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘user’: np.ndarray, ‘item’: np.ndarray}. user: user feature. item: item feature.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
- class openasce.extension.debias.PDADebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a PDA model.
Model: PDA (Popularity-bias Deconfounding and Adjusting).
Link: https://arxiv.org/pdf/2105.06067.pdf.
Author: Yang Zhang, Fuli Feng, Xiangnan He, Tianxin Wei, Chonggang Song, Guohui Ling and Yongdong Zhang.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a PDA model.\n\n Model: PDA (Popularity-bias Deconfounding and Adjusting).\n\n Link: https://arxiv.org/pdf/2105.06067.pdf.\n\n Author: Yang Zhang, Fuli Feng, Xiangnan He, Tianxin Wei, Chonggang Song, Guohui Ling and Yongdong Zhang.\n\n '¶
- __module__ = 'openasce.extension.debias.pda'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘mit’: np.ndarray}. feature: train feature. mit: indicte the popularity of the item.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
x – the original input.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
Subpackages¶
Submodules¶
openasce.extension.debias.cfr module¶
- class openasce.extension.debias.cfr.CFRModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a CFR model.
Model: CFR (CounterFactual Regression).
Paper: Estimating individual treatment effect: generalization bounds and algorithms.
Link: http://proceedings.mlr.press/v70/shalit17a/shalit17a.pdf.
Author: Uri Shalit, Fredrik D. Johansson and David Sontag.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a CFR model.\n\n Model: CFR (CounterFactual Regression).\n\n Paper: Estimating individual treatment effect: generalization bounds and algorithms.\n\n Link: http://proceedings.mlr.press/v70/shalit17a/shalit17a.pdf.\n\n Author: Uri Shalit, Fredrik D. Johansson and David Sontag.\n '¶
- __module__ = 'openasce.extension.debias.cfr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘treatment’: np.ndarray}. feature: train feature. treatment: binary treatment or multiple discrete treatment.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.debias_ips module¶
- class openasce.extension.debias.debias_ips.IPSDebiasModel(hidden_units: Dict, min_propensity: float = 0.01, alpha: float = 0.1, lr: float = 0.1, name: str = 'ips_debias')[source]¶
Bases:
CausalDebiasModelInverse Propensity Score Model of the causal debias.
Model: IPS (Inverse Propensity Score)
Paper: Estimating causal effects from large data sets using propensity scores[J].
Author: Rubin, Donald B.
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
alpha (float) – hyperparameters of propensity loss
- __annotations__ = {}¶
- __doc__ = 'Inverse Propensity Score Model of the causal debias.\n\n Model: IPS (Inverse Propensity Score)\n\n Paper: Estimating causal effects from large data sets using propensity scores[J].\n\n Author: Rubin, Donald B.\n '¶
- __init__(hidden_units: Dict, min_propensity: float = 0.01, alpha: float = 0.1, lr: float = 0.1, name: str = 'ips_debias') None[source]¶
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
alpha (float) – hyperparameters of propensity loss
- __module__ = 'openasce.extension.debias.debias_ips'¶
- _call(*, x: Tensor, y: Tensor, c: Dict[str, Tensor], training: bool) Union[None, Dict[str, Tensor]][source]¶
- Parameters
x – one batch of features
y – one batch of labels, shape: [batch_size], outcome labels
c – one batch for each concerned columns of the samples, here, {‘treatment’: Iterable[tf.Tensor]}
training – True means training and False for predict
- Returns
None for training and Dict for predict
- property trainable_variables¶
openasce.extension.debias.dice module¶
- class openasce.extension.debias.dice.DICEDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a DICE model.
Model: DICE (Disentangling Interest and Conformity with Causal Embedding).
Link: https://arxiv.org/pdf/2006.11011.pdf.
Author: Yu Zheng, Chen Gao, Xiang Li, Xiangnan He, Depeng Jin, Yong Li.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a DICE model.\n\n Model: DICE (Disentangling Interest and Conformity with Causal Embedding).\n\n Link: https://arxiv.org/pdf/2006.11011.pdf.\n\n Author: Yu Zheng, Chen Gao, Xiang Li, Xiangnan He, Depeng Jin, Yong Li.\n\n '¶
- __module__ = 'openasce.extension.debias.dice'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘mask’: np.ndarray}. feature: train feature. mask: indicate the instance belong to interest or conformity, 1 means interest, 0 means conformity.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding prediction tensors, where logits_interest: model output logits tensor. logits_conformity: model output logits tensor. logits_click: model output logits tensor. conformity_emb: model output conformity_emb tensor. interest_emb: model output interest_emb tensor. mask: indicate the instance belong to interest or conformity, 1 means interest, 0 means conformity.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.dmbr module¶
- class openasce.extension.debias.dmbr.DMBRDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a DMBR model.
Model: DMBR (De-Matching Bias Recommendation).
Paper: Alleviating Matching Bias in Marketing Recommendations.
Link: https://dl.acm.org/doi/abs/10.1145/3539618.3591854.
Author: Junpeng Fang, Qing Cui, Gongduo Zhang, Caizhi Tang, Lihong Gu, Longfei Li, Jinjie Gu, Jun Zhou, Fei Wu.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a DMBR model.\n\n Model: DMBR (De-Matching Bias Recommendation).\n\n Paper: Alleviating Matching Bias in Marketing Recommendations.\n\n Link: https://dl.acm.org/doi/abs/10.1145/3539618.3591854.\n\n Author: Junpeng Fang, Qing Cui, Gongduo Zhang, Caizhi Tang, Lihong Gu, Longfei Li, Jinjie Gu, Jun Zhou, Fei Wu.\n\n '¶
- __module__ = 'openasce.extension.debias.dmbr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘confounder’: np.ndarray}. feature: train feature. confounder: confounder feature.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.doubly_robust module¶
- class openasce.extension.debias.doubly_robust.DRDebiasModel(hidden_units: Dict, min_propensity: float = 0.01, t_is_multi_class: bool = False, t_as_feature: bool = False, lr: float = 0.1, name: str = 'dr_debias')[source]¶
Bases:
CausalDebiasModelDoubly Robust Model for Debiasing Exposure/Post-click.
Model: DR (Doubly robust)
Paper: Doubly robust joint learning for recommendation on data missing not at random[C].
Link: https://proceedings.mlr.press/v97/wang19n.html.
Author: Wang X, Zhang R, Sun Y, et al.
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
t_is_multi_class (bool) – wether the treatment label is multi-class.
t_as_feature (bool) – wether the treatment is observed feature.
lr (float) – learning rate
- __annotations__ = {}¶
- __doc__ = 'Doubly Robust Model for Debiasing Exposure/Post-click.\n\n Model: DR (Doubly robust)\n\n Paper: Doubly robust joint learning for recommendation on data missing not at random[C].\n\n Link: https://proceedings.mlr.press/v97/wang19n.html.\n\n Author: Wang X, Zhang R, Sun Y, et al.\n '¶
- __init__(hidden_units: Dict, min_propensity: float = 0.01, t_is_multi_class: bool = False, t_as_feature: bool = False, lr: float = 0.1, name: str = 'dr_debias') None[source]¶
Initialize.
- Parameters
hidden_units (dict) – list of positive integer, the layer number and units in each layer.
min_propensity (float) – The minimum propensity at which to clip propensity estimates to avoid dividing by zero.
t_is_multi_class (bool) – wether the treatment label is multi-class.
t_as_feature (bool) – wether the treatment is observed feature.
lr (float) – learning rate
- __module__ = 'openasce.extension.debias.doubly_robust'¶
- _call(*, x: Tensor, y: Tensor, c: Dict[str, Tensor], training: bool) Union[None, Dict[str, Tensor]][source]¶
- Parameters
x – one batch of features
y – one batch of labels, shape: [batch_size, 2], including ctr and cvr labels
c – one batch for each concerned columns of the samples, here, {‘treatment’: Iterable[tf.Tensor]}
training – True means training and False for predict
- Returns
None for training and Dict for predict
- property trainable_variables¶
openasce.extension.debias.fairco module¶
- class openasce.extension.debias.fairco.FAIRCODebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a FAIRCO model.
Model: FAIRCO (Inverse Probability Weighting).
Paper: Controlling Fairness and Bias in Dynamic Learning-to-Rank.
Link: https://arxiv.org/pdf/2005.14713.pdf.
Author: Marco Morik, Ashudeep Singh, Jessica Hong, and Thorsten Joachims.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a FAIRCO model.\n\n Model: FAIRCO (Inverse Probability Weighting).\n\n Paper: Controlling Fairness and Bias in Dynamic Learning-to-Rank.\n\n Link: https://arxiv.org/pdf/2005.14713.pdf.\n\n Author: Marco Morik, Ashudeep Singh, Jessica Hong, and Thorsten Joachims.\n '¶
- __module__ = 'openasce.extension.debias.fairco'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘weight’: np.ndarray, ‘group’: np.ndarray}. feature: train feature. weight: indicates the exposure proportion of item perspective. group: indicates the group identity of the item.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.ipw module¶
- class openasce.extension.debias.ipw.IPWDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a IPW model.
Model: IPW (Inverse Probability Weighting).
Paper: Inverse probability weighted estimation for general missing data problems.
Link: https://www.econstor.eu/bitstream/10419/79298/1/386079048.pdf.
Author: Jeffrey M. Wooldridge.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a IPW model.\n\n Model: IPW (Inverse Probability Weighting).\n\n Paper: Inverse probability weighted estimation for general missing data problems.\n\n Link: https://www.econstor.eu/bitstream/10419/79298/1/386079048.pdf.\n\n Author: Jeffrey M. Wooldridge.\n '¶
- __module__ = 'openasce.extension.debias.ipw'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘weight’: np.ndarray}. feature: train feature. weight: indicates the exposure proportion of item perspective.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.macr module¶
- class openasce.extension.debias.macr.MACRDebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a MACR model.
Model: MACR (Model-Agnostic Counterfactual Reasoning).
Paper: Model-agnostic counterfactual reasoning for eliminating popularity bias in recommender system.
Link: https://arxiv.org/pdf/2010.15363.pdf.
Author: Tianxin Wei, Fuli Feng, Jiawei Chen, Ziwei Wu, Jinfeng Yi and Xiangnan He.
- __annotations__ = {}¶
- __doc__ = 'Building a MACR model.\n\n Model: MACR (Model-Agnostic Counterfactual Reasoning).\n\n Paper: Model-agnostic counterfactual reasoning for eliminating popularity bias in recommender system.\n\n Link: https://arxiv.org/pdf/2010.15363.pdf.\n\n Author: Tianxin Wei, Fuli Feng, Jiawei Chen, Ziwei Wu, Jinfeng Yi and Xiangnan He.\n '¶
- __module__ = 'openasce.extension.debias.macr'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘user’: np.ndarray, ‘item’: np.ndarray}. user: user feature. item: item feature.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶
openasce.extension.debias.pda module¶
- class openasce.extension.debias.pda.PDADebiasModel(params: Dict)[source]¶
Bases:
CausalDebiasModelBuilding a PDA model.
Model: PDA (Popularity-bias Deconfounding and Adjusting).
Link: https://arxiv.org/pdf/2105.06067.pdf.
Author: Yang Zhang, Fuli Feng, Xiangnan He, Tianxin Wei, Chonggang Song, Guohui Ling and Yongdong Zhang.
Initialize.
- Parameters
params – parameter dict.
- __annotations__ = {}¶
- __doc__ = 'Building a PDA model.\n\n Model: PDA (Popularity-bias Deconfounding and Adjusting).\n\n Link: https://arxiv.org/pdf/2105.06067.pdf.\n\n Author: Yang Zhang, Fuli Feng, Xiangnan He, Tianxin Wei, Chonggang Song, Guohui Ling and Yongdong Zhang.\n\n '¶
- __module__ = 'openasce.extension.debias.pda'¶
- _call(*, x: ndarray, y: ndarray, c: Dict[str, ndarray], training: bool) Union[None, Dict[str, ndarray]][source]¶
- Building a callable function.
fit and predict are the base class interface methods to be called by outside users, which should not be overloaded. _call is used to implement the logic of the algorithm after it has been overloaded.
- Parameters
x – the original input feature.
y – the original input label.
c – the original input dict, here, {‘feature’: np.ndarray, ‘mit’: np.ndarray}. feature: train feature. mit: indicte the popularity of the item.
training – bool, identify the status.
- Returns
- A callable function,
for training, return loss, optimizer, and model; for inference, return the prediction dict.
- loss(predictions: Dict, labels: Tensor)[source]¶
Compute scalar loss tensors with respect to provided labels.
- Parameters
predictions – a dictionary holding predicted tensors.
labels – label tensor dict.
x – the original input.
- Returns
A scalar loss or A dictionary mapping strings (loss names) to scalar loss.
- property trainable_variables¶