Skip to content

StanfordHCI/spiral-of-silence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This repository contains the code and data for Zhao et al. "Mapping the Spiral of Silence: Surveying Unspoken Opinions in Online Communities" to appear at CHI 2026.

Repository Structure

spiral-of-silence/
├── generate_viewpoints.py    # Script to generate topics and viewpoints using LLMs
├── utils.py                  # Utility functions for Reddit API and OpenAI API
├── paper_analyses.ipynb      # Python notebook for data analysis and visualizations
├── Regression.Rmd            # R markdown file for statistical modeling
├── data.csv                  # Survey data (participant responses)
├── prompts/                  # LLM prompts for topic/viewpoint generation
│   ├── topic_1.json          # Prompt for generating controversial topics
│   ├── viewpoint_1.json      # Prompt for generating viewpoints on topics
│   └── summarize_1.json     # Prompt for shortening viewpoints
└── README.md                 # This file

Setup

Prerequisites

  • = Python 3.10

  • R (for statistical analyses)
  • Reddit API credentials
  • OpenAI API key

Installation

  1. Clone this repository:
git clone <repository-url>
cd spiral-of-silence
  1. Install Python dependencies:
pip install praw openai python-dotenv pandas tqdm numpy matplotlib scipy jupyter
  1. Create a .env file in the root directory with your API credentials:
REDDIT_CLIENT=your_reddit_client_id
REDDIT_SECRET=your_reddit_secret
OPENAI_API=your_openai_api_key

Usage

Generating Topics and Viewpoints

The generate_viewpoints.py script generates controversial topics and corresponding viewpoints for specified Reddit subreddits:

from generate_viewpoints import main

# Generate topics and viewpoints for subreddits
subreddits = ['politics', 'technology', 'science']
filepath = 'output_{}.json'  # Output file pattern
main(subreddits, filepath, model='gpt-4o')

The script performs three steps:

  1. Topic Generation: Generates controversial topics that would lead to disagreement within each subreddit
  2. Viewpoint Generation: Creates viewpoints representing different sides of each topic
  3. Viewpoint Shortening: Condenses viewpoints to shorter statements

Data

The data.csv file contains survey responses with the following key variables:

  • Participant characteristics: Age, Gender, Race, Political, Karma, Usage, Posting, WTSC
  • Community characteristics: Subreddit, Diversity, Inclusion, Safety, percent (content removal rate), modratio
  • Topic/Viewpoint: Topic, Viewpoint, Agreement, Sub_Agree, Incongruency
  • Outcomes: Comment_Likelihood, Upvote_Likelihood

Citation

@inproceedings{zhao2026spiral,
   author = {Dora Zhao and Diyi Yang and Michael S. Bernstein},
   title = {Mapping the Spiral of Silence: Surveying Unspoken Opinions in Online Communities},
   booktitle = {Proceedings of the 2026 CHI Conference on Human Factors in Computing Systems},
   year = {2026}
}

About

Codebase for "Mapping the Spiral of Silence: Quantifying Unspoken Opinions in Online Communities"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors