    def _check_types(self) -> None:
        """
        Check that all the instances have the same types.
        """
        field_name_to_type_counters: Dict[str, Counter] = defaultdict(lambda: Counter())
        field_counts: Counter = Counter()
        for instance in self.instances:
            for field_name, value in instance.fields.items():
                field_name_to_type_counters[field_name][value.__class__.__name__] += 1
                field_counts[field_name] += 1
        for field_name, type_counters in field_name_to_type_counters.items():
            if len(type_counters) > 1:
                raise ConfigurationError(
                    "You cannot construct a Batch with non-homogeneous Instances. "
                    f"Field '{field_name}' has {len(type_counters)} different types: "
                    f"{', '.join(type_counters.keys())}"
                )
            if field_counts[field_name] != len(self.instances):
                raise ConfigurationError(
                    "You cannot construct a Batch with non-homogeneous Instances. "
                    f"Field '{field_name}' present in some Instances but not others."
                )
Check that all the instances have the same types.
allennlp/data/batch.py