(self, example)
| 596 | return self._infer_feature_from_example(example) |
| 597 | |
| 598 | def _infer_feature_from_example(self, example): |
| 599 | if isinstance(self.features, Features): |
| 600 | return self.features |
| 601 | else: |
| 602 | for features in self.features: |
| 603 | try: |
| 604 | self._enforce_nested_string_type(features, example) |
| 605 | features.encode_example(example) |
| 606 | return features |
| 607 | except (ValueError, TypeError): |
| 608 | continue |
| 609 | feature_strings = "\n".join([f"Feature option {i}: {feature}" for i, feature in enumerate(self.features)]) |
| 610 | error_msg = ( |
| 611 | f"Predictions and/or references don't match the expected format.\n" |
| 612 | f"Expected format:\n{feature_strings},\n" |
| 613 | f"Input predictions: {summarize_if_long_list(example['predictions'])},\n" |
| 614 | f"Input references: {summarize_if_long_list(example['references'])}" |
| 615 | ) |
| 616 | raise ValueError(error_msg) from None |
| 617 | |
| 618 | def _feature_names(self): |
| 619 | if isinstance(self.features, list): |
no test coverage detected