BehaviorBench / scripts /generate_croissant.py
mingzhu0527's picture
Release BehaviorBench artifact (from lyang84/BehaviorBench-camera-ready)
f9b150b verified
Raw History Blame Contribute Delete
8.66 kB
#!/usr/bin/env python3
"""Generate Croissant 1.1 + minimal RAI metadata for BehaviorBench."""
import hashlib
import json
from pathlib import Path
import pyarrow as pa
import pyarrow.parquet as pq
ROOT = Path(__file__).resolve().parents[1]
BASE = "https://huggingface.co/datasets/Salesforce/BehaviorBench"
RAW = BASE + "/resolve/main/"
def field_type(t):
"""Return (Croissant type, repeated) for validator-safe scalar fields.
Current mlcroissant record generation cannot reliably cast nested Parquet
struct values (including list<struct<...>>). Those columns remain present
in the distributed Parquet files but are omitted from RecordSet fields.
"""
repeated = False
if pa.types.is_list(t) or pa.types.is_large_list(t):
t = t.value_type
repeated = True
if pa.types.is_boolean(t): return "sc:Boolean", repeated
if pa.types.is_integer(t): return "sc:Integer", repeated
if pa.types.is_floating(t) or pa.types.is_decimal(t): return "sc:Float", repeated
if pa.types.is_string(t) or pa.types.is_large_string(t): return "sc:Text", repeated
return None
def sha256_file(path, chunk_size=8 * 1024 * 1024):
digest = hashlib.sha256()
with path.open("rb") as stream:
for chunk in iter(lambda: stream.read(chunk_size), b""):
digest.update(chunk)
return digest.hexdigest()
def canonical_files():
files=[]
for top in (ROOT/"dataset", ROOT/"benchmark"):
for p in top.rglob("*.parquet"):
# Generated evaluation source caches are provenance aids, not record sets.
if "evaluation/sources" in p.as_posix(): continue
files.append(p)
return sorted(files)
def main():
distributions=[]; recordsets=[]
for p in canonical_files():
rel=p.relative_to(ROOT).as_posix(); fid=rel
distributions.append({
"@type":"cr:FileObject", "@id":fid,
"name":rel, "contentUrl":RAW+rel,
"encodingFormat":"application/x-parquet",
"sha256":sha256_file(p),
})
pf=pq.ParquetFile(p); schema=pf.schema_arrow
rid=BASE+"#records/"+rel.removesuffix(".parquet")
fields=[]
for f in schema:
type_info = field_type(f.type)
if type_info is None:
continue
data_type, repeated = type_info
field = {
"@type":"cr:Field", "@id":rid+"/"+f.name,
"name":f.name, "dataType":data_type,
"source":{"fileObject":fid,"extract":{"column":f.name}},
}
if repeated:
field["repeated"] = True
fields.append(field)
recordsets.append({
"@type":"cr:RecordSet", "@id":rid, "name":rel,
"description":f"Rows from {rel} ({pf.metadata.num_rows:,} records).",
"field":fields,
})
doc={
"@context":{
"@language":"en", "@vocab":"https://schema.org/",
"sc":"https://schema.org/", "cr":"http://mlcommons.org/croissant/",
"rai":"http://mlcommons.org/croissant/RAI/",
"dct":"http://purl.org/dc/terms/", "prov":"http://www.w3.org/ns/prov#",
"arrayShape":"cr:arrayShape", "citeAs":"cr:citeAs",
"column":"cr:column", "conformsTo":"dct:conformsTo",
"containedIn":"cr:containedIn", "data":{"@id":"cr:data","@type":"@json"},
"dataType":{"@id":"cr:dataType","@type":"@vocab"},
"description":{"@container":"@language"},
"equivalentProperty":"cr:equivalentProperty",
"examples":{"@id":"cr:examples","@type":"@json"},
"extract":"cr:extract", "field":"cr:field",
"fileObject":"cr:fileObject", "fileProperty":"cr:fileProperty",
"fileSet":"cr:fileSet", "format":"cr:format", "includes":"cr:includes",
"isArray":"cr:isArray", "isLiveDataset":"cr:isLiveDataset",
"jsonPath":"cr:jsonPath", "key":"cr:key", "md5":"cr:md5",
"name":{"@container":"@language"}, "parentField":"cr:parentField",
"path":"cr:path", "recordSet":"cr:recordSet", "references":"cr:references",
"regex":"cr:regex", "repeated":"cr:repeated", "replace":"cr:replace",
"samplingRate":"cr:samplingRate", "separator":"cr:separator",
"source":"cr:source", "subField":"cr:subField", "transform":"cr:transform"
},
"@type":"sc:Dataset",
"name":"BehaviorBench",
"alternateName":"BehaviorBench: Modeling Real-World User Decisions from Behavioral Traces",
"description":"A benchmark derived from public Polymarket and Polygon behavioral traces for wallet-level Belief and Trade prediction under Direct, Profile, and Retrieval interfaces.",
"url":BASE,
"license":"https://www.apache.org/licenses/LICENSE-2.0",
"conformsTo":"http://mlcommons.org/croissant/1.1",
"citeAs":"BehaviorBench: Modeling Real-World User Decisions from Behavioral Traces (NeurIPS 2026 E&D submission).",
"version":"1.0.0",
"datePublished":"2026",
"inLanguage":"en",
"keywords":["behavioral modeling","user modeling","prediction markets","Polymarket","personalization","benchmark"],
"isAccessibleForFree":True,
"distribution":distributions,
"recordSet":recordsets,
"rai:dataLimitations":"Observable wallet behavior is an imperfect proxy for internal belief or preference. The sample represents active Polymarket wallets rather than the general population. Belief confidence is concentrated at 0 and 1; ties do not uniquely identify direction. Trade values use estimated mark-price conversion. Generalization beyond this platform and block range is not established.",
"rai:dataBiases":"Activity filtering favors active wallets; automated strategies, market makers, hedgers, and arbitrageurs may be overrepresented. Market topics and participation are time-dependent. Generated profiles inherit biases from their generator models.",
"rai:personalSensitiveInformation":"The data contain public pseudonymous blockchain wallet addresses and behavioral traces that may support sensitive inferences about financial interests, risk preferences, politics, or sports. No verified real-world identities or demographic attributes are included. Deanonymization and consequential use are not intended.",
"rai:dataUseCases":"Intended for research evaluation of personalized behavioral prediction, sequence modeling, profile representations, and retrieval augmentation. Not intended for identity attribution, financial advice, surveillance, credit/employment decisions, law enforcement, or targeting individuals.",
"rai:dataSocialImpact":"Potential benefits include reproducible evaluation of personalized systems. Risks include surveillance, profiling, deanonymization, manipulation, and overclaiming psychological inference from financial behavior. Mitigations are documented in docs/RESPONSIBLE_AI.md.",
"rai:hasSyntheticData":True,
"rai:dataCollection":"Derived from public Polymarket and Polygon on-chain records covering released block heights approximately 30,000,825 through 80,000,000. The release contains processed source tables rather than a complete raw chain archive.",
"rai:dataReleaseMaintenance":"Version material corrections in CHANGELOG.md; regenerate checksums and Croissant metadata for each release.",
"rai:machineAnnotationTools":"Belief and Trade labels are deterministic transformations of holdings and transactions. Profile interface fields are language-model-generated summaries and retain generator-model metadata where available.",
"prov:wasDerivedFrom":[{"@type":"sc:Dataset","name":"Public Polymarket and Polygon records","url":"https://polymarket.com/"}],
"prov:wasGeneratedBy":[
{"@type":"sc:CreateAction","name":"Belief construction","description":"Aggregate wallet-market holdings into stance and normalized position imbalance, then create fixed per-wallet temporal splits."},
{"@type":"sc:CreateAction","name":"Trade construction","description":"Order transactions by block/log index, reconstruct position changes, derive increase/decrease/close labels and estimated USDC amount, then create fixed per-wallet temporal splits."},
{"@type":"sc:CreateAction","name":"Benchmark interfaces","description":"Render Direct prompts, model-generated Profile representations, and Retrieval contexts from support wallets excluded from the experiment set."}
]
}
(ROOT/"croissant.json").write_text(json.dumps(doc,ensure_ascii=False,indent=2)+"\n")
print(f"Wrote {len(distributions)} distributions and {len(recordsets)} record sets")
if __name__=="__main__": main()