CoolFace
Apppublic

LonghaoWang/anthropic-values-explorer

sourceHugging Facemitupdated 5d agoView on Hugging Face
0likes
app.py58 linesDownload Raw Back to root
1"""Explore Anthropic public datasets on the Hub (CPU Space)."""2from __future__ import annotations3 4import gradio as gr5import pandas as pd6from datasets import load_dataset7 8CATALOG = {9    "Anthropic/hh-rlhf": "Helpful & Harmless RLHF preference pairs",10    "Anthropic/model-written-evals": "Model-written evaluation suites",11    "Anthropic/discrim-eval": "Discrimination evaluation prompts",12    "Anthropic/persuasion": "Persuasion / influence prompts",13    "Anthropic/election_questions": "Election-related question set",14    "Anthropic/values-in-the-wild": "Values / preference research signals",15    "Anthropic/EconomicIndex": "Economic index research data",16}17 18 19def load_preview(name: str, split: str, n: int):20    try:21        ds = load_dataset(name, split=split, trust_remote_code=True)22    except Exception:23        # try first available split24        dsd = load_dataset(name)25        split = list(dsd.keys())[0]26        ds = dsd[split]27    n = min(int(n), len(ds))28    rows = [ds[i] for i in range(n)]29    df = pd.DataFrame(rows)30    # stringify nested cells31    for c in df.columns:32        df[c] = df[c].map(lambda x: x if isinstance(x, (str, int, float, bool)) or x is None else str(x)[:500])33    info = f"{name} | split={split} | rows={len(ds)} | showing={n}"34    return info, df35 36 37with gr.Blocks(title="Anthropic Values Explorer") as demo:38    gr.Markdown("""# Anthropic Public Dataset Explorer39Anthropic 在 Hub 上**没有开源模型权重**,但有高质量研究数据集。本 Space 方便浏览与抽样。40""")41    name = gr.Dropdown(list(CATALOG.keys()), value="Anthropic/hh-rlhf", label="Dataset")42    desc = gr.Markdown(CATALOG["Anthropic/hh-rlhf"])43    with gr.Row():44        split = gr.Textbox(value="train", label="Split")45        n = gr.Slider(5, 100, value=20, step=5, label="Preview rows")46    btn = gr.Button("Load preview", variant="primary")47    info = gr.Textbox(label="Info")48    table = gr.Dataframe(label="Preview", wrap=True)49 50    def on_change(n_):51        return CATALOG.get(n_, "")52 53    name.change(on_change, name, desc)54    btn.click(load_preview, [name, split, n], [info, table])55 56if __name__ == "__main__":57    demo.queue().launch()58