    def __getstate__(self):
        """
        Need to sanitize defaultdict and defaultdict-like objects
        by converting them to vanilla dicts when we pickle the vocabulary.
        """
        state = copy.copy(self.__dict__)
        state["_token_to_index"] = dict(state["_token_to_index"])
        state["_index_to_token"] = dict(state["_index_to_token"])

        if "_retained_counter" in state:
            state["_retained_counter"] = {
                key: dict(value) for key, value in state["_retained_counter"].items()
            }

        return state
Need to sanitize defaultdict and defaultdict-like objects
by converting them to vanilla dicts when we pickle the vocabulary.
allennlp/data/vocabulary.py