Plaiglab / scripts /gen_corpus.py
SanidhyaDhangar's picture
PlaigLab — Hugging Face Space (Docker) clean deploy
ebebfe8
Raw
History Blame Contribute Delete
16.1 kB
"""Generate the synthetic source corpus (simulating tiered internet sources)
and four test submissions with known ground truth:
clean.txt -- original paper on a topic absent from the corpus
clone.txt -- lit review + methodology copied verbatim from a tier-1 source
mosaic.txt -- lit review woven from two IoT sources with synonym tweaks
idea.txt -- same study as a source, fully re-rendered (idea plagiarism)
"""
import json
import os
import sys
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from plagdetect.textutils import mosaic_mix, sentences, synonymize # noqa: E402
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CORPUS_DIR = os.path.join(ROOT, "data", "corpus")
SUB_DIR = os.path.join(ROOT, "data", "submissions")
TOPICS = {
"bh": dict(tech="consortium blockchain", domain="healthcare data management",
entity="electronic health records", problem="patient privacy leakage",
method="smart-contract based access control", tool="Hyperledger Fabric",
metric="data breach incidence", adj="patient-centric"),
"io": dict(tech="lightweight intrusion detection", domain="industrial IoT networks",
entity="sensor telemetry streams", problem="botnet infiltration",
method="federated anomaly detection", tool="edge gateway accelerators",
metric="attack detection latency", adj="energy-aware"),
"cr": dict(tech="multispectral deep learning", domain="precision agriculture",
entity="UAV-captured field imagery", problem="late blight outbreaks",
method="attention-based disease classification", tool="ResNet-50 backbones",
metric="seasonal yield loss", adj="smallholder-friendly"),
"ed": dict(tech="immersive virtual reality", domain="engineering education",
entity="laboratory simulations", problem="declining skill transfer",
method="haptic-guided procedural training", tool="Unity XR toolkit",
metric="skill retention", adj="curriculum-aligned"),
"tg": dict(tech="spatio-temporal graph networks", domain="urban traffic management",
entity="loop detector measurements", problem="recurrent congestion spillback",
method="graph attention flow forecasting", tool="adaptive signal controllers",
metric="average commute delay", adj="city-scale"),
}
CLEAN_TOPIC = dict(tech="autonomous drone logistics", domain="last-mile parcel delivery",
entity="aerial delivery corridors", problem="payload routing inefficiency",
method="multi-agent route negotiation", tool="ROS2 flight stacks",
metric="delivery turnaround time", adj="weather-resilient")
SURNAMES = ["Sharma", "Chen", "Gupta", "Okafor", "Martinez", "Kim", "Patel",
"Nguyen", "Silva", "Hassan", "Tanaka", "Kowalski", "Mehta", "Johansson"]
VENUES = ["IEEE Access", "ACM Computing Surveys", "Future Generation Computer Systems",
"Journal of Network and Computer Applications", "Sensors",
"IEEE Transactions on Industrial Informatics",
"Expert Systems with Applications", "IEEE Internet of Things Journal"]
SECTIONS = ["abstract", "introduction", "literature_review", "methodology",
"results", "conclusion"]
# Two disjoint template sets: P renders corpus papers, A renders the
# "idea plagiarism" re-write (same facts, different surface form).
P = {
"abstract": [
"This paper proposes a {adj} {tech} framework for {domain}.",
"We address {problem} by introducing {method} built on {tool}.",
"Experiments on {n} cases show a {imp}% improvement in {metric}.",
"The framework demonstrates an F1 score of {f1} with p = {p}.",
"Our findings establish {tech} as a practical remedy for {problem}.",
],
"introduction": [
"The rapid growth of {entity} has made {problem} a central concern for {domain} [{r1}].",
"Conventional safeguards struggle to keep pace with the scale of modern {entity} [{r2}].",
"Recent advances in {tech} offer a promising direction for {domain}.",
"However, existing deployments rarely integrate {method} in an end-to-end manner.",
"In this paper we design, implement, and evaluate a {adj} pipeline that couples {tech} with {method}.",
"Our contributions include a reference architecture on {tool} and an evaluation across {n} cases.",
"The remainder of this paper reviews prior work, details the methodology, and reports results.",
],
"literature_review": [
"Early studies of {tech} focused primarily on feasibility within {domain} [{r1}].",
"Subsequent work between {y0} and {y1} shifted attention toward {method} [{r2}].",
"Several authors report that {problem} remains the dominant failure mode in production systems [{r3}].",
"Benchmark efforts using {tool} demonstrate significant gains in {metric} [{r4}].",
"A recurring limitation across these studies is the absence of {adj} evaluation protocols.",
"Surveys of {domain} consistently identify {entity} as the most vulnerable asset class [{r1}].",
"Despite this progress, no prior work unifies {tech} and {method} under realistic workloads.",
],
"methodology": [
"Our research design follows a controlled experimental protocol over {n} cases collected from {y0} to {y1}.",
"The core of the system is {method} implemented on {tool}.",
"Each instance of {entity} is normalized, segmented, and assigned a cryptographic provenance tag.",
"We configure the {tech} layer with a three-stage validation pipeline to suppress {problem}.",
"Hyper-parameters were selected by grid search, holding out 20% of cases for validation.",
"Statistical significance is assessed with paired tests at alpha = 0.05.",
"All experiments are repeated five times and we report the mean with confidence intervals.",
],
"results": [
"The proposed framework improves {metric} by {imp}% relative to the strongest baseline.",
"Across {n} cases the system attains an F1 score of {f1} with p = {p}.",
"Ablation shows that removing {method} degrades performance by {imp2}%.",
"Latency overhead introduced by the {tech} layer remains below acceptable operational thresholds.",
"These results confirm that {adj} integration of {tool} is feasible at scale.",
"Error analysis attributes most residual failures to noisy {entity}.",
],
"conclusion": [
"We presented a {adj} {tech} framework that mitigates {problem} in {domain}.",
"Evaluation over {n} cases demonstrated a {imp}% improvement in {metric}.",
"Future work will extend {method} to cross-organizational settings.",
"We will also study the long-term governance of {entity} under this architecture.",
],
}
A = {
"abstract": [
"A {adj} architecture leveraging {tech} is introduced for {domain}.",
"To counter {problem}, the design embeds {method} on top of {tool}.",
"An evaluation spanning {n} cases records {imp}% better {metric}.",
"F1 reaches {f1} and the effect is significant at p = {p}.",
"The evidence positions {tech} as a credible answer to {problem}.",
],
"introduction": [
"{problem} has become unavoidable as {entity} proliferate across {domain} [{r1}].",
"Legacy protections were never engineered for today's volume of {entity} [{r2}].",
"{tech} has recently matured into a viable foundation for {domain}.",
"Yet end-to-end adoption of {method} remains rare in deployed systems.",
"Here we build and assess a {adj} stack uniting {tech} with {method}.",
"We contribute a {tool} reference design plus a study of {n} cases.",
"The paper proceeds through related work, methods, and findings.",
],
"literature_review": [
"Initial investigations asked whether {tech} could work at all inside {domain} [{r1}].",
"From {y0} to {y1}, the community pivoted toward {method} [{r2}].",
"Multiple groups observe that {problem} still dominates operational incidents [{r3}].",
"Evaluations built on {tool} report meaningful movement in {metric} [{r4}].",
"What these efforts share is a lack of {adj} testing regimes.",
"Review articles repeatedly single out {entity} as the weakest link [{r1}].",
"Still missing is a treatment that joins {tech} and {method} under production load.",
],
"methodology": [
"We run a controlled experiment on {n} cases gathered between {y0} and {y1}.",
"{method} sits at the heart of the platform, realized with {tool}.",
"Every {entity} record is cleaned, partitioned, and stamped with provenance metadata.",
"A three-phase validation chain in the {tech} layer guards against {problem}.",
"Grid search over a 20% held-out split fixes all hyper-parameters.",
"Paired significance testing uses alpha = 0.05 throughout.",
"Five repetitions per condition yield means and confidence bounds.",
],
"results": [
"{metric} improves by {imp}% over the best competing baseline.",
"On {n} cases the platform reaches F1 = {f1} at p = {p}.",
"Dropping {method} in ablation costs {imp2}% of performance.",
"Overhead from the {tech} layer stays within operational budgets.",
"{adj} deployment of {tool} therefore scales in practice.",
"Most remaining errors trace back to corrupted {entity}.",
],
"conclusion": [
"This work delivered a {adj} {tech} stack that curbs {problem} in {domain}.",
"A study of {n} cases yielded {imp}% gains in {metric}.",
"Extending {method} across organizations is the next step.",
"Governance of {entity} over long horizons also merits study.",
],
}
def sample_vals(rng):
return dict(imp=int(rng.randint(38, 82)), imp2=int(rng.randint(9, 36)),
n=int(rng.randint(120, 950)),
p=round(float(rng.uniform(0.001, 0.04)), 3),
f1=round(float(rng.uniform(0.81, 0.96)), 2),
y0=int(rng.randint(2015, 2019)), y1=int(rng.randint(2019, 2023)),
r1=int(rng.randint(1, 11)), r2=int(rng.randint(1, 11)),
r3=int(rng.randint(1, 11)), r4=int(rng.randint(1, 11)))
def render_sections(terms, vals, rng, alt=False):
tpl = A if alt else P
mapping = {**terms, **vals}
secs = {}
for sec in SECTIONS:
pool = tpl[sec]
k = min(len(pool), 6)
idx = rng.choice(len(pool), size=k, replace=False)
secs[sec] = " ".join(pool[i].format(**mapping) for i in sorted(idx))
return secs
def make_refs(terms, rng):
titles = [
"A survey of {tech} in {domain}", "{method}: opportunities and challenges",
"Securing {entity} with {tech}", "Towards {adj} {domain}",
"Mitigating {problem} using {method}", "{tool} in practice",
"Benchmarking {metric} under {tech}", "Rethinking {problem}",
"On the limits of {tech} for {entity}", "{domain}: a systematic review",
"Adaptive {method} for dynamic environments",
"Privacy and {entity}: an empirical study",
"A framework for {adj} deployment of {tool}",
"Deep evaluation of {method} at scale",
]
refs = []
for t in titles:
a = str(rng.choice(SURNAMES))
v = str(rng.choice(VENUES))
y = int(rng.randint(2015, 2024))
refs.append(f'{a[0]}. {a}, "{t.format(**terms).capitalize()}," {v}, {y}')
return refs
def make_title(terms, rng, alt=False):
forms = (["{adj} {tech} for {domain}: an empirical study",
"Mitigating {problem} with {method}",
"{tech} meets {domain}: design and evaluation"] if not alt else
["Rethinking {domain} through {adj} {tech}",
"{method} against {problem}: a new architecture"])
return str(rng.choice(forms)).format(**terms).capitalize()
def paper_txt(title, secs, refs):
head = {"abstract": "Abstract", "introduction": "1. Introduction",
"literature_review": "2. Literature Review",
"methodology": "3. Methodology", "results": "4. Results",
"conclusion": "5. Conclusion"}
lines = [title, ""]
for k in SECTIONS:
lines += [head[k], secs[k], ""]
lines.append("References")
lines += [f"[{i + 1}] {r}." for i, r in enumerate(refs)]
return "\n".join(lines)
def main():
os.makedirs(CORPUS_DIR, exist_ok=True)
os.makedirs(SUB_DIR, exist_ok=True)
rng = np.random.RandomState(123)
topic_refs = {k: make_refs(t, rng) for k, t in TOPICS.items()}
forced_tiers = {"bh02": 1, "io01": 1, "io05": 2, "tg02": 1}
corpus = {}
for key, terms in TOPICS.items():
for i in range(12):
doc_id = f"{key}{i:02d}"
vals = sample_vals(rng)
secs = render_sections(terms, vals, rng, alt=False)
refs = [str(r) for r in rng.choice(topic_refs[key], 9, replace=False)]
other = str(rng.choice([k for k in TOPICS if k != key]))
refs += [str(r) for r in rng.choice(topic_refs[other], 2, replace=False)]
tier = forced_tiers.get(doc_id,
int(rng.choice([1, 2, 3, 4],
p=[0.4, 0.3, 0.2, 0.1])))
doc = {"doc_id": doc_id, "title": make_title(terms, rng),
"sections": secs, "references": refs, "tier": tier,
"year": int(rng.randint(2016, 2024)),
"topic": key, "vals": vals}
corpus[doc_id] = doc
with open(os.path.join(CORPUS_DIR, f"{doc_id}.json"), "w",
encoding="utf-8") as f:
json.dump(doc, f, indent=1)
# ---- submissions -------------------------------------------------------
subs = {}
vals = sample_vals(rng)
secs = render_sections(CLEAN_TOPIC, vals, rng)
subs["clean"] = paper_txt(make_title(CLEAN_TOPIC, rng), secs,
make_refs(CLEAN_TOPIC, rng)[:9])
src = corpus["bh02"]
vals = sample_vals(rng)
secs = render_sections(TOPICS["bh"], vals, rng)
secs["literature_review"] = src["sections"]["literature_review"]
secs["methodology"] = src["sections"]["methodology"]
refs = [str(r) for r in rng.choice(topic_refs["bh"], 8, replace=False)]
subs["clone"] = paper_txt(make_title(TOPICS["bh"], rng), secs, refs)
s1, s2 = corpus["io01"], corpus["io05"]
vals = sample_vals(rng)
secs = render_sections(TOPICS["io"], vals, rng)
secs["literature_review"] = mosaic_mix(
sentences(s1["sections"]["literature_review"]),
sentences(s2["sections"]["literature_review"]), rng)
secs["results"] = synonymize(s1["sections"]["results"], rng, p=0.5)
refs = [str(r) for r in rng.choice(topic_refs["io"], 8, replace=False)]
subs["mosaic"] = paper_txt(make_title(TOPICS["io"], rng), secs, refs)
src = corpus["tg02"]
rng_idea = np.random.RandomState(777)
secs = render_sections(TOPICS["tg"], src["vals"], rng_idea, alt=True)
refs = [str(r) for r in rng_idea.choice(src["references"], 6, replace=False)]
subs["idea"] = paper_txt(make_title(TOPICS["tg"], rng_idea, alt=True),
secs, refs)
for name, txt in subs.items():
with open(os.path.join(SUB_DIR, f"{name}.txt"), "w", encoding="utf-8") as f:
f.write(txt)
truth = {"clean": ["CLEAN"], "clone": ["PLAGIARIZED"],
"mosaic": ["PLAGIARIZED", "SUSPICIOUS"],
"idea": ["SUSPICIOUS", "PLAGIARIZED"]}
with open(os.path.join(SUB_DIR, "truth.json"), "w", encoding="utf-8") as f:
json.dump(truth, f, indent=1)
print(f"corpus: {len(corpus)} docs -> {CORPUS_DIR}")
print(f"submissions: {list(subs)} -> {SUB_DIR}")
if __name__ == "__main__":
main()