Registrations for these workshops are now closed
- Faculty coordinator: Raffaele Vacca
- Instructors: Federico Bianchi, Ayan-Yue Gupta, Minsu Jang, Francesco Renzini
- Where: University of Milan, Department of Social and Political Sciences (via Pace, 10 – 20122 Milan, Italy)
- When: May-June 2025 (dates/times below)
This series of 8 workshops offers a practical introduction to methods of computational social science and their implementation with Python and R. These are practical, hands-on workshops in which participants will run Python or R code on real-world data and will do coding exercises on their own laptops. All sessions will be held at the University of Milan (Unimi), Department of Social and Political Sciences. These workshops are in-person only.
Participants are free to attend all or just some of the sessions. However, knowledge of the introductory Python topics covered in Sessions #1 and #4 is necessary and assumed for participants in other Python-based sessions. The workshops are open to PhD students, postdoc researchers, and faculty members from any institutional affiliation, but priority will be given to NASP and Unimi students and personnel (attendance is limited to 30 participants).
This initiative is supported by the Network for the Advancement of Social and Political Studies (NASP) and the Unimi Computational Models and Designs Hub and Behave Lab, in collaboration with the Unimi Department of Social and Political Sciences. It is also possible thanks to support from the ConsNet, NetHealth, and FAiR projects.
Workshop sessions:
- Text-as-data: pre-processing and describing the data (15/5)
- Text-as-data: word embeddings and topic modeling (21/5)
- Getting data with APIs and web scraping (22/5)
- Modeling social networks: Exponential Random Graph Models (28/5)
Modeling networks and behaviors: Stochastic Actor-Oriented Models(canceled)- Geospatial data processing and visualization (4/6)
- Introduction to agent-based modeling (5/6)
- Agent-based modeling with empirical data (12/6)

