Add Paper A (IEEE TAI) complete draft with Firm A-calibrated dual-method classification
Paper draft includes all sections (Abstract through Conclusion), 36 references, and supporting scripts. Key methodology: Cosine similarity + dHash dual-method verification with thresholds calibrated against known-replication firm (Firm A). Includes: - 8 section markdown files (paper_a_*.md) - Ablation study script (ResNet-50 vs VGG-16 vs EfficientNet-B0) - Recalibrated classification script (84,386 PDFs, 5-tier system) - Figure generation and Word export scripts - Citation renumbering script ([1]-[36]) - Signature analysis pipeline (12 steps) - YOLO extraction scripts Three rounds of AI review completed (GPT-5.4, Claude Opus 4.6, Gemini 3 Pro). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,493 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Ablation Study: Backbone Comparison for Signature Feature Extraction
|
||||
====================================================================
|
||||
Compares ResNet-50 vs VGG-16 vs EfficientNet-B0 on:
|
||||
1. Feature extraction speed
|
||||
2. Intra/Inter class cosine similarity separation (Cohen's d)
|
||||
3. KDE crossover point
|
||||
4. Firm A (known replication) distribution
|
||||
|
||||
Usage:
|
||||
python ablation_backbone_comparison.py # Run all backbones
|
||||
python ablation_backbone_comparison.py --extract # Feature extraction only
|
||||
python ablation_backbone_comparison.py --analyze # Analysis only (features must exist)
|
||||
"""
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torchvision.models as models
|
||||
import torchvision.transforms as transforms
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
import numpy as np
|
||||
import sqlite3
|
||||
import time
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from collections import defaultdict
|
||||
from tqdm import tqdm
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
|
||||
# === Configuration ===
|
||||
IMAGES_DIR = Path("/Volumes/NV2/PDF-Processing/yolo-signatures/images")
|
||||
FEATURES_DIR = Path("/Volumes/NV2/PDF-Processing/signature-analysis/features")
|
||||
DB_PATH = Path("/Volumes/NV2/PDF-Processing/signature-analysis/signature_analysis.db")
|
||||
OUTPUT_DIR = Path("/Volumes/NV2/PDF-Processing/signature-analysis/ablation")
|
||||
FILENAMES_PATH = FEATURES_DIR / "signature_filenames.txt"
|
||||
|
||||
BATCH_SIZE = 64
|
||||
NUM_WORKERS = 4
|
||||
DEVICE = torch.device("mps" if torch.backends.mps.is_available() else
|
||||
"cuda" if torch.cuda.is_available() else "cpu")
|
||||
|
||||
# Sampling for analysis
|
||||
INTER_CLASS_SAMPLE_SIZE = 500_000
|
||||
INTRA_CLASS_MIN_SIGNATURES = 3
|
||||
RANDOM_SEED = 42
|
||||
|
||||
# Known replication firm (Deloitte Taiwan = 勤業眾信)
|
||||
FIRM_A_NAME = "勤業眾信聯合"
|
||||
|
||||
BACKBONES = {
|
||||
"resnet50": {
|
||||
"model_fn": lambda: models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V2),
|
||||
"feature_dim": 2048,
|
||||
"description": "ResNet-50 (ImageNet1K_V2)",
|
||||
},
|
||||
"vgg16": {
|
||||
"model_fn": lambda: models.vgg16(weights=models.VGG16_Weights.IMAGENET1K_V1),
|
||||
"feature_dim": 4096,
|
||||
"description": "VGG-16 (ImageNet1K_V1)",
|
||||
},
|
||||
"efficientnet_b0": {
|
||||
"model_fn": lambda: models.efficientnet_b0(weights=models.EfficientNet_B0_Weights.IMAGENET1K_V1),
|
||||
"feature_dim": 1280,
|
||||
"description": "EfficientNet-B0 (ImageNet1K_V1)",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class SignatureDataset(Dataset):
|
||||
def __init__(self, image_paths, transform=None):
|
||||
self.image_paths = image_paths
|
||||
self.transform = transform
|
||||
|
||||
def __len__(self):
|
||||
return len(self.image_paths)
|
||||
|
||||
def __getitem__(self, idx):
|
||||
import cv2
|
||||
img_path = self.image_paths[idx]
|
||||
img = cv2.imread(str(img_path))
|
||||
if img is None:
|
||||
img = np.ones((224, 224, 3), dtype=np.uint8) * 255
|
||||
else:
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
img = self._resize_with_padding(img, 224, 224)
|
||||
if self.transform:
|
||||
img = self.transform(img)
|
||||
return img, str(img_path.name)
|
||||
|
||||
@staticmethod
|
||||
def _resize_with_padding(img, target_w, target_h):
|
||||
h, w = img.shape[:2]
|
||||
scale = min(target_w / w, target_h / h)
|
||||
new_w, new_h = int(w * scale), int(h * scale)
|
||||
import cv2
|
||||
resized = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
||||
canvas = np.ones((target_h, target_w, 3), dtype=np.uint8) * 255
|
||||
x_off = (target_w - new_w) // 2
|
||||
y_off = (target_h - new_h) // 2
|
||||
canvas[y_off:y_off+new_h, x_off:x_off+new_w] = resized
|
||||
return canvas
|
||||
|
||||
|
||||
def build_feature_extractor(backbone_name):
|
||||
"""Build a feature extractor for the given backbone."""
|
||||
config = BACKBONES[backbone_name]
|
||||
model = config["model_fn"]()
|
||||
|
||||
if backbone_name == "vgg16":
|
||||
features_part = model.features
|
||||
avgpool = model.avgpool
|
||||
# Drop last Linear (classifier) to get 4096-dim output
|
||||
classifier_part = nn.Sequential(*list(model.classifier.children())[:-1])
|
||||
|
||||
class VGGFeatureExtractor(nn.Module):
|
||||
def __init__(self, features, avgpool, classifier):
|
||||
super().__init__()
|
||||
self.features = features
|
||||
self.avgpool = avgpool
|
||||
self.classifier = classifier
|
||||
|
||||
def forward(self, x):
|
||||
x = self.features(x)
|
||||
x = self.avgpool(x)
|
||||
x = torch.flatten(x, 1)
|
||||
x = self.classifier(x)
|
||||
return x
|
||||
|
||||
model = VGGFeatureExtractor(features_part, avgpool, classifier_part)
|
||||
|
||||
elif backbone_name == "resnet50":
|
||||
model = nn.Sequential(*list(model.children())[:-1])
|
||||
|
||||
elif backbone_name == "efficientnet_b0":
|
||||
model.classifier = nn.Identity()
|
||||
|
||||
model = model.to(DEVICE)
|
||||
model.eval()
|
||||
return model
|
||||
|
||||
|
||||
def extract_features(backbone_name):
|
||||
"""Extract features for all signatures using the given backbone."""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Extracting features: {BACKBONES[backbone_name]['description']}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
output_path = OUTPUT_DIR / f"features_{backbone_name}.npy"
|
||||
if output_path.exists():
|
||||
print(f" Features already exist: {output_path}")
|
||||
print(f" Skipping extraction. Delete file to re-extract.")
|
||||
return np.load(output_path)
|
||||
|
||||
# Load filenames
|
||||
with open(FILENAMES_PATH) as f:
|
||||
filenames = [line.strip() for line in f if line.strip()]
|
||||
print(f" Images: {len(filenames):,}")
|
||||
|
||||
image_paths = [IMAGES_DIR / fn for fn in filenames]
|
||||
|
||||
# Build model
|
||||
model = build_feature_extractor(backbone_name)
|
||||
|
||||
transform = transforms.Compose([
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
||||
])
|
||||
|
||||
dataset = SignatureDataset(image_paths, transform=transform)
|
||||
dataloader = DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=False,
|
||||
num_workers=NUM_WORKERS, pin_memory=True)
|
||||
|
||||
all_features = []
|
||||
start_time = time.time()
|
||||
|
||||
with torch.no_grad():
|
||||
for images, _ in tqdm(dataloader, desc=f" {backbone_name}"):
|
||||
images = images.to(DEVICE)
|
||||
feats = model(images)
|
||||
feats = feats.view(feats.size(0), -1) # flatten
|
||||
feats = nn.functional.normalize(feats, p=2, dim=1) # L2 normalize
|
||||
all_features.append(feats.cpu().numpy())
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
all_features = np.vstack(all_features)
|
||||
|
||||
print(f" Feature shape: {all_features.shape}")
|
||||
print(f" Time: {elapsed:.1f}s ({elapsed/60:.1f}min)")
|
||||
print(f" Speed: {len(filenames)/elapsed:.1f} images/sec")
|
||||
|
||||
# Save
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
np.save(output_path, all_features)
|
||||
print(f" Saved: {output_path} ({all_features.nbytes / 1e9:.2f} GB)")
|
||||
|
||||
return all_features
|
||||
|
||||
|
||||
def load_accountant_data():
|
||||
"""Load accountant assignments and firm info from DB."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute('''
|
||||
SELECT image_filename, assigned_accountant
|
||||
FROM signatures
|
||||
WHERE feature_vector IS NOT NULL
|
||||
ORDER BY signature_id
|
||||
''')
|
||||
sig_rows = cur.fetchall()
|
||||
|
||||
cur.execute('SELECT name, firm FROM accountants')
|
||||
acct_firm = {r[0]: r[1] for r in cur.fetchall()}
|
||||
|
||||
conn.close()
|
||||
|
||||
filename_to_acct = {r[0]: r[1] for r in sig_rows}
|
||||
return filename_to_acct, acct_firm
|
||||
|
||||
|
||||
def analyze_backbone(backbone_name, features, filenames, filename_to_acct, acct_firm):
|
||||
"""Compute intra/inter class stats for a backbone's features."""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Analyzing: {BACKBONES[backbone_name]['description']}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
np.random.seed(RANDOM_SEED)
|
||||
|
||||
# Map features to accountants
|
||||
accountants = []
|
||||
valid_indices = []
|
||||
for i, fn in enumerate(filenames):
|
||||
acct = filename_to_acct.get(fn)
|
||||
if acct:
|
||||
accountants.append(acct)
|
||||
valid_indices.append(i)
|
||||
|
||||
valid_features = features[valid_indices]
|
||||
print(f" Valid signatures with accountant: {len(valid_indices):,}")
|
||||
|
||||
# Group by accountant
|
||||
acct_groups = defaultdict(list)
|
||||
for i, acct in enumerate(accountants):
|
||||
acct_groups[acct].append(i)
|
||||
|
||||
# --- Intra-class ---
|
||||
print(" Computing intra-class similarities...")
|
||||
intra_sims = []
|
||||
for acct, indices in tqdm(acct_groups.items(), desc=" Intra-class", leave=False):
|
||||
if len(indices) < INTRA_CLASS_MIN_SIGNATURES:
|
||||
continue
|
||||
vecs = valid_features[indices]
|
||||
sim_matrix = vecs @ vecs.T
|
||||
n = len(indices)
|
||||
triu_idx = np.triu_indices(n, k=1)
|
||||
intra_sims.extend(sim_matrix[triu_idx].tolist())
|
||||
|
||||
intra_sims = np.array(intra_sims)
|
||||
print(f" Intra-class pairs: {len(intra_sims):,}")
|
||||
|
||||
# --- Inter-class ---
|
||||
print(" Computing inter-class similarities...")
|
||||
all_acct_list = list(acct_groups.keys())
|
||||
inter_sims = []
|
||||
for _ in range(INTER_CLASS_SAMPLE_SIZE):
|
||||
a1, a2 = np.random.choice(len(all_acct_list), 2, replace=False)
|
||||
i1 = np.random.choice(acct_groups[all_acct_list[a1]])
|
||||
i2 = np.random.choice(acct_groups[all_acct_list[a2]])
|
||||
sim = float(valid_features[i1] @ valid_features[i2])
|
||||
inter_sims.append(sim)
|
||||
inter_sims = np.array(inter_sims)
|
||||
print(f" Inter-class pairs: {len(inter_sims):,}")
|
||||
|
||||
# --- Firm A (known replication) ---
|
||||
print(f" Computing Firm A ({FIRM_A_NAME}) distribution...")
|
||||
firm_a_accts = [acct for acct in acct_groups if acct_firm.get(acct) == FIRM_A_NAME]
|
||||
firm_a_sims = []
|
||||
for acct in firm_a_accts:
|
||||
indices = acct_groups[acct]
|
||||
if len(indices) < 2:
|
||||
continue
|
||||
vecs = valid_features[indices]
|
||||
sim_matrix = vecs @ vecs.T
|
||||
n = len(indices)
|
||||
triu_idx = np.triu_indices(n, k=1)
|
||||
firm_a_sims.extend(sim_matrix[triu_idx].tolist())
|
||||
firm_a_sims = np.array(firm_a_sims) if firm_a_sims else np.array([])
|
||||
print(f" Firm A accountants: {len(firm_a_accts)}, pairs: {len(firm_a_sims):,}")
|
||||
|
||||
# --- Statistics ---
|
||||
def dist_stats(arr, name):
|
||||
return {
|
||||
"name": name,
|
||||
"n": len(arr),
|
||||
"mean": float(np.mean(arr)),
|
||||
"std": float(np.std(arr)),
|
||||
"median": float(np.median(arr)),
|
||||
"p1": float(np.percentile(arr, 1)),
|
||||
"p5": float(np.percentile(arr, 5)),
|
||||
"p25": float(np.percentile(arr, 25)),
|
||||
"p75": float(np.percentile(arr, 75)),
|
||||
"p95": float(np.percentile(arr, 95)),
|
||||
"p99": float(np.percentile(arr, 99)),
|
||||
"min": float(np.min(arr)),
|
||||
"max": float(np.max(arr)),
|
||||
}
|
||||
|
||||
intra_stats = dist_stats(intra_sims, "intra")
|
||||
inter_stats = dist_stats(inter_sims, "inter")
|
||||
firm_a_stats = dist_stats(firm_a_sims, "firm_a") if len(firm_a_sims) > 0 else None
|
||||
|
||||
# Cohen's d
|
||||
pooled_std = np.sqrt((intra_stats["std"]**2 + inter_stats["std"]**2) / 2)
|
||||
cohens_d = (intra_stats["mean"] - inter_stats["mean"]) / pooled_std if pooled_std > 0 else 0
|
||||
|
||||
# KDE crossover
|
||||
try:
|
||||
from scipy.stats import gaussian_kde
|
||||
x_grid = np.linspace(0, 1, 1000)
|
||||
kde_intra = gaussian_kde(intra_sims)
|
||||
kde_inter = gaussian_kde(inter_sims)
|
||||
diff = kde_intra(x_grid) - kde_inter(x_grid)
|
||||
sign_changes = np.where(np.diff(np.sign(diff)))[0]
|
||||
crossovers = x_grid[sign_changes]
|
||||
valid_crossovers = crossovers[(crossovers > 0.5) & (crossovers < 1.0)]
|
||||
kde_crossover = float(valid_crossovers[-1]) if len(valid_crossovers) > 0 else None
|
||||
except Exception as e:
|
||||
print(f" KDE crossover computation failed: {e}")
|
||||
kde_crossover = None
|
||||
|
||||
results = {
|
||||
"backbone": backbone_name,
|
||||
"description": BACKBONES[backbone_name]["description"],
|
||||
"feature_dim": BACKBONES[backbone_name]["feature_dim"],
|
||||
"intra": intra_stats,
|
||||
"inter": inter_stats,
|
||||
"firm_a": firm_a_stats,
|
||||
"cohens_d": float(cohens_d),
|
||||
"kde_crossover": kde_crossover,
|
||||
}
|
||||
|
||||
# Print summary
|
||||
print(f"\n --- {backbone_name} Summary ---")
|
||||
print(f" Feature dim: {results['feature_dim']}")
|
||||
print(f" Intra mean: {intra_stats['mean']:.4f} +/- {intra_stats['std']:.4f}")
|
||||
print(f" Inter mean: {inter_stats['mean']:.4f} +/- {inter_stats['std']:.4f}")
|
||||
print(f" Cohen's d: {cohens_d:.4f}")
|
||||
print(f" KDE crossover: {kde_crossover}")
|
||||
if firm_a_stats:
|
||||
print(f" Firm A mean: {firm_a_stats['mean']:.4f} +/- {firm_a_stats['std']:.4f}")
|
||||
print(f" Firm A 1st pct: {firm_a_stats['p1']:.4f}")
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def generate_comparison_table(all_results):
|
||||
"""Generate a markdown comparison table."""
|
||||
print(f"\n{'='*60}")
|
||||
print("COMPARISON TABLE")
|
||||
print(f"{'='*60}\n")
|
||||
|
||||
results_by_name = {r["backbone"]: r for r in all_results}
|
||||
|
||||
def get_val(backbone, key, sub=None):
|
||||
r = results_by_name.get(backbone)
|
||||
if not r:
|
||||
return None
|
||||
if sub:
|
||||
section = r.get(sub)
|
||||
if isinstance(section, dict):
|
||||
return section.get(key)
|
||||
return None
|
||||
return r.get(key)
|
||||
|
||||
def fmt(val, fmt_str=".4f"):
|
||||
if val is None:
|
||||
return "---"
|
||||
if isinstance(val, int):
|
||||
return str(val)
|
||||
return f"{val:{fmt_str}}"
|
||||
|
||||
names = ["resnet50", "vgg16", "efficientnet_b0"]
|
||||
header = "| Metric | ResNet-50 | VGG-16 | EfficientNet-B0 |"
|
||||
sep = "|--------|-----------|--------|-----------------|"
|
||||
|
||||
rows = [
|
||||
f"| Feature dim | {fmt(get_val('resnet50','feature_dim'),'')} | {fmt(get_val('vgg16','feature_dim'),'')} | {fmt(get_val('efficientnet_b0','feature_dim'),'')} |",
|
||||
f"| Intra mean | {fmt(get_val('resnet50','mean','intra'))} | {fmt(get_val('vgg16','mean','intra'))} | {fmt(get_val('efficientnet_b0','mean','intra'))} |",
|
||||
f"| Intra std | {fmt(get_val('resnet50','std','intra'))} | {fmt(get_val('vgg16','std','intra'))} | {fmt(get_val('efficientnet_b0','std','intra'))} |",
|
||||
f"| Inter mean | {fmt(get_val('resnet50','mean','inter'))} | {fmt(get_val('vgg16','mean','inter'))} | {fmt(get_val('efficientnet_b0','mean','inter'))} |",
|
||||
f"| Inter std | {fmt(get_val('resnet50','std','inter'))} | {fmt(get_val('vgg16','std','inter'))} | {fmt(get_val('efficientnet_b0','std','inter'))} |",
|
||||
f"| **Cohen's d** | **{fmt(get_val('resnet50','cohens_d'))}** | **{fmt(get_val('vgg16','cohens_d'))}** | **{fmt(get_val('efficientnet_b0','cohens_d'))}** |",
|
||||
f"| KDE crossover | {fmt(get_val('resnet50','kde_crossover'))} | {fmt(get_val('vgg16','kde_crossover'))} | {fmt(get_val('efficientnet_b0','kde_crossover'))} |",
|
||||
f"| Firm A mean | {fmt(get_val('resnet50','mean','firm_a'))} | {fmt(get_val('vgg16','mean','firm_a'))} | {fmt(get_val('efficientnet_b0','mean','firm_a'))} |",
|
||||
f"| Firm A 1st pct | {fmt(get_val('resnet50','p1','firm_a'))} | {fmt(get_val('vgg16','p1','firm_a'))} | {fmt(get_val('efficientnet_b0','p1','firm_a'))} |",
|
||||
]
|
||||
|
||||
table = "\n".join([header, sep] + rows)
|
||||
print(table)
|
||||
|
||||
# Save report
|
||||
report_path = OUTPUT_DIR / "ablation_comparison.md"
|
||||
with open(report_path, 'w') as f:
|
||||
f.write("# Ablation Study: Backbone Comparison\n\n")
|
||||
f.write(f"Date: {time.strftime('%Y-%m-%d %H:%M')}\n\n")
|
||||
f.write("## Comparison Table\n\n")
|
||||
f.write(table + "\n\n")
|
||||
f.write("## Interpretation\n\n")
|
||||
f.write("- **Cohen's d**: Higher = better separation between same-CPA and different-CPA signatures\n")
|
||||
f.write("- **KDE crossover**: The Bayes-optimal decision boundary (higher = easier to classify)\n")
|
||||
f.write("- **Firm A**: Known replication firm; expect very high mean similarity\n")
|
||||
f.write("- **Firm A 1st percentile**: Lower bound of known-replication similarity\n")
|
||||
|
||||
json_path = OUTPUT_DIR / "ablation_results.json"
|
||||
with open(json_path, 'w') as f:
|
||||
json.dump(all_results, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"\n Report saved: {report_path}")
|
||||
print(f" Raw data saved: {json_path}")
|
||||
|
||||
return table
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Ablation: backbone comparison")
|
||||
parser.add_argument("--extract", action="store_true", help="Feature extraction only")
|
||||
parser.add_argument("--analyze", action="store_true", help="Analysis only")
|
||||
parser.add_argument("--backbone", type=str, help="Run single backbone (resnet50/vgg16/efficientnet_b0)")
|
||||
args = parser.parse_args()
|
||||
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Load filenames
|
||||
with open(FILENAMES_PATH) as f:
|
||||
filenames = [line.strip() for line in f if line.strip()]
|
||||
|
||||
backbones_to_run = [args.backbone] if args.backbone else list(BACKBONES.keys())
|
||||
|
||||
if not args.analyze:
|
||||
# === Phase 1: Feature Extraction ===
|
||||
print("\n" + "=" * 60)
|
||||
print("PHASE 1: FEATURE EXTRACTION")
|
||||
print("=" * 60)
|
||||
|
||||
# For ResNet-50, copy existing features instead of re-extracting
|
||||
resnet_ablation_path = OUTPUT_DIR / "features_resnet50.npy"
|
||||
resnet_existing_path = FEATURES_DIR / "signature_features.npy"
|
||||
if "resnet50" in backbones_to_run and not resnet_ablation_path.exists() and resnet_existing_path.exists():
|
||||
print(f"\nCopying existing ResNet-50 features...")
|
||||
import shutil
|
||||
resnet_ablation_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(resnet_existing_path, resnet_ablation_path)
|
||||
print(f" Copied: {resnet_ablation_path}")
|
||||
|
||||
for name in backbones_to_run:
|
||||
if name == "resnet50" and resnet_ablation_path.exists():
|
||||
continue
|
||||
extract_features(name)
|
||||
|
||||
if args.extract:
|
||||
print("\nFeature extraction complete. Run with --analyze to compute statistics.")
|
||||
return
|
||||
|
||||
# === Phase 2: Analysis ===
|
||||
print("\n" + "=" * 60)
|
||||
print("PHASE 2: ANALYSIS")
|
||||
print("=" * 60)
|
||||
|
||||
filename_to_acct, acct_firm = load_accountant_data()
|
||||
|
||||
all_results = []
|
||||
for name in backbones_to_run:
|
||||
feat_path = OUTPUT_DIR / f"features_{name}.npy"
|
||||
if not feat_path.exists():
|
||||
print(f"\n WARNING: {feat_path} not found, skipping {name}")
|
||||
continue
|
||||
features = np.load(feat_path)
|
||||
results = analyze_backbone(name, features, filenames, filename_to_acct, acct_firm)
|
||||
all_results.append(results)
|
||||
|
||||
if len(all_results) > 1:
|
||||
generate_comparison_table(all_results)
|
||||
elif len(all_results) == 1:
|
||||
print(f"\nOnly one backbone analyzed. Run all three for comparison table.")
|
||||
|
||||
print("\nDone!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
# Build complete Paper A Word document from section markdown files
|
||||
# Uses pandoc with embedded figures
|
||||
|
||||
PAPER_DIR="/Volumes/NV2/pdf_recognize/paper"
|
||||
FIG_DIR="/Volumes/NV2/PDF-Processing/signature-analysis/paper_figures"
|
||||
OUTPUT="$PAPER_DIR/Paper_A_IEEE_TAI_Draft_v2.docx"
|
||||
|
||||
# Create combined markdown with title page
|
||||
cat > "$PAPER_DIR/_combined.md" << 'TITLEEOF'
|
||||
---
|
||||
title: "Automated Detection of Digitally Replicated Signatures in Large-Scale Financial Audit Reports"
|
||||
author: "[Authors removed for double-blind review]"
|
||||
date: ""
|
||||
geometry: margin=1in
|
||||
fontsize: 11pt
|
||||
---
|
||||
|
||||
TITLEEOF
|
||||
|
||||
# Append each section (strip the # heading line if it duplicates)
|
||||
for section in \
|
||||
paper_a_abstract.md \
|
||||
paper_a_impact_statement.md \
|
||||
paper_a_introduction.md \
|
||||
paper_a_related_work.md \
|
||||
paper_a_methodology.md \
|
||||
paper_a_results.md \
|
||||
paper_a_discussion.md \
|
||||
paper_a_conclusion.md \
|
||||
paper_a_references.md
|
||||
do
|
||||
echo "" >> "$PAPER_DIR/_combined.md"
|
||||
# Strip HTML comments and append
|
||||
sed '/^<!--/,/-->$/d' "$PAPER_DIR/$section" >> "$PAPER_DIR/_combined.md"
|
||||
echo "" >> "$PAPER_DIR/_combined.md"
|
||||
done
|
||||
|
||||
# Insert figure references as actual images
|
||||
# Fig 1 after "Fig. 1 illustrates"
|
||||
sed -i '' "s|Fig. 1 illustrates the overall architecture.|Fig. 1 illustrates the overall architecture.\n\n{width=100%}\n|" "$PAPER_DIR/_combined.md"
|
||||
|
||||
# Fig 2 after "Fig. 2 presents the cosine"
|
||||
sed -i '' "s|Fig. 2 presents the cosine similarity distributions|Fig. 2 presents the cosine similarity distributions|" "$PAPER_DIR/_combined.md"
|
||||
sed -i '' "/^Fig. 2 presents the cosine/a\\
|
||||
\\
|
||||
{width=60%}\\
|
||||
" "$PAPER_DIR/_combined.md"
|
||||
|
||||
# Fig 3 after "Fig. 3 presents"
|
||||
sed -i '' "/^Fig. 3 presents/a\\
|
||||
\\
|
||||
{width=60%}\\
|
||||
" "$PAPER_DIR/_combined.md"
|
||||
|
||||
# Fig 4 after "we compared three pre-trained"
|
||||
sed -i '' "/^To validate the choice of ResNet-50.*we conducted/a\\
|
||||
\\
|
||||
{width=100%}\\
|
||||
" "$PAPER_DIR/_combined.md"
|
||||
|
||||
# Build with pandoc
|
||||
pandoc "$PAPER_DIR/_combined.md" \
|
||||
-o "$OUTPUT" \
|
||||
--reference-doc=/dev/null \
|
||||
-f markdown \
|
||||
--wrap=none \
|
||||
2>&1
|
||||
|
||||
# If reference-doc fails, try without it
|
||||
if [ $? -ne 0 ]; then
|
||||
pandoc "$PAPER_DIR/_combined.md" \
|
||||
-o "$OUTPUT" \
|
||||
-f markdown \
|
||||
--wrap=none \
|
||||
2>&1
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm -f "$PAPER_DIR/_combined.md"
|
||||
|
||||
echo "Output: $OUTPUT"
|
||||
ls -lh "$OUTPUT"
|
||||
@@ -0,0 +1,231 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export Paper A v2 to Word, reading from md section files."""
|
||||
|
||||
from docx import Document
|
||||
from docx.shared import Inches, Pt, RGBColor
|
||||
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
PAPER_DIR = Path("/Volumes/NV2/pdf_recognize/paper")
|
||||
FIG_DIR = Path("/Volumes/NV2/PDF-Processing/signature-analysis/paper_figures")
|
||||
OUTPUT = PAPER_DIR / "Paper_A_IEEE_TAI_Draft_v2.docx"
|
||||
|
||||
SECTIONS = [
|
||||
"paper_a_abstract.md",
|
||||
"paper_a_impact_statement.md",
|
||||
"paper_a_introduction.md",
|
||||
"paper_a_related_work.md",
|
||||
"paper_a_methodology.md",
|
||||
"paper_a_results.md",
|
||||
"paper_a_discussion.md",
|
||||
"paper_a_conclusion.md",
|
||||
"paper_a_references.md",
|
||||
]
|
||||
|
||||
FIGURES = {
|
||||
"Fig. 1 illustrates": ("fig1_pipeline.png", "Fig. 1. Pipeline architecture for automated signature replication detection.", 6.5),
|
||||
"Fig. 2 presents": ("fig2_intra_inter_kde.png", "Fig. 2. Cosine similarity distributions: intra-class vs. inter-class with KDE crossover at 0.837.", 3.5),
|
||||
"Fig. 3 presents": ("fig3_firm_a_calibration.png", "Fig. 3. Per-signature best-match cosine similarity: Firm A (known replication) vs. other CPAs.", 3.5),
|
||||
"conducted an ablation study comparing three": ("fig4_ablation.png", "Fig. 4. Ablation study comparing three feature extraction backbones.", 6.5),
|
||||
}
|
||||
|
||||
|
||||
def strip_comments(text):
|
||||
"""Remove HTML comments from markdown."""
|
||||
return re.sub(r'<!--.*?-->', '', text, flags=re.DOTALL)
|
||||
|
||||
|
||||
def extract_tables(text):
|
||||
"""Find markdown tables and return (before, table_lines, after) tuples."""
|
||||
lines = text.split('\n')
|
||||
tables = []
|
||||
i = 0
|
||||
while i < len(lines):
|
||||
if '|' in lines[i] and i + 1 < len(lines) and re.match(r'\s*\|[-|: ]+\|', lines[i+1]):
|
||||
start = i
|
||||
while i < len(lines) and '|' in lines[i]:
|
||||
i += 1
|
||||
tables.append((start, lines[start:i]))
|
||||
else:
|
||||
i += 1
|
||||
return tables
|
||||
|
||||
|
||||
def add_md_table(doc, table_lines):
|
||||
"""Convert markdown table to docx table."""
|
||||
rows_data = []
|
||||
for line in table_lines:
|
||||
cells = [c.strip() for c in line.strip('|').split('|')]
|
||||
if not re.match(r'^[-: ]+$', cells[0]):
|
||||
rows_data.append(cells)
|
||||
|
||||
if len(rows_data) < 2:
|
||||
return
|
||||
|
||||
ncols = len(rows_data[0])
|
||||
table = doc.add_table(rows=len(rows_data), cols=ncols)
|
||||
table.style = 'Table Grid'
|
||||
|
||||
for r_idx, row in enumerate(rows_data):
|
||||
for c_idx in range(min(len(row), ncols)):
|
||||
cell = table.rows[r_idx].cells[c_idx]
|
||||
cell.text = row[c_idx]
|
||||
for p in cell.paragraphs:
|
||||
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
for run in p.runs:
|
||||
run.font.size = Pt(8)
|
||||
run.font.name = 'Times New Roman'
|
||||
if r_idx == 0:
|
||||
run.bold = True
|
||||
|
||||
doc.add_paragraph()
|
||||
|
||||
|
||||
def process_section(doc, filepath):
|
||||
"""Process a markdown section file into docx."""
|
||||
text = filepath.read_text(encoding='utf-8')
|
||||
text = strip_comments(text)
|
||||
|
||||
lines = text.split('\n')
|
||||
i = 0
|
||||
while i < len(lines):
|
||||
line = lines[i]
|
||||
stripped = line.strip()
|
||||
|
||||
# Skip empty lines
|
||||
if not stripped:
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Headings
|
||||
if stripped.startswith('# '):
|
||||
h = doc.add_heading(stripped[2:], level=1)
|
||||
for run in h.runs:
|
||||
run.font.color.rgb = RGBColor(0, 0, 0)
|
||||
i += 1
|
||||
continue
|
||||
elif stripped.startswith('## '):
|
||||
h = doc.add_heading(stripped[3:], level=2)
|
||||
for run in h.runs:
|
||||
run.font.color.rgb = RGBColor(0, 0, 0)
|
||||
i += 1
|
||||
continue
|
||||
elif stripped.startswith('### '):
|
||||
h = doc.add_heading(stripped[4:], level=3)
|
||||
for run in h.runs:
|
||||
run.font.color.rgb = RGBColor(0, 0, 0)
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Markdown table
|
||||
if '|' in stripped and i + 1 < len(lines) and re.match(r'\s*\|[-|: ]+\|', lines[i+1]):
|
||||
table_lines = []
|
||||
while i < len(lines) and '|' in lines[i]:
|
||||
table_lines.append(lines[i])
|
||||
i += 1
|
||||
add_md_table(doc, table_lines)
|
||||
continue
|
||||
|
||||
# Numbered list
|
||||
if re.match(r'^\d+\.\s', stripped):
|
||||
p = doc.add_paragraph(style='List Number')
|
||||
content = re.sub(r'^\d+\.\s', '', stripped)
|
||||
content = re.sub(r'\*\*(.+?)\*\*', r'\1', content) # strip bold markers
|
||||
run = p.add_run(content)
|
||||
run.font.size = Pt(10)
|
||||
run.font.name = 'Times New Roman'
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Bullet list
|
||||
if stripped.startswith('- '):
|
||||
p = doc.add_paragraph(style='List Bullet')
|
||||
content = stripped[2:]
|
||||
content = re.sub(r'\*\*(.+?)\*\*', r'\1', content)
|
||||
run = p.add_run(content)
|
||||
run.font.size = Pt(10)
|
||||
run.font.name = 'Times New Roman'
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Regular paragraph - collect continuation lines
|
||||
para_lines = [stripped]
|
||||
i += 1
|
||||
while i < len(lines):
|
||||
next_line = lines[i].strip()
|
||||
if not next_line or next_line.startswith('#') or next_line.startswith('|') or \
|
||||
next_line.startswith('- ') or re.match(r'^\d+\.\s', next_line):
|
||||
break
|
||||
para_lines.append(next_line)
|
||||
i += 1
|
||||
|
||||
para_text = ' '.join(para_lines)
|
||||
# Clean markdown formatting
|
||||
para_text = re.sub(r'\*\*\*(.+?)\*\*\*', r'\1', para_text) # bold italic
|
||||
para_text = re.sub(r'\*\*(.+?)\*\*', r'\1', para_text) # bold
|
||||
para_text = re.sub(r'\*(.+?)\*', r'\1', para_text) # italic
|
||||
para_text = re.sub(r'`(.+?)`', r'\1', para_text) # code
|
||||
para_text = para_text.replace('$$', '') # LaTeX delimiters
|
||||
para_text = para_text.replace('---', '\u2014') # em dash
|
||||
|
||||
p = doc.add_paragraph()
|
||||
p.paragraph_format.space_after = Pt(6)
|
||||
run = p.add_run(para_text)
|
||||
run.font.size = Pt(10)
|
||||
run.font.name = 'Times New Roman'
|
||||
|
||||
# Check if we should insert a figure after this paragraph
|
||||
for trigger, (fig_file, caption, width) in FIGURES.items():
|
||||
if trigger in para_text:
|
||||
fig_path = FIG_DIR / fig_file
|
||||
if fig_path.exists():
|
||||
fp = doc.add_paragraph()
|
||||
fp.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
fr = fp.add_run()
|
||||
fr.add_picture(str(fig_path), width=Inches(width))
|
||||
|
||||
cp = doc.add_paragraph()
|
||||
cp.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
cr = cp.add_run(caption)
|
||||
cr.font.size = Pt(9)
|
||||
cr.font.name = 'Times New Roman'
|
||||
cr.italic = True
|
||||
|
||||
|
||||
def main():
|
||||
doc = Document()
|
||||
|
||||
# Set default font
|
||||
style = doc.styles['Normal']
|
||||
style.font.name = 'Times New Roman'
|
||||
style.font.size = Pt(10)
|
||||
|
||||
# Title page
|
||||
p = doc.add_paragraph()
|
||||
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
p.paragraph_format.space_after = Pt(12)
|
||||
run = p.add_run("Automated Detection of Digitally Replicated Signatures\nin Large-Scale Financial Audit Reports")
|
||||
run.font.size = Pt(16)
|
||||
run.font.name = 'Times New Roman'
|
||||
run.bold = True
|
||||
|
||||
p = doc.add_paragraph()
|
||||
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
p.paragraph_format.space_after = Pt(20)
|
||||
run = p.add_run("[Authors removed for double-blind review]")
|
||||
run.font.size = Pt(10)
|
||||
run.italic = True
|
||||
|
||||
# Process each section
|
||||
for section_file in SECTIONS:
|
||||
filepath = PAPER_DIR / section_file
|
||||
if filepath.exists():
|
||||
process_section(doc, filepath)
|
||||
|
||||
doc.save(str(OUTPUT))
|
||||
print(f"Saved: {OUTPUT}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,392 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate all figures for Paper A (IEEE TAI submission).
|
||||
Outputs to /Volumes/NV2/PDF-Processing/signature-analysis/paper_figures/
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import sqlite3
|
||||
import json
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.patches as mpatches
|
||||
from matplotlib.patches import FancyBboxPatch, FancyArrowPatch
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
|
||||
# Config
|
||||
DB_PATH = '/Volumes/NV2/PDF-Processing/signature-analysis/signature_analysis.db'
|
||||
ABLATION_PATH = '/Volumes/NV2/PDF-Processing/signature-analysis/ablation/ablation_results.json'
|
||||
OUTPUT_DIR = Path('/Volumes/NV2/PDF-Processing/signature-analysis/paper_figures')
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
RANDOM_SEED = 42
|
||||
np.random.seed(RANDOM_SEED)
|
||||
|
||||
# IEEE formatting
|
||||
plt.rcParams.update({
|
||||
'font.family': 'serif',
|
||||
'font.serif': ['Times New Roman', 'DejaVu Serif'],
|
||||
'font.size': 9,
|
||||
'axes.labelsize': 10,
|
||||
'axes.titlesize': 10,
|
||||
'xtick.labelsize': 8,
|
||||
'ytick.labelsize': 8,
|
||||
'legend.fontsize': 8,
|
||||
'figure.dpi': 300,
|
||||
'savefig.dpi': 300,
|
||||
'savefig.bbox': 'tight',
|
||||
'savefig.pad_inches': 0.05,
|
||||
})
|
||||
|
||||
# IEEE column widths
|
||||
COL_WIDTH = 3.5 # single column inches
|
||||
FULL_WIDTH = 7.16 # full page width inches
|
||||
|
||||
|
||||
def load_signature_data():
|
||||
"""Load per-signature best-match similarities and accountant info."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute('''
|
||||
SELECT s.assigned_accountant, s.max_similarity_to_same_accountant, a.firm
|
||||
FROM signatures s
|
||||
LEFT JOIN accountants a ON s.assigned_accountant = a.name
|
||||
WHERE s.max_similarity_to_same_accountant IS NOT NULL
|
||||
AND s.assigned_accountant IS NOT NULL
|
||||
''')
|
||||
rows = cur.fetchall()
|
||||
conn.close()
|
||||
|
||||
data = {
|
||||
'accountants': [r[0] for r in rows],
|
||||
'max_sims': np.array([r[1] for r in rows]),
|
||||
'firms': [r[2] for r in rows],
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
def load_intra_inter_from_features():
|
||||
"""Compute intra/inter class distributions from feature vectors."""
|
||||
print("Loading features for intra/inter distributions...")
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute('''
|
||||
SELECT assigned_accountant, feature_vector
|
||||
FROM signatures
|
||||
WHERE feature_vector IS NOT NULL AND assigned_accountant IS NOT NULL
|
||||
''')
|
||||
rows = cur.fetchall()
|
||||
conn.close()
|
||||
|
||||
acct_groups = defaultdict(list)
|
||||
features_list = []
|
||||
accountants = []
|
||||
for r in rows:
|
||||
feat = np.frombuffer(r[1], dtype=np.float32)
|
||||
idx = len(features_list)
|
||||
features_list.append(feat)
|
||||
accountants.append(r[0])
|
||||
acct_groups[r[0]].append(idx)
|
||||
|
||||
features = np.array(features_list)
|
||||
print(f" Loaded {len(features)} signatures, {len(acct_groups)} accountants")
|
||||
|
||||
# Intra-class
|
||||
print(" Computing intra-class...")
|
||||
intra_sims = []
|
||||
for acct, indices in acct_groups.items():
|
||||
if len(indices) < 3:
|
||||
continue
|
||||
vecs = features[indices]
|
||||
sim_matrix = vecs @ vecs.T
|
||||
n = len(indices)
|
||||
triu_idx = np.triu_indices(n, k=1)
|
||||
intra_sims.extend(sim_matrix[triu_idx].tolist())
|
||||
intra_sims = np.array(intra_sims)
|
||||
print(f" Intra-class: {len(intra_sims):,} pairs")
|
||||
|
||||
# Inter-class
|
||||
print(" Computing inter-class...")
|
||||
all_acct_list = list(acct_groups.keys())
|
||||
inter_sims = []
|
||||
for _ in range(500_000):
|
||||
a1, a2 = np.random.choice(len(all_acct_list), 2, replace=False)
|
||||
i1 = np.random.choice(acct_groups[all_acct_list[a1]])
|
||||
i2 = np.random.choice(acct_groups[all_acct_list[a2]])
|
||||
sim = float(features[i1] @ features[i2])
|
||||
inter_sims.append(sim)
|
||||
inter_sims = np.array(inter_sims)
|
||||
print(f" Inter-class: {len(inter_sims):,} pairs")
|
||||
|
||||
return intra_sims, inter_sims
|
||||
|
||||
|
||||
def fig1_pipeline(output_path):
|
||||
"""Fig 1: Pipeline architecture diagram."""
|
||||
print("Generating Fig 1: Pipeline...")
|
||||
|
||||
fig, ax = plt.subplots(1, 1, figsize=(FULL_WIDTH, 1.8))
|
||||
ax.set_xlim(0, 10)
|
||||
ax.set_ylim(0, 2)
|
||||
ax.axis('off')
|
||||
|
||||
# Stages
|
||||
stages = [
|
||||
("90,282\nPDFs", "#E3F2FD"),
|
||||
("VLM\nPre-screen", "#BBDEFB"),
|
||||
("YOLO\nDetection", "#90CAF9"),
|
||||
("ResNet-50\nFeatures", "#64B5F6"),
|
||||
("Cosine +\npHash", "#42A5F5"),
|
||||
("Calibration\n& Classify", "#1E88E5"),
|
||||
]
|
||||
|
||||
annotations = [
|
||||
"86,072 docs",
|
||||
"182,328 sigs",
|
||||
"2048-dim",
|
||||
"Dual verify",
|
||||
"Verdicts",
|
||||
]
|
||||
|
||||
box_w = 1.3
|
||||
box_h = 1.0
|
||||
gap = 0.38
|
||||
start_x = 0.15
|
||||
y_center = 1.0
|
||||
|
||||
for i, (label, color) in enumerate(stages):
|
||||
x = start_x + i * (box_w + gap)
|
||||
box = FancyBboxPatch(
|
||||
(x, y_center - box_h/2), box_w, box_h,
|
||||
boxstyle="round,pad=0.1",
|
||||
facecolor=color, edgecolor='#1565C0', linewidth=1.2
|
||||
)
|
||||
ax.add_patch(box)
|
||||
ax.text(x + box_w/2, y_center, label,
|
||||
ha='center', va='center', fontsize=8, fontweight='bold',
|
||||
color='#0D47A1' if i < 3 else 'white')
|
||||
|
||||
# Arrow + annotation
|
||||
if i < len(stages) - 1:
|
||||
arrow_x = x + box_w + 0.02
|
||||
ax.annotate('', xy=(arrow_x + gap - 0.04, y_center),
|
||||
xytext=(arrow_x, y_center),
|
||||
arrowprops=dict(arrowstyle='->', color='#1565C0', lw=1.5))
|
||||
ax.text(arrow_x + gap/2, y_center - 0.62, annotations[i],
|
||||
ha='center', va='top', fontsize=6.5, color='#555555', style='italic')
|
||||
|
||||
plt.savefig(output_path, format='png')
|
||||
plt.savefig(output_path.with_suffix('.pdf'), format='pdf')
|
||||
plt.close()
|
||||
print(f" Saved: {output_path}")
|
||||
|
||||
|
||||
def fig2_intra_inter_kde(intra_sims, inter_sims, output_path):
|
||||
"""Fig 2: Intra vs Inter class cosine similarity distributions."""
|
||||
print("Generating Fig 2: Intra vs Inter KDE...")
|
||||
from scipy.stats import gaussian_kde
|
||||
|
||||
fig, ax = plt.subplots(1, 1, figsize=(COL_WIDTH, 2.5))
|
||||
|
||||
x_grid = np.linspace(0.3, 1.0, 500)
|
||||
|
||||
kde_intra = gaussian_kde(intra_sims, bw_method=0.02)
|
||||
kde_inter = gaussian_kde(inter_sims, bw_method=0.02)
|
||||
|
||||
y_intra = kde_intra(x_grid)
|
||||
y_inter = kde_inter(x_grid)
|
||||
|
||||
ax.fill_between(x_grid, y_intra, alpha=0.3, color='#E53935', label='Intra-class (same CPA)')
|
||||
ax.fill_between(x_grid, y_inter, alpha=0.3, color='#1E88E5', label='Inter-class (diff. CPA)')
|
||||
ax.plot(x_grid, y_intra, color='#C62828', linewidth=1.5)
|
||||
ax.plot(x_grid, y_inter, color='#1565C0', linewidth=1.5)
|
||||
|
||||
# Find crossover
|
||||
diff = y_intra - y_inter
|
||||
sign_changes = np.where(np.diff(np.sign(diff)))[0]
|
||||
crossovers = x_grid[sign_changes]
|
||||
valid = crossovers[(crossovers > 0.5) & (crossovers < 1.0)]
|
||||
if len(valid) > 0:
|
||||
xover = valid[-1]
|
||||
ax.axvline(x=xover, color='#4CAF50', linestyle='--', linewidth=1.2, alpha=0.8)
|
||||
ax.text(xover + 0.01, ax.get_ylim()[1] * 0.85, f'KDE crossover\n= {xover:.3f}',
|
||||
fontsize=7, color='#2E7D32', va='top')
|
||||
|
||||
ax.set_xlabel('Cosine Similarity')
|
||||
ax.set_ylabel('Density')
|
||||
ax.legend(loc='upper left', framealpha=0.9)
|
||||
ax.set_xlim(0.35, 1.0)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(output_path, format='png')
|
||||
plt.savefig(output_path.with_suffix('.pdf'), format='pdf')
|
||||
plt.close()
|
||||
print(f" Saved: {output_path}")
|
||||
|
||||
|
||||
def fig3_firm_a_calibration(data, output_path):
|
||||
"""Fig 3: Firm A calibration - per-signature best match distribution."""
|
||||
print("Generating Fig 3: Firm A Calibration...")
|
||||
from scipy.stats import gaussian_kde
|
||||
|
||||
firm_a_mask = np.array([f == '勤業眾信聯合' for f in data['firms']])
|
||||
non_firm_a_mask = ~firm_a_mask
|
||||
|
||||
firm_a_sims = data['max_sims'][firm_a_mask]
|
||||
others_sims = data['max_sims'][non_firm_a_mask]
|
||||
|
||||
fig, ax = plt.subplots(1, 1, figsize=(COL_WIDTH, 2.5))
|
||||
|
||||
x_grid = np.linspace(0.5, 1.0, 500)
|
||||
|
||||
kde_a = gaussian_kde(firm_a_sims, bw_method=0.015)
|
||||
kde_others = gaussian_kde(others_sims, bw_method=0.015)
|
||||
|
||||
y_a = kde_a(x_grid)
|
||||
y_others = kde_others(x_grid)
|
||||
|
||||
ax.fill_between(x_grid, y_a, alpha=0.35, color='#E53935',
|
||||
label=f'Firm A (known replication, n={len(firm_a_sims):,})')
|
||||
ax.fill_between(x_grid, y_others, alpha=0.25, color='#78909C',
|
||||
label=f'Other CPAs (n={len(others_sims):,})')
|
||||
ax.plot(x_grid, y_a, color='#C62828', linewidth=1.5)
|
||||
ax.plot(x_grid, y_others, color='#546E7A', linewidth=1.5)
|
||||
|
||||
# Mark key statistics
|
||||
p1 = np.percentile(firm_a_sims, 1)
|
||||
ax.axvline(x=p1, color='#E53935', linestyle=':', linewidth=1, alpha=0.7)
|
||||
ax.text(p1 - 0.01, ax.get_ylim()[1] * 0.5 if ax.get_ylim()[1] > 0 else 10,
|
||||
f'Firm A\n1st pct\n= {p1:.3f}', fontsize=6.5, color='#C62828',
|
||||
ha='right', va='center')
|
||||
|
||||
mean_a = firm_a_sims.mean()
|
||||
ax.axvline(x=mean_a, color='#E53935', linestyle='--', linewidth=1, alpha=0.7)
|
||||
|
||||
ax.set_xlabel('Per-Signature Best-Match Cosine Similarity')
|
||||
ax.set_ylabel('Density')
|
||||
ax.legend(loc='upper left', framealpha=0.9, fontsize=7)
|
||||
ax.set_xlim(0.5, 1.005)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(output_path, format='png')
|
||||
plt.savefig(output_path.with_suffix('.pdf'), format='pdf')
|
||||
plt.close()
|
||||
print(f" Saved: {output_path}")
|
||||
|
||||
|
||||
def fig4_ablation(output_path):
|
||||
"""Fig 4: Ablation backbone comparison."""
|
||||
print("Generating Fig 4: Ablation...")
|
||||
|
||||
with open(ABLATION_PATH) as f:
|
||||
results = json.load(f)
|
||||
|
||||
backbones = ['ResNet-50\n(2048-d)', 'VGG-16\n(4096-d)', 'EfficientNet-B0\n(1280-d)']
|
||||
backbone_keys = ['resnet50', 'vgg16', 'efficientnet_b0']
|
||||
results_map = {r['backbone']: r for r in results}
|
||||
|
||||
fig, axes = plt.subplots(1, 3, figsize=(FULL_WIDTH, 2.2))
|
||||
|
||||
colors = ['#1E88E5', '#FFA726', '#66BB6A']
|
||||
|
||||
# Panel (a): Intra/Inter means with error bars
|
||||
ax = axes[0]
|
||||
x = np.arange(len(backbones))
|
||||
width = 0.35
|
||||
|
||||
intra_means = [results_map[k]['intra']['mean'] for k in backbone_keys]
|
||||
intra_stds = [results_map[k]['intra']['std'] for k in backbone_keys]
|
||||
inter_means = [results_map[k]['inter']['mean'] for k in backbone_keys]
|
||||
inter_stds = [results_map[k]['inter']['std'] for k in backbone_keys]
|
||||
|
||||
bars1 = ax.bar(x - width/2, intra_means, width, yerr=intra_stds,
|
||||
color='#E53935', alpha=0.7, label='Intra', capsize=3, error_kw={'linewidth': 0.8})
|
||||
bars2 = ax.bar(x + width/2, inter_means, width, yerr=inter_stds,
|
||||
color='#1E88E5', alpha=0.7, label='Inter', capsize=3, error_kw={'linewidth': 0.8})
|
||||
|
||||
ax.set_ylabel('Cosine Similarity')
|
||||
ax.set_xticks(x)
|
||||
ax.set_xticklabels(backbones, fontsize=7)
|
||||
ax.legend(fontsize=7)
|
||||
ax.set_ylim(0.5, 1.0)
|
||||
ax.set_title('(a) Mean Similarity', fontsize=9)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
# Panel (b): Cohen's d
|
||||
ax = axes[1]
|
||||
cohens_ds = [results_map[k]['cohens_d'] for k in backbone_keys]
|
||||
bars = ax.bar(x, cohens_ds, 0.5, color=colors, alpha=0.8, edgecolor='#333', linewidth=0.5)
|
||||
ax.set_ylabel("Cohen's d")
|
||||
ax.set_xticks(x)
|
||||
ax.set_xticklabels(backbones, fontsize=7)
|
||||
ax.set_ylim(0, 0.9)
|
||||
ax.set_title("(b) Cohen's d", fontsize=9)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
# Add value labels
|
||||
for bar, val in zip(bars, cohens_ds):
|
||||
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.02,
|
||||
f'{val:.3f}', ha='center', va='bottom', fontsize=7, fontweight='bold')
|
||||
|
||||
# Panel (c): KDE crossover
|
||||
ax = axes[2]
|
||||
crossovers = [results_map[k]['kde_crossover'] for k in backbone_keys]
|
||||
bars = ax.bar(x, crossovers, 0.5, color=colors, alpha=0.8, edgecolor='#333', linewidth=0.5)
|
||||
ax.set_ylabel('KDE Crossover')
|
||||
ax.set_xticks(x)
|
||||
ax.set_xticklabels(backbones, fontsize=7)
|
||||
ax.set_ylim(0.7, 0.9)
|
||||
ax.set_title('(c) KDE Crossover', fontsize=9)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
for bar, val in zip(bars, crossovers):
|
||||
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.005,
|
||||
f'{val:.3f}', ha='center', va='bottom', fontsize=7, fontweight='bold')
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(output_path, format='png')
|
||||
plt.savefig(output_path.with_suffix('.pdf'), format='pdf')
|
||||
plt.close()
|
||||
print(f" Saved: {output_path}")
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("Generating Paper Figures")
|
||||
print("=" * 60)
|
||||
|
||||
# Fig 1: Pipeline (no data needed)
|
||||
fig1_pipeline(OUTPUT_DIR / 'fig1_pipeline.png')
|
||||
|
||||
# Fig 4: Ablation (uses pre-computed JSON)
|
||||
fig4_ablation(OUTPUT_DIR / 'fig4_ablation.png')
|
||||
|
||||
# Load data for Fig 2 & 3
|
||||
data = load_signature_data()
|
||||
print(f"Loaded {len(data['max_sims']):,} signatures")
|
||||
|
||||
# Fig 3: Firm A calibration (uses per-signature best match from DB)
|
||||
fig3_firm_a_calibration(data, OUTPUT_DIR / 'fig3_firm_a_calibration.png')
|
||||
|
||||
# Fig 2: Intra vs Inter (needs full feature vectors)
|
||||
intra_sims, inter_sims = load_intra_inter_from_features()
|
||||
fig2_intra_inter_kde(intra_sims, inter_sims, OUTPUT_DIR / 'fig2_intra_inter_kde.png')
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("All figures saved to:", OUTPUT_DIR)
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,413 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate complete PDF-level Excel report with Firm A-calibrated dual-method classification.
|
||||
Output: One row per PDF with identification, CPA info, detection stats,
|
||||
cosine similarity, dHash distance, and new dual-method verdicts.
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import numpy as np
|
||||
import openpyxl
|
||||
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
DB_PATH = '/Volumes/NV2/PDF-Processing/signature-analysis/signature_analysis.db'
|
||||
OUTPUT_DIR = Path('/Volumes/NV2/PDF-Processing/signature-analysis/recalibrated')
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
OUTPUT_PATH = OUTPUT_DIR / 'pdf_level_recalibrated_report.xlsx'
|
||||
|
||||
FIRM_A = '勤業眾信聯合'
|
||||
KDE_CROSSOVER = 0.837
|
||||
COSINE_HIGH = 0.95
|
||||
PHASH_HIGH_CONF = 5
|
||||
PHASH_MOD_CONF = 15
|
||||
|
||||
|
||||
def load_all_data():
|
||||
"""Load all signature data grouped by PDF."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Get all signatures with their stats
|
||||
cur.execute('''
|
||||
SELECT s.signature_id, s.image_filename, s.assigned_accountant,
|
||||
s.max_similarity_to_same_accountant,
|
||||
s.phash_distance_to_closest,
|
||||
s.ssim_to_closest,
|
||||
s.signature_verdict,
|
||||
a.firm, a.risk_level, a.mean_similarity, a.ratio_gt_95,
|
||||
a.signature_count
|
||||
FROM signatures s
|
||||
LEFT JOIN accountants a ON s.assigned_accountant = a.name
|
||||
WHERE s.assigned_accountant IS NOT NULL
|
||||
''')
|
||||
rows = cur.fetchall()
|
||||
|
||||
# Get PDF metadata from the master index or derive from filenames
|
||||
# Also get YOLO detection info
|
||||
cur.execute('''
|
||||
SELECT s.image_filename,
|
||||
s.detection_confidence
|
||||
FROM signatures s
|
||||
''')
|
||||
detection_rows = cur.fetchall()
|
||||
detection_conf = {r[0]: r[1] for r in detection_rows}
|
||||
|
||||
conn.close()
|
||||
|
||||
# Group by PDF
|
||||
pdf_data = defaultdict(lambda: {
|
||||
'signatures': [],
|
||||
'accountants': set(),
|
||||
'firms': set(),
|
||||
})
|
||||
|
||||
for r in rows:
|
||||
sig_id, filename, accountant, cosine, phash, ssim, verdict, \
|
||||
firm, risk, mean_sim, ratio95, sig_count = r
|
||||
|
||||
# Extract PDF key from filename
|
||||
# Format: {company}_{year}_{type}_page{N}_sig{M}.png or similar
|
||||
parts = filename.rsplit('_sig', 1)
|
||||
pdf_key = parts[0] if len(parts) > 1 else filename.rsplit('.', 1)[0]
|
||||
page_parts = pdf_key.rsplit('_page', 1)
|
||||
pdf_key = page_parts[0] if len(page_parts) > 1 else pdf_key
|
||||
|
||||
pdf_data[pdf_key]['signatures'].append({
|
||||
'sig_id': sig_id,
|
||||
'filename': filename,
|
||||
'accountant': accountant,
|
||||
'cosine': cosine,
|
||||
'phash': phash,
|
||||
'ssim': ssim,
|
||||
'old_verdict': verdict,
|
||||
'firm': firm,
|
||||
'risk_level': risk,
|
||||
'acct_mean_sim': mean_sim,
|
||||
'acct_ratio_95': ratio95,
|
||||
'acct_sig_count': sig_count,
|
||||
'detection_conf': detection_conf.get(filename),
|
||||
})
|
||||
if accountant:
|
||||
pdf_data[pdf_key]['accountants'].add(accountant)
|
||||
if firm:
|
||||
pdf_data[pdf_key]['firms'].add(firm)
|
||||
|
||||
print(f"Loaded {sum(len(v['signatures']) for v in pdf_data.values()):,} signatures across {len(pdf_data):,} PDFs")
|
||||
return pdf_data
|
||||
|
||||
|
||||
def classify_dual_method(max_cosine, min_phash):
|
||||
"""New dual-method classification with Firm A-calibrated thresholds."""
|
||||
if max_cosine is None:
|
||||
return 'unknown', 'none'
|
||||
|
||||
if max_cosine > COSINE_HIGH:
|
||||
if min_phash is not None and min_phash <= PHASH_HIGH_CONF:
|
||||
return 'high_confidence_replication', 'high'
|
||||
elif min_phash is not None and min_phash <= PHASH_MOD_CONF:
|
||||
return 'moderate_confidence_replication', 'medium'
|
||||
else:
|
||||
return 'high_style_consistency', 'low'
|
||||
elif max_cosine > KDE_CROSSOVER:
|
||||
return 'uncertain', 'low'
|
||||
else:
|
||||
return 'likely_genuine', 'medium'
|
||||
|
||||
|
||||
def build_report(pdf_data):
|
||||
"""Build Excel report."""
|
||||
wb = openpyxl.Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "PDF-Level Report"
|
||||
|
||||
# Define columns
|
||||
columns = [
|
||||
# Group A: PDF Identification (Blue)
|
||||
('pdf_key', 'PDF Key'),
|
||||
('n_signatures', '# Signatures'),
|
||||
|
||||
# Group B: CPA Info (Green)
|
||||
('accountant_1', 'CPA 1 Name'),
|
||||
('accountant_2', 'CPA 2 Name'),
|
||||
('firm_1', 'Firm 1'),
|
||||
('firm_2', 'Firm 2'),
|
||||
('is_firm_a', 'Is Firm A'),
|
||||
|
||||
# Group C: Detection (Yellow)
|
||||
('avg_detection_conf', 'Avg Detection Conf'),
|
||||
|
||||
# Group D: Cosine Similarity - Sig 1 (Red)
|
||||
('sig1_cosine', 'Sig1 Max Cosine'),
|
||||
('sig1_cosine_verdict', 'Sig1 Cosine Verdict'),
|
||||
('sig1_acct_mean', 'Sig1 CPA Mean Sim'),
|
||||
('sig1_acct_ratio95', 'Sig1 CPA >0.95 Ratio'),
|
||||
('sig1_acct_count', 'Sig1 CPA Sig Count'),
|
||||
|
||||
# Group E: Cosine Similarity - Sig 2 (Purple)
|
||||
('sig2_cosine', 'Sig2 Max Cosine'),
|
||||
('sig2_cosine_verdict', 'Sig2 Cosine Verdict'),
|
||||
('sig2_acct_mean', 'Sig2 CPA Mean Sim'),
|
||||
('sig2_acct_ratio95', 'Sig2 CPA >0.95 Ratio'),
|
||||
('sig2_acct_count', 'Sig2 CPA Sig Count'),
|
||||
|
||||
# Group F: dHash Distance (Orange)
|
||||
('min_phash', 'Min dHash Distance'),
|
||||
('max_phash', 'Max dHash Distance'),
|
||||
('avg_phash', 'Avg dHash Distance'),
|
||||
('sig1_phash', 'Sig1 dHash Distance'),
|
||||
('sig2_phash', 'Sig2 dHash Distance'),
|
||||
|
||||
# Group G: SSIM (for reference only) (Gray)
|
||||
('max_ssim', 'Max SSIM'),
|
||||
('avg_ssim', 'Avg SSIM'),
|
||||
|
||||
# Group H: Dual-Method Classification (Dark Blue)
|
||||
('dual_verdict', 'Dual-Method Verdict'),
|
||||
('dual_confidence', 'Confidence Level'),
|
||||
('max_cosine', 'PDF Max Cosine'),
|
||||
('pdf_min_phash', 'PDF Min dHash'),
|
||||
|
||||
# Group I: CPA Risk (Teal)
|
||||
('sig1_risk', 'Sig1 CPA Risk Level'),
|
||||
('sig2_risk', 'Sig2 CPA Risk Level'),
|
||||
]
|
||||
|
||||
col_keys = [c[0] for c in columns]
|
||||
col_names = [c[1] for c in columns]
|
||||
|
||||
# Header styles
|
||||
header_fill = PatternFill(start_color='1F4E79', end_color='1F4E79', fill_type='solid')
|
||||
header_font = Font(name='Arial', size=9, bold=True, color='FFFFFF')
|
||||
data_font = Font(name='Arial', size=9)
|
||||
thin_border = Border(
|
||||
left=Side(style='thin'),
|
||||
right=Side(style='thin'),
|
||||
top=Side(style='thin'),
|
||||
bottom=Side(style='thin'),
|
||||
)
|
||||
|
||||
# Group colors
|
||||
group_colors = {
|
||||
'A': 'D6E4F0', # Blue - PDF ID
|
||||
'B': 'D9E2D0', # Green - CPA
|
||||
'C': 'FFF2CC', # Yellow - Detection
|
||||
'D': 'F4CCCC', # Red - Cosine Sig1
|
||||
'E': 'E1D5E7', # Purple - Cosine Sig2
|
||||
'F': 'FFE0B2', # Orange - dHash
|
||||
'G': 'E0E0E0', # Gray - SSIM
|
||||
'H': 'B3D4FC', # Dark Blue - Dual method
|
||||
'I': 'B2DFDB', # Teal - Risk
|
||||
}
|
||||
|
||||
group_ranges = {
|
||||
'A': (0, 2), 'B': (2, 7), 'C': (7, 8),
|
||||
'D': (8, 13), 'E': (13, 18), 'F': (18, 23),
|
||||
'G': (23, 25), 'H': (25, 29), 'I': (29, 31),
|
||||
}
|
||||
|
||||
# Write header
|
||||
for col_idx, name in enumerate(col_names, 1):
|
||||
cell = ws.cell(row=1, column=col_idx, value=name)
|
||||
cell.font = header_font
|
||||
cell.fill = header_fill
|
||||
cell.alignment = Alignment(horizontal='center', wrap_text=True)
|
||||
cell.border = thin_border
|
||||
|
||||
# Process PDFs
|
||||
row_idx = 2
|
||||
verdict_counts = defaultdict(int)
|
||||
firm_a_counts = defaultdict(int)
|
||||
|
||||
for pdf_key, pdata in sorted(pdf_data.items()):
|
||||
sigs = pdata['signatures']
|
||||
if not sigs:
|
||||
continue
|
||||
|
||||
# Sort signatures by position (sig1, sig2)
|
||||
sigs_sorted = sorted(sigs, key=lambda s: s['filename'])
|
||||
sig1 = sigs_sorted[0] if len(sigs_sorted) > 0 else None
|
||||
sig2 = sigs_sorted[1] if len(sigs_sorted) > 1 else None
|
||||
|
||||
# Compute PDF-level aggregates
|
||||
cosines = [s['cosine'] for s in sigs if s['cosine'] is not None]
|
||||
phashes = [s['phash'] for s in sigs if s['phash'] is not None]
|
||||
ssims = [s['ssim'] for s in sigs if s['ssim'] is not None]
|
||||
confs = [s['detection_conf'] for s in sigs if s['detection_conf'] is not None]
|
||||
|
||||
max_cosine = max(cosines) if cosines else None
|
||||
min_phash = min(phashes) if phashes else None
|
||||
max_phash = max(phashes) if phashes else None
|
||||
avg_phash = np.mean(phashes) if phashes else None
|
||||
max_ssim = max(ssims) if ssims else None
|
||||
avg_ssim = np.mean(ssims) if ssims else None
|
||||
avg_conf = np.mean(confs) if confs else None
|
||||
|
||||
is_firm_a = FIRM_A in pdata['firms']
|
||||
|
||||
# Dual-method classification
|
||||
verdict, confidence = classify_dual_method(max_cosine, min_phash)
|
||||
verdict_counts[verdict] += 1
|
||||
if is_firm_a:
|
||||
firm_a_counts[verdict] += 1
|
||||
|
||||
# Cosine verdicts per signature
|
||||
def cosine_verdict(cos):
|
||||
if cos is None: return None
|
||||
if cos > COSINE_HIGH: return 'high'
|
||||
if cos > KDE_CROSSOVER: return 'uncertain'
|
||||
return 'low'
|
||||
|
||||
# Build row
|
||||
row_data = {
|
||||
'pdf_key': pdf_key,
|
||||
'n_signatures': len(sigs),
|
||||
'accountant_1': sig1['accountant'] if sig1 else None,
|
||||
'accountant_2': sig2['accountant'] if sig2 else None,
|
||||
'firm_1': sig1['firm'] if sig1 else None,
|
||||
'firm_2': sig2['firm'] if sig2 else None,
|
||||
'is_firm_a': 'Yes' if is_firm_a else 'No',
|
||||
'avg_detection_conf': round(avg_conf, 4) if avg_conf else None,
|
||||
'sig1_cosine': round(sig1['cosine'], 4) if sig1 and sig1['cosine'] else None,
|
||||
'sig1_cosine_verdict': cosine_verdict(sig1['cosine']) if sig1 else None,
|
||||
'sig1_acct_mean': round(sig1['acct_mean_sim'], 4) if sig1 and sig1['acct_mean_sim'] else None,
|
||||
'sig1_acct_ratio95': round(sig1['acct_ratio_95'], 4) if sig1 and sig1['acct_ratio_95'] else None,
|
||||
'sig1_acct_count': sig1['acct_sig_count'] if sig1 else None,
|
||||
'sig2_cosine': round(sig2['cosine'], 4) if sig2 and sig2['cosine'] else None,
|
||||
'sig2_cosine_verdict': cosine_verdict(sig2['cosine']) if sig2 else None,
|
||||
'sig2_acct_mean': round(sig2['acct_mean_sim'], 4) if sig2 and sig2['acct_mean_sim'] else None,
|
||||
'sig2_acct_ratio95': round(sig2['acct_ratio_95'], 4) if sig2 and sig2['acct_ratio_95'] else None,
|
||||
'sig2_acct_count': sig2['acct_sig_count'] if sig2 else None,
|
||||
'min_phash': min_phash,
|
||||
'max_phash': max_phash,
|
||||
'avg_phash': round(avg_phash, 2) if avg_phash is not None else None,
|
||||
'sig1_phash': sig1['phash'] if sig1 else None,
|
||||
'sig2_phash': sig2['phash'] if sig2 else None,
|
||||
'max_ssim': round(max_ssim, 4) if max_ssim is not None else None,
|
||||
'avg_ssim': round(avg_ssim, 4) if avg_ssim is not None else None,
|
||||
'dual_verdict': verdict,
|
||||
'dual_confidence': confidence,
|
||||
'max_cosine': round(max_cosine, 4) if max_cosine is not None else None,
|
||||
'pdf_min_phash': min_phash,
|
||||
'sig1_risk': sig1['risk_level'] if sig1 else None,
|
||||
'sig2_risk': sig2['risk_level'] if sig2 else None,
|
||||
}
|
||||
|
||||
for col_idx, key in enumerate(col_keys, 1):
|
||||
val = row_data.get(key)
|
||||
cell = ws.cell(row=row_idx, column=col_idx, value=val)
|
||||
cell.font = data_font
|
||||
cell.border = thin_border
|
||||
|
||||
# Color by group
|
||||
for group, (start, end) in group_ranges.items():
|
||||
if start <= col_idx - 1 < end:
|
||||
cell.fill = PatternFill(start_color=group_colors[group],
|
||||
end_color=group_colors[group],
|
||||
fill_type='solid')
|
||||
break
|
||||
|
||||
# Highlight Firm A rows
|
||||
if is_firm_a and col_idx == 7:
|
||||
cell.font = Font(name='Arial', size=9, bold=True, color='CC0000')
|
||||
|
||||
# Color verdicts
|
||||
if key == 'dual_verdict':
|
||||
colors = {
|
||||
'high_confidence_replication': 'FF0000',
|
||||
'moderate_confidence_replication': 'FF6600',
|
||||
'high_style_consistency': '009900',
|
||||
'uncertain': 'FF9900',
|
||||
'likely_genuine': '006600',
|
||||
}
|
||||
if val in colors:
|
||||
cell.font = Font(name='Arial', size=9, bold=True, color=colors[val])
|
||||
|
||||
row_idx += 1
|
||||
|
||||
# Auto-width
|
||||
for col_idx in range(1, len(col_keys) + 1):
|
||||
ws.column_dimensions[openpyxl.utils.get_column_letter(col_idx)].width = 15
|
||||
|
||||
# Freeze header
|
||||
ws.freeze_panes = 'A2'
|
||||
ws.auto_filter.ref = f"A1:{openpyxl.utils.get_column_letter(len(col_keys))}{row_idx-1}"
|
||||
|
||||
# === Summary Sheet ===
|
||||
ws2 = wb.create_sheet("Summary")
|
||||
ws2.cell(row=1, column=1, value="Dual-Method Classification Summary").font = Font(size=14, bold=True)
|
||||
ws2.cell(row=2, column=1, value=f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}")
|
||||
ws2.cell(row=3, column=1, value=f"Calibration: Firm A (dHash median=5, p95=15)")
|
||||
|
||||
ws2.cell(row=5, column=1, value="Verdict").font = Font(bold=True)
|
||||
ws2.cell(row=5, column=2, value="Count").font = Font(bold=True)
|
||||
ws2.cell(row=5, column=3, value="%").font = Font(bold=True)
|
||||
ws2.cell(row=5, column=4, value="Firm A").font = Font(bold=True)
|
||||
ws2.cell(row=5, column=5, value="Firm A %").font = Font(bold=True)
|
||||
|
||||
total = sum(verdict_counts.values())
|
||||
fa_total = sum(firm_a_counts.values())
|
||||
order = ['high_confidence_replication', 'moderate_confidence_replication',
|
||||
'high_style_consistency', 'uncertain', 'likely_genuine', 'unknown']
|
||||
|
||||
for i, v in enumerate(order):
|
||||
n = verdict_counts.get(v, 0)
|
||||
fa = firm_a_counts.get(v, 0)
|
||||
ws2.cell(row=6+i, column=1, value=v)
|
||||
ws2.cell(row=6+i, column=2, value=n)
|
||||
ws2.cell(row=6+i, column=3, value=f"{100*n/total:.1f}%" if total > 0 else "0%")
|
||||
ws2.cell(row=6+i, column=4, value=fa)
|
||||
ws2.cell(row=6+i, column=5, value=f"{100*fa/fa_total:.1f}%" if fa_total > 0 else "0%")
|
||||
|
||||
ws2.cell(row=6+len(order), column=1, value="Total").font = Font(bold=True)
|
||||
ws2.cell(row=6+len(order), column=2, value=total)
|
||||
ws2.cell(row=6+len(order), column=4, value=fa_total)
|
||||
|
||||
# Thresholds
|
||||
ws2.cell(row=15, column=1, value="Thresholds Used").font = Font(size=12, bold=True)
|
||||
ws2.cell(row=16, column=1, value="Cosine high threshold")
|
||||
ws2.cell(row=16, column=2, value=COSINE_HIGH)
|
||||
ws2.cell(row=17, column=1, value="KDE crossover")
|
||||
ws2.cell(row=17, column=2, value=KDE_CROSSOVER)
|
||||
ws2.cell(row=18, column=1, value="dHash high-confidence (Firm A median)")
|
||||
ws2.cell(row=18, column=2, value=PHASH_HIGH_CONF)
|
||||
ws2.cell(row=19, column=1, value="dHash moderate-confidence (Firm A p95)")
|
||||
ws2.cell(row=19, column=2, value=PHASH_MOD_CONF)
|
||||
|
||||
for col in range(1, 6):
|
||||
ws2.column_dimensions[openpyxl.utils.get_column_letter(col)].width = 30
|
||||
|
||||
# Save
|
||||
wb.save(str(OUTPUT_PATH))
|
||||
print(f"\nSaved: {OUTPUT_PATH}")
|
||||
print(f"Total PDFs: {total:,}")
|
||||
print(f"Firm A PDFs: {fa_total:,}")
|
||||
|
||||
# Print summary
|
||||
print(f"\n{'Verdict':<35} {'Count':>8} {'%':>7} | {'Firm A':>8} {'%':>7}")
|
||||
print("-" * 70)
|
||||
for v in order:
|
||||
n = verdict_counts.get(v, 0)
|
||||
fa = firm_a_counts.get(v, 0)
|
||||
if n > 0:
|
||||
print(f" {v:<33} {n:>8,} {100*n/total:>6.1f}% | {fa:>8,} {100*fa/fa_total:>6.1f}%"
|
||||
if fa_total > 0 else f" {v:<33} {n:>8,} {100*n/total:>6.1f}%")
|
||||
print("-" * 70)
|
||||
print(f" {'Total':<33} {total:>8,} | {fa_total:>8,}")
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("Generating Recalibrated PDF-Level Report")
|
||||
print(f"Calibration: Firm A ({FIRM_A})")
|
||||
print(f"Method: Dual (Cosine + dHash)")
|
||||
print("=" * 60)
|
||||
|
||||
pdf_data = load_all_data()
|
||||
build_report(pdf_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,16 @@
|
||||
# Abstract
|
||||
|
||||
<!-- 150-250 words -->
|
||||
|
||||
Regulations in many jurisdictions require Certified Public Accountants (CPAs) to attest to each audit report they certify, typically by affixing a signature or seal.
|
||||
However, the digitization of financial reporting makes it straightforward to reuse a scanned signature image across multiple reports, potentially undermining the intent of individualized attestation.
|
||||
Unlike signature forgery, where an impostor imitates another person's handwriting, signature replication involves a legitimate signer reusing a digital copy of their own genuine signature---a practice that is difficult to detect through manual inspection at scale.
|
||||
We present an end-to-end AI pipeline that automatically detects signature replication in financial audit reports.
|
||||
The pipeline employs a Vision-Language Model for signature page identification, YOLOv11 for signature region detection, and ResNet-50 for deep feature extraction, followed by a dual-method verification combining cosine similarity with difference hashing (dHash).
|
||||
This dual-method design distinguishes consistent handwriting style (high feature similarity but divergent perceptual hashes) from digital replication (convergent evidence across both methods), addressing an ambiguity that single-metric approaches cannot resolve.
|
||||
We apply this pipeline to 90,282 audit reports filed by publicly listed companies in Taiwan over a decade (2013--2023), analyzing 182,328 signatures from 758 CPAs.
|
||||
Using an accounting firm independently identified as employing digital replication as a calibration reference, we establish empirically grounded detection thresholds.
|
||||
Our analysis reveals that among documents with high feature-level similarity (cosine > 0.95), the structural verification layer stratifies them into distinct populations: 41% with converging replication evidence, 52% with partial structural similarity, and 7% with no structural corroboration despite near-identical features---demonstrating that single-metric approaches conflate style consistency with digital duplication.
|
||||
To our knowledge, this represents the largest-scale analysis of signature authenticity in financial audit documents to date.
|
||||
|
||||
<!-- Word count: ~220 -->
|
||||
@@ -0,0 +1,21 @@
|
||||
# VI. Conclusion and Future Work
|
||||
|
||||
## Conclusion
|
||||
|
||||
We have presented an end-to-end AI pipeline for detecting digitally replicated signatures in financial audit reports at scale.
|
||||
Applied to 90,282 audit reports from Taiwanese publicly listed companies spanning 2013--2023, our system extracted and analyzed 182,328 CPA signatures using a combination of VLM-based page identification, YOLO-based signature detection, deep feature extraction, and dual-method similarity verification.
|
||||
|
||||
Our key findings are threefold.
|
||||
First, we argued that signature replication detection is a distinct problem from signature forgery detection, requiring different analytical tools focused on intra-signer similarity distributions.
|
||||
Second, we showed that combining cosine similarity of deep features with difference hashing is essential for meaningful classification---among 71,656 documents with high feature-level similarity, the structural verification layer revealed that only 41% exhibit converging replication evidence, while 7% show no structural corroboration despite near-identical features, demonstrating that a single-metric approach conflates style consistency with digital duplication.
|
||||
Third, we introduced a calibration methodology using a known-replication reference group whose distributional characteristics (dHash median = 5, 95th percentile = 15) directly informed the classification thresholds, achieving 96.9% capture of the calibration group.
|
||||
|
||||
An ablation study comparing three feature extraction backbones (ResNet-50, VGG-16, EfficientNet-B0) confirmed that ResNet-50 offers the best balance of discriminative power, classification stability, and computational efficiency for this task.
|
||||
|
||||
## Future Work
|
||||
|
||||
Several directions merit further investigation.
|
||||
Domain-adapted feature extractors, trained or fine-tuned on signature-specific datasets, may improve discriminative performance beyond the transferred ImageNet features used in this study.
|
||||
Temporal analysis of signature similarity trends---tracking how individual CPAs' similarity profiles evolve over years---could reveal transitions between genuine signing and digital replication practices.
|
||||
The pipeline's applicability to other jurisdictions and document types (e.g., corporate filings in other countries, legal documents, medical records) warrants exploration.
|
||||
Finally, integration with regulatory monitoring systems and small-scale ground truth validation through expert review would strengthen the practical deployment potential of this approach.
|
||||
@@ -0,0 +1,57 @@
|
||||
# V. Discussion
|
||||
|
||||
## A. Replication Detection as a Distinct Problem
|
||||
|
||||
Our results highlight the importance of distinguishing signature replication detection from the well-studied signature forgery detection problem.
|
||||
In forgery detection, the challenge lies in modeling the variability of skilled forgers who produce plausible imitations of a target signature.
|
||||
In replication detection, the signer's identity is not in question; the challenge is distinguishing between legitimate intra-signer consistency (a CPA who signs similarly each time) and digital duplication (a CPA who reuses a scanned image).
|
||||
|
||||
This distinction has direct methodological consequences.
|
||||
Forgery detection systems optimize for inter-class discriminability---maximizing the gap between genuine and forged signatures.
|
||||
Replication detection, by contrast, requires sensitivity to the *upper tail* of the intra-class similarity distribution, where the boundary between consistent handwriting and digital copies becomes ambiguous.
|
||||
The dual-method framework we propose---combining semantic-level features (cosine similarity) with structural-level features (pHash)---addresses this ambiguity in a way that single-method approaches cannot.
|
||||
|
||||
## B. The Style-Replication Gap
|
||||
|
||||
Perhaps the most important empirical finding is the stratification that the dual-method framework reveals within the high-cosine population.
|
||||
Of 71,656 documents with cosine similarity exceeding 0.95, the dHash dimension partitions them into three distinct groups: 29,529 (41.2%) with high-confidence structural evidence of replication, 36,994 (51.7%) with moderate structural similarity, and 5,133 (7.2%) with no structural corroboration despite near-identical feature-level appearance.
|
||||
A cosine-only approach would treat all 71,656 identically; the dual-method framework separates them into populations with fundamentally different interpretations.
|
||||
|
||||
The 7.2% classified as "high style consistency" (cosine > 0.95 but dHash > 15) are particularly informative.
|
||||
Several plausible explanations may account for their high feature similarity without structural identity, though we lack direct evidence to confirm their relative contributions.
|
||||
Many accountants may develop highly consistent signing habits---using similar pen pressure, stroke order, and spatial layout---resulting in signatures that appear nearly identical at the feature level while retaining the microscopic variations inherent to handwriting.
|
||||
Some may use signing pads or templates that further constrain variability without constituting digital replication.
|
||||
The dual-method framework correctly identifies these as distinct from digitally replicated signatures by detecting the absence of structural-level convergence.
|
||||
|
||||
## C. Value of Known-Replication Calibration
|
||||
|
||||
The use of Firm A as a calibration reference addresses a fundamental challenge in document forensics: the scarcity of ground truth labels.
|
||||
In most forensic applications, establishing ground truth requires expensive manual verification or access to privileged information about document provenance.
|
||||
Our approach leverages domain knowledge---the established practice of digital signature replication at a specific firm---to create a naturally occurring positive control group within the dataset.
|
||||
|
||||
This calibration strategy has broader applicability beyond signature analysis.
|
||||
Any forensic detection system operating on real-world corpora can benefit from identifying subpopulations with known characteristics (positive or negative) to anchor threshold selection, particularly when the distributions of interest are non-normal and percentile-based thresholds are preferred over parametric alternatives.
|
||||
|
||||
## D. Limitations
|
||||
|
||||
Several limitations should be acknowledged.
|
||||
|
||||
First, comprehensive ground truth labels are not available for the full dataset.
|
||||
While Firm A provides a known-replication reference and the dual-method framework produces internally consistent results, the classification of non-Firm-A documents relies on statistical inference without independent per-document ground truth.
|
||||
A small-scale manual verification study (e.g., 100--200 documents sampled across classification categories) would strengthen confidence in the classification boundaries.
|
||||
|
||||
Second, the ResNet-50 feature extractor was used with pre-trained ImageNet weights without domain-specific fine-tuning.
|
||||
While our ablation study and prior literature [20]--[22] support the effectiveness of transferred ImageNet features for signature comparison, a signature-specific feature extractor trained on a curated dataset could improve discriminative performance.
|
||||
|
||||
Third, the red stamp removal preprocessing uses simple HSV color space filtering, which may introduce artifacts where handwritten strokes overlap with red seal impressions.
|
||||
In these overlap regions, blended pixels are replaced with white, potentially creating small gaps in the signature strokes that could reduce dHash similarity.
|
||||
This effect would make replication harder to detect (biasing toward false negatives) rather than easier, but the magnitude of the impact has not been quantified.
|
||||
|
||||
Fourth, scanning equipment, PDF generation software, and compression algorithms may have changed over the 10-year study period (2013--2023), potentially affecting similarity measurements.
|
||||
While cosine similarity and dHash are designed to be robust to such variations, longitudinal confounds cannot be entirely excluded.
|
||||
|
||||
Fifth, the classification framework treats all signatures from a CPA as belonging to a single class, not accounting for potential changes in signing practice over time (e.g., a CPA who signed genuinely in early years but adopted digital replication later).
|
||||
Temporal segmentation of signature similarity could reveal such transitions but is beyond the scope of this study.
|
||||
|
||||
Finally, the legal and regulatory implications of our findings depend on jurisdictional definitions of "signature" and "signing."
|
||||
Whether digital replication of a CPA's own genuine signature constitutes a violation of signing requirements is a legal question that our technical analysis can inform but cannot resolve.
|
||||
@@ -0,0 +1,10 @@
|
||||
# Impact Statement
|
||||
|
||||
<!-- 100-150 words. Non-specialist readable. No jargon. Specific, not vague. -->
|
||||
|
||||
Auditor signatures on financial reports are a key safeguard of corporate accountability.
|
||||
When Certified Public Accountants digitally copy and paste a single signature image across multiple reports instead of signing each one individually, this safeguard is undermined---yet detecting such practices through manual inspection is infeasible at the scale of modern financial markets.
|
||||
We developed an artificial intelligence system that automatically extracts and analyzes signatures from over 90,000 audit reports spanning over a decade of filings by publicly listed companies.
|
||||
By combining deep learning-based visual feature analysis with perceptual hashing, the system distinguishes genuinely handwritten signatures from digitally replicated ones.
|
||||
Our analysis reveals substantial variation in signature similarity patterns across accounting firms, with a calibration group independently identified as using digital replication exhibiting distinctly higher similarity scores.
|
||||
After further validation, this technology could serve as an automated screening tool to support financial regulators in monitoring signature authenticity at national scale.
|
||||
@@ -0,0 +1,81 @@
|
||||
# I. Introduction
|
||||
|
||||
<!-- Target: ~1.5 pages double-column IEEE format. Double-blind: no author/institution info. -->
|
||||
|
||||
Financial audit reports serve as a critical mechanism for ensuring corporate accountability and investor protection.
|
||||
In Taiwan, the Certified Public Accountant Act (會計師法 §4) and the Financial Supervisory Commission's attestation regulations (查核簽證核准準則 §6) require that certifying CPAs affix their signature or seal (簽名或蓋章) to each audit report [1].
|
||||
While the law permits either a handwritten signature or a seal, the CPA's attestation on each report is intended to represent a deliberate, individual act of professional endorsement for that specific audit engagement [2].
|
||||
|
||||
The digitization of financial reporting, however, has introduced a practice that challenges this intent.
|
||||
As audit reports are now routinely generated, transmitted, and archived as PDF documents, it is technically trivial for a CPA to digitally replicate a single scanned signature image and paste it across multiple reports.
|
||||
Although this practice may fall within the literal statutory requirement of "signature or seal," it raises substantive concerns about audit quality, as an identically reproduced signature applied across hundreds of reports may not represent meaningful attestation of individual professional judgment for each engagement.
|
||||
Unlike traditional signature forgery, where a third party attempts to imitate another person's handwriting, signature replication involves the legitimate signer reusing a digital copy of their own genuine signature.
|
||||
This practice, while potentially widespread, is virtually undetectable through manual inspection at scale: regulatory agencies overseeing thousands of publicly listed companies cannot feasibly examine each signature for evidence of digital duplication.
|
||||
|
||||
The distinction between signature *replication* and signature *forgery* is both conceptually and technically important.
|
||||
The extensive body of research on offline signature verification [3]--[8] has focused almost exclusively on forgery detection---determining whether a questioned signature was produced by its purported author or by an impostor.
|
||||
This framing presupposes that the central threat is identity fraud.
|
||||
In our context, identity is not in question; the CPA is indeed the legitimate signer.
|
||||
The question is whether the physical act of signing occurred for each individual report, or whether a single signing event was digitally propagated across many reports.
|
||||
This replication detection problem differs fundamentally from forgery detection: while it does not require modeling the variability of skilled forgers, it introduces the distinct challenge of separating legitimate intra-signer consistency from digital duplication, requiring an analytical framework focused on detecting abnormally high similarity across documents.
|
||||
|
||||
Despite the significance of this problem for audit quality and regulatory oversight, no prior work has specifically addressed the detection of same-signer digital replication in financial audit documents at scale.
|
||||
Woodruff et al. [9] developed an automated pipeline for signature analysis in corporate filings for anti-money laundering investigations, but their work focused on author clustering (grouping signatures by signer identity) rather than detecting reuse of digital copies.
|
||||
Copy-move forgery detection methods [10], [11] address duplicated regions within or across images, but are designed for natural images and do not account for the specific characteristics of scanned document signatures, where legitimate visual similarity between a signer's authentic signatures is expected and must be distinguished from digital duplication.
|
||||
Research on near-duplicate image detection using perceptual hashing combined with deep learning [12], [13] provides relevant methodological foundations, but has not been applied to document forensics or signature analysis.
|
||||
|
||||
In this paper, we present a fully automated, end-to-end pipeline for detecting digitally replicated CPA signatures in audit reports at scale.
|
||||
Our approach processes raw PDF documents through six sequential stages: (1) signature page identification using a Vision-Language Model (VLM), (2) signature region detection using a trained YOLOv11 object detector, (3) deep feature extraction via a pre-trained ResNet-50 convolutional neural network, (4) dual-method similarity verification combining cosine similarity of deep features with difference hash (dHash) distance, (5) distribution-free threshold calibration using a known-replication reference group, and (6) statistical classification with cross-method validation.
|
||||
|
||||
The dual-method verification is central to our contribution.
|
||||
Cosine similarity of deep feature embeddings captures high-level visual style similarity---it can identify signatures that share similar stroke patterns and spatial layouts---but cannot distinguish between a CPA who signs consistently and one who reuses a digital copy.
|
||||
Perceptual hashing (specifically, difference hashing), by contrast, encodes structural-level image gradients into compact binary fingerprints that are robust to scan noise but sensitive to substantive content differences.
|
||||
By requiring convergent evidence from both methods, we can differentiate *style consistency* (high cosine similarity but divergent pHash) from *digital replication* (high cosine similarity with convergent pHash), resolving an ambiguity that neither method can address alone.
|
||||
|
||||
A distinctive feature of our approach is the use of a known-replication calibration group for threshold validation.
|
||||
One major Big-4 accounting firm in Taiwan (hereafter "Firm A") is widely recognized within the audit profession as using digitally replicated signatures across its audit reports.
|
||||
This status was established through three independent lines of evidence prior to our analysis: (1) visual inspection of a random sample of Firm A's reports reveals pixel-identical signature images across different audit engagements and fiscal years; (2) the practice is acknowledged as common knowledge among audit practitioners in Taiwan; and (3) our subsequent quantitative analysis confirmed this independently, with 92.5% of Firm A's signatures exhibiting best-match cosine similarity exceeding 0.95, consistent with digital replication rather than handwriting.
|
||||
Importantly, Firm A's known-replication status was not derived from the thresholds we calibrate against it; the identification is based on domain knowledge and visual evidence that is independent of the statistical pipeline.
|
||||
This provides an empirical anchor for calibrating detection thresholds: any threshold that fails to classify the vast majority of Firm A's signatures as replicated is demonstrably too conservative, while Firm A's distributional characteristics establish the range of similarity values achievable through replication in real-world scanned documents.
|
||||
This calibration strategy---using a known-positive subpopulation to validate detection thresholds---addresses a persistent challenge in document forensics, where comprehensive ground truth labels are scarce.
|
||||
|
||||
We apply this pipeline to 90,282 audit reports filed by publicly listed companies in Taiwan between 2013 and 2023, extracting and analyzing 182,328 individual CPA signatures from 758 unique accountants.
|
||||
To our knowledge, this represents the largest-scale forensic analysis of signature authenticity in financial documents reported in the literature.
|
||||
|
||||
The contributions of this paper are summarized as follows:
|
||||
|
||||
1. **Problem formulation:** We formally define the signature replication detection problem as distinct from signature forgery detection, and argue that it requires a different analytical framework focused on intra-signer similarity distributions rather than genuine-versus-forged classification.
|
||||
|
||||
2. **End-to-end pipeline:** We present a pipeline that processes raw PDF audit reports through VLM-based page identification, YOLO-based signature detection, deep feature extraction, and dual-method similarity verification, with automated inference requiring no manual intervention after initial training and annotation.
|
||||
|
||||
3. **Dual-method verification:** We demonstrate that combining deep feature cosine similarity with perceptual hashing resolves the fundamental ambiguity between style consistency and digital replication, supported by an ablation study comparing three feature extraction backbones.
|
||||
|
||||
4. **Calibration methodology:** We introduce a threshold calibration approach using a known-replication reference group, providing empirical validation in a domain where labeled ground truth is scarce.
|
||||
|
||||
5. **Large-scale empirical analysis:** We report findings from the analysis of over 90,000 audit reports spanning a decade, providing the first large-scale empirical evidence on signature replication practices in financial reporting.
|
||||
|
||||
The remainder of this paper is organized as follows.
|
||||
Section II reviews related work on signature verification, document forensics, and perceptual hashing.
|
||||
Section III describes the proposed methodology.
|
||||
Section IV presents experimental results including the ablation study and calibration group analysis.
|
||||
Section V discusses the implications and limitations of our findings.
|
||||
Section VI concludes with directions for future work.
|
||||
|
||||
<!--
|
||||
REFERENCES used in Introduction:
|
||||
[1] Taiwan CPA Act §4 (會計師法第4條) + FSC Attestation Regulations §6 (查核簽證核准準則第6條)
|
||||
- CPA Act: https://law.moj.gov.tw/ENG/LawClass/LawAll.aspx?pcode=G0400067
|
||||
- FSC Regs: https://law.moj.gov.tw/LawClass/LawAll.aspx?pcode=G0400013
|
||||
[2] Yen, Chang & Chen 2013 — Does the signature of a CPA matter? (Res. Account. Regul., vol. 25, no. 2)
|
||||
[2] Bromley et al. 1993 — Siamese time delay neural network for signature verification (NeurIPS)
|
||||
[3] Dey et al. 2017 — SigNet: Siamese CNN for writer-independent offline SV (arXiv:1707.02131)
|
||||
[4] Hadjadj et al. 2020 — Single known sample offline SV (Applied Sciences)
|
||||
[5] Li et al. 2024 — TransOSV: Transformer for offline SV (Pattern Recognition)
|
||||
[6] Tehsin et al. 2024 — Triplet Siamese for digital documents (Mathematics)
|
||||
[7] Brimoh & Olisah 2024 — Consensus threshold for offline SV (arXiv:2401.03085)
|
||||
[8] Woodruff et al. 2021 — Fully automatic pipeline for document signature analysis / money laundering (arXiv:2107.14091)
|
||||
[9] Abramova & Böhme 2016 — Copy-move forgery detection in scanned text documents (Electronic Imaging)
|
||||
[10] Copy-move forgery detection survey — MTAP 2024
|
||||
[11] Jakhar & Borah 2025 — Near-duplicate detection using pHash + deep learning (Info. Processing & Management)
|
||||
[12] Pizzi et al. 2022 — SSCD: Self-supervised copy detection (CVPR)
|
||||
-->
|
||||
@@ -0,0 +1,146 @@
|
||||
# III. Methodology
|
||||
|
||||
## A. Pipeline Overview
|
||||
|
||||
We propose a six-stage pipeline for large-scale signature replication detection in scanned financial documents.
|
||||
Fig. 1 illustrates the overall architecture.
|
||||
The pipeline takes as input a corpus of PDF audit reports and produces, for each document, a classification of its CPA signatures into one of four categories---definite replication, likely replication, uncertain, or likely genuine---along with supporting evidence from multiple verification methods.
|
||||
|
||||
<!--
|
||||
[Figure 1: Pipeline Architecture - clean vector diagram]
|
||||
90,282 PDFs → VLM Pre-screening → 86,072 PDFs
|
||||
→ YOLOv11 Detection → 182,328 signatures
|
||||
→ ResNet-50 Features → 2048-dim embeddings
|
||||
→ Dual-Method Verification (Cosine + pHash)
|
||||
→ Threshold Calibration (Firm A) → Classification
|
||||
-->
|
||||
|
||||
## B. Data Collection
|
||||
|
||||
The dataset comprises 90,282 annual financial audit reports filed by publicly listed companies in Taiwan, covering fiscal years 2013 to 2023.
|
||||
The reports were collected from the Market Observation Post System (MOPS) operated by the Taiwan Stock Exchange Corporation, the official repository for mandatory corporate filings.
|
||||
An automated web scraping pipeline using Selenium WebDriver was developed to systematically download all audit reports for each listed company across the study period.
|
||||
Each report is a multi-page PDF document containing, among other content, the auditor's report page bearing the handwritten signatures of the certifying CPAs.
|
||||
|
||||
CPA names, affiliated accounting firms, and audit engagement tenure were obtained from a publicly available audit firm tenure registry encompassing 758 unique CPAs across 15 document types, with the majority (86.4%) being standard audit reports.
|
||||
Table I summarizes the dataset composition.
|
||||
|
||||
<!-- TABLE I: Dataset Summary
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| Total PDF documents | 90,282 |
|
||||
| Date range | 2013–2023 |
|
||||
| Documents with signatures | 86,072 (95.4%) |
|
||||
| Unique CPAs identified | 758 |
|
||||
| Accounting firms | >50 |
|
||||
-->
|
||||
|
||||
## C. Signature Page Identification
|
||||
|
||||
To identify which page of each multi-page PDF contains the auditor's signatures, we employed the Qwen2.5-VL vision-language model (32B parameters) [24] as an automated pre-screening mechanism.
|
||||
Each PDF page was rendered to JPEG at 180 DPI and submitted to the VLM with a structured prompt requesting a binary determination of whether the page contains a Chinese handwritten signature.
|
||||
The model was configured with temperature 0 for deterministic output.
|
||||
|
||||
The scanning range was restricted to the first quartile of each document's page count, reflecting the regulatory structure of Taiwanese audit reports in which the auditor's report page is consistently located in the first quarter of the document.
|
||||
Scanning terminated upon the first positive detection.
|
||||
This process identified 86,072 documents with signature pages; the remaining 4,198 documents (4.6%) were classified as having no signatures and excluded.
|
||||
An additional 12 corrupted PDFs were excluded, yielding a final set of 86,071 documents.
|
||||
|
||||
Cross-validation between the VLM and subsequent YOLO detection confirmed high agreement: YOLO successfully detected signature regions in 98.8% of VLM-positive documents, establishing an upper bound on the VLM false positive rate of 1.2%.
|
||||
|
||||
## D. Signature Detection
|
||||
|
||||
We adopted YOLOv11n (nano variant) [25] for signature region localization.
|
||||
A training set of 500 randomly sampled signature pages was annotated using a custom web-based interface following a two-stage protocol: primary annotation followed by independent review and correction.
|
||||
A region was labeled as "signature" if it contained any Chinese handwritten content attributable to a personal signature, regardless of overlap with official stamps.
|
||||
|
||||
The model was trained for 100 epochs on a 425/75 training/validation split with COCO pre-trained initialization, achieving strong detection performance (Table II).
|
||||
|
||||
<!-- TABLE II: YOLO Detection Performance
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Precision | 0.97–0.98 |
|
||||
| Recall | 0.95–0.98 |
|
||||
| mAP@0.50 | 0.98–0.99 |
|
||||
| mAP@0.50:0.95 | 0.85–0.90 |
|
||||
-->
|
||||
|
||||
Batch inference on all 86,071 documents extracted 182,328 signature images at a rate of 43.1 documents per second (8 workers).
|
||||
A red stamp removal step was applied to each cropped signature using HSV color space filtering, replacing detected red regions with white pixels to isolate the handwritten content.
|
||||
|
||||
Each signature was matched to its corresponding CPA using positional order (first or second signature on the page) against the official CPA registry, achieving a 92.6% match rate (168,755 of 182,328 signatures).
|
||||
|
||||
## E. Feature Extraction
|
||||
|
||||
Each extracted signature was encoded into a feature vector using a pre-trained ResNet-50 convolutional neural network [26] with ImageNet-1K V2 weights, used as a fixed feature extractor without fine-tuning.
|
||||
The final classification layer was removed, yielding the 2048-dimensional output of the global average pooling layer.
|
||||
|
||||
Preprocessing consisted of resizing to 224×224 pixels with aspect ratio preservation and white padding, followed by ImageNet channel normalization.
|
||||
All feature vectors were L2-normalized, ensuring that cosine similarity equals the dot product.
|
||||
|
||||
The choice of ResNet-50 without fine-tuning was motivated by three considerations: (1) the task is similarity comparison rather than classification, making general-purpose discriminative features sufficient; (2) ImageNet features have been shown to transfer effectively to document analysis tasks [20], [21]; and (3) avoiding domain-specific fine-tuning reduces the risk of overfitting to dataset-specific artifacts, though we note that a fine-tuned model could potentially improve discriminative performance (see Section V-D).
|
||||
|
||||
This design choice is validated by an ablation study (Section IV-F) comparing ResNet-50 against VGG-16 and EfficientNet-B0.
|
||||
|
||||
## F. Dual-Method Similarity Verification
|
||||
|
||||
For each signature, the most similar signature from the same CPA across all other documents was identified via cosine similarity of feature vectors.
|
||||
Two complementary measures were then computed against this closest match:
|
||||
|
||||
**Cosine similarity** captures high-level visual style similarity:
|
||||
|
||||
$$\text{sim}(\mathbf{f}_A, \mathbf{f}_B) = \mathbf{f}_A \cdot \mathbf{f}_B$$
|
||||
|
||||
where $\mathbf{f}_A$ and $\mathbf{f}_B$ are L2-normalized feature vectors.
|
||||
A high cosine similarity indicates that two signatures share similar visual characteristics---stroke patterns, spatial layout, and overall appearance---but does not distinguish between consistent handwriting style and digital duplication.
|
||||
|
||||
**Perceptual hash distance** captures structural-level similarity.
|
||||
Specifically, we employ a difference hash (dHash) [27], a perceptual hashing variant that encodes relative intensity gradients rather than absolute pixel values.
|
||||
Each signature image is resized to 9×8 pixels and converted to grayscale; horizontal gradient differences between adjacent columns produce a 64-bit binary fingerprint.
|
||||
The Hamming distance between two fingerprints quantifies perceptual dissimilarity: a distance of 0 indicates structurally identical images, while distances exceeding 15 indicate clearly different images.
|
||||
Unlike DCT-based perceptual hashes, dHash is computationally lightweight and particularly effective for detecting near-exact duplicates with minor scan-induced variations [19].
|
||||
|
||||
The complementarity of these two measures is the key to resolving the style-versus-replication ambiguity:
|
||||
|
||||
- High cosine similarity + low pHash distance → converging evidence of digital replication
|
||||
- High cosine similarity + high pHash distance → consistent handwriting style, not replication
|
||||
|
||||
This dual-method design was preferred over SSIM (Structural Similarity Index), which proved unreliable for scanned documents: a known-replication firm exhibited a mean SSIM of only 0.70 due to scan-induced pixel-level variations, despite near-identical visual content.
|
||||
Cosine similarity and pHash are both robust to the noise introduced by the print-scan cycle, making them more suitable for this application.
|
||||
|
||||
## G. Threshold Selection and Calibration
|
||||
|
||||
### Distribution-Free Thresholds
|
||||
|
||||
To establish classification thresholds, we computed cosine similarity distributions for two groups:
|
||||
|
||||
- **Intra-class** (same CPA): all pairwise similarities among signatures attributed to the same CPA (41.3M pairs from 728 CPAs with ≥3 signatures)
|
||||
- **Inter-class** (different CPAs): 500,000 randomly sampled cross-CPA pairs
|
||||
|
||||
Shapiro-Wilk tests rejected normality for both distributions ($p < 0.001$), motivating the use of distribution-free, percentile-based thresholds rather than parametric ($\mu \pm k\sigma$) approaches.
|
||||
|
||||
The primary threshold was derived via Kernel Density Estimation (KDE) [28]: the crossover point where the intra-class and inter-class density functions intersect.
|
||||
Under equal prior probabilities and symmetric misclassification costs, this crossover approximates the optimal decision boundary between the two classes.
|
||||
|
||||
### Known-Replication Calibration
|
||||
|
||||
A distinctive aspect of our methodology is the use of Firm A---a major Big-4 accounting firm whose use of digitally replicated signatures was established through independent visual inspection and domain knowledge prior to threshold calibration (see Section I)---as a calibration reference.
|
||||
Firm A's signature similarity distribution provides two critical anchors:
|
||||
|
||||
1. **Lower bound validation:** Any detection threshold must classify the vast majority of Firm A's signatures as replicated; a threshold that fails this criterion is too conservative.
|
||||
2. **Replication floor estimation:** Firm A's 1st percentile of cosine similarity establishes how low similarity scores can fall even among confirmed replicated signatures, due to scan noise and PDF compression artifacts. This lower bound on replication similarity informs the minimum sensitivity required of any detection threshold.
|
||||
|
||||
This calibration strategy addresses a persistent challenge in document forensics where comprehensive ground truth labels are unavailable.
|
||||
|
||||
## H. Classification
|
||||
|
||||
The final per-document classification uses exclusively the dual-method framework (cosine similarity + dHash distance), with thresholds calibrated against Firm A's known-replication distribution.
|
||||
Firm A's dHash distances show a median of 5 and a 95th percentile of 15; we use these empirical values to define confidence tiers:
|
||||
|
||||
1. **High-confidence replication:** Cosine similarity > 0.95 AND dHash distance ≤ 5. Both feature-level and structural-level evidence converge, consistent with Firm A's median behavior.
|
||||
2. **Moderate-confidence replication:** Cosine similarity > 0.95 AND dHash distance 6--15. Feature-level evidence is strong; structural similarity is present but below the Firm A median, possibly due to scan variations.
|
||||
3. **High style consistency:** Cosine similarity > 0.95 AND dHash distance > 15. High feature-level similarity without structural corroboration---consistent with a CPA who signs very consistently but not digitally.
|
||||
4. **Uncertain:** Cosine similarity between the KDE crossover (0.837) and 0.95, without sufficient evidence for classification in either direction.
|
||||
5. **Likely genuine:** Cosine similarity below the KDE crossover threshold.
|
||||
|
||||
The dHash thresholds (≤ 5 and ≤ 15) are directly derived from Firm A's calibration distribution rather than set ad hoc, ensuring that the classification boundaries are empirically grounded.
|
||||
@@ -0,0 +1,282 @@
|
||||
# Paper A: IEEE TAI Outline (Draft)
|
||||
|
||||
> **Target:** IEEE Transactions on Artificial Intelligence (Regular Paper, ≤10 pages)
|
||||
> **Review:** Double-blind
|
||||
> **Status:** Outline — 待討論確認後再展開各 section
|
||||
|
||||
---
|
||||
|
||||
## Title (候選)
|
||||
|
||||
1. "Automated Detection of Digitally Replicated Signatures in Large-Scale Financial Audit Reports"
|
||||
2. "Are They Really Signing? A Deep Learning Pipeline for Detecting Signature Replication in 90K Audit Reports"
|
||||
3. "Large-Scale Forensic Analysis of CPA Signature Authenticity Using Deep Features and Perceptual Hashing"
|
||||
|
||||
> 建議用 1 或 3,學術正式感較強。2 比較 catchy 但 TAI 可能偏保守。
|
||||
|
||||
---
|
||||
|
||||
## Abstract (150-250 words)
|
||||
|
||||
**要素:**
|
||||
- Problem: 審計報告要求親簽,但實務上可能用數位複製(套印)
|
||||
- Gap: 目前無大規模自動化偵測方法
|
||||
- Method: VLM pre-screening → YOLO detection → ResNet-50 feature extraction → Cosine + pHash verification
|
||||
- Scale: 90,282 PDFs, 182,328 signatures, 758 CPAs, 2013-2023
|
||||
- Key finding: 以已知套印事務所作為校準,建立 distribution-free threshold
|
||||
- Contribution: first large-scale study, end-to-end pipeline, empirical threshold validation
|
||||
|
||||
---
|
||||
|
||||
## Impact Statement (100-150 words)
|
||||
|
||||
**方向(非專業人士看得懂):**
|
||||
|
||||
審計報告上的會計師簽名是財務報告可信度的重要保障。若簽名並非每次親簽,而是數位複製貼上,將影響審計品質與投資人保護。本研究開發了一套自動化 AI pipeline,分析了超過 9 萬份、橫跨 10 年的台灣上市公司審計報告,從中提取並比對 18 萬個簽名。透過深度學習特徵與感知雜湊的交叉驗證,我們能區分「風格一致的親簽」與「數位複製的套印」。研究發現部分會計事務所的簽名呈現統計上不可能由手寫產生的一致性。本方法可直接應用於金融監理機構的自動化稽核系統。
|
||||
|
||||
> 注意:投稿時寫英文版,這裡先用中文定調內容方向。
|
||||
|
||||
---
|
||||
|
||||
## I. Introduction (~1.5 pages)
|
||||
|
||||
### 段落結構:
|
||||
|
||||
**P1 — Problem context**
|
||||
- 審計報告簽名的法律意義(台灣法規要求親簽)
|
||||
- 數位化後的漏洞:PDF 報告中的簽名容易被複製貼上
|
||||
- 監理機構無法逐份人工檢查
|
||||
|
||||
**P2 — Why this matters (motivation)**
|
||||
- 審計品質 → 投資人保護 → 資本市場信任
|
||||
- 簽名真偽是審計獨立性的 proxy indicator
|
||||
- [REF: 審計品質相關文獻]
|
||||
|
||||
**P3 — What exists (gap)**
|
||||
- 現有簽名驗證研究集中在 forgery detection(偽造偵測)
|
||||
- 我們的問題不同:不是問「是不是本人簽的」,而是「是不是每次都親簽」
|
||||
- Replication detection ≠ Forgery detection
|
||||
- 無大規模、真實財報的相關研究
|
||||
|
||||
**P4 — What we do (contribution)**
|
||||
- End-to-end pipeline: VLM → YOLO → ResNet → Cosine + pHash
|
||||
- Scale: 90K+ documents, 180K+ signatures, 10 years
|
||||
- Distribution-free threshold with known-replication calibration group
|
||||
- First study applying AI to audit signature authenticity at this scale
|
||||
|
||||
**P5 — Paper organization**
|
||||
- 一句話帶過各 section
|
||||
|
||||
### Contribution list (明確列出):
|
||||
1. **Pipeline**: 完整的端到端自動化簽名真偽偵測系統
|
||||
2. **Scale**: 迄今最大規模的審計報告簽名分析(90K PDFs, 180K signatures)
|
||||
3. **Methodology**: 結合深度特徵(Cosine)與感知雜湊(pHash)的雙層驗證,解決「風格一致 vs 數位複製」的區分問題
|
||||
4. **Calibration**: 利用已知套印事務所作為 ground truth 校準,建立 distribution-free 閾值
|
||||
|
||||
---
|
||||
|
||||
## II. Related Work (~1 page)
|
||||
|
||||
### A. Offline Signature Verification
|
||||
- Siamese networks: Bromley et al. 1993, Dey et al. 2017 (SigNet)
|
||||
- CNN-based: Hadjadj et al. 2020 (single known sample)
|
||||
- Triplet Siamese: Mathematics 2024
|
||||
- Consensus threshold: arXiv:2401.03085
|
||||
- **定位差異**: 這些都是 forgery detection(驗真偽),我們是 replication detection(驗套印)
|
||||
|
||||
### B. Document Forensics & Copy-Move Detection
|
||||
- Copy-move forgery detection survey (MTAP 2024)
|
||||
- Image forensics in scanned documents
|
||||
- **定位差異**: 通常針對圖片竄改,非針對簽名重複使用
|
||||
|
||||
### C. VLM & Object Detection in Document Analysis
|
||||
- Vision-Language Models for document understanding
|
||||
- YOLO variants in document element detection
|
||||
- **定位差異**: 我們用 VLM + YOLO 作為 pipeline 前端,非核心貢獻但需說明
|
||||
|
||||
### D. Perceptual Hashing for Image Comparison
|
||||
- pHash in near-duplicate detection
|
||||
- 與 deep features 的互補性
|
||||
|
||||
---
|
||||
|
||||
## III. Methodology (~3 pages)
|
||||
|
||||
> 從 methodology_draft_v1.md 精簡,聚焦在核心方法,省略實作細節
|
||||
|
||||
### A. Pipeline Overview
|
||||
- Figure 1: 全流程圖(精簡版)
|
||||
- 各階段一句話描述
|
||||
|
||||
### B. Data Collection
|
||||
- 90,282 PDFs from TWSE MOPS, 2013-2023
|
||||
- Table I: Dataset summary(精簡版)
|
||||
- CPA registry matching
|
||||
|
||||
### C. Signature Detection
|
||||
- VLM pre-screening (Qwen2.5-VL): hit-and-stop strategy, 86,072 docs
|
||||
- YOLOv11n: 500 annotated → mAP50=0.99 → 182,328 signatures
|
||||
- Red stamp removal post-processing
|
||||
- **省略**: VLM prompt 全文、annotation protocol 細節、validation 細節 → 放 footnote 或略提
|
||||
|
||||
### D. Feature Extraction
|
||||
- ResNet-50 (ImageNet1K_V2), no fine-tuning, 2048-dim, L2 normalized
|
||||
- Why no fine-tuning: similarity task, not classification; generalizability
|
||||
- CPA matching: 92.6% success rate
|
||||
|
||||
### E. Dual-Method Verification (核心)
|
||||
- **Cosine similarity**: captures style-level similarity (high-level)
|
||||
- **pHash distance**: captures perceptual-level similarity (structural)
|
||||
- 為什麼這個組合:
|
||||
- Cosine 高 + pHash 低距離 = 強證據(數位複製)
|
||||
- Cosine 高 + pHash 高距離 = 風格一致但非複製(親簽)
|
||||
- 互補性解決了單一指標的歧義
|
||||
- **SSIM 為何排除**: 掃描雜訊敏感,已知套印的 SSIM 僅 0.70(footnote 帶過)
|
||||
|
||||
### F. Threshold Selection
|
||||
- Distribution-free approach(非常態 → 百分位數)
|
||||
- KDE crossover = 0.838
|
||||
- Intra/Inter class distributions(Table + Figure)
|
||||
- **Calibration via known-replication firm**(key contribution):
|
||||
- Deloitte Taiwan: domain knowledge 確認全部套印
|
||||
- Cosine mean = 0.980, 1st percentile = 0.908
|
||||
- pHash ≤5: 58.75%
|
||||
- 用作閾值校準的 anchor point
|
||||
|
||||
> 注意雙盲:不能寫 "Deloitte",改用 "Firm A (a Big-4 firm known to use digital replication)"
|
||||
|
||||
---
|
||||
|
||||
## IV. Experiments and Results (~2.5 pages)
|
||||
|
||||
### A. Experimental Setup
|
||||
- Hardware/software environment
|
||||
- Evaluation metrics 定義
|
||||
|
||||
### B. Signature Detection Performance
|
||||
- Table: YOLO metrics (Precision, Recall, mAP)
|
||||
- VLM-YOLO agreement rate: 98.8%
|
||||
|
||||
### C. Distribution Analysis
|
||||
- Figure: Intra vs Inter cosine similarity distributions
|
||||
- Figure: pHash distance distributions (intra vs inter)
|
||||
- Table: Distributional statistics
|
||||
- Normality tests → justify percentile-based thresholds
|
||||
|
||||
### D. Calibration Group Analysis (重點)
|
||||
- "Firm A" (已知套印) 的 Cosine/pHash 分布
|
||||
- vs 非四大的分布比較
|
||||
- KDE crossover (Firm A vs non-Big-4) = 0.969
|
||||
- Figure: Firm A distribution vs overall distribution
|
||||
- **這是最有說服力的 section**
|
||||
|
||||
### E. Classification Results
|
||||
- Table: Overall verdict distribution (definite_copy / likely_copy / uncertain / genuine)
|
||||
- Cross-method agreement analysis
|
||||
- **Key finding**: Cosine-high ≠ pixel-identical
|
||||
- 71,656 PDFs with Cosine > 0.95
|
||||
- 只有 3.4% 同時 SSIM > 0.95
|
||||
- 只有 0.4% pixel-identical
|
||||
|
||||
### F. Ablation Study (新增,增強 AI 貢獻)
|
||||
- **Feature backbone comparison**: ResNet-50 vs VGG-16 vs EfficientNet-B0
|
||||
- 比較 intra/inter class separation (Cohen's d)
|
||||
- 計算量 vs 判別力 trade-off
|
||||
- **Single method vs dual method**:
|
||||
- Cosine only vs pHash only vs Cosine + pHash
|
||||
- 用 Firm A 作為 positive set,計算 precision/recall
|
||||
- **Threshold sensitivity**:
|
||||
- 不同 cosine threshold 下的分類結果變化
|
||||
- ROC-like curve(以 Firm A 為 positive)
|
||||
|
||||
---
|
||||
|
||||
## V. Discussion (~1 page)
|
||||
|
||||
### A. Replication vs Forgery: A Distinction That Matters
|
||||
- 我們的問題本質上更簡單也更直接
|
||||
- 不需要考慮仿冒者的存在
|
||||
- Physical impossibility argument: 同一人每次親簽不可能像素相同
|
||||
|
||||
### B. The Gap Between Style Similarity and Digital Replication
|
||||
- 81.4% likely_copy (Cosine) vs 2.8% definite_copy (pixel-level)
|
||||
- 解讀:多數 CPA 簽名風格高度一致,但非數位複製
|
||||
- 可能原因:使用簽名板、固定簽署環境
|
||||
- **Policy implication**: 僅靠 Cosine 會嚴重高估套印率
|
||||
|
||||
### C. The Value of a Known-Replication Calibration Group
|
||||
- 有 ground truth anchor 對閾值校準的重要性
|
||||
- 可推廣到其他 document forensics 問題
|
||||
|
||||
### D. Limitations
|
||||
- 精簡版 limitations(3-4 點)
|
||||
- No labeled ground truth for full dataset
|
||||
- Feature extractor not fine-tuned
|
||||
- Scan quality variation over 10 years
|
||||
- Regulatory/legal definition of "replication" varies
|
||||
|
||||
---
|
||||
|
||||
## VI. Conclusion and Future Work (~0.5 page)
|
||||
|
||||
### Conclusion
|
||||
- 總結 pipeline、規模、key findings
|
||||
- 強調 dual-method 的必要性(Cosine alone 不夠)
|
||||
- Calibration group 的方法論貢獻
|
||||
|
||||
### Future Work
|
||||
- Fine-tuned signature-specific feature extractor
|
||||
- Temporal analysis (year-over-year trends)
|
||||
- Cross-country generalization
|
||||
- Integration with regulatory monitoring systems
|
||||
- Small-scale ground truth validation (100-200 PDFs)
|
||||
|
||||
---
|
||||
|
||||
## Figures & Tables Budget (10 頁限制下的分配)
|
||||
|
||||
| # | Type | Content | Est. space |
|
||||
|---|------|---------|------------|
|
||||
| Fig 1 | Pipeline | 全流程圖 | 1/3 page |
|
||||
| Fig 2 | Distribution | Intra vs Inter cosine KDE | 1/3 page |
|
||||
| Fig 3 | Distribution | pHash distance intra vs inter | 1/4 page |
|
||||
| Fig 4 | Calibration | Firm A vs overall distribution | 1/3 page |
|
||||
| Fig 5 | Ablation | Backbone comparison / threshold sensitivity | 1/3 page |
|
||||
| Table I | Data | Dataset summary | 1/4 page |
|
||||
| Table II | Detection | YOLO performance | 1/6 page |
|
||||
| Table III | Statistics | Distribution stats + tests | 1/4 page |
|
||||
| Table IV | Results | Classification verdicts | 1/4 page |
|
||||
| Table V | Ablation | Feature backbone comparison | 1/4 page |
|
||||
|
||||
**Total figures/tables**: ~3 pages → Text: ~7 pages → Feasible for 10-page limit
|
||||
|
||||
---
|
||||
|
||||
## 待辦 Checklist
|
||||
|
||||
### 需要新增的分析(Ablation Study)
|
||||
- [ ] ResNet-50 vs VGG-16 vs EfficientNet-B0 feature comparison
|
||||
- [ ] Single method vs dual method precision/recall (with Firm A as positive set)
|
||||
- [ ] Threshold sensitivity curve
|
||||
|
||||
### 需要整理的圖表
|
||||
- [ ] Fig 1: Pipeline diagram (clean vector version)
|
||||
- [ ] Fig 4: Firm A calibration distribution (新圖)
|
||||
- [ ] Fig 5: Ablation results (新圖)
|
||||
- [ ] 所有圖表英文化
|
||||
|
||||
### 寫作
|
||||
- [ ] Impact Statement (英文版)
|
||||
- [ ] Abstract (英文版)
|
||||
- [ ] Introduction
|
||||
- [ ] Related Work — 需要補充文獻搜索
|
||||
- [ ] Methodology (從 v1 精簡)
|
||||
- [ ] Results (新寫)
|
||||
- [ ] Discussion (新寫)
|
||||
- [ ] Conclusion
|
||||
|
||||
### 投稿準備
|
||||
- [ ] 匿名化(Deloitte → Firm A,移除所有可辨識資訊)
|
||||
- [ ] IEEE LaTeX template
|
||||
- [ ] Reference 格式化(IEEE numbered style)
|
||||
- [ ] 相似度指數 < 20%
|
||||
@@ -0,0 +1,77 @@
|
||||
# References
|
||||
|
||||
<!-- IEEE numbered style, sequential by first appearance in text -->
|
||||
|
||||
[1] Taiwan Certified Public Accountant Act (會計師法), Art. 4; FSC Attestation Regulations (查核簽證核准準則), Art. 6. Available: https://law.moj.gov.tw/ENG/LawClass/LawAll.aspx?pcode=G0400067
|
||||
|
||||
[2] S.-H. Yen, Y.-S. Chang, and H.-L. Chen, "Does the signature of a CPA matter? Evidence from Taiwan," *Res. Account. Regul.*, vol. 25, no. 2, pp. 230–235, 2013.
|
||||
|
||||
[3] J. Bromley et al., "Signature verification using a Siamese time delay neural network," in *Proc. NeurIPS*, 1993.
|
||||
|
||||
[4] S. Dey et al., "SigNet: Convolutional Siamese network for writer independent offline signature verification," arXiv:1707.02131, 2017.
|
||||
|
||||
[5] I. Hadjadj et al., "An offline signature verification method based on a single known sample and an explainable deep learning approach," *Appl. Sci.*, vol. 10, no. 11, p. 3716, 2020.
|
||||
|
||||
[6] H. Li et al., "TransOSV: Offline signature verification with transformers," *Pattern Recognit.*, vol. 145, p. 109882, 2024.
|
||||
|
||||
[7] S. Tehsin et al., "Enhancing signature verification using triplet Siamese similarity networks in digital documents," *Mathematics*, vol. 12, no. 17, p. 2757, 2024.
|
||||
|
||||
[8] P. Brimoh and C. C. Olisah, "Consensus-threshold criterion for offline signature verification using CNN learned representations," arXiv:2401.03085, 2024.
|
||||
|
||||
[9] N. Woodruff et al., "Fully-automatic pipeline for document signature analysis to detect money laundering activities," arXiv:2107.14091, 2021.
|
||||
|
||||
[10] S. Abramova and R. Bohme, "Detecting copy-move forgeries in scanned text documents," in *Proc. Electronic Imaging*, 2016.
|
||||
|
||||
[11] Y. Li et al., "Copy-move forgery detection in digital image forensics: A survey," *Multimedia Tools Appl.*, 2024.
|
||||
|
||||
[12] Y. Jakhar and M. D. Borah, "Effective near-duplicate image detection using perceptual hashing and deep learning," *Inf. Process. Manage.*, p. 104086, 2025.
|
||||
|
||||
[13] E. Pizzi et al., "A self-supervised descriptor for image copy detection," in *Proc. CVPR*, 2022.
|
||||
|
||||
[14] L. G. Hafemann, R. Sabourin, and L. S. Oliveira, "Learning features for offline handwritten signature verification using deep convolutional neural networks," *Pattern Recognit.*, vol. 70, pp. 163–176, 2017.
|
||||
|
||||
[15] E. N. Zois, D. Tsourounis, and D. Kalivas, "Similarity distance learning on SPD manifold for writer independent offline signature verification," *IEEE Trans. Inf. Forensics Security*, vol. 19, pp. 1342–1356, 2024.
|
||||
|
||||
[16] L. G. Hafemann, R. Sabourin, and L. S. Oliveira, "Meta-learning for fast classifier adaptation to new users of signature verification systems," *IEEE Trans. Inf. Forensics Security*, vol. 15, pp. 1735–1745, 2019.
|
||||
|
||||
[17] H. Farid, "Image forgery detection," *IEEE Signal Process. Mag.*, vol. 26, no. 2, pp. 16–25, 2009.
|
||||
|
||||
[18] F. Z. Mehrjardi, A. M. Latif, M. S. Zarchi, and R. Sheikhpour, "A survey on deep learning-based image forgery detection," *Pattern Recognit.*, vol. 144, art. no. 109778, 2023.
|
||||
|
||||
[19] J. Luo et al., "A survey of perceptual hashing for multimedia," *ACM Trans. Multimedia Comput. Commun. Appl.*, vol. 21, no. 7, 2025.
|
||||
|
||||
[20] D. Engin et al., "Offline signature verification on real-world documents," in *Proc. CVPRW*, 2020.
|
||||
|
||||
[21] D. Tsourounis et al., "From text to signatures: Knowledge transfer for efficient deep feature learning in offline signature verification," *Expert Syst. Appl.*, 2022.
|
||||
|
||||
[22] B. Chamakh and O. Bounouh, "A unified ResNet18-based approach for offline signature classification and verification," *Procedia Comput. Sci.*, vol. 270, 2025.
|
||||
|
||||
[23] A. Babenko, A. Slesarev, A. Chigorin, and V. Lempitsky, "Neural codes for image retrieval," in *Proc. ECCV*, 2014, pp. 584–599.
|
||||
|
||||
[24] Qwen2.5-VL Technical Report, Alibaba Group, 2025.
|
||||
|
||||
[25] Ultralytics, "YOLOv11 documentation," 2024. [Online]. Available: https://docs.ultralytics.com/
|
||||
|
||||
[26] K. He, X. Zhang, S. Ren, and J. Sun, "Deep residual learning for image recognition," in *Proc. CVPR*, 2016.
|
||||
|
||||
[27] N. Krawetz, "Kind of like that," The Hacker Factor Blog, 2013. [Online]. Available: https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
||||
|
||||
[28] B. W. Silverman, *Density Estimation for Statistics and Data Analysis*. London: Chapman & Hall, 1986.
|
||||
|
||||
[29] J. Cohen, *Statistical Power Analysis for the Behavioral Sciences*, 2nd ed. Hillsdale, NJ: Lawrence Erlbaum, 1988.
|
||||
|
||||
[30] Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image quality assessment: From error visibility to structural similarity," *IEEE Trans. Image Process.*, vol. 13, no. 4, pp. 600–612, 2004.
|
||||
|
||||
[31] J. V. Carcello and C. Li, "Costs and benefits of requiring an engagement partner signature: Recent experience in the United Kingdom," *The Accounting Review*, vol. 88, no. 5, pp. 1511–1546, 2013.
|
||||
|
||||
[32] A. D. Blay, M. Notbohm, C. Schelleman, and A. Valencia, "Audit quality effects of an individual audit engagement partner signature mandate," *Int. J. Auditing*, vol. 18, no. 3, pp. 172–192, 2014.
|
||||
|
||||
[33] W. Chi, H. Huang, Y. Liao, and H. Xie, "Mandatory audit partner rotation, audit quality, and market perception: Evidence from Taiwan," *Contemp. Account. Res.*, vol. 26, no. 2, pp. 359–391, 2009.
|
||||
|
||||
[34] J. Redmon, S. Divvala, R. Girshick, and A. Farhadi, "You only look once: Unified, real-time object detection," in *Proc. CVPR*, 2016, pp. 779–788.
|
||||
|
||||
[35] J. Zhang, J. Huang, S. Jin, and S. Lu, "Vision-language models for vision tasks: A survey," *IEEE Trans. Pattern Anal. Mach. Intell.*, vol. 46, no. 8, pp. 5625–5644, 2024.
|
||||
|
||||
[36] H. B. Mann and D. R. Whitney, "On a test of whether one of two random variables is stochastically larger than the other," *Ann. Math. Statist.*, vol. 18, no. 1, pp. 50–60, 1947.
|
||||
|
||||
<!-- Total: 36 references -->
|
||||
@@ -0,0 +1,77 @@
|
||||
# II. Related Work
|
||||
|
||||
## A. Offline Signature Verification
|
||||
|
||||
Offline signature verification---determining whether a static signature image is genuine or forged---has been studied extensively using deep learning.
|
||||
Bromley et al. [3] introduced the Siamese neural network architecture for signature verification, establishing the pairwise comparison paradigm that remains dominant.
|
||||
Hafemann et al. [20] demonstrated that deep CNN features learned from signature images provide strong discriminative representations for writer-independent verification, establishing the foundational baseline for subsequent work.
|
||||
Dey et al. [4] proposed SigNet, a convolutional Siamese network for writer-independent offline verification, extending this paradigm to generalize across signers without per-writer retraining.
|
||||
Hadjadj et al. [5] addressed the practical constraint of limited reference samples, achieving competitive verification accuracy using only a single known genuine signature per writer.
|
||||
More recently, Li et al. [6] introduced TransOSV, the first Vision Transformer-based approach, achieving state-of-the-art results.
|
||||
Tehsin et al. [7] evaluated distance metrics for triplet Siamese networks, finding that Manhattan distance outperformed cosine and Euclidean alternatives.
|
||||
Zois et al. [21] proposed similarity distance learning on SPD manifolds for writer-independent verification, achieving robust cross-dataset transfer---a property relevant to our setting where CPA signatures span diverse writing styles.
|
||||
Hafemann et al. [16] further addressed the practical challenge of adapting to new users through meta-learning, reducing the enrollment burden for signature verification systems.
|
||||
|
||||
A common thread in this literature is the assumption that the primary threat is *identity fraud*: a forger attempting to produce a convincing imitation of another person's signature.
|
||||
Our work addresses a fundamentally different problem---detecting whether the *legitimate signer* reused a digital copy of their own signature---which requires analyzing intra-signer similarity distributions rather than modeling inter-signer discriminability.
|
||||
|
||||
Brimoh and Olisah [8] proposed a consensus-threshold approach that derives classification boundaries from known genuine reference pairs, the methodology most closely related to our calibration strategy.
|
||||
However, their method operates on standard verification benchmarks with laboratory-collected signatures, whereas our approach applies threshold calibration using a known-replication subpopulation identified through domain expertise in real-world regulatory documents.
|
||||
|
||||
## B. Document Forensics and Copy Detection
|
||||
|
||||
Image forensics encompasses a broad range of techniques for detecting manipulated visual content [17], with recent surveys highlighting the growing role of deep learning in forgery detection [18].
|
||||
Copy-move forgery detection (CMFD) identifies duplicated regions within or across images, typically targeting manipulated photographs [11].
|
||||
Abramova and Bohme [10] adapted block-based CMFD to scanned text documents, noting that standard methods perform poorly in this domain because legitimate character repetitions produce high similarity scores that confound duplicate detection.
|
||||
|
||||
Woodruff et al. [9] developed the work most closely related to ours: a fully automated pipeline for extracting and analyzing signatures from corporate filings in the context of anti-money laundering investigations.
|
||||
Their system uses connected component analysis for signature detection, GANs for noise removal, and Siamese networks for author clustering.
|
||||
While their pipeline shares our goal of large-scale automated signature analysis on real regulatory documents, their objective---grouping signatures by authorship---differs fundamentally from ours, which is detecting digital replication within a single author's signatures across documents.
|
||||
|
||||
In the domain of image copy detection, Pizzi et al. [13] proposed SSCD, a self-supervised descriptor using ResNet-50 with contrastive learning for large-scale copy detection on natural images.
|
||||
Their work demonstrates that pre-trained CNN features with cosine similarity provide a strong baseline for identifying near-duplicate images, a finding that supports our feature extraction approach.
|
||||
|
||||
## C. Perceptual Hashing
|
||||
|
||||
Perceptual hashing algorithms generate compact fingerprints that are robust to minor image transformations while remaining sensitive to substantive content changes [19].
|
||||
Unlike cryptographic hashes, which change entirely with any pixel modification, perceptual hashes produce similar outputs for visually similar inputs, making them suitable for near-duplicate detection in scanned documents where minor variations arise from the scanning process.
|
||||
|
||||
Jakhar and Borah [12] demonstrated that combining perceptual hashing with deep learning features significantly outperforms either approach alone for near-duplicate image detection, achieving AUROC of 0.99 on standard benchmarks.
|
||||
Their two-stage architecture---pHash for fast structural comparison followed by deep features for semantic verification---provides methodological precedent for our dual-method approach, though applied to natural images rather than document signatures.
|
||||
|
||||
Our work differs from prior perceptual hashing studies in its application context and in the specific challenge it addresses: distinguishing legitimate high visual consistency (a careful signer producing similar-looking signatures) from digital duplication (identical pixel content arising from copy-paste operations) in scanned financial documents.
|
||||
|
||||
## D. Deep Feature Extraction for Signature Analysis
|
||||
|
||||
Several studies have explored pre-trained CNN features for signature comparison without metric learning or Siamese architectures.
|
||||
Engin et al. [14] used ResNet-50 features with cosine similarity for offline signature verification on real-world scanned documents, incorporating CycleGAN-based stamp removal as preprocessing---a pipeline design closely paralleling our approach.
|
||||
Tsourounis et al. [15] demonstrated successful transfer from handwritten text recognition to signature verification, showing that CNN features trained on related but distinct handwriting tasks generalize effectively to signature comparison.
|
||||
Chamakh and Bounouh [22] confirmed that a simple ResNet backbone with cosine similarity achieves competitive verification accuracy across multilingual signature datasets without fine-tuning, supporting the viability of our off-the-shelf feature extraction approach.
|
||||
|
||||
Babenko et al. [23] established that CNN-extracted neural codes with cosine similarity provide an effective framework for image retrieval and matching, a finding that underpins our feature comparison approach.
|
||||
These findings collectively suggest that pre-trained CNN features, when L2-normalized and compared via cosine similarity, provide a robust and computationally efficient representation for signature comparison---particularly suitable for large-scale applications where the computational overhead of Siamese training or metric learning is impractical.
|
||||
|
||||
<!--
|
||||
REFERENCES for Related Work (see paper_a_references.md for full list):
|
||||
[3] Bromley et al. 1993 — Siamese TDNN (NeurIPS)
|
||||
[4] Dey et al. 2017 — SigNet (arXiv:1707.02131)
|
||||
[5] Hadjadj et al. 2020 — Single sample SV (Applied Sciences)
|
||||
[6] Li et al. 2024 — TransOSV (Pattern Recognition)
|
||||
[7] Tehsin et al. 2024 — Triplet Siamese (Mathematics)
|
||||
[8] Brimoh & Olisah 2024 — Consensus threshold (arXiv:2401.03085)
|
||||
[9] Woodruff et al. 2021 — AML signature pipeline (arXiv:2107.14091)
|
||||
[10] Copy-move forgery detection survey — MTAP 2024
|
||||
[11] Abramova & Böhme 2016 — CMFD in scanned docs (Electronic Imaging)
|
||||
[12] Jakhar & Borah 2025 — pHash + DL (Info. Processing & Management)
|
||||
[13] Pizzi et al. 2022 — SSCD (CVPR)
|
||||
[14] Perceptual hashing survey — ACM TOMM 2025
|
||||
[15] Engin et al. 2020 — ResNet + cosine on real docs (CVPRW)
|
||||
[16] Tsourounis et al. 2022 — Transfer from text to signatures (Expert Systems with Applications)
|
||||
[17] Chamakh & Bounouh 2025 — ResNet18 unified SV (Procedia Computer Science)
|
||||
[24] Hafemann et al. 2017 — CNN features for signature verification (Pattern Recognition)
|
||||
[25] Hafemann et al. 2019 — Meta-learning for signature verification (IEEE TIFS)
|
||||
[26] Zois et al. 2024 — SPD manifold signature verification (IEEE TIFS)
|
||||
[27] Farid 2009 — Image forgery detection survey (IEEE SPM)
|
||||
[28] Mehrjardi et al. 2023 — DL-based image forgery detection survey (Pattern Recognition)
|
||||
[29] Babenko et al. 2014 — Neural codes for image retrieval (ECCV)
|
||||
-->
|
||||
@@ -0,0 +1,153 @@
|
||||
# IV. Experiments and Results
|
||||
|
||||
## A. Experimental Setup
|
||||
|
||||
All experiments were conducted on a workstation equipped with an Apple Silicon processor with Metal Performance Shaders (MPS) GPU acceleration.
|
||||
Feature extraction used PyTorch 2.9 with torchvision model implementations.
|
||||
The complete pipeline---from raw PDF processing through final classification---was implemented in Python.
|
||||
|
||||
|
||||
## B. Signature Detection Performance
|
||||
|
||||
The YOLOv11n model achieved high detection performance on the validation set (Table II), with all loss components converging by epoch 60 and no significant overfitting despite the relatively small training set (425 images).
|
||||
We note that Table II reports validation-set metrics, as no separate hold-out test set was reserved given the small annotation budget (500 images total).
|
||||
However, the subsequent production deployment provides practical validation: batch inference on 86,071 documents yielded 182,328 extracted signatures (Table III), with an average of 2.14 signatures per document, consistent with the standard practice of two certifying CPAs per audit report.
|
||||
The high VLM--YOLO agreement rate (98.8%) further corroborates detection reliability at scale.
|
||||
|
||||
<!-- TABLE III: Extraction Results
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Documents processed | 86,071 |
|
||||
| Documents with detections | 85,042 (98.8%) |
|
||||
| Total signatures extracted | 182,328 |
|
||||
| Avg. signatures per document | 2.14 |
|
||||
| CPA-matched signatures | 168,755 (92.6%) |
|
||||
| Processing rate | 43.1 docs/sec |
|
||||
-->
|
||||
|
||||
## C. Distribution Analysis
|
||||
|
||||
Fig. 2 presents the cosine similarity distributions for intra-class (same CPA) and inter-class (different CPAs) pairs.
|
||||
Table IV summarizes the distributional statistics.
|
||||
|
||||
<!-- TABLE IV: Cosine Similarity Distribution Statistics
|
||||
| Statistic | Intra-class | Inter-class |
|
||||
|-----------|-------------|-------------|
|
||||
| N (pairs) | 41,352,824 | 500,000 |
|
||||
| Mean | 0.821 | 0.758 |
|
||||
| Std. Dev. | 0.098 | 0.090 |
|
||||
| Median | 0.836 | 0.774 |
|
||||
| Skewness | −0.711 | −0.851 |
|
||||
| Kurtosis | 0.550 | 1.027 |
|
||||
-->
|
||||
|
||||
Both distributions are left-skewed and leptokurtic.
|
||||
Shapiro-Wilk and Kolmogorov-Smirnov tests rejected normality for both ($p < 0.001$), confirming that parametric thresholds based on normality assumptions would be inappropriate.
|
||||
Distribution fitting identified the lognormal distribution as the best parametric fit (lowest AIC) for both classes, though we use this result only descriptively; all subsequent thresholds are derived nonparametrically via KDE to avoid distributional assumptions.
|
||||
|
||||
The KDE crossover---where the two density functions intersect---was located at 0.837.
|
||||
Under the assumption of equal prior probabilities and equal misclassification costs, this crossover approximates the optimal decision boundary between the two classes.
|
||||
We note that this threshold is derived from all-pairs similarity distributions and is used as a reference point for interpreting per-signature best-match scores; the relationship between the two scales is mediated by the fact that the best-match statistic selects the maximum over all pairwise comparisons for a given CPA, producing systematically higher values (see Section IV-D).
|
||||
|
||||
Statistical tests confirmed significant separation between the two distributions (Table V).
|
||||
|
||||
<!-- TABLE V: Statistical Separation Tests
|
||||
| Test | Statistic | p-value |
|
||||
|------|-----------|---------|
|
||||
| Mann-Whitney U | 6.91 × 10⁹ | < 0.001 |
|
||||
| Welch's t-test | t = 149.36 | < 0.001 |
|
||||
| K-S 2-sample | D = 0.290 | < 0.001 |
|
||||
| Cohen's d | 0.669 | — |
|
||||
-->
|
||||
|
||||
We emphasize that the pairwise observations are not independent---the same signature participates in multiple pairs---which inflates the effective sample size and renders p-values unreliable as measures of evidence strength.
|
||||
We therefore rely primarily on Cohen's $d$ as an effect-size measure that is less sensitive to sample size.
|
||||
Cohen's $d$ of 0.669 indicates a medium effect size [29], confirming that the distributional difference is practically meaningful, not merely an artifact of the large sample count.
|
||||
|
||||
## D. Calibration Group Analysis
|
||||
|
||||
Fig. 3 presents the cosine similarity distribution of Firm A (the known-replication reference group) compared to the overall intra-class distribution.
|
||||
|
||||
Firm A comprises 180 CPAs contributing 16.0 million intra-firm signature pairs.
|
||||
Its distributional characteristics provide empirical anchors for threshold validation:
|
||||
|
||||
<!-- TABLE VI: Firm A Calibration Statistics (per-signature best match, ResNet-50)
|
||||
| Statistic | Firm A | All CPAs |
|
||||
|-----------|--------|----------|
|
||||
| N (signatures) | 60,448 | 168,740 |
|
||||
| Mean | 0.980 | 0.961 |
|
||||
| Std. Dev. | 0.019 | 0.029 |
|
||||
| Median | 0.986 | — |
|
||||
| 1st percentile | 0.908 | — |
|
||||
| 5th percentile | 0.941 | — |
|
||||
| % > 0.95 | 92.5% | — |
|
||||
| % > 0.90 | 99.3% | — |
|
||||
-->
|
||||
|
||||
Firm A's per-signature best-match cosine similarity (mean = 0.980, std = 0.019) is notably higher and more concentrated than the overall CPA population (mean = 0.961, std = 0.029).
|
||||
Critically, 99.3% of Firm A's signatures exhibit a best-match similarity exceeding 0.90, and the 1st percentile is 0.908---establishing that any threshold set above 0.91 would fail to capture the most dissimilar replicated signatures in the calibration group.
|
||||
|
||||
This concentration provides strong empirical validation for the threshold selection: the KDE crossover at 0.837 captures essentially all of Firm A's signatures (>99.9%), while more conservative thresholds (e.g., 0.95) still capture 92.5%.
|
||||
The narrow spread (std = 0.019) further confirms that digital replication produces highly predictable similarity scores, as expected when the same source image is reused across documents with only scan-induced variations.
|
||||
|
||||
## E. Classification Results
|
||||
|
||||
Table VII presents the classification results for 84,386 documents using the dual-method framework with Firm A-calibrated thresholds.
|
||||
|
||||
<!-- TABLE VII: Recalibrated Classification Results (Dual-Method: Cosine + dHash)
|
||||
| Verdict | N (PDFs) | % | Firm A | Firm A % |
|
||||
|---------|----------|---|--------|----------|
|
||||
| High-confidence replication | 29,529 | 35.0% | 22,970 | 76.0% |
|
||||
| Moderate-confidence replication | 36,994 | 43.8% | 6,311 | 20.9% |
|
||||
| High style consistency | 5,133 | 6.1% | 183 | 0.6% |
|
||||
| Uncertain | 12,683 | 15.0% | 758 | 2.5% |
|
||||
| Likely genuine | 47 | 0.1% | 4 | 0.0% |
|
||||
-->
|
||||
|
||||
The dual-method classification reveals a nuanced picture within the 71,656 documents exceeding the cosine similarity threshold of 0.95.
|
||||
Rather than treating these uniformly as "likely copies" (as a single-metric approach would), the dHash dimension stratifies them into three distinct populations:
|
||||
29,529 (41.2%) show converging structural evidence of replication (dHash ≤ 5),
|
||||
36,994 (51.7%) show partial structural similarity (dHash 6--15) consistent with replication degraded by scan variations,
|
||||
and 5,133 (7.2%) show no structural corroboration (dHash > 15), suggesting high signing consistency rather than digital duplication.
|
||||
|
||||
### Calibration Validation
|
||||
|
||||
The Firm A column in Table VII validates the calibration: 96.9% of Firm A's documents are classified as replication (high or moderate confidence), and only 0.6% fall into the "high style consistency" category.
|
||||
This confirms that the dHash thresholds, derived from Firm A's distributional characteristics (median = 5, 95th percentile = 15), correctly capture the known-replication population.
|
||||
|
||||
Among non-Firm-A CPAs with cosine > 0.95, only 11.3% exhibit dHash ≤ 5, compared to 58.7% for Firm A---a five-fold difference that demonstrates the discriminative power of the structural verification layer.
|
||||
|
||||
## F. Ablation Study: Feature Backbone Comparison
|
||||
|
||||
To validate the choice of ResNet-50 as the feature extraction backbone, we conducted an ablation study comparing three pre-trained architectures: ResNet-50 (2048-dim), VGG-16 (4096-dim), and EfficientNet-B0 (1280-dim).
|
||||
All models used ImageNet pre-trained weights without fine-tuning, with identical preprocessing and L2 normalization.
|
||||
Table IX presents the comparison.
|
||||
|
||||
<!-- TABLE IX: Backbone Comparison
|
||||
| Metric | ResNet-50 | VGG-16 | EfficientNet-B0 |
|
||||
|--------|-----------|--------|-----------------|
|
||||
| Feature dim | 2048 | 4096 | 1280 |
|
||||
| Intra mean | 0.821 | 0.822 | 0.786 |
|
||||
| Inter mean | 0.758 | 0.767 | 0.699 |
|
||||
| Cohen's d | 0.669 | 0.564 | 0.707 |
|
||||
| KDE crossover | 0.837 | 0.850 | 0.792 |
|
||||
| Firm A mean (all-pairs) | 0.826 | 0.820 | 0.810 |
|
||||
| Firm A 1st pct (all-pairs) | 0.543 | 0.520 | 0.454 |
|
||||
|
||||
Note: Firm A values in this table are computed over all intra-firm pairwise
|
||||
similarities (16.0M pairs) for cross-backbone comparability. These differ from
|
||||
the per-signature best-match values in Table VI (mean = 0.980), which reflect
|
||||
the classification-relevant statistic: the similarity of each signature to its
|
||||
single closest match from the same CPA.
|
||||
-->
|
||||
|
||||
EfficientNet-B0 achieves the highest Cohen's $d$ (0.707), indicating the greatest statistical separation between intra-class and inter-class distributions.
|
||||
However, it also exhibits the widest distributional spread (intra std = 0.123 vs. ResNet-50's 0.098), resulting in lower per-sample classification confidence.
|
||||
VGG-16 performs worst on all key metrics despite having the highest feature dimensionality (4096), suggesting that additional dimensions do not contribute discriminative information for this task.
|
||||
|
||||
ResNet-50 provides the best overall balance:
|
||||
(1) Cohen's $d$ of 0.669 is competitive with EfficientNet-B0's 0.707;
|
||||
(2) its tighter distributions yield more reliable individual classifications;
|
||||
(3) the highest Firm A all-pairs 1st percentile (0.543) indicates that known-replication signatures are least likely to produce low-similarity outlier pairs under this backbone; and
|
||||
(4) its 2048-dimensional features offer a practical compromise between discriminative capacity and computational/storage efficiency for processing 182K+ signatures.
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Recalibrate classification using Firm A as ground truth.
|
||||
Dual-method only: Cosine + dHash (drops SSIM and pixel-identical).
|
||||
|
||||
Approach:
|
||||
1. Load per-signature best-match cosine + pHash from DB
|
||||
2. Use Firm A (勤業眾信聯合) as known-positive calibration set
|
||||
3. Analyze 2D distribution (cosine × pHash) for Firm A vs others
|
||||
4. Determine calibrated thresholds
|
||||
5. Reclassify all PDFs
|
||||
6. Output new Table VII
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import numpy as np
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
DB_PATH = '/Volumes/NV2/PDF-Processing/signature-analysis/signature_analysis.db'
|
||||
OUTPUT_DIR = Path('/Volumes/NV2/PDF-Processing/signature-analysis/recalibrated')
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
FIRM_A = '勤業眾信聯合'
|
||||
KDE_CROSSOVER = 0.837 # from intra/inter analysis
|
||||
|
||||
|
||||
def load_data():
|
||||
"""Load per-signature data with cosine and pHash."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute('''
|
||||
SELECT s.signature_id, s.image_filename, s.assigned_accountant,
|
||||
s.max_similarity_to_same_accountant,
|
||||
s.phash_distance_to_closest,
|
||||
a.firm
|
||||
FROM signatures s
|
||||
LEFT JOIN accountants a ON s.assigned_accountant = a.name
|
||||
WHERE s.assigned_accountant IS NOT NULL
|
||||
AND s.max_similarity_to_same_accountant IS NOT NULL
|
||||
''')
|
||||
rows = cur.fetchall()
|
||||
conn.close()
|
||||
|
||||
data = []
|
||||
for r in rows:
|
||||
data.append({
|
||||
'sig_id': r[0],
|
||||
'filename': r[1],
|
||||
'accountant': r[2],
|
||||
'cosine': r[3],
|
||||
'phash': r[4], # may be None
|
||||
'firm': r[5],
|
||||
})
|
||||
print(f"Loaded {len(data):,} signatures")
|
||||
return data
|
||||
|
||||
|
||||
def analyze_firm_a(data):
|
||||
"""Analyze Firm A's dual-method distribution to calibrate thresholds."""
|
||||
firm_a = [d for d in data if d['firm'] == FIRM_A]
|
||||
others = [d for d in data if d['firm'] != FIRM_A]
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"FIRM A CALIBRATION ANALYSIS")
|
||||
print(f"{'='*60}")
|
||||
print(f"Firm A signatures: {len(firm_a):,}")
|
||||
print(f"Other signatures: {len(others):,}")
|
||||
|
||||
# Firm A cosine distribution
|
||||
fa_cosine = np.array([d['cosine'] for d in firm_a])
|
||||
ot_cosine = np.array([d['cosine'] for d in others])
|
||||
|
||||
print(f"\n--- Cosine Similarity ---")
|
||||
print(f"Firm A: mean={fa_cosine.mean():.4f}, std={fa_cosine.std():.4f}, "
|
||||
f"p1={np.percentile(fa_cosine,1):.4f}, p5={np.percentile(fa_cosine,5):.4f}")
|
||||
print(f"Others: mean={ot_cosine.mean():.4f}, std={ot_cosine.std():.4f}")
|
||||
|
||||
# Firm A pHash distribution (only where available)
|
||||
fa_phash = [d['phash'] for d in firm_a if d['phash'] is not None]
|
||||
ot_phash = [d['phash'] for d in others if d['phash'] is not None]
|
||||
|
||||
print(f"\n--- pHash (dHash) Distance ---")
|
||||
print(f"Firm A with pHash: {len(fa_phash):,}")
|
||||
print(f"Others with pHash: {len(ot_phash):,}")
|
||||
|
||||
if fa_phash:
|
||||
fa_ph = np.array(fa_phash)
|
||||
print(f"Firm A: mean={fa_ph.mean():.2f}, median={np.median(fa_ph):.0f}, "
|
||||
f"p95={np.percentile(fa_ph,95):.0f}")
|
||||
print(f" pHash=0: {(fa_ph==0).sum():,} ({100*(fa_ph==0).mean():.1f}%)")
|
||||
print(f" pHash<=2: {(fa_ph<=2).sum():,} ({100*(fa_ph<=2).mean():.1f}%)")
|
||||
print(f" pHash<=5: {(fa_ph<=5).sum():,} ({100*(fa_ph<=5).mean():.1f}%)")
|
||||
print(f" pHash<=10:{(fa_ph<=10).sum():,} ({100*(fa_ph<=10).mean():.1f}%)")
|
||||
print(f" pHash<=15:{(fa_ph<=15).sum():,} ({100*(fa_ph<=15).mean():.1f}%)")
|
||||
print(f" pHash>15: {(fa_ph>15).sum():,} ({100*(fa_ph>15).mean():.1f}%)")
|
||||
|
||||
if ot_phash:
|
||||
ot_ph = np.array(ot_phash)
|
||||
print(f"\nOthers: mean={ot_ph.mean():.2f}, median={np.median(ot_ph):.0f}")
|
||||
print(f" pHash=0: {(ot_ph==0).sum():,} ({100*(ot_ph==0).mean():.1f}%)")
|
||||
print(f" pHash<=5: {(ot_ph<=5).sum():,} ({100*(ot_ph<=5).mean():.1f}%)")
|
||||
print(f" pHash<=10:{(ot_ph<=10).sum():,} ({100*(ot_ph<=10).mean():.1f}%)")
|
||||
print(f" pHash>15: {(ot_ph>15).sum():,} ({100*(ot_ph>15).mean():.1f}%)")
|
||||
|
||||
# 2D analysis: cosine × pHash for Firm A
|
||||
print(f"\n--- 2D Analysis: Cosine × pHash (Firm A) ---")
|
||||
fa_both = [(d['cosine'], d['phash']) for d in firm_a if d['phash'] is not None]
|
||||
if fa_both:
|
||||
cosines, phashes = zip(*fa_both)
|
||||
cosines = np.array(cosines)
|
||||
phashes = np.array(phashes)
|
||||
|
||||
# Cross-tabulate
|
||||
for cos_thresh in [0.95, 0.90, KDE_CROSSOVER]:
|
||||
for ph_thresh in [5, 10, 15]:
|
||||
match = ((cosines > cos_thresh) & (phashes <= ph_thresh)).sum()
|
||||
total = len(cosines)
|
||||
print(f" Cosine>{cos_thresh:.3f} AND pHash<={ph_thresh}: "
|
||||
f"{match:,}/{total:,} ({100*match/total:.1f}%)")
|
||||
|
||||
# Same for others (high cosine subset)
|
||||
print(f"\n--- 2D Analysis: Cosine × pHash (Others, cosine > 0.95 only) ---")
|
||||
ot_both_high = [(d['cosine'], d['phash']) for d in others
|
||||
if d['phash'] is not None and d['cosine'] > 0.95]
|
||||
if ot_both_high:
|
||||
cosines_o, phashes_o = zip(*ot_both_high)
|
||||
phashes_o = np.array(phashes_o)
|
||||
print(f" N (others with cosine>0.95 and pHash): {len(ot_both_high):,}")
|
||||
for ph_thresh in [5, 10, 15]:
|
||||
match = (phashes_o <= ph_thresh).sum()
|
||||
print(f" pHash<={ph_thresh}: {match:,}/{len(phashes_o):,} ({100*match/len(phashes_o):.1f}%)")
|
||||
|
||||
return fa_phash, ot_phash
|
||||
|
||||
|
||||
def reclassify_pdfs(data):
|
||||
"""
|
||||
Reclassify all PDFs using calibrated dual-method thresholds.
|
||||
|
||||
New classification (cosine + dHash only):
|
||||
1. High-confidence replication: cosine > 0.95 AND pHash ≤ 5
|
||||
2. Moderate-confidence replication: cosine > 0.95 AND pHash 6-15
|
||||
3. High style consistency: cosine > 0.95 AND (pHash > 15 OR pHash unavailable)
|
||||
4. Uncertain: cosine between KDE_CROSSOVER and 0.95
|
||||
5. Likely genuine: cosine < KDE_CROSSOVER
|
||||
"""
|
||||
# Group signatures by PDF (derive PDF from filename pattern)
|
||||
# Filename format: {company}_{year}_{type}_sig{N}.png or similar
|
||||
# We need to group by source PDF
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Get PDF-level data
|
||||
cur.execute('''
|
||||
SELECT s.signature_id, s.image_filename, s.assigned_accountant,
|
||||
s.max_similarity_to_same_accountant,
|
||||
s.phash_distance_to_closest,
|
||||
a.firm
|
||||
FROM signatures s
|
||||
LEFT JOIN accountants a ON s.assigned_accountant = a.name
|
||||
WHERE s.assigned_accountant IS NOT NULL
|
||||
AND s.max_similarity_to_same_accountant IS NOT NULL
|
||||
''')
|
||||
rows = cur.fetchall()
|
||||
|
||||
# Group by PDF: extract PDF identifier from filename
|
||||
# Signature filenames are like: {pdfname}_page{N}_sig{M}.png
|
||||
pdf_sigs = defaultdict(list)
|
||||
for r in rows:
|
||||
sig_id, filename, accountant, cosine, phash, firm = r
|
||||
# Extract PDF name (everything before _page or _sig)
|
||||
parts = filename.rsplit('_sig', 1)
|
||||
pdf_key = parts[0] if len(parts) > 1 else filename.rsplit('.', 1)[0]
|
||||
# Further strip _page part
|
||||
page_parts = pdf_key.rsplit('_page', 1)
|
||||
pdf_key = page_parts[0] if len(page_parts) > 1 else pdf_key
|
||||
|
||||
pdf_sigs[pdf_key].append({
|
||||
'cosine': cosine,
|
||||
'phash': phash,
|
||||
'firm': firm,
|
||||
'accountant': accountant,
|
||||
})
|
||||
|
||||
conn.close()
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"RECLASSIFICATION (Dual-Method: Cosine + dHash)")
|
||||
print(f"{'='*60}")
|
||||
print(f"Total PDFs: {len(pdf_sigs):,}")
|
||||
|
||||
# Classify each PDF based on its signatures
|
||||
verdicts = defaultdict(int)
|
||||
firm_a_verdicts = defaultdict(int)
|
||||
details = []
|
||||
|
||||
for pdf_key, sigs in pdf_sigs.items():
|
||||
# Use the signature with the highest cosine as the representative
|
||||
best_sig = max(sigs, key=lambda s: s['cosine'])
|
||||
cosine = best_sig['cosine']
|
||||
phash = best_sig['phash']
|
||||
is_firm_a = best_sig['firm'] == FIRM_A
|
||||
|
||||
# Also check if ANY signature in this PDF has low pHash
|
||||
min_phash = None
|
||||
for s in sigs:
|
||||
if s['phash'] is not None:
|
||||
if min_phash is None or s['phash'] < min_phash:
|
||||
min_phash = s['phash']
|
||||
|
||||
# Classification
|
||||
if cosine > 0.95 and min_phash is not None and min_phash <= 5:
|
||||
verdict = 'high_confidence_replication'
|
||||
elif cosine > 0.95 and min_phash is not None and min_phash <= 15:
|
||||
verdict = 'moderate_confidence_replication'
|
||||
elif cosine > 0.95:
|
||||
verdict = 'high_style_consistency'
|
||||
elif cosine > KDE_CROSSOVER:
|
||||
verdict = 'uncertain'
|
||||
else:
|
||||
verdict = 'likely_genuine'
|
||||
|
||||
verdicts[verdict] += 1
|
||||
if is_firm_a:
|
||||
firm_a_verdicts[verdict] += 1
|
||||
|
||||
details.append({
|
||||
'pdf': pdf_key,
|
||||
'cosine': cosine,
|
||||
'min_phash': min_phash,
|
||||
'verdict': verdict,
|
||||
'is_firm_a': is_firm_a,
|
||||
})
|
||||
|
||||
total = sum(verdicts.values())
|
||||
firm_a_total = sum(firm_a_verdicts.values())
|
||||
|
||||
# Print results
|
||||
print(f"\n--- New Classification Results ---")
|
||||
print(f"{'Verdict':<35} {'Count':>8} {'%':>7} | {'Firm A':>8} {'%':>7}")
|
||||
print("-" * 75)
|
||||
|
||||
order = ['high_confidence_replication', 'moderate_confidence_replication',
|
||||
'high_style_consistency', 'uncertain', 'likely_genuine']
|
||||
labels = {
|
||||
'high_confidence_replication': 'High-conf. replication',
|
||||
'moderate_confidence_replication': 'Moderate-conf. replication',
|
||||
'high_style_consistency': 'High style consistency',
|
||||
'uncertain': 'Uncertain',
|
||||
'likely_genuine': 'Likely genuine',
|
||||
}
|
||||
|
||||
for v in order:
|
||||
n = verdicts.get(v, 0)
|
||||
fa = firm_a_verdicts.get(v, 0)
|
||||
pct = 100 * n / total if total > 0 else 0
|
||||
fa_pct = 100 * fa / firm_a_total if firm_a_total > 0 else 0
|
||||
print(f" {labels.get(v, v):<33} {n:>8,} {pct:>6.1f}% | {fa:>8,} {fa_pct:>6.1f}%")
|
||||
|
||||
print("-" * 75)
|
||||
print(f" {'Total':<33} {total:>8,} {'100.0%':>7} | {firm_a_total:>8,} {'100.0%':>7}")
|
||||
|
||||
# Precision/Recall using Firm A as positive set
|
||||
print(f"\n--- Firm A Capture Rate (Calibration Validation) ---")
|
||||
fa_replication = firm_a_verdicts.get('high_confidence_replication', 0) + \
|
||||
firm_a_verdicts.get('moderate_confidence_replication', 0)
|
||||
print(f" Firm A classified as replication (high+moderate): {fa_replication:,}/{firm_a_total:,} "
|
||||
f"({100*fa_replication/firm_a_total:.1f}%)")
|
||||
|
||||
fa_high = firm_a_verdicts.get('high_confidence_replication', 0)
|
||||
print(f" Firm A classified as high-confidence: {fa_high:,}/{firm_a_total:,} "
|
||||
f"({100*fa_high/firm_a_total:.1f}%)")
|
||||
|
||||
# Save results
|
||||
results = {
|
||||
'classification': {v: verdicts.get(v, 0) for v in order},
|
||||
'firm_a': {v: firm_a_verdicts.get(v, 0) for v in order},
|
||||
'total_pdfs': total,
|
||||
'firm_a_pdfs': firm_a_total,
|
||||
'thresholds': {
|
||||
'cosine_high': 0.95,
|
||||
'kde_crossover': KDE_CROSSOVER,
|
||||
'phash_high_confidence': 5,
|
||||
'phash_moderate_confidence': 15,
|
||||
},
|
||||
}
|
||||
|
||||
with open(OUTPUT_DIR / 'recalibrated_results.json', 'w') as f:
|
||||
json.dump(results, f, indent=2)
|
||||
|
||||
print(f"\nResults saved: {OUTPUT_DIR / 'recalibrated_results.json'}")
|
||||
return results
|
||||
|
||||
|
||||
def main():
|
||||
data = load_data()
|
||||
analyze_firm_a(data)
|
||||
results = reclassify_pdfs(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Renumber all in-text citations to sequential order by first appearance.
|
||||
Also rewrites references.md with the final numbering.
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
PAPER_DIR = Path("/Volumes/NV2/pdf_recognize/paper")
|
||||
|
||||
# === FINAL NUMBERING (by order of first appearance in paper) ===
|
||||
# Format: new_number: (short_key, full_citation)
|
||||
FINAL_REFS = {
|
||||
1: ("cpa_act", 'Taiwan Certified Public Accountant Act (會計師法), Art. 4; FSC Attestation Regulations (查核簽證核准準則), Art. 6. Available: https://law.moj.gov.tw/ENG/LawClass/LawAll.aspx?pcode=G0400067'),
|
||||
2: ("yen2013", 'S.-H. Yen, Y.-S. Chang, and H.-L. Chen, "Does the signature of a CPA matter? Evidence from Taiwan," *Res. Account. Regul.*, vol. 25, no. 2, pp. 230–235, 2013.'),
|
||||
3: ("bromley1993", 'J. Bromley et al., "Signature verification using a Siamese time delay neural network," in *Proc. NeurIPS*, 1993.'),
|
||||
4: ("dey2017", 'S. Dey et al., "SigNet: Convolutional Siamese network for writer independent offline signature verification," arXiv:1707.02131, 2017.'),
|
||||
5: ("hadjadj2020", 'I. Hadjadj et al., "An offline signature verification method based on a single known sample and an explainable deep learning approach," *Appl. Sci.*, vol. 10, no. 11, p. 3716, 2020.'),
|
||||
6: ("li2024", 'H. Li et al., "TransOSV: Offline signature verification with transformers," *Pattern Recognit.*, vol. 145, p. 109882, 2024.'),
|
||||
7: ("tehsin2024", 'S. Tehsin et al., "Enhancing signature verification using triplet Siamese similarity networks in digital documents," *Mathematics*, vol. 12, no. 17, p. 2757, 2024.'),
|
||||
8: ("brimoh2024", 'P. Brimoh and C. C. Olisah, "Consensus-threshold criterion for offline signature verification using CNN learned representations," arXiv:2401.03085, 2024.'),
|
||||
9: ("woodruff2021", 'N. Woodruff et al., "Fully-automatic pipeline for document signature analysis to detect money laundering activities," arXiv:2107.14091, 2021.'),
|
||||
10: ("abramova2016", 'S. Abramova and R. Bohme, "Detecting copy-move forgeries in scanned text documents," in *Proc. Electronic Imaging*, 2016.'),
|
||||
11: ("cmfd_survey", 'Y. Li et al., "Copy-move forgery detection in digital image forensics: A survey," *Multimedia Tools Appl.*, 2024.'),
|
||||
12: ("jakhar2025", 'Y. Jakhar and M. D. Borah, "Effective near-duplicate image detection using perceptual hashing and deep learning," *Inf. Process. Manage.*, p. 104086, 2025.'),
|
||||
13: ("pizzi2022", 'E. Pizzi et al., "A self-supervised descriptor for image copy detection," in *Proc. CVPR*, 2022.'),
|
||||
14: ("hafemann2017", 'L. G. Hafemann, R. Sabourin, and L. S. Oliveira, "Learning features for offline handwritten signature verification using deep convolutional neural networks," *Pattern Recognit.*, vol. 70, pp. 163–176, 2017.'),
|
||||
15: ("zois2024", 'E. N. Zois, D. Tsourounis, and D. Kalivas, "Similarity distance learning on SPD manifold for writer independent offline signature verification," *IEEE Trans. Inf. Forensics Security*, vol. 19, pp. 1342–1356, 2024.'),
|
||||
16: ("hafemann2019", 'L. G. Hafemann, R. Sabourin, and L. S. Oliveira, "Meta-learning for fast classifier adaptation to new users of signature verification systems," *IEEE Trans. Inf. Forensics Security*, vol. 15, pp. 1735–1745, 2019.'),
|
||||
17: ("farid2009", 'H. Farid, "Image forgery detection," *IEEE Signal Process. Mag.*, vol. 26, no. 2, pp. 16–25, 2009.'),
|
||||
18: ("mehrjardi2023", 'F. Z. Mehrjardi, A. M. Latif, M. S. Zarchi, and R. Sheikhpour, "A survey on deep learning-based image forgery detection," *Pattern Recognit.*, vol. 144, art. no. 109778, 2023.'),
|
||||
19: ("phash_survey", 'J. Luo et al., "A survey of perceptual hashing for multimedia," *ACM Trans. Multimedia Comput. Commun. Appl.*, vol. 21, no. 7, 2025.'),
|
||||
20: ("engin2020", 'D. Engin et al., "Offline signature verification on real-world documents," in *Proc. CVPRW*, 2020.'),
|
||||
21: ("tsourounis2022", 'D. Tsourounis et al., "From text to signatures: Knowledge transfer for efficient deep feature learning in offline signature verification," *Expert Syst. Appl.*, 2022.'),
|
||||
22: ("chamakh2025", 'B. Chamakh and O. Bounouh, "A unified ResNet18-based approach for offline signature classification and verification," *Procedia Comput. Sci.*, vol. 270, 2025.'),
|
||||
23: ("babenko2014", 'A. Babenko, A. Slesarev, A. Chigorin, and V. Lempitsky, "Neural codes for image retrieval," in *Proc. ECCV*, 2014, pp. 584–599.'),
|
||||
24: ("qwen2025", 'Qwen2.5-VL Technical Report, Alibaba Group, 2025.'),
|
||||
25: ("yolov11", 'Ultralytics, "YOLOv11 documentation," 2024. [Online]. Available: https://docs.ultralytics.com/'),
|
||||
26: ("he2016", 'K. He, X. Zhang, S. Ren, and J. Sun, "Deep residual learning for image recognition," in *Proc. CVPR*, 2016.'),
|
||||
27: ("krawetz2013", 'N. Krawetz, "Kind of like that," The Hacker Factor Blog, 2013. [Online]. Available: https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html'),
|
||||
28: ("silverman1986", 'B. W. Silverman, *Density Estimation for Statistics and Data Analysis*. London: Chapman & Hall, 1986.'),
|
||||
29: ("cohen1988", 'J. Cohen, *Statistical Power Analysis for the Behavioral Sciences*, 2nd ed. Hillsdale, NJ: Lawrence Erlbaum, 1988.'),
|
||||
30: ("wang2004", 'Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image quality assessment: From error visibility to structural similarity," *IEEE Trans. Image Process.*, vol. 13, no. 4, pp. 600–612, 2004.'),
|
||||
31: ("carcello2013", 'J. V. Carcello and C. Li, "Costs and benefits of requiring an engagement partner signature: Recent experience in the United Kingdom," *The Accounting Review*, vol. 88, no. 5, pp. 1511–1546, 2013.'),
|
||||
32: ("blay2014", 'A. D. Blay, M. Notbohm, C. Schelleman, and A. Valencia, "Audit quality effects of an individual audit engagement partner signature mandate," *Int. J. Auditing*, vol. 18, no. 3, pp. 172–192, 2014.'),
|
||||
33: ("chi2009", 'W. Chi, H. Huang, Y. Liao, and H. Xie, "Mandatory audit partner rotation, audit quality, and market perception: Evidence from Taiwan," *Contemp. Account. Res.*, vol. 26, no. 2, pp. 359–391, 2009.'),
|
||||
34: ("redmon2016", 'J. Redmon, S. Divvala, R. Girshick, and A. Farhadi, "You only look once: Unified, real-time object detection," in *Proc. CVPR*, 2016, pp. 779–788.'),
|
||||
35: ("vlm_survey", 'J. Zhang, J. Huang, S. Jin, and S. Lu, "Vision-language models for vision tasks: A survey," *IEEE Trans. Pattern Anal. Mach. Intell.*, vol. 46, no. 8, pp. 5625–5644, 2024.'),
|
||||
36: ("mann1947", 'H. B. Mann and D. R. Whitney, "On a test of whether one of two random variables is stochastically larger than the other," *Ann. Math. Statist.*, vol. 18, no. 1, pp. 50–60, 1947.'),
|
||||
}
|
||||
|
||||
# === LINE-SPECIFIC REPLACEMENTS PER FILE ===
|
||||
# Each entry: (unique_context_string, old_text, new_text)
|
||||
|
||||
INTRO_FIXES = [
|
||||
# Line 16: SV range should start at [3] not [2] (since [2] is Yen)
|
||||
("offline signature verification [2]--[7]",
|
||||
"offline signature verification [2]--[7]",
|
||||
"offline signature verification [3]--[8]"),
|
||||
# Line 23: Woodruff
|
||||
("Woodruff et al. [8]",
|
||||
"Woodruff et al. [8]",
|
||||
"Woodruff et al. [9]"),
|
||||
# Line 24: CMFD refs
|
||||
("Copy-move forgery detection methods [9], [10]",
|
||||
"methods [9], [10]",
|
||||
"methods [10], [11]"),
|
||||
# Line 25: pHash+DL refs
|
||||
("perceptual hashing combined with deep learning [11], [12]",
|
||||
"deep learning [11], [12]",
|
||||
"deep learning [12], [13]"),
|
||||
# Line 28: pHash -> dHash in pipeline description
|
||||
("perceptual hash (pHash) distance",
|
||||
"perceptual hash (pHash) distance",
|
||||
"difference hash (dHash) distance"),
|
||||
]
|
||||
|
||||
RW_FIXES = [
|
||||
# Line 7: Hafemann 2017
|
||||
("Hafemann et al. [24]", "et al. [24]", "et al. [14]"),
|
||||
# Line 12: Zois
|
||||
("Zois et al. [26]", "et al. [26]", "et al. [15]"),
|
||||
# Line 13: Hafemann 2019
|
||||
("Hafemann et al. [25]", "et al. [25]", "et al. [16]"),
|
||||
# Line 18: Brimoh (wrongly [7], should be [8])
|
||||
("Brimoh and Olisah [7]", "Olisah [7]", "Olisah [8]"),
|
||||
# Line 23: Farid
|
||||
("manipulated visual content [27]", "content [27]", "content [17]"),
|
||||
# Line 23: Mehrjardi
|
||||
("forgery detection [28]", "detection [28]", "detection [18]"),
|
||||
# Line 24: CMFD survey
|
||||
("manipulated photographs [10]", "photographs [10]", "photographs [11]"),
|
||||
# Line 25: Abramova (was [11], should be [10])
|
||||
("Abramova and Bohme [11]", "Bohme [11]", "Bohme [10]"),
|
||||
# Line 27: Woodruff (was [8], should be [9])
|
||||
("Woodruff et al. [8]", "et al. [8]", "et al. [9]"),
|
||||
# Line 31: Pizzi (was [12], should be [13])
|
||||
("Pizzi et al. [12]", "et al. [12]", "et al. [13]"),
|
||||
# Line 36: pHash survey (was [13], should be [19])
|
||||
("substantive content changes [13]", "changes [13]", "changes [19]"),
|
||||
# Line 39: Jakhar (was [11], should be [12])
|
||||
("Jakhar and Borah [11]", "Borah [11]", "Borah [12]"),
|
||||
# Line 47: Engin (was [14], should be [20])
|
||||
("Engin et al. [14]", "et al. [14]", "et al. [20]"),
|
||||
# Line 48: Tsourounis (was [15], should be [21])
|
||||
("Tsourounis et al. [15]", "et al. [15]", "et al. [21]"),
|
||||
# Line 49: Chamakh (was [16], should be [22])
|
||||
("Chamakh and Bounouh [16]", "Bounouh [16]", "Bounouh [22]"),
|
||||
# Line 51: Babenko (was [29], should be [23])
|
||||
("Babenko et al. [29]", "et al. [29]", "et al. [23]"),
|
||||
]
|
||||
|
||||
METH_FIXES = [
|
||||
# Line 40: Qwen (was [17], should be [24])
|
||||
("parameters) [17]", ") [17]", ") [24]"),
|
||||
# Line 53: YOLO (was [18], should be [25])
|
||||
("(nano variant) [18]", "variant) [18]", "variant) [25]"),
|
||||
# Line 75: ResNet (was [19], should be [26])
|
||||
("neural network [19]", "network [19]", "network [26]"),
|
||||
# Line 81: Engin, Tsourounis (was [14], [15], should be [20], [21])
|
||||
("document analysis tasks [14], [15]",
|
||||
"tasks [14], [15]",
|
||||
"tasks [20], [21]"),
|
||||
# Line 98: Krawetz dHash (was [36], should be [27])
|
||||
("(dHash) [36]", ") [36]", ") [27]"),
|
||||
# Line 101: pHash survey ref (was [14], should be [19])
|
||||
("scan-induced variations [14]",
|
||||
"variations [14]",
|
||||
"variations [19]"),
|
||||
# Line 122: Silverman KDE (was [33], should be [28])
|
||||
("(KDE) [33]", ") [33]", ") [28]"),
|
||||
]
|
||||
|
||||
RESULTS_FIXES = [
|
||||
# Cohen's d citation (was [34], should be [29])
|
||||
("effect size [34]", "size [34]", "size [29]"),
|
||||
]
|
||||
|
||||
DISCUSSION_FIXES = [
|
||||
# Engin/Tsourounis/Chamakh range (was [14]--[16], should be [20]--[22])
|
||||
("prior literature [14]--[16]",
|
||||
"literature [14]--[16]",
|
||||
"literature [20]--[22]"),
|
||||
]
|
||||
|
||||
|
||||
def apply_fixes(filepath, fixes):
|
||||
text = filepath.read_text(encoding='utf-8')
|
||||
changes = 0
|
||||
for context, old, new in fixes:
|
||||
if context in text:
|
||||
text = text.replace(old, new, 1)
|
||||
changes += 1
|
||||
else:
|
||||
print(f" WARNING: context not found in {filepath.name}: {context[:60]}...")
|
||||
filepath.write_text(text, encoding='utf-8')
|
||||
print(f" {filepath.name}: {changes} fixes applied")
|
||||
return changes
|
||||
|
||||
|
||||
def rewrite_references():
|
||||
"""Rewrite references.md with final sequential numbering."""
|
||||
lines = ["# References\n\n"]
|
||||
lines.append("<!-- IEEE numbered style, sequential by first appearance in text -->\n\n")
|
||||
|
||||
for num, (key, citation) in sorted(FINAL_REFS.items()):
|
||||
lines.append(f"[{num}] {citation}\n\n")
|
||||
|
||||
lines.append(f"<!-- Total: {len(FINAL_REFS)} references -->\n")
|
||||
|
||||
ref_path = PAPER_DIR / "paper_a_references.md"
|
||||
ref_path.write_text("".join(lines), encoding='utf-8')
|
||||
print(f" paper_a_references.md: rewritten with {len(FINAL_REFS)} references")
|
||||
|
||||
|
||||
def main():
|
||||
print("Renumbering citations...\n")
|
||||
|
||||
total = 0
|
||||
total += apply_fixes(PAPER_DIR / "paper_a_introduction.md", INTRO_FIXES)
|
||||
total += apply_fixes(PAPER_DIR / "paper_a_related_work.md", RW_FIXES)
|
||||
total += apply_fixes(PAPER_DIR / "paper_a_methodology.md", METH_FIXES)
|
||||
total += apply_fixes(PAPER_DIR / "paper_a_results.md", RESULTS_FIXES)
|
||||
total += apply_fixes(PAPER_DIR / "paper_a_discussion.md", DISCUSSION_FIXES)
|
||||
|
||||
print(f"\nTotal fixes: {total}")
|
||||
|
||||
print("\nRewriting references.md...")
|
||||
rewrite_references()
|
||||
|
||||
print("\nDone! Verify with: grep -n '\\[.*\\]' paper/paper_a_*.md")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user