Conditional Probability Classifiers

This module contains code to build a conditional probability classifier, which is inspired by this paper: https://arxiv.org/pdf/1911.06475.pdf
import pandas as pd

source

build_standard_condition_mask

 build_standard_condition_mask (df_labels, label1, label2)
_df_labels=pd.DataFrame({
    'col_1':[0,0,0,1,1,2,2,2],
    'col_2':[0,1,2,3,4,5,6,7]
})
_df_labels

# 0 -> (0,1,2), 1 -> (3,4), 2-> (5,6,7)
col_1 col_2
0 0 0
1 0 1
2 0 2
3 1 3
4 1 4
5 2 5
6 2 6
7 2 7
print(build_standard_condition_mask(_df_labels,'col_1','col_2'))
tensor([[ True, False, False,  True,  True,  True, False, False, False, False,
         False],
        [False,  True, False, False, False, False,  True,  True, False, False,
         False],
        [False, False,  True, False, False, False, False, False,  True,  True,
          True]])

source

RobertaHSCCProbSequenceClassification

 RobertaHSCCProbSequenceClassification (config, size_l1=None,
                                        size_l2=None, standard_mask=None,
                                        layer2concat=4, device=None,
                                        head_class=None,
                                        **head_class_kwargs)

Roberta Conditional Probability Architecture with Hidden-State-Concatenation for Sequence Classification task

Type Default Details
config HuggingFace model configuration
size_l1 NoneType None Number of classes for head 1
size_l2 NoneType None Number of classes for head 2
standard_mask NoneType None Mask for conditional probability
layer2concat int 4 number of hidden layer to concatenate (counting from top)
device NoneType None CPU or GPU
head_class NoneType None The class object of the head. You can use RobertaClassificationHeadCustom as default
head_class_kwargs