DEV Community

Serguey Asael Shinder
Serguey Asael Shinder

Posted on

You Asked the Model for Headlines Under Thirty Characters and Half of Them Ran Over

The ad platform allows
thirty characters per headline.

Not thirty one.

You had two hundred products
and no time,
so you wrote a prompt.

Five headlines each.

Every one
under thirty characters.

Count them before you answer.

It came back fast,
in a neat list,
and at the bottom
a reassuring line.

All headlines are within
the thirty character limit.

The upload rejected
about half of them.

Thirty four.

Thirty one.

Twenty nine,
then forty.

The model
had not been lazy.

It was being asked
to measure something
it does not see.

A model does not read letters.

Before your prompt reaches it,
the text is cut into tokens,
chunks that are often a whole word,
sometimes part of one,
sometimes a word with its space.

Each chunk becomes a number.

That number is what it reads,
and what it writes.

How many letters
are inside a chunk
is something it can only
half remember from training,
never look at.

It is the same reason
a model can fail
to count the letters
in a simple word.

And there is a second problem.

It writes one chunk at a time,
left to right.

To land at twenty eight characters
it would have to know
the length of the whole line
before it has written it.

It cannot go back and measure.

So it aims,
and the aim is roughly right,
and roughly is not
what a hard limit wants.

The line at the bottom,
all within the limit,
was not a measurement either.

It was the sentence
that usually follows
a list like that.

So count in code.

One call to len
is exact,
free,
and never reassures you.

Ask for more candidates
than you need,
throw out every one over the limit,
and keep the best of the rest.

If too few survive,
send back the long ones
with their real counts.

This one is thirty four.

Cut four.

That works much better
than asking it to count,
because now
it is editing to a number
you gave it.

And never fix length
by cutting the string.

A headline chopped at thirty
is the word Free
turning into Fre.

Let the model write.

Let the code measure.

– Serguey Asael Shinder

Top comments (0)