PMGraph / REPRODUCE.md
shawntzx's picture
PMGraph v2 release
0268c35
|
Raw History Blame Contribute Delete
25.9 kB

PMGraph release package

This package lets you reproduce every number reported in the paper from scratch: the corrected graph, both benchmark tasks (manufacturer–product relation completion, and recorded-material-relation recovery), both image-fusion designs, and the data-quality verification scripts. It is a flat layout on purpose (scripts use simple relative filenames, matching how they were developed) — run everything with this directory as your working directory.

License: CC BY 4.0, confirmed. Authors: Yunqing Li and Zixiang Tang (co-first-authors, both Lenovo). Contact: yli59@lenovo.com. PROVENANCE_AND_ETHICS.md documents a direct written record of SUDOKN lead Farhad Ameri personally and repeatedly supplying this exact source data for this explicitly-stated benchmark-paper purpose; Lenovo IP clearance is confirmed. Code: https://github.com/llmresearchbase/PMGraph · Data: https://huggingface.co/datasets/shawntzx/PMGraph (revision v2). CHANGELOG.md documents what changed vs. the prior HuggingFace release and the maintenance plan going forward.

Setup

Requires Python 3.11 or 3.12 (the pinned pandas==3.0.6/numpy==2.5.3 wheels target these; not tested on other versions).

python -m venv .venv

Activate it, then install — Windows (cmd.exe):

.venv\Scripts\activate
pip install -r requirements.txt

macOS/Linux (bash):

source .venv/bin/activate
pip install -r requirements.txt

pip install -r requirements.txt installs CPU-only PyTorch by default on Windows (confirmed: a plain pip install with no --index-url, on a system with no pre-cached GPU build, pulls the CPU wheel) — every script in this package runs fine on CPU, just slower for the GNN steps (minutes, not hours, at this graph's scale). For a CUDA build instead, install PyTorch first from https://pytorch.org/get-started/locally/ for your CUDA version, then run pip install -r requirements.txt (it will not downgrade an already-satisfied torch pin). This is separate from the VLM track's own isolated venv (step 8), which has its own, newer PyTorch/CUDA requirement.

Get the data files

The four largest data files are hosted on HuggingFace rather than in the git repository. Download them into the repository root (the scripts expect a flat layout):

pip install -U huggingface_hub
hf download shawntzx/PMGraph Cleaned_Master_CSV_v3.csv hetero_graphs/Graph_A.pt frozen_split_GraphA_seed42.pt manufacturer_image_release_asset.pt --repo-type dataset --revision v2 --local-dir .

What's included vs. what you build locally

Included in this package Regenerated by running a script
Cleaned_Master_CSV_v3.csv (source directory) hetero_graphs/Graph_A.pt is included too, but Graph-A-Builder.py rebuilds it identically — run audit_edge_fidelity.py to verify this yourself
manufacturer_image_release_asset.pt (embeddings + website URLs, no raw images) —
manufacturer_validity_mask.pt, excluded_entries_v1.json —
Frozen splits (frozen_split_GraphA_seed42.pt, material_task_split.json, material_edges.pt) —
manufacturer_features_no_material.pt build_material_task_features.py rebuilds it
experiment1_sage_checkpoint.pt (the archived Task A checkpoint) step 2 below retrains its own fresh copy from scratch — shipping the archived checkpoint lets you run diagnose_task_a_checkpoint_device.py for a fixed-checkpoint, inference-only reproduction check, independent of Task A's documented cross-environment (CPU/GPU) training-time non-determinism (Section 5.1)

Images are not included as pixel data. manufacturer_image_release_asset.pt carries, per manufacturer: a 32-dim SVD-compressed and a 768-dim raw Jina-CLIP image embedding (None/zero-equivalent where has_image is False), plus each manufacturer's website URL (domain-level, not a per-image link — no per-image URL was ever recorded during collection). See DATA_CARD.md and the paper's Section 6 for why.

Step-by-step: reproduce every result

Run these from the repository root.

1. Verify the graph's build-reproducibility (Section 3.4)

python audit_edge_fidelity.py

Expect: identical edge sets (same m2i/p2i ordering): True, and the same 15-row / 11-graph-node known-issue list reported in the paper's Section 3.5.

2. Task A — manufacturer–product relation completion (Section 4.1, 5.1)

python experiment1_sage_grouped.py          # trains SAGE, saves experiment1_sage_checkpoint.pt
python experiment1_grouped_baselines.py     # degree baseline (+ an INVALID textsim column, see below), random negatives
python experiment1_degree_matched_robustness.py   # reuses the SAGE checkpoint; ALSO recomputes degree
                                                    # (+ same invalid textsim) under degree-matched negatives
python experiment1_degree_baseline_precision_check.py   # confirms degree-matched AUC is ~0.500, not exactly 0.5
python experiment1_textsim_shared_space.py              # the CORRECTED textsim baseline -- use this one

Expect: singleton-bucket SAGE AUC ≈0.7346 (random negatives) from the first script, ≈0.578 (degree-matched negatives) from the third — the sensitivity reported in Section 5.1. This step's SAGE training is NOT guaranteed to reproduce these numbers closely on CPU, and unlike the Task B steps below this was NOT previously disclosed — found via an independent third-party rerun, then diagnosed to a confirmed root cause (not left as a guess). That rerun (CPU-only torch, fixed seed=42, this package's own requirements.txt) got singleton AUC=0.8155 (vs. archived 0.7346) and overall test AUC=0.6945 (vs. this same script's own archived full-test-set figure of 0.5998 — note this is a different number from the 0.6012 you may see elsewhere in the paper's Section 5.1 sensitivity table, which is computed on the 45-positive-smaller subset retained after degree-matching exclusions, not the full test set; both are correctly archived, for different populations) — an 8-11 point absolute gap, larger than anything seen in the MLP-based Task B steps. Three checks pinned this down, not left as a hedge: (1) graph/split/CSV/scripts are byte-identical (md5) between the archive and this package, and pinned dependency versions match exactly — the only difference found was torch==2.5.1+cu121 (GPU build, archived) vs. +cpu (CPU build, the default pip install path on Windows, Section above); (2) the archived, already-trained checkpoint evaluated on CPU vs. GPU gave identical results to 6 decimals — ruling out inference/eval as the source; (3) retraining from scratch with the same seed on the original GPU machine reproduced the archived metrics exactly (though not byte-identical weights) — ruling out ordinary same-machine training chaos. Conclusion: this is specifically a cross-environment (CPU-vs-GPU) training-time effect — CPU/GPU floating-point non-associativity in graph-convolution scatter-reduce operations compounding over many training epochs, to which Task A's graph convolutions are considerably more exposed than Task B's plain 2-layer MLP (0.1-0.15pp gap under the same kind of check). Do not expect a close reproduction of the exact AUC numbers for this step on CPU; expect the same qualitative finding instead (SAGE clearly exceeds simple baselines under random negatives; that advantage shrinks sharply but does not vanish under degree-matched negatives). The degree-matched robustness script (third command above) reuses this step's own checkpoint rather than retraining, so its own divergence from the archived ≈0.578 is an echo of this same root cause, not an independent issue.

