You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

consistency_metric.py 970 B

12345678910111213141516171819202122232425262728
  1. from typing import Optional
  2. from ablkit.data.evaluation.base_metric import BaseMetric
  3. from ablkit.data.structures import ListData
  4. from ablkit.reasoning import KBBase
  5. class ConsistencyMetric(BaseMetric):
  6. def __init__(self, kb: KBBase, prefix: Optional[str] = None) -> None:
  7. super().__init__(prefix)
  8. self.kb = kb
  9. def process(self, data_examples: ListData) -> None:
  10. pred_pseudo_label = data_examples.pred_pseudo_label
  11. learned_rules = self.kb.learned_rules
  12. consistent_num = sum(
  13. [
  14. self.kb.consist_rule(instance, learned_rules[len(instance)])
  15. for instance in pred_pseudo_label
  16. ]
  17. )
  18. self.results.append((consistent_num, len(pred_pseudo_label)))
  19. def compute_metrics(self) -> dict:
  20. results = self.results
  21. metrics = dict()
  22. metrics["consistency"] = sum(t[0] for t in results) / sum(t[1] for t in results)
  23. return metrics

An efficient Python toolkit for Abductive Learning (ABL), a novel paradigm that integrates machine learning and logical reasoning in a unified framework.