Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

# Run this cell, don't change anything.
from datascience import *
import numpy as np

from IPython.display import HTML, display
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use("ggplot")

import warnings
warnings.filterwarnings('ignore')
%reload_ext autoreload
%autoreload 2

from bs4 import BeautifulSoup
import re
import requests

Project Part A: Introduction

The full specification for this project is in Google Docs:

The full description of each dataset is in Google Docs:

This Jupyter notebook contains code cells that should accompany your Final Project Part A PDF submission. You should submit this notebook (and associated files) by exporting and uploading a ZIP to Gradescope.



Part 1: Pick Your Dataset




Question 1: Task Shortname

Read the full description of this task in the Google Doc. What follows in this part of the notebook is a guide for how to explore dataset files.

All datasets are in the datasets subdirectory: materials-fa25/project/project_final/datasets. Navigate to this directory using the file explorer on DataHub. See the Google Doc for details.

Option 1: Look at the data with datascience library

To load in, say, emotion.csv into a datascience Table, first construct a file path as a string with this subdirectory, separated by forwardslashes:

csv_fname = "datasets/emotion.csv"

Then you can load this in as usual to a datascience Table. See below.

csv_fname = "datasets/emotion.csv" # replace this line

table = Table.read_table(csv_fname)
table.show(3)
Loading...
# your code here for exploring data

Option 2: Look at the data with a spreadsheets program

You can also download this CSV and import into your spreadsheet program of choice, e.g., Google Spreadsheets or Microsoft Excel.

To download the CSV file, go to the file in the DataHub file explorer (sidebar). Right click --> Download.



Part 2: Exploratory Data Analysis (EDA)




Question 2: Contextual Analysis

No code.




Question 3: Explore the CSV

Feel free to use the cell below to explore your data.

csv_fname = "datasets/emotion.csv" # replace this line

table = Table.read_table(csv_fname)

# your code here




Question 4: Distribution of “Human Gold Labels”


Question 4a

Write code that visualizes the distribution of labels in your dataset. Depending on how many sets of labels you have, you may need to produce multiple visualizations.

In the cell below, write code that produces this visualization.

  • You should use the datascience library and associated visualization methods in this course.

  • Your analysis should be on <shortname>.csv, where <shortname> is the shortname of your CSS task. Do not look at <shortname>_train.csv nor <shortname>_val_uncoded.csv; these are used for the next part.

In your Google Doc report, include screenshot(s) of the resulting visualization(s). You do not need to screenshot your code; writing your code in the cell below is sufficient.

csv_fname = "datasets/emotion.csv" # replace this line

table = Table.read_table(csv_fname)

# your code here for producing a visualization




Question 5: Distribution of Text


Question 5a

Write code that reports the top 20 most frequent words in your dataset, across all sentences, ignoring stop words.

Hints/recommendations:

  • This question is intentionally open-ended.

  • We’ve imported the stopwords package for you above.

  • A reasonable solution will use some sort of dictionary.

    • Look at the bag of words model that you constructed in a previous project. Translate that approach to this application.

    • If you want to challenge yourself, we recommend you look at the CountVectorizer library in the sklearn documentation.

  • It is alright to use Generative AI for this question, but you will be expected to understand your approach. Depending on your approach, during grading we may ask you follow-up questions about your code.


[Tutorial] Helper code

The cell to write your code is listed at the very end of this question. Before that, we have a few helper cells to get you going.

Stop words: The below cells install the stop_words package and provide an example of usage.

# just run this cell
!pip install stop-words
Collecting stop-words
  Using cached stop_words-2025.11.4-py3-none-any.whl.metadata (14 kB)
Using cached stop_words-2025.11.4-py3-none-any.whl (59 kB)
Installing collected packages: stop-words
Successfully installed stop-words-2025.11.4
# just run this cell

from stop_words import get_stop_words

# Get English stop words
stop_words = get_stop_words('english')

# five random words
Table().with_columns("word", stop_words).sample(5).column("word")
array(['mz', 'appreciate', 'this', 'yes', 'qv'], dtype='<U10')

Split by whitespace: Depending on your dataset, you may find it useful to go beyond the split method we gave you in class. The following cell uses regular expressions (not covered in this course) to take some text and split it based on all non-alphanumeric characters. Feel free to use it.