The textsim column printed by the second and third scripts is INVALID (cosine similarity between two independently-fit SVD spaces that share no basis — found and fixed this round, see Graph-A-Builder.py's separate manufacturer/product TF-IDF+SVD fits) — use experiment1_textsim_shared_space.py's output instead, which fits one shared TF-IDF vocabulary over both sides. The fifth script also confirms the degree-matched degree baseline's AUC is ≈0.500 (0.500010 at 6-decimal precision — the 2.41% non-exact fallback matches keep it from being exactly 0.5), not "0.5 by construction" as an earlier draft claimed.

3. Task B, no-graph feature baseline (Section 5.2) — run this first

python material_recovery_mlp_baseline.py   # 3 seeds, no message passing at all

Expect: Recall@5/@10 ≈ 0.5312±0.0008 / 0.7284±0.0020 (has-image group) — matching or slightly exceeding the GNN baseline in step 5 below, with much tighter seed-to-seed variance. This script has no graph-convolution kernels, so it does not carry the GPU/cuDNN non-determinism the GNN scripts below do — but an independent third-party rerun on a different machine (Section 7.1 of the paper) found it is not byte-identical across environments either: that rerun's per-seed LR grid-search selected a different learning rate than the archived run for every seed, landing at Recall@5/@10 = 0.5326±0.0038 / 0.7295±0.0017 — close (≈0.1–0.15pp off) but not exact. This is ordinary CPU floating-point non-associativity (no BLAS/ thread-count pinning, no torch.use_deterministic_algorithms(True)) tipping early-stopping/LR-selection onto a different grid point on different hardware, not a package bug — but do not expect a byte-identical reproduction on a machine other than the one that produced the archived numbers; expect the same magnitude and the same qualitative finding (matches or slightly exceeds the GNN baseline, tighter variance) instead. Read this result before the GNN results below — it's the reference point that makes clear how much signal already exists before any graph structure or image is added.

Optionally, verify this isn't leakage/overfitting: python material_recovery_mlp_overfitting_check.py (reports train vs. val vs. test Recall at the selected checkpoint — expect a small ~0.8pp train-test gap on Recall@10, essentially none on Recall@5).

4. Task B, no-graph MLP + image — completes the 2x3 comparison (Section 5.2)

python material_recovery_mlp_image_baseline.py   # 3 seeds, real + zeroed image, no graph

Answers whether Design A's image signal (step 5) is specific to the GNN's propagation mechanism, or shows up in a model with no graph access at all. Expect: real-vs-zeroed ΔRecall@5=+0.91pp±0.37, ΔRecall@10=+0.80pp±0.23 (has-image group), positive across all 3 seeds on both metrics — similar magnitude to the GNN's own real-vs-zeroed signal (step 5), slightly larger. This is reported in the paper as the strongest evidence that the image signal is a property of the information itself, not of a specific architecture's ability to exploit it — read the full 2x3 table in Section 5.2 before drawing conclusions from either baseline in isolation. Calibration note: an independent CPU-only rerun of this exact script got ΔRecall@5=+1.66pp (vs. archived +0.91pp) — still positive on all 3 seeds, same qualitative finding, but nearly 2x the archived magnitude. This is a single-sample realization within the variance this project has already measured for this exact quantity (manufacturer-level bootstrap CI, Section 5.2: cross-seed std ≈0.37-0.55pp for this delta) — not a new, separate instability, but worth knowing the real-world spread can land this far from the archived mean on a single run.

5. Task B, Design A — concat + 32-dim SVD image fusion (Section 4.2, 5.2)

python material_recovery_pilot.py       # single-seed sanity + full LR grid
python material_recovery_multiseed.py   # 3 seeds (42/43/44), the paper's reference numbers

Expect: the 3-seed, has-image-group Recall@5/@10 absolute values and real-vs-zeroed / real-vs-text deltas reported in Section 5.2's Design A table.

Verified while assembling this package: the deterministic part of this pipeline (the frequency baseline, which involves no training) reproduced the paper's number exactly (0.4799/0.6766). The trained conditions reproduced results of the same character but not byte-identical to the archived seed=42 row — on a GPU, re-running the same seed can select a different LR from the grid and land at a different trained result, because cuDNN convolution kernels are not guaranteed bit-reproducible across runs even with a fixed seed.

We also ran the full 3-seed material_recovery_multiseed.py once, independently, from inside this package (results/material_recovery_multiseed_results_INDEPENDENT_RERUN.md) — this is real additional evidence, not a hypothetical caveat:

has-image group Paper's archived numbers This independent rerun
Real − zeroed, ΔRecall@5 +0.81pp ± 0.50, positive all 3 seeds +1.30pp ± 1.06, positive all 3 seeds
Real − zeroed, ΔRecall@10 +0.62pp ± 0.22, positive all 3 seeds +1.17pp ± 0.65, positive all 3 seeds
Real − text-only, ΔRecall@5 +0.16pp, sign flips across seeds −0.42pp ± 0.15, consistently negative this time
Real − text-only, ΔRecall@10 +1.49pp, positive all 3 seeds +0.31pp ± 0.42, mixed this time

Read this precisely: the paper's central multimodal finding — real image beats its same-architecture zeroed control, direction-consistent across all 3 seeds, on both Recall@5 and Recall@10 — replicated independently on a completely separate rerun. The exact magnitudes did not match (expected, per the GPU non-determinism above), and were in fact larger here. The weaker, already-heavily-hedged real-vs-text-only comparison not only has different magnitudes but a different qualitative pattern this time (R5 flipped from inconsistent-sign to consistently negative) — this is further evidence that comparison specifically should not be treated as a stable finding, consistent with how the paper already characterizes it. Treat the archived 3-seed numbers as the paper's authoritative reference; use this rerun as confirmation that the pipeline is correctly wired and that the real-vs-zeroed direction is robust to at least one full independent re-execution, not as a second number to average in.

6. Task B, Design B — raw 768-dim + independent-projection fusion (Section 5.2)

python material_recovery_v2_fusion.py --sanity   # quick single-seed check
python material_recovery_v2_fusion.py            # full 3-seed run

Expect: Design B's text-only/real/zeroed absolute values. No single numeric target exists for the --sanity single-seed run specifically — it was historically used only to confirm the pipeline runs end-to-end, not as a citable reference point (confirmed via an independent third-party check, which correctly flagged this as a documentation gap). The closest available reference is results/material_recovery_v2fusion_results.md's own seed=42 row (full 3-seed run) — but expect wide swings, not just small numeric drift: that file's own 3 seeds already span Recall@10 from 0.45 to 0.79 across conditions (Design B is independently disclosed elsewhere in this README/paper as highly seed-unstable), so a --sanity rerun landing far from any single archived row is consistent with, not contrary to, what's already known about this design. Note the confound documented in the paper's Section 5.2: Design B's model (IndependentFusionSAGE) applies a LayerNorm to the text branch in every condition, including text_only — Design A's HeteroSAGE does not. The two designs' text-only baselines are not the same implementation; do not treat a Design A/B difference as isolating "compression" or "fusion method" alone.

7. Architecture-equivalence verification (Section 5.3)

python check3_round4_architecture_equivalence.py

Expect: both checks PASS, max abs diff 0.0 on the weight-transplant check. This does not retrain anything — it uses shared (not necessarily trained) weights to verify the real/zeroed comparison's architecture is sound, independent of any specific training run.

8. Task B, VLM zero-shot comparison — Qwen3-VL-2B-Instruct (Section 5.4)

cd vlm_experiment
python -m venv .venv   # SEPARATE venv — needs transformers>=4.57, torch>=2.9,
                        # incompatible with the pinned transformers/torch used
                        # by every other script in this package
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
pip install transformers accelerate qwen-vl-utils pillow pandas huggingface_hub
python run_vlm_eval.py --mode test
python analyze_vlm_test_results.py

Raw website images are not shipped in this package (consistent with the no-pixel-redistribution stance in Section 6) — image_manifest.json records each used image's manufacturer, order, and SHA-256 hash, but re-running from scratch requires re-deriving them from the same HF-hosted scrape (vlm_select_images.py shows how). The frozen outputs (vlm_results_test.json/.jsonl, vlm_test_analysis.json) are included so the paper's Section 5.4 numbers can be checked without re-running the model at all. Expect (has-image test, n=605, paired): TEXT Recall@5/@10 = 0.2483/0.3351, TEXT+IMAGE = 0.1858/0.3070, bootstrap 95% CI on both paired differences excluding zero (both negative) — see vlm_test_analysis.json.

9. Supplementary post-hoc metric — Hit@1 (Section 5.5)

python material_recovery_hit_at_1.py         # MLP track: reuses the already-
                                               # selected per-seed LRs from
                                               # step 3/4, no new search
cd vlm_experiment && python vlm_hit_at_1.py   # VLM track: re-parses the
                                               # already-saved raw text from
                                               # step 8, zero rerun

This is explicitly a post-hoc metric (computed after the Recall@5/@10 results above had already been seen) and supplements, not replaces, those results — see Section 5.5's disclosure before citing these numbers alone. vlm_hit_at_1.py reports both a PRIMARY view (full 605-manufacturer population, zero-valid-response cases scored as misses — the number cited in the paper) and a SECONDARY view (matched 586-subset excluding those cases), listed together for transparency.

10. Manufacturer-level bootstrap CI for the real−zeroed image difference (Section 5.2)

python material_recovery_image_diff_ci.py       # MLP track: reuses already-
                                                   # selected per-seed LRs,
                                                   # deterministic, no new search
python material_recovery_gnn_image_diff_ci.py   # GNN track: same, but GNN
                                                   # training is NOT bit-
                                                   # reproducible (GPU/cuDNN) --
                                                   # point estimates will differ
                                                   # slightly from step 5's
                                                   # archived table, expected

Answers a different question from the cross-seed mean±std already reported: how much uncertainty does the test-set sample size itself contribute, at a fixed trained model? Expect the point-estimate direction to be positive in nearly every seed/metric/model combination (matching the cross-seed pattern), but the manufacturer-level bootstrap CI to exclude zero in only some of them — reported honestly as a small, direction-consistent-but-not- uniformly-significant effect, not oversold as statistically certain.

11. Task A pairwise no-graph MLP baseline (Section 4.1, 5.1)

python experiment1_pairwise_mlp.py

A feature-only pairwise MLP (manufacturer 64-dim attribute feature concatenated with the candidate product's 64-dim TF-IDF feature, no edge_index, no graph convolution) trained with the same frozen split and FocalLoss as SAGE, LR selected from its own validation-only grid. Single run (seed 42). Reports AUC under both negative-sampling protocols, plus a population-matched re-score of SAGE/Degree/Shared-space-text on the exact same 11,214-positive population used by the archived SAGE=0.6012 figure. Expect: overall AUC exceeds SAGE under both protocols; SAGE still leads on singleton pairs under random negatives, but that ordering reverses under degree-matched negatives.

12. Task B text-mention grouping diagnostic (Section 4.2, 5.2)

python experiment_task_b_text_mention_grouping.py

Stratifies the 7,830 test positive (manufacturer, material) pairs by whether the target material is word-boundary-mentioned in the manufacturer's visible text (product strings, business description, NAICS description — never the masked Material_Capability field). Reports a per-label Hit@5/@10 (not the per-manufacturer Recall@K used elsewhere — different averaging unit, not directly comparable) for Frequency and the already-archived single-seed attributes-only MLP. Expect: ~86% of positives have no detected mention; the MLP still exceeds Frequency on that harder group.

13. Random relation-correctness audit (Section 3.4, item 4)

python random_relation_audit.py

Reproduces the deterministic random sample only (seed=2026, n=20 of 112,930 raw manufacturer-product rows); the plausibility judgments themselves (17 plausible, 1 borderline, 2 confirmed errors — 3 cases cross-checked against the live manufacturer website) are recorded by hand in random_relation_audit_results.md, not re-derived by the script.

Known data-quality issue (Section 3.5) — disclosed, not silently fixed

manufacturer_validity_mask.pt flags 3 confirmed non-manufacturer nodes (exact indices: 0, 5516, 6236) and 3 extraction-artifact edges on a 4th node (index 1712), at the current node/edge indexing — no reindexing needed to use it. All results this package reproduces (steps 2–5 above) were computed without this mask applied; it is provided for anyone building on this resource going forward. See excluded_entries_v1.json for the full reasoning per entry, and the paper's Section 3.5 for why it wasn't retroactively applied here (reindexing would desynchronize the frozen splits above).

Checked directly, not left as an open question: apply_validity_mask_task_a.py re-scores the archived Task A checkpoint with every mask-affected test pair removed (overall/singleton AUC change by at most 0.0001; 9 of 22,518 test pairs affected), and apply_validity_mask_task_b.py reruns Task B's attributes-only MLP baseline's 3-seed protocol with the one affected training example removed (Recall@5/@10 change by at most 0.0021, within the baseline's existing seed-to-seed std). Run either script from this directory to reproduce; results are also archived in apply_validity_mask_task_a_results.md / apply_validity_mask_task_b_results.md.

File reference

File Role
Graph-A-Builder.py Builds the graph from the source CSV
audit_edge_fidelity.py Full-population build-reproducibility + known-issue screen
LP-ABCD.py Shared HeteroSAGE, FocalLoss, train/eval helpers
freeze_split.py Produces frozen_split_GraphA_seed42.pt (Task A split)
experiment1_sage_grouped.py / experiment1_degree_matched_robustness.py Task A training + the two negative-sampling protocols
build_material_task_split.py / _features.py / _edges.py Produce Task B's frozen vocab/split/features/edges
material_recovery_mlp_baseline.py Task B, no-graph feature-only baseline
material_recovery_mlp_overfitting_check.py Verifies the MLP baseline isn't leakage/overfitting — reports train vs. val vs. test Recall
material_recovery_mlp_image_baseline.py Task B, no-graph MLP + real/zeroed image — completes the 2x3 model×image table
material_recovery_pilot.py / _multiseed.py Task B, Design A (concat + 32-dim)
material_recovery_v2_fusion.py Task B, Design B (raw 768-dim + independent projection)
check3_round4_architecture_equivalence.py Section 5.3's verification
experiment1_grouped_baselines.py / experiment1_degree_matched_robustness.py Section 5.1 — degree training-free baseline under both negative-sampling protocols (their textsim column is invalid — superseded)
experiment1_degree_baseline_precision_check.py Section 5.1 — confirms degree-matched degree-baseline AUC is ≈0.500, not exactly 0.5
experiment1_textsim_shared_space.py Section 5.1 — the CORRECTED textsim baseline (shared TF-IDF space); use this, not the one printed by the two scripts above
make_resource_diagram.py Section 3's Figure 1 (resource schema) — regenerates figures/resource_schema.png/.svg
material_recovery_image_diff_ci.py / _gnn_image_diff_ci.py Section 5.2 — manufacturer-level bootstrap CI for the real−zeroed difference, MLP and GNN tracks
material_recovery_hit_at_1.py Section 5.5, MLP track — Hit@1 with already-selected LRs, no new search
vlm_experiment/run_vlm_eval.py Section 5.4 — Qwen3-VL-2B-Instruct zero-shot TEXT/TEXT+IMAGE eval (separate venv)
vlm_experiment/vlm_hit_at_1.py Section 5.5, VLM track — re-parses already-saved raw text, zero rerun
vlm_experiment/vlm_select_images.py / vlm_build_text_fields.py Builds the VLM track's image selection + text-field inputs
vlm_experiment/analyze_vlm_test_results.py Section 5.4's Recall@K, bootstrap CIs, parse diagnostics
results/ Reference outputs this code should reproduce

Full claim-by-claim traceability is in the paper's own Appendix.