Team Ai
Apppublic

joshnavip/ai-code-detection

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
step5_metadata_consistency_check.py53 linesDownload Raw Back to preprocessing
1import pandas as pd2 3DATA_PATH = "dataset/processed/dataset_step2_cleaned.csv"4 5def main():6    df = pd.read_csv(DATA_PATH)7 8    # -------------------------------9    # Handle Label column safely10    # -------------------------------11    if "Label" not in df.columns:12        if "Label (0- HUMAN, 1-AI)" in df.columns:13            df = df.rename(columns={"Label (0- HUMAN, 1-AI)": "Label"})14        else:15            print("⚠️ Label column not found. Skipping label-based checks.")16 17    # -------------------------------18    # Normalize Language column19    # -------------------------------20    if "Language" in df.columns:21        df["Language"] = df["Language"].astype(str).str.strip().str.lower()22 23    print("\n🧩 METADATA CONSISTENCY CHECK\n")24 25    # -------------------------------26    # Language consistency27    # -------------------------------28    print("🌐 Language distribution:")29    if "Language" in df.columns:30        print(df["Language"].value_counts())31    else:32        print("  Language column not found")33 34    # -------------------------------35    # Label vs Source_Type consistency36    # -------------------------------37    print("\n🏷️ Label vs Source_Type consistency:")38    if "Label" in df.columns and "Source_Type" in df.columns:39        cross_tab = pd.crosstab(df["Label"], df["Source_Type"])40        print(cross_tab)41 42        print("\nExpected behavior:")43        print("  Label 0 (Human) → Source_Type should be 'human'")44        print("  Label 1 (AI)    → Source_Type should be 'ai'")45 46    else:47        print("  Required columns not found for consistency check")48 49    print("\nMetadata consistency check completed ✅")50 51if __name__ == "__main__":52    main()53