Skip to content

hikoseon12/socialllm-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Session 1 — ICWSM 2026 Social LLM Simulation Tutorial

Topic: Hands-on materials for the Moral Machine + LLM persona experiments.

Layout

tutorial/
├── socialllm_tutorial.ipynb     # main hands-on notebook (run this)
├── tutorial_utils/              # helper modules used by the notebook
│   ├── config.py                # character pools
│   ├── generate_scenarios.py    # Moral Machine scenario generator
│   ├── prompts.py               # persona prompt templates
│   ├── llm_inference.py         # OpenAI / HuggingFace inference helper
│   ├── responses.py             # response -> conjoint long format
│   ├── scoring.py               # weighted-OLS / ACME (Python port of R)
│   ├── pipeline.py              # end-to-end: generate -> infer -> score
│   └── visualization.py         # radar-plot helpers
├── model_result/                     # pre-computed responses (CSV)
│   ├── Human/                   # aggregate human responses
│   ├── GPT-4o/                  # GPT-4o, 10k scenarios
│   ├── GPT-3.5/                 # GPT-3.5 Turbo
│   └── Llama2/                  # Llama-2-7b-chat
└── legacy_r/                    # original R scoring scripts (kept for reference;
                                 # the notebook uses tutorial_utils/scoring.py)

Each model_result/<model>/ folder has:

  • Baseline.csv – baseline (no persona) responses
  • Age.csv, Culture.csv, Education.csv, Gender.csv, Income.csv, Political.csv, Religious.csv – two-column comparisons between contrasting personas

Quick start — local Jupyter

pip install pandas numpy matplotlib seaborn statsmodels tqdm jupyter
# optional, only for Step 2 / 3 / 5 (LLM inference)
pip install openai            # if you have an OpenAI / OpenRouter API key
pip install transformers torch   # if you want the local HF fallback

jupyter notebook socialllm_tutorial.ipynb

Quick start — Google Colab

Open this Colab link directly — the notebook lives at the root of the socialllm-tutorial repo:

Open In Colab

https://colab.research.google.com/github/hikoseon12/socialllm-tutorial/blob/main/socialllm_tutorial.ipynb

Then just run the first cell ("Setup cell — run me first"). It auto-clones the repo into the Colab VM, brings tutorial_utils/ and model_result/ into the working directory, and pip-installs the required packages. Everything below then "just works".

If you don't want to use GitHub, you can also drag-and-drop the tutorial_utils/ and model_result/ folders into Colab's left-hand "Files" panel before running the rest of the cells.

Steps in the notebook

  1. Hands-on judging – go to https://www.moralmachine.net/ and answer the 13 scenarios yourself.
  2. LLM responses on sample scenarios – generate Moral Machine prompts and run them through either the OpenAI API, OpenRouter, or a local HuggingFace model.
  3. Persona injection – prepend a persona instruction (TEMPLATE1 from the persona-MM paper) and re-run.
  4. Pre-computed comparison – paper-style radar grid comparing Human / GPT-4o / GPT-3.5 / Llama2 across all 7 persona categories.
  5. Run your own pipeline – generate ~50–100 fresh scenarios, call the model, convert to the conjoint format, compute the 9-dim ACME scores (Python port of the original R calculate_score.R), and drop the result into model_result/MyModel/ for side-by-side radar plotting.

Papers

About

Tutorial: LLM-based Agentic Simulations for Social Science (ICWSM 2026 Tutorial)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors