Skip to content

Commit 65c3a79

Browse files
author
Zhe Wang
committed
fix: logic hardening, data label consistency, and CLI shim creation
1 parent 2936e17 commit 65c3a79

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎inspector.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""
3+
FairProp Inspector CLI - Unified Entry Point
4+
Matches documentation: python inspector.py --check "text"
5+
"""
6+
import sys
7+
import argparse
8+
import os
9+
10+
# Ensure src is in python path
11+
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
12+
13+
from inference.predict import predict
14+
15+
def main():
16+
parser = argparse.ArgumentParser(description="FairProp Inspector CLI")
17+
parser.add_argument("--check", type=str, required=True, help="Property description to inspect")
18+
parser.add_argument("--model", type=str, default="artifacts/model", help="Path to trained model")
19+
args = parser.parse_args()
20+
21+
label, confidence = predict(args.check, args.model)
22+
23+
print("-" * 40)
24+
print(f"FairProp Inspector Analysis")
25+
print("-" * 40)
26+
print(f"Input: {args.check}")
27+
print(f"Prediction: {label}")
28+
print(f"Confidence: {confidence:.2%}")
29+
print("-" * 40)
30+
31+
if __name__ == "__main__":
32+
main()

‎src/generator/generate_data.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def generate_synthetic_data(rules: Dict, num_samples: int) -> List[Dict]:
2222

2323
# Mock generation logic for skeleton
2424
templates = [
25-
("No kids allowed.", "NON_COMPLIANT", "Quiet community available for all residents."),
26-
("Great for families.", "COMPLIANT", "Great for families."),
27-
("Christian only.", "NON_COMPLIANT", "Open to people of all faiths."),
28-
("Walking distance to shops.", "COMPLIANT", "Walking distance to shops.")
25+
("No kids allowed.", 1, "Quiet community available for all residents."),
26+
("Great for families.", 0, "Great for families."),
27+
("Christian only.", 1, "Open to people of all faiths."),
28+
("Walking distance to shops.", 0, "Walking distance to shops.")
2929
]
3030

3131
for _ in range(num_samples):

‎src/trainer/train.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ def load_data(file_path: str) -> Dataset:
6565
logger.critical("Failed to parse JSON data.")
6666
sys.exit(1)
6767

68-
# Format for HF Dataset: list of dicts -> dict of lists
68+
# Label mapping to handle both strings and integers
69+
label_map = {"COMPLIANT": 0, "NON_COMPLIANT": 1}
70+
6971
hf_data = {
7072
"text": [item["text"] for item in data],
71-
"label": [item["label"] for item in data]
73+
"label": [
74+
item["label"] if isinstance(item["label"], int)
75+
else label_map.get(item["label"], 0)
76+
for item in data
77+
]
7278
}
7379
logger.info(f"Successfully loaded [bold green]{len(data)}[/bold green] examples.")
7480
return Dataset.from_dict(hf_data)

0 commit comments

Comments
 (0)