AI Hints
Home›Fine-Tuning LLMs Tutorial›Working with Datasets
Fine-Tuning LLMs · Lesson 27 of 120

Our Project Data

Riverside Books messages.

⏱ 2 min read▶ Video at 43:55🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

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.

  • Our data for the whole course
  • Riverside Books messages
  • Each with the right answer

Five intents

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.

IntentExample
order_statusWhere is my copy of Dune?
returnI want to return Emma.
priceHow much is Circe?
stockIs Matilda in stock?
complaintI was charged twice for Rebecca.

Explore the data

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 Counter
from datasets import load_dataset

data = 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.

Two tasks, one dataset

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.

keyvalue
Task 1classify the intent
Task 2write JSON: intent + book
Test set77 unseen messages
Some phrasingsnever seen in training

Summary

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.

Key takeaways
  • 5 intents
  • 527 train, 77 test
  • Classify, then generate
Next up: Classification Fine-Tuning — teach a model to sort text