0% found this document useful (0 votes)
6 views4 pages

In-Context Learning for Data Prediction

The document discusses the concept of in-context learning, where a model can be trained to perform tasks using existing data without additional training data. It provides examples of how to structure tabular data into prompts for the model to predict missing information or classify data. The author emphasizes the effectiveness of this method in automating tasks and generating accurate predictions based on minimal input data.

Uploaded by

hussam.felimban
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

In-Context Learning for Data Prediction

The document discusses the concept of in-context learning, where a model can be trained to perform tasks using existing data without additional training data. It provides examples of how to structure tabular data into prompts for the model to predict missing information or classify data. The author emphasizes the effectiveness of this method in automating tasks and generating accurate predictions based on minimal input data.

Uploaded by

hussam.felimban
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Now, so far, we've really just tapped

into the model's existing training. We haven't really taught it anything new. We've
given it new information, and we've
had it do different AI related tasks on that information, but it hasn't really
been trained with anything new. Now, we've given it new instructions, but we
haven't given it new
training data per se. And we can essentially do that
with in-context learning. Now, we used in-context learning and we've done it to do
things like improve
our writing and make it sound more like us because it can learn from the patterns
in written material that we give it. But it can also learn from patterns and data
and examples that we give
it of tasks being performed. And so let's look at how this plays out in
using it in a machine learning context. So anytime we have data, and I particularly
want you to think
about data that looks like a table. If you have data that's in Excel or
CSV or some other table format, this is prime data, prime information
to go and use for in-context learning. Because you have all of sort of the key
ingredients that you need to go and teach it. And so we're going to take an
example, and we're going to start off
with a simple example. But it's a simple example,
but it's a tricky example because there's no obvious sort of
what is it that I'm supposed to do? Like, if you took existing
machine learning things, it'd be sort of tricky to get them
to do this task particularly well. So here's the task is we have this
list of all of these catalog items. But what we want to do is we want to
take these flowery descriptions, like duck-shaped ladle, and
we want to boil it down to just ladle, which if you look at the column over
there, that's just the simple description. And we have Japanese tea set
with cherry blossom motif, and we want to boil that down to tea set. Now, the last
row,
we don't have it boiled down yet. It says metallic sculpture
of a dancing couple, and we want it to go and learn what to do and
fill that in for us. So what we're going to do is we're going
to try to figure out how do we teach it and how do we craft a prompt that
essentially trains it to perform this task, because that's what our
prompt is going to be doing. Our prompt is essentially going to be
training the model through in-context learning to be able to accomplish this
task, which is this stripping down of the data and filling in that column,
that missing column. And I want you to think about that. Let's say I had a table of
data and there was a column that I
want to fill in or predict. How would I go about doing that? And this is what
you're going to do. Now, typically, the way we want to do
this is we want to take that data and we want to reshape it a little bit. And the
way we typically want to reshape
it is we want to create a set of examples that show the correct input and
then the correct output. And there's many different
formats you can use for this, but I'm going to start with
a really simple one, which is I'm going to show it the correct
input, like what the row would be, and then the correct output,
which was what that last column should be. So I start off with the first row
in the data, and it's this q. 106582670, duck-shaped ladle. And that is my example
input. And I've given it the instructions that
it should go and complete the pattern. Now, this is what my input is formatted
as, and that's essentially every row, I'm going to go show it everything
except the last column. That's going to be the input, and then the output is going
to be the last
column that I'm trying to predict. So I want you to think about this in terms
of a table and imagining there's a last column that you're trying to predict
the value for or fill in the value for. And it could be classification,
it could be recommendation, it could be prediction,
it could be whatever that task is. But I want you to get this mental model of
a table where the thing you're looking for is that last missing column
that we want to fill in. Now, when we format it, what we do is
we say the data that's in the columns that we know is going to
be this input like this. We show it input colon,
and then that column. And it could be tabular separated data,
space separated data, comma separated data,
however you want to do it. But what's generally important is that
it's all in one row with no line breaks. So if you need to try to get rid
of the line breaks, if you can, then we show it the last column. But we say output
colon last column. And the idea behind this
is we're teaching it. If you see this input,
this is the output that we're expecting. So this is how we're reshaping
that table into a prompt. Now, once we've done that, then what we're
going to do is we're going to go and try to get it to fill in a missing label. So
you'll notice right above
this output right here, what I've got is essentially the input
that I'm looking to produce the label for. So in this case,
it's large porcelain teapot. And so
I've shown it all the columns that I have. And now I'm trying to get it to predict
the missing column by saying output colon and basically telling it, hey, I
need to know what the output is for this. Basically, I need to know
what the missing column is. And then when I go and do that,
what it says is teapot, which is the correct answer. Now, you notice I didn't tell
it how to perform the task. I didn't say, go and look at this and
try to remove all the flowery language and boil it down to one object. I just
showed it examples. And essentially, what we've done is we've trained the model
in a prompt to perform this task. It's performed the task
force on the new input, and then it's given us the new column
that we can now put into the data. And the correct column is teapot,
like we see here. Now, you can take any type of data. Now, it won't always work. It
can't always figure out what
the answer is because there may not be enough information. But you see, the kind of
the structure I
want you to have in your head is anytime I see a table, if there is a column
that I want to be able to predict or fill in in some way, then I can think
about how to reshape that table as a prompt where I take my prior information
and I put it in in this format, and then I use this last column as
something I'm going to predict. And I do output colon,
and I try to get it. Now, you can have different prefixes. Prefix can matter, it
cannot matter. It's a little bit of a something that you
have to think about depending on what you're trying to get it to do. But input
output tends
to work pretty well. So now let's take a longer example and
see how we might do this and start scaling it up on more data. So I've built my
prompt, and
it doesn't fit on the one screen anymore, but I've built my prompt, and it
basically has all of the examples
of the task correctly performed. Here's the input here's
the correct output, and that's basically showing each row where
I have the correct value for the column. And now what I want to do is
fill in a whole bunch of rows. I want to fill in the column for a whole bunch of
rows that I
don't have that column for. And so what I do is I've built my existing
prompt and now I can save that thing. I can use it over and
over with that essentially training data. And now what I'm going to do is,
I'm going to say, create the output for each of the following inputs. Now, it
probably would have been
better if I'd gone ahead and prefixed each of these with input,
but I got a little lazy and Claude is really smart, so
it was able to figure it out. What we get now is it goes through and
it processes each and every row and it performs the task that has learned. So now
it's essentially doing batch
processing of that task on that input data that I gave it. And notice I never gave
it
instructions about how to do this. It just learned it. And this is the power of in
context learning is we can go and teach it new things. When you start thinking of
all the tables
you work with on a daily basis, and this simple idea that maybe I can
translate that table into a prompt that then it can use to help me predict some
missing column or some column I'd like to automate filling in, you can start
to see where this gets really powerful. So I'm going to take
some more complex data. So this is a data set that I got off of
Kaggle, which is where you can go and download open datasets. And it's a whole
bunch of online courses. And it has enrollment, it has rating,
it has some other information about them. It also has a category. So what we're
going to
do is classification. We're going to have it learn to classify
these different classes into their category, or what is the category? Is that a
technology class, a marketing,
a finance, an office tools class? And it's going to learn
how to classify courses. So what I'm going to do is I'm going to
take the very last course in this data set, and
I'm going to remove one of the columns. I'm going to remove the category column.
And the category for this data set for
this course was technology. So I've taken this last row, and
I'm going to strip out the category, which is technology. And then I'm going to see
if Claude can predict it. So I go and I create a prompt. Now, in this case,
I am getting even lazier. Now, this is not the best thing to do,
but I'm getting really lazy. And I kind of want to show you that
sometimes you can get lucky and just be really lazy and you can directly
take your, your tabular data and move it into a prompt and
get some amazing results. And that's what I got here. So I took a whole segment
of those courses. I took,
I think all of the ones you see here. So it looks like we've got about 33
courses that I gave it the correct answer for. And then there's some dots,
because again, my prompt doesn't fit. But I wanted to show you the last row,
and then in the last row down here, what you see for course 33 is that I've
actually gone and removed the category. So I've left that column blank. And the
instructions I've given it
are predict the missing category for the course. Now, there's probably way better
ways
to format this prompt to make sure it works really well. But even if we just go and
start copying
and pasting tabular data in Excel type data, you can get some really
powerful results sometimes. So I'm asking it to classify the course
based solely in the course identifier, which is course 33. The fact that it's
taught
on LinkedIn learning, the price of the course, the average. I guess it's the rating
for
the course, and the number of people enrolled, that's it. No title of the course,
nothing else. Can it solely based on those data points
predict what category the course is? And I'll tell you what, I cannot. There's no
way I can easily predict this. And I don't know if you can spot it and
immediately tell, probably not because that pretty small,
that table that I showed you. But it goes through and it says,
to predict the missing category for course 33, I'll analyze the patterns in
the given data and consider factors like course duration, enrollment, completion
rate, platform, price, and rating. Here's my thought process. Based on these
factors, the most
likely categories are, number one, technology, which is the correct answer. Number
two, programming and
number three, data science. Among these, technology seems to be
the best fit considering the duration, platform, and rating. It's a broad category
that could explain
the moderate enrollment numbers while, and it went on with its explanation. But
what's amazing is it nailed
the classification test. It is a technology course. And if we go back up and
we look originally, yep, it's technology. It got it right. And if we look at the
data
that was working off. I mean, it's really generic stuff,
and it absolutely killed it. Now, we've got from that
to this really rich. Now, what's also amazing about this
is it's explaining its answer, which is really powerful, because now,
as a human being, I can follow up and I can say, does that make sense? Now, what's
interesting is even with its
answer, and even all of its explanation, it's really hard for me to work backwards
and say, does that actually make sense? Because I'm just flabbergasted that it
can get this from that little data. Now, if I went and analyzed the courses
and did a lot of statistical analysis, maybe it would make sense to me. But think
of how much
work that would take. And I just fed this in, and
I got an excellent answer, an excellent classification of it. I essentially trained
it in a prompt. Now, if I wanted to go back and I want
to classify and try to categorize other courses, all I have to do is save
this prompt and change the last row. I'd fill in the row that at the end with
a new row that is missing the category, and then I'd ask it to predict it. And then
I would go in and
fill in another new row, or I'd fill in a series of courses and
ask it to predict each of them. And so you can work with it. And suddenly we're
going from just
having it perform tasks that it already knows how to do, and
suddenly we're getting it, and we're actually training it on totally new
data and getting it to predict things and classify things based on data that
it was never trained on before. We're essentially training it with our
prompt through in-context learning and examples, and that's wildly powerful.

You might also like