def _to_datasets_dict(self) -> Dict:
        """Helper method to put token classification records in a `datasets.Dataset`"""

        # create a dict first, where we make the necessary transformations
        def entities_to_dict(
            entities: Optional[List[Union[Tuple[str, int, int, float], Tuple[str, int, int]]]],
        ) -> Optional[List[Dict[str, Union[str, int, float]]]]:
            if entities is None:
                return None
            return [
                {"label": ent[0], "start": ent[1], "end": ent[2]}
                if len(ent) == 3
                else {"label": ent[0], "start": ent[1], "end": ent[2], "score": ent[3]}
                for ent in entities
            ]

        ds_dict = {}
        for key in self._RECORD_TYPE.__fields__:
            if key == "prediction":
                ds_dict[key] = [entities_to_dict(rec.prediction) for rec in self._records]
            elif key == "annotation":
                ds_dict[key] = [entities_to_dict(rec.annotation) for rec in self._records]
            elif key == "id":
                ds_dict[key] = [None if rec.id is None else str(rec.id) for rec in self._records]
            elif key == "metadata":
                ds_dict[key] = [getattr(rec, key) or None for rec in self._records]
            else:
                ds_dict[key] = [getattr(rec, key) for rec in self._records]

        return ds_dict
Helper method to put token classification records in a `datasets.Dataset`
argilla-v1/src/argilla_v1/client/datasets.py