Browse Source

[MNT] change entail to check_equal

ab_data
Gao Enhao 2 years ago
parent
commit
15d79ee1f2
4 changed files with 8 additions and 8 deletions
  1. +3
    -3
      abl/evaluation/semantics_metric.py
  2. +3
    -3
      abl/reasoning/search_based_kb.py
  3. +1
    -1
      examples/hwf/hwf_kb.py
  4. +1
    -1
      examples/mnist_add/mnist_add_kb.py

+ 3
- 3
abl/evaluation/semantics_metric.py View File

@@ -11,12 +11,12 @@ class SemanticsMetric(BaseMetric):

def process(self, data_samples: Sequence[dict]) -> None:
for data_sample in data_samples:
if self.kb.entail(data_sample, data_sample["Y"][0]):
if self.kb.check_equal(data_sample, data_sample["Y"][0]):
self.results.append(1)
else:
self.results.append(0)
def compute_metrics(self, results: list) -> dict:
metrics = dict()
metrics["semantics_accuracy"] = sum(results) / len(results)
return metrics
return metrics

+ 3
- 3
abl/reasoning/search_based_kb.py View File

@@ -53,8 +53,8 @@ class SearchBasedKB(BaseKB, ABC):
)

@abstractmethod
def entail(self, data_sample: ListData, y: Any):
"""Placeholder for entail."""
def check_equal(self, data_sample: ListData, y: Any):
"""Placeholder for check_equal."""
pass

def abduce_candidates(
@@ -75,7 +75,7 @@ class SearchBasedKB(BaseKB, ABC):
for i, idx in enumerate(revision_idx):
candidate[idx] = c[i]
new_data_sample["pred_pseudo_label"][0] = candidate
if self.entail(new_data_sample, new_data_sample["Y"][0]):
if self.check_equal(new_data_sample, new_data_sample["Y"][0]):
candidates.append(candidate)
return candidates



+ 1
- 1
examples/hwf/hwf_kb.py View File

@@ -32,7 +32,7 @@ class HWF_KB(GroundKB):
data_sample["Y"] = [eval("".join(formula))]
return data_sample["Y"][0]

def entail(self, data_sample: ListData, y: Any):
def check_equal(self, data_sample: ListData, y: Any):
if not self._valid_candidate(data_sample):
return False
formula = data_sample["pred_pseudo_label"][0]


+ 1
- 1
examples/mnist_add/mnist_add_kb.py View File

@@ -15,7 +15,7 @@ class AddKB(SearchBasedKB):
def get_key(self, data_sample: ListData):
return (data_sample.to_tuple("pred_pseudo_label"), data_sample["Y"][0])

def entail(self, data_sample: ListData, y: Any):
def check_equal(self, data_sample: ListData, y: Any):
return self.logic_forward(data_sample) == y

def logic_forward(self, data_sample):


Loading…
Cancel
Save