def __init__(self,
                 data_root,
                 image_root,
                 text_type,
                 image_type,
                 **kwargs):
        """
        A dataset for semi-supervised learning, especially for cmml
        **Comprehensive Semi-Supervised Multi-Modal Learning**
        """
        super(SemiDataset, self).__init__()

        self.data_root = data_root
        self.image_root = image_root
        self.image_type = image_type
        self.text_type = text_type

        self.bow_dim = kwargs.get('bow_dim', 2912)   # default 2912 from cmml paper
        self.supervised_ratio = kwargs.get('supervise_ratio', 0.3)

        # load data reader
        self.reader = CocoReader(data_root=self.data_root, image_root=self.image_root)

        # for extract global feature for image
        self.transform = T.Compose([
            T.Resize((224, 224)),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406],
                        std=[0.229, 0.224, 0.225])
        ])

        self.train_img_id, self.train_txt_id = self.reader.train_by_text()
        self.valid_img_id, self.valid_txt_id = self.reader.valid_by_text()
        self.test_img_id, self.test_txt_id = self.reader.test_by_text()

        # build bag-of-word feature for all text
        text_dict = self.reader.text
        idx_list = list(text_dict.keys())    # total idx for text
        text_list = list(text_dict.values())      # total raw text
        total_train_list = self.reader.total_train_text     # total train text
        text_feat = build_bow(total_train_list, text_list, self.bow_dim)

        self.text = {}
        for i in range(len(idx_list)):
            self.text[idx_list[i]] = text_feat[i]

        self.split = 'train'

        # split supervised data and unsupervised data from train dataset
        permutation = np.random.permutation(len(self.train_img_id))
        self.train_img_id = np.array(self.train_img_id)
        self.train_txt_id = np.array(self.train_txt_id)

        self.train_img_id = self.train_img_id[permutation]
        self.train_txt_id = self.train_txt_id[permutation]

        self.supervised_split = int(self.supervised_ratio * 10)
        self.unsupervised_split = int((1 - self.supervised_ratio) * 10)

        self.supervised_image = self.train_img_id[:int(len(self.train_img_id) * self.supervised_ratio)]
        self.supervised_text = self.train_txt_id[:int(len(self.train_txt_id) * self.supervised_ratio)]
        self.unsupervised_image = self.train_img_id[int(len(self.train_img_id) * self.supervised_ratio):]
        self.unsupervised_text = self.train_txt_id[int(len(self.train_txt_id) * self.supervised_ratio):]

        A dataset for semi-supervised learning, especially for cmml
        **Comprehensive Semi-Supervised Multi-Modal Learning**
        
torchmm/datasets/semi_dataset.py