MCPcopy Create free account
hub / github.com/huggingface/evaluate / add

Method add

src/evaluate/module.py:548–589  ·  view source on GitHub ↗

Add one prediction and reference for the evaluation module's stack. Args: prediction (`list/array/tensor`, *optional*): Predictions. reference (`list/array/tensor`, *optional*): References. Example: ```py >>>

(self, *, prediction=None, reference=None, **kwargs)

Source from the content-addressed store, hash-verified

546 raise ValueError(error_msg) from None
547
548 def add(self, *, prediction=None, reference=None, **kwargs):
549 """Add one prediction and reference for the evaluation module's stack.
550
551 Args:
552 prediction (`list/array/tensor`, *optional*):
553 Predictions.
554 reference (`list/array/tensor`, *optional*):
555 References.
556
557 Example:
558
559 ```py
560 >>> import evaluate
561 >>> accuracy = evaluate.load("accuracy")
562 >>> accuracy.add(references=[0,1], predictions=[1,0])
563 ```
564 """
565 bad_inputs = [input_name for input_name in kwargs if input_name not in self._feature_names()]
566 if bad_inputs:
567 raise ValueError(
568 f"Bad inputs for evaluation module: {bad_inputs}. All required inputs are {list(self._feature_names())}"
569 )
570 example = {"predictions": prediction, "references": reference, **kwargs}
571 example = {input_name: example[input_name] for input_name in self._feature_names()}
572 if self.writer is None:
573 self.selected_feature_format = self._infer_feature_from_example(example)
574 self._init_writer()
575 try:
576 self._enforce_nested_string_type(self.selected_feature_format, example)
577 example = self.selected_feature_format.encode_example(example)
578 self.writer.write(example)
579 except (pa.ArrowInvalid, TypeError):
580 error_msg = (
581 f"Evaluation module inputs don't match the expected format.\n"
582 f"Expected format: {self.selected_feature_format},\n"
583 )
584 error_msg_inputs = ",\n".join(
585 f"Input {input_name}: {summarize_if_long_list(example[input_name])}"
586 for input_name in self.selected_feature_format
587 )
588 error_msg += error_msg_inputs
589 raise ValueError(error_msg) from None
590
591 def _infer_feature_from_batch(self, batch):
592 if isinstance(self.features, Features):

Callers 13

addMethod · 0.45
metric_add_and_computeFunction · 0.45
test_dummy_metricMethod · 0.45
test_input_numpyMethod · 0.45
test_input_torchMethod · 0.45
test_input_tfMethod · 0.45
test_addMethod · 0.45
setUpMethod · 0.45
tar_jsonl_pathFunction · 0.45

Calls 5

_feature_namesMethod · 0.95
_init_writerMethod · 0.95
summarize_if_long_listFunction · 0.85

Tested by 11

metric_add_and_computeFunction · 0.36
test_dummy_metricMethod · 0.36
test_input_numpyMethod · 0.36
test_input_torchMethod · 0.36
test_input_tfMethod · 0.36
test_addMethod · 0.36
setUpMethod · 0.36
tar_jsonl_pathFunction · 0.36
tar_nested_jsonl_pathFunction · 0.36