def _trim_vocab(vocab, vocab_size):
        """Discard start, end, pad and unk tokens if already present.

        Args:
            vocab(list): Vocabulary.
            vocab_size(int): The size of the vocabulary.

        Returns:
            word2id(list): Word to index list.
            id2word(list): Index to word list.
        """
        if "<s>" in vocab:
            del vocab["<s>"]
        if "<pad>" in vocab:
            del vocab["<pad>"]
        if "</s>" in vocab:
            del vocab["</s>"]
        if "<unk>" in vocab:
            del vocab["<unk>"]

        word2id = {"<s>": 0, "<pad>": 1, "</s>": 2, "<unk>": 3}

        id2word = {0: "<s>", 1: "<pad>", 2: "</s>", 3: "<unk>"}

        sorted_word2id = sorted(
            vocab.items(), key=operator.itemgetter(1), reverse=True
        )

        if vocab_size != -1:
            sorted_words = [x[0] for x in sorted_word2id[:vocab_size]]
        else:
            sorted_words = [x[0] for x in sorted_word2id]

        for ind, word in enumerate(sorted_words):
            word2id[word] = ind + 4

        for ind, word in enumerate(sorted_words):
            id2word[ind + 4] = word

        return word2id, id2word
Discard start, end, pad and unk tokens if already present.

        Args:
            vocab(list): Vocabulary.
            vocab_size(int): The size of the vocabulary.

        Returns:
            word2id(list): Word to index list.
            id2word(list): Index to word list.
        
utils_nlp/models/gensen/utils.py