Let's get to know the data we'll use for the rest of the course. Customer messages, sent to Riverside Books. Each one has a label, which is the right answer.
Each message has an intent, which is what the customer wants. Order status means, where is my order? Return means they want to send a book back. Price is a question about cost. Stock asks if a book is available. And complaint means they're unhappy. Each message also names one book.
This time, we load two files at once, a train file and a test file, into a dataset dictionary. Counter counts how many messages have each intent. Then we print three test messages. Run it. Five hundred and twenty seven training rows, and seventy seven test rows. The five intents are nicely balanced, about a hundred each. And the messages are short, and a little messy, like real ones.
app.pypython
from collections import Counterfrom datasets import load_datasetdata = load_dataset("json", data_files={"train": "tickets_train.jsonl", "test": "tickets_test.jsonl"})print(data)print(Counter(data["train"]["intent"]))for row in data["test"].select(range(3)): print(f"{row['intent']:13} {row['book']:11} {row['message']}")
Output
DatasetDict({
train: Dataset({
features: ['message', 'intent', 'book'],
num_rows: 527
})
test: Dataset({
features: ['message', 'intent', 'book'],
num_rows: 77
})
})
Counter({'stock': 108, 'price': 107, 'order_status': 105, 'return': 104, 'complaint':
103})
price Persuasion Tell me the price of Persuasion. Thank you!
complaint Matilda Hello! I'm unhappy with how my Matilda order was handled.
Cheers
order_status Beloved Still waiting for Beloved, what's going on? Thanks.
We'll use this data for two tasks. First, classification. A small model reads a message, and picks one of the five intents. Second, generation. A language model reads a message, and writes a short JSON answer, with the intent, and the book. The test set also has some phrasings that never appear in training, to check the model really learned.
Let's recap. Our data is Riverside Books messages. Each has an intent, and a book. The classes are balanced. And we'll use it for classification first, then generation. Next, our first fine-tuning, a classifier.