SONUB home

Only our team reads this. Don't include passwords or card numbers.

Thank you! We read every message and use it to decide what to improve next.

Close Send
EN English 한국어 日本語 简体中文 繁體中文 हिन्दी বাংলা اردو Español Português Français Deutsch Русский العربية Bahasa Indonesia Tiếng Việt ไทย Türkçe

How to enable notifications

Notifications are unavailable in this browser or on this address. Try a supported browser on the secure SONUB site.

If notifications are blocked, allow them in your browser settings.

  1. Open the site controls beside the address bar, or your browser’s site settings. Set Notifications for this site to Allow.
  2. In your device settings, allow notifications for your browser and check Do Not Disturb or Focus.
  3. Return to SONUB and reload the page. Once notifications are on, the bell disappears.

On iPhone or iPad, add SONUB to your Home Screen, open it there, then allow notifications.

Build AI in five steps

Every project goes through the same five steps: preparation, & visualization, data , and model evaluation. Build a small spam filter in your and walk through all five.

Messy pieces of writing go into a filter machine, duplicates and scraps fall out, and a neat stack of clean data comes out
1

Data preparation

Data rarely comes from one place. Here the messages are in three files with different formats:

  • (sms.csv): a text file whose columns are separated by commas. opens it as a table.
  • TSV (mail.tsv): a text file whose columns are separated by tabs.
  • (chat.jsonl): JSON writes data as "name": value pairs inside { }. This file has one JSON object on each line.

Each file names its columns differently and writes the answer differently.

Data preparation means gathering everything into one common format, without changing the content yet. Cleaning comes later, in step 3, after you have looked at the data in step 2. If you clean now, you may throw away something you have not understood yet.

The logic, step by step

  1. Read each file csv · json
  2. Rename to common columns text · label · source
  3. Count the rows (rows)
  4. Save one table data/all.csv

csv.DictReader reads a CSV file row by row as a , so r["message"] is the message column. For the TSV file, delimiter="\t" tells it that a tab separates the columns. The JSONL file is read one line at a time with json.loads.

Every row becomes {"text": …, "label": …, "source": …}. The label is copied as it is, so 1, spam and yes all stay different for now. The source column remembers where each row came from; you will need it to compare the sources in step 2.

The same job with real-world tools

With pandas, each file is one read call, and pd.concat stacks them into one table.

  • pd.read_csv()
  • pd.read_json(lines=True)
  • pd.concat()
  • df.to_csv()

Type and try

Open 1-prepare.ipynb and run the cells one by one with Shift+Enter. After the last cell, open data/all.csv in the file browser and look at the table it made.

1-prepare.ipynbThe full code of this notebook
# Step 1. Data preparation — read three sources and save them in one common format.
import csv
import json
import os

rows = []

# sms.csv: columns message, is_spam (1 or 0)
with open("assets/sms.csv", newline="", encoding="utf-8") as f:
    for r in csv.DictReader(f):
        rows.append({"text": r["message"], "label": r["is_spam"], "source": "sms"})

# mail.tsv: columns body, category (spam or ham), separated by tabs
with open("assets/mail.tsv", newline="", encoding="utf-8") as f:
    for r in csv.DictReader(f, delimiter="\t"):
        rows.append({"text": r["body"], "label": r["category"], "source": "mail"})

# chat.jsonl: one JSON object per line, keys text and label (yes or no)
with open("assets/chat.jsonl", encoding="utf-8") as f:
    for line in f:
        r = json.loads(line)
        rows.append({"text": r["text"], "label": r["label"], "source": "chat"})

print("rows by source")
for source in ["sms", "mail", "chat"]:
    count = sum(1 for r in rows if r["source"] == source)
    print(f"  {source:5} {count}")
print("total", len(rows))

os.makedirs("data", exist_ok=True)
with open("data/all.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=["text", "label", "source"])
    writer.writeheader()
    writer.writerows(rows)
print("saved data/all.csv")
Run ▸ Run All CellsWhat you should see
rows by source
  sms   65
  mail  59
  chat  59
total 183
saved data/all.csv

Done when

The notebook prints 65 rows for sms, 59 for mail and 59 for chat, 183 in total. Check this against the raw files: in a new cell, len(open("assets/sms.csv").readlines()) counts the lines of a file, and a CSV or TSV file has one extra line for the column names. Not one row may be lost or added.

If you get stuck

: 'message' means the column name does not match the first line of the file; open assets/sms.csv and compare. means the notebook is not in the basic/ folder; open it from basic/ in the file browser.

Booking time has passed