Note: Empty strings should not be considered in your solution—you should look at the example below for behavior with non alphanumeric symbols.

# just run this cell
import re
def split_into_words(any_chunk_of_text):
    lowercase_text = any_chunk_of_text.lower()
    split_words = re.split("\W+", lowercase_text)
    return split_words 

example_text = "#SCOTUS rules they can rule anything they damn well please, regardless of We The People. Welcome to #tyranny.   #USA #SemST!"
example_words = split_into_words(example_text)
print(example_words)
print(len(example_words))
['', 'scotus', 'rules', 'they', 'can', 'rule', 'anything', 'they', 'damn', 'well', 'please', 'regardless', 'of', 'we', 'the', 'people', 'welcome', 'to', 'tyranny', 'usa', 'semst', '']
22

Complete Question 5a

# write your code here

In your Google Doc report, list the top 20 words (ignoring stop words) across your text data, sorted by most common first. You do not need to screenshot your code; writing your code in the provided cell of this notebook is sufficient.



Part 3: Hand-coding




Question 6: Develop Coding Strategy

No code.




Question 7: Hand-code your data

Read the full description of this task in the Google Doc. What follows in this part of the notebook is a guide for how to upload your codes.


Option 1: Make a datascience Table and save it

This cell does the following:

  1. Load in the data from <shortname>_val_uncoded.csv and assign to table_val.

  2. Make two new arrays with human codes, humanA_arr and humanB_arr.

  3. Add these two columns to table_val and call the columns humanA and humanB, respectively.

  4. Call table_val.to_csv(fname) that exports the table to the specified fname path. Here, we’ve named fname to <shortname>_val_human.csv, but you should replace <shortname> with your task shortname, e.g., emotion_val_human.csv.

This strategy will be very useful for Part B of the project, when you assign many AI code labels. For now, it will seem a bit tedious.

from datascience import *
table_val = Table.read_table("datasets/emotion_val_uncoded.csv") # edit this line
table_val.num_rows
30
# feel free to change this code as you see fit

table_val = Table.read_table("datasets/emotion_val_uncoded.csv") # edit this line

humanA_arr = [0] * 30 # replace this line with Person A's human-coded labels
humanB_arr = [0] * 30 # replace this line with Person B's human-coded labels

table_val = table_val.with_columns(
                "humanA", humanA_arr,
                "humanB", humanB_arr)

fname = "emotion_val_human.csv"
table_val.to_csv(fname)

After modifying the above cell, your <shortname>_val_human.csv should be saved to the project_final directory.


Option 2: Upload a CSV from a spreadsheets program

Depending on how you and your partner decide to individually code results, you may find it useful to use a spreadsheet program, e.g., Google Spreadsheets.

  1. Download the <shortname>_val_uncoded.csv.

  2. Upload it to Google Spreadsheets.

  3. Make two tabs, one for each partner. Fill in codes. Don’t peek at each other’s work.

  4. Make one sheet with two new columns labeled humanA and humanB.

  5. File --> Download --> Comma Separated Values (.csv). Rename the file to <shortname>_val_human.csv.

  6. Upload into DataHub by dragging the file into the DataHub File Explorer.




Question 8: Inter-Reliability Agreement

Report Cohen’s Kappa (κ\kappa) as a measure of the agreement between you and your partner’s hand-coded labels. Additionally, use the Data 6 Notes to report the agreement level based on your computed κ.

Notes:

  • We have provided some starter code to compute Cohen’s Kappa below. It uses the cohen_kappa_score function from the sklearn library.

  • It is okay to report low κ\kappa/agreement level in this part. This part is graded on completion.

  • We are not comparing your codes to the human gold standard; for that we will need the F1 score. We explore this in Part B of the assignment.

Complete this part by writing code to compute Cohen’s Kappa (κ\kappa) in the cell below. Then, in your report, report κ\kappa and the agreement level.

# edit the below code as needed

from sklearn.metrics import cohen_kappa_score

human_fname = "emotion_val_human.csv" # replace this line

human_codes = Table.read_table(human_fname)
kappa = cohen_kappa_score(human_codes.column("humanA"), human_codes.column("humanB"))
kappa

Done!!!

You should download a ZIP of this folder, which should include this notebook AND the <shortname>_val_human.csv file you created in Part 3. Read the Google Doc for submission instructions.

Part B to be released soon!