class PTBPOSLoader:
    def __init__(self, set_tagset=True, test_portion=0.1, validation_portion=0.1):
        if set_tagset:
            self.ptb = list(treebank.tagged_sents(tagset='universal'))
        else:
            self.ptb = list(treebank.tagged_sents())

        self.test_portion = test_portion
        self.validation_portion = validation_portion
        self.split_train_val_test_set()
 
    def split_train_val_test_set(self):
        self.train_set, self.test_set = train_test_split(self.ptb, 
                                                         test_size=self.test_portion,
                                                         random_state=100)
        self.train_set, self.val_set = train_test_split(self.train_set,
                                                        test_size=self.validation_portion,
                                                        random_state=100)
        return self.train_set, self.val_set, self.test_set

    def extract_all_words_tag(self):
        self.train_words_tag = [word_tag for record in self.train_set for word_tag in record]
        self.val_words_tag = [word_tag for record in self.val_set for word_tag in record]
        self.test_words_tag = [word_tag for record in self.test_set for word_tag in record]
        return self.train_words_tag, self.val_words_tag, self.test_words_tag

    def set_vocab_and_tagset(self):
        vocab = set([word_tag[0] for word_tag in self.train_words_tag])
        tagset = sorted(list(set([pair[1] for pair in self.train_words_tag])))
        return vocab, tagset
        
       
refactor this in a professional manner 