1. Text-as-data: pre-processing and describing the data
- Instructor: Ayan-Yue Gupta
- Date: Thursday, 15/5/2025 (14:30-16:30)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: Intro to Python: setup, variables, operations, iteration, functions, classes; text-as-data and natural language processing; text data tokenization, stopword removal, splitting.
Description
This session will familiarize students with the fundamentals of Python while simultaneously learning preprocessing operations for text data. First, there will be a brief introduction describing what text-as-data and NLP are and why they are used in the social sciences. Then, using a toy text dataset, students will learn about the fundamentals of Python through the following topics. Setup: pip, writing code in a text editor, running python code from the terminal, virtual environment basics (venv), importing modules. Variables and operations: strings, integers, floats, Booleans. Basic data structures: lists and dictionaries. Iteration: for loops, while loops, flow control. Reading and writing files. Functions and classes. These topics will be introduced through practical exercises on tokenizing text, removing stopwords, splitting text into chunks, integrating these tasks into functions and classes.
Requirements
Any text editor for coding (e.g. Notepad++, Sublime Text, CotEditor, VS Code); pip; Python.
Setup
Before the workshop:
- Download the latest stable version of Python here. Full instructions for installing Python for your particular operating system can be found here (see section 4 for Python on Windows, section 5 for Python on MacOS).
- Ensure you have a text editor installed. Your computer should have a default one installed like Notepad or TextEdit – you can just use that. Alternatively, you can try other options, such as Notepad++ for Windows or CotEditor for Mac OS.
- Once Python is installed, download and install
pip. This can be done from the command line (command prompt in Windows, terminal in MacOS and Linux). Open your command line and run the following commands to install pip depending on your operating system:- Windows:
py -m ensurepip --upgrade - Mac OS or Linux:
python -m ensurepip --upgrade(if you get a “command not found” error, typepython3instead ofpythonin this code)
- Windows:
2. Text-as-data: word embeddings and topic modeling
- Instructor: Ayan-Yue Gupta
- Date: Wednesday, 21/5/2025 (16:30-18:30)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: Word embeddings; word2vec and fastext; numpy arrays; BERT; topic modelling.
Description
In this session we will explain the intuition behind word embeddings through practical exercises. To grasp the intuition, students will first do exercises using pre-trained static embeddings (word2vec, fastext etc.) to see how distances between embeddings correspond to differences in the meanings of words. This will also get students used to numpy arrays as a type of data structure. Then, students will do exercises to practice training static word embeddings. In the second half of the session students will be introduced to contextual embeddings with BERT and will conduct exercises on (1) using contextual embeddings to perform topic modelling and (2) visualizing and describing the results of topic modelling.
Requirements
numpy, gensim, transformers, bertopic, sentence transformers, matplotlib.
Setup
Before the workshop, make sure you have completed the setup for Session 1 and that you have Python and pip installed.
Then set up a python virtual environment with the following instructions. Don’t worry too much about what a virtual environment is — if you were unable to attend the first session, I will explain that in other sessions too:
- Choose or create a folder where you want your virtual environment to be. For example, you might choose or create the folder
C:\Users\YourUsername\Documents\Projects\my_python_project - Open your command line (command prompt in Windows, terminal in MacOS and Linux) and use the
cdcommand to navigate to the folder you selected/created in point (1) within the command line, for example:cd C:\Users\YourUsername\Documents\Projects\my_python_project - Use the following command to create a virtual environment named
env1:python -m venv env1(if you get a “command not found” error, typepython3instead ofpythonin this code) - You now have a virtual environment called
env1in the folder you selected/created in point (1). Every time you need to activateenv1, you’ll need to make sure you have navigated to the folder containing it usingcd, and then you’ll need to enter the following command:- (For Windows):
env1\Scripts\activate - (For MacOS/Linux):
source env1/bin/activate
- (For Windows):
- Make sure you have activated
env1. Then run the following commands:pip install gensimpip install numpypip install bertopic
3. Getting data with APIs and web scraping
- Instructor: Ayan-Yue Gupta
- Date: Thursday, 22/5/2025 (14:30-16:30)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: APIs; authorizations; JSON dictionaries; web scraping; BeautifulSoup.
Description
The first half of this session will teach students the fundamentals of API usage with exercises based on Youtube’s API. Exercises will be designed to get students familiar with the steps common to API usage, authorization, each API’s Python interface, and writing data in dictionary form to JSON files. The second half will be focused on web scraping. Here, students will learn how to make Python requests, how to inspect webpage elements that contain useful data one might want to collect using their browsers’ inspection tool, and how to select elements using BeautifulSoup. Students will also be taught some of the practical considerations of web scraping, such as making your code pause between each request to avoid server overload, understanding that scraping some websites might not be permitted, etc.
Requirements
requests, json, beautifulsoup, os.
Setup
Before the workshop, make sure you have completed the setup for Session 1 and that you have Python and pip installed.
Then set up a python virtual environment with the following instructions. Don’t worry too much about what a virtual environment is — if you were unable to attend the first session, I will explain that in other sessions too:
- Choose or create a folder where you want your virtual environment to be. For example, you might choose or create the folder
C:\Users\YourUsername\Documents\Projects\my_python_project - Open your command line (command prompt in Windows, terminal in MacOS and Linux) and use the
cdcommand to navigate to the folder you selected/created in point (1) within the command line, for example:cd C:\Users\YourUsername\Documents\Projects\my_python_project - Use the following command to create a virtual environment named
env1:python -m venv env1 - You now have a virtual environment called
env1in the folder you selected/created in point (1). Every time you need to activateenv1, you’ll need to make sure you have navigated to the folder containing it usingcd, and then you’ll need to enter the following command:- (For Windows):
env1\Scripts\activate - (For MacOS/Linux):
source env1/bin/activate
- (For Windows):
- Make sure you have activated
env1. Then run the following commands:pip install --upgrade google-api-python-clientpip install --upgrade google-auth-oauthlib google-auth-httplib2pip install beautifulsoup4
- Follow instructions here (under “Before you start”). This is needed to use the Youtube API, which is what we will be practising with in the session.
4. Modeling social networks: Exponential Random Graph Models
- Instructor: Federico Bianchi
- Date: Tuesday, 28/5/2025 (10:00-12:00)
- Location: Via Pace 10, Milan (Room A)
- Software: R
- Topics: Social network analysis; statistical modeling of network data; selection and influence; interdependencies in network data; Exponential Random Graph Models; statnet and ergm packages.
Description
This session introduces students to network modeling concepts with a focus on Exponential Random Graph Models (ERGMs), a statistical framework designed to model the complex dependencies found in social network data. Through hands-on activities, students will explore the theoretical foundations and practical applications of ERGMs. We will start by introducing social network analysis, relational data and their statistical modeling, actor sets, and relational ties. Second, we will consider the core issues of network formation (selection) and network effects (influence). Here, students will learn to distinguish selection mechanisms (e.g., selecting friends based on their characteristics) from influence processes (e.g., changing one’s behavior to imitate peers). Third, we will turn to interdependencies in network observations and explore how ERGMs provide solutions by modeling complex relational structures beyond conventional statistical approaches. Students will see how ERGMs can be used for the study of real-world social phenomena – from the formation of friendships among prison inmates to diplomatic alliances between countries – while disentangling selection and influence in networks. Finally, students will work on exercises that involve constructing and interpreting simple ERGM models using simulated data, exploring parameters like reciprocity, homophily, and transitivity. Exercises will also include steps for model specification, interpretation of parameters, and considerations of model fit.
Requirements
Basic knowledge of R is assumed, including familiarity with data frames and their manipulation, installing and loading packages, creating and working with R objects, basic functions, and data visualization. The R packages ergm, sna, network, and igraph are required.
Setup
- Download the latest version of R here (select a location near you)
- Follow instructions to install R in your computer
- If you already downloaded R some time ago, please update it to the latest version
- Download the latest version of RStudio (free version) here
- Follow instructions to install RStudio in your computer
- If you already downloaded RStudio some time ago, please update it to the latest version
- Install the following R packages:
ergm,sna,network,igraph
5. Modeling networks and behaviors: Stochastic Actor-Oriented Models
This session is canceled
- Software: R
- Topics: Longitudinal network data; network evolution; network-behavior co-evolution; Stochastic Actor-Oriented Models.
Description
This session introduces Stochastic Actor-Oriented Models (SAOMs) and their applications to the study of network evolution and network-behavior co-evolution. The session will blend theory with hands-on exercises, using the RSiena package to implement SAOMs with real-world datasets. We will start with an overview of SAOM and why it is essential for dynamic network modeling, understanding network formation as an inherently dynamic process, and considering the importance of modeling longitudinal data to capture changes in network structure and actor behavior over time. Second, we will review the foundations of SAOMs: actor orientation (how actors influence network evolution by selectively forming or ending ties), basics of probabilistic modeling in network dynamics (emphasizing individual choices within social structures), concepts of continuous-time modeling and micro-steps as incremental changes in network structure. Third, we will consider core SAOM principles (rate functions and objective functions), the algorithm of network evolution simulating real-time interactions, and examples of network effects in friendship formation (e.g., reciprocity, transitivity, homophily). We will use SAOM to test hypotheses with real-world data and consider issues of model assumptions, model construction, simulating network changes, and calibrating parameters. Finally, we will examine simulation-based estimation methods to optimize SAOM parameters, logistic regression interpretations of results, and how to understand effect sizes and assess model fit.
Requirements
Basic knowledge of R is assumed, including familiarity with data frames and their manipulation, installing and loading packages, creating and working with R objects, basic functions, and data visualization. The R packages ergm, sna, network, and igraph are required.
Setup
- Download the latest version of R here (select a location near you)
- Follow instructions to install R in your computer
- If you already downloaded R some time ago, please update it to the latest version
- Download the latest version of RStudio (free version) here
- Follow instructions to install RStudio in your computer
- If you already downloaded RStudio some time ago, please update it to the latest version
- Install the following R packages:
ergm,sna,network,igraph
6. Geospatial data processing and visualization
- Instructor: Minsu Jang
- Date: Wednesday, 4/6/2025 (10:00-12:00)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: Intro to Python: Pandas DataFrames, GeoJSON, Conda, JupyterLab, Jupyter Notebook, package versions; geospatial data; data visualization; interactive maps; topic modeling.
Description
This session has two primary objectives. In the first half, students will explore key features of geospatial data, including handling polygon data, importing and exporting GeoJSON data, and integrating geospatial data with Pandas DataFrames. Additionally, the session will cover essential tools for Python programming, such as Conda (Anaconda), JupyterLab, Jupyter Notebook, and creating virtual environments and managing package versions with YAML files. The second half of the session focuses on applying practical skills using a dataset of Airbnb reviews from Milan. Here, students will learn how to process and visualize geospatial data in Python. They will also engage in hands-on exercises for topic modeling of accommodation review comments, along with the visualization of these results on an interactive map.
Requirements
Install Anaconda. Additional materials will be provided prior to the workshop.
Setup
This session assumes that participants have completed the previous sessions, especially Session 1 and Session 2. If you have not, please ensure you are familiar with the following:
- What a virtual environment is
- How to install Python libraries using
pip
Setup instructions for this session:
- Download the latest stable version of Anaconda here.
- Visit Inside Airbnb and find “Milan.” Download all files into your working directory.
- Go here and download
css-python-geo.yml. - Open your command line (for Windows users, please use
Anaconda Prompt) and run the following commands to create a pre-defined virtual environment using the downloaded file:conda env create -f css-python-geo.ymlconda activate css-python-geo
7. Introduction to agent-based modeling
- Instructor: Minsu Jang
- Date: Wednesday, 5/6/2025 (14:30-16:30)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: Agent-based modeling; mesa; opinion formation and diffusion; Bounded-Confidence Model.
Description
In this session, students will be introduced to agent-based models (ABMs) for computational social science. ABMs simulate individual behaviors, interactions between individual agents, and their aggregation to reveal system-wide or macro-level effects. This makes ABMs powerful tools for studying complex systems, social dynamics, and the link between micro-level behaviors and macro-level outcomes. This session introduces the mesa library (a Python alternative to the popular ABM software NetLogo), covering its structure and core modules essential for implementing ABMs. Through hands-on practice, students will build and simulate the Bounded-Confidence Model of opinion formation in mesa, gaining practical experience in simulating social dynamics and modeling opinion shifts across individuals. This model will also be used in the following advanced ABM session.
Requirements
Install mesa. Course materials will be provided prior to the workshop.
Setup
This session assumes that participants have completed the previous sessions, especially Session 1 and Session 2. If you have not, please ensure you are familiar with the following:
- What a virtual environment is
- How to install Python libraries using
pip
Setup instructions for this session:
- To install the
mesalibrary, open your command line (for Windows users, useAnaconda Prompt) and run the following code:pip install -U mesa
8. Agent-based modeling with empirical data
- Instructor: Francesco Renzini
- Date: Thursday, 12/6/2025 (14:30-16:30)
- Location: Via Pace 10, Milan (Room A)
- Software: Python
- Topics: Agent-Based Models; Bounded-Confidence Model; Approximate Bayesian Computation; mesa and pyabc; model calibration and validation.
Description
Agent-based models are not used just to simulate theories and study hypothetical scenarios, they can also be integrated with empirical data to make inferences about social mechanisms and dynamics happening in the real world. In this session, students will explore the incorporation of data into ABMs, focusing on parameter estimation for the Bounded-Confidence Model of opinion dynamics introduced in the previous session. Using Approximate Bayesian Computation, students will estimate model parameters from empirical opinion distributions. The pyabc and mesa Python packages will be used to make statistical inferences about the importance of various micro-level generative processes in explaining the empirical patterns observed in the data. While this session is mostly practical, it also provides a general introduction to foundational concepts in the calibration and validation of agent-based models. The session will end by pointing students to further resources for more in-depth study of techniques and algorithms of ABM calibration and validation.
Requirements
Install the latest versions of mesa and pyabc. Course materials will be provided prior to the workshop. Students will be granted access to a permanent GitHub repository with the dedicated materials for reproducibility. A text editor for programming is also required (e.g., Notepad++, Sublime Text, VS Code, etc.).
Setup
This session assumes that participants have completed the previous session or are familiar with its contents, including the Python basics covered in Sessions 1, 2, and 7.
Setup instructions for this session. To install the required packages, you have two options:
Option 1: Quick Installation via pip
If you already have Python installed, simply run in bash:
pip install pyabc
pip install seaborn
Option 2: Use the Preconfigured Conda Environment
1. Deactivate any currently active environment. In bash:
conda deactivate
2. Create a new environment from the file environment.yml, provided in Dropbox (see the shared Dropbox folder for this session). In bash:
conda env create -f environment.yml
3. Activate the new environment. In bash:
conda activate abm-estimation
