    def _guess_sorting_keys(self, instances: Iterable[Instance], num_instances: int = 10) -> None:
        """
        Use `num_instances` instances from the dataset to infer the keys used
        for sorting the dataset for bucketing.

        # Parameters

        instances : `Iterable[Instance]`, required.
            The dataset to guess sorting keys for.
        num_instances : `int`, optional (default = `10`)
            The number of instances to use to guess sorting keys. Typically
            the default value is completely sufficient, but if your instances
            are not homogeneous, you might need more.
        """
        max_length = 0.0
        longest_field: Optional[str] = None
        for i, instance in enumerate(instances):
            for field_name, field in instance.fields.items():
                length = len(field)
                if length > max_length:
                    max_length = length
                    longest_field = field_name
            if i > num_instances:
                # Only use num_instances instances to guess the sorting keys.
                break

        if not longest_field:
            # This shouldn't ever happen (you basically have to have an empty instance list), but
            # just in case...
            raise AssertionError(
                "Found no field that needed padding; we are surprised you got this error, please "
                "open an issue on github"
            )
        self.sorting_keys = [longest_field]
Use `num_instances` instances from the dataset to infer the keys used
for sorting the dataset for bucketing.

# Parameters

instances : `Iterable[Instance]`, required.
The dataset to guess sorting keys for.
num_instances : `int`, optional (default = `10`)
The number of instances to use to guess sorting keys. Typically
the default value is completely sufficient, but if your instances
are not homogeneous, you might need more.
allennlp/data/samplers/bucket_batch_sampler.py