← Back to the track

Learn machine learning · part 7 · session 1

Order is information

Two lines, the same four words, opposite meanings. This classifier only counts how many times each word appears. It never sees which word came first, so 'not good' and 'good not' arrive as the same thing, and you are going to build the pair that proves it.

After this session you will be able to build two lines a word-counting classifier cannot tell apart, and say what counting throws away.

seq.orderSession 7.1About 25 minutesYour check: demonstrate the idea yourself

The gate: one submission in which all four checks hold, with equality tested on the scores rather than on the probabilities.

01 · The question

Two lines, the same four words, opposite meanings. "not good" against "good not" is the smallest version of the problem. In Part 1 you turned rows into columns and it cost you nothing. Text is a , and it does not survive that treatment.

What the counter actually sees

illustrativethe two word counts, drawn for the lesson
Two orders, one jar. The classifier reads the jar.

Below is a classifier that counts words and drops where they sit, fitted here on 24 short phrases I wrote for this session. Your job is to build the pair of lines it cannot separate, using only its own vocabulary. Twenty five minutes, and the gate is a behaviour rather than a number.

02 · Predict

Before anything runs

Reverse the word order of a phrase this classifier scores. What happens to its output?

Reverse the word order of a phrase this classifier scores. What happens to its output?

Choose something first.

03 · Try it

1 · read the training set

The 24 phrases this classifier is fitted on

syntheticwritten for this session

I wrote these lines for one exercise about word order. They are not drawn from anywhere and they are not sentiment data. The label says which side of the exercise a line was written for and nothing else.

Twenty four training phrases with the label each was written for.
#phraselabel
1this meal was very good1
2this meal was not good0
3the room is clean and warm1
4the room is dirty and cold0
5a lovely day1
6a terrible day0
7the service was quite fast1
8the service was very slow0
9the film is really great1
10the film is really dull0
11the book was fine1
12the book was poor0
13that trip was always good1
14that trip was never good0
15the price is quite fine1
16the price is quite awful0
17it was a good meal1
18it was a bad meal0
19not bad1
20not great0
21the day was warm and lovely1
22the day was cold and dull0
23clean enough but not great1
24not clean enough and too cold0
The 8 held-out phrases
Eight held-out phrases with the label each was written for.
#phraselabel
1the meal was great1
2the meal was terrible0
3a fast service1
4a slow service0
5this book is quite good1
6this book is not good0
7the room was lovely and clean1
8the room was poor and dirty0

2 · fit the classifier

200 full-batch gradient steps at learning rate 0.5 over the 24 phrases above. The input is one count per vocabulary word and nothing else: where a word sits in the line is not part of it.

3 and 4 · score a phrase, then reverse it

Fit the classifier first.

5 · build the pair

computed in this browserchecked in this browser

Two lines, both built from the 40 words below, with the same word counts and opposite intended labels. The engine checks four things in order and names the first that fails.

The 40 words you can use

a · always · and · awful · bad · book · but · clean · cold · day · dirty · dull · enough · fast · film · fine · good · great · is · it · lovely · meal · never · not · poor · price · quite · really · room · service · slow · terrible · that · the · this · too · trip · very · warm · was

The label you intend for line A
The label you intend for line B

Fit the classifier first.

Ask for a hint

Rungs open as you run the session, not as time passes. You have run it 0 times.

1. A question: available after 3 evaluated runs.

2. A narrowing: available after 5 evaluated runs.

3. A worked fragment, on another vocabulary: available after 7 evaluated runs.

4. The answer, on this session's vocabulary: available after 9 evaluated runs.

04 · Compare

05 · Check your understanding

Your check: an outcome you produce

not yet

All four checks hold in one submission: both lines use only vocabulary words, the word counts are identical, the intended labels differ, and the two scores come out the same to twelve decimals. The scores are compared rather than the probabilities, because two probabilities can agree to printing precision while the scores differ.

Not met yet. Keep working the session.

The two lines must come out with the same score. I allow a difference of 0.000000000001 because adding the same numbers in a different order leaves a speck of rounding dust.

Save your takeaway

Your takeaway

Edit it into your own words, or keep the line as it is.

Fit the classifier above before adding it to the shelf, so the weights on the shelf are the ones you saw.