And a massive welcome back one more time to LM engineering.
We are in week three, day two and we are getting into open source models.
So as a reminder you can already do frontier models back to front.
You can build multimodal AI assistants.
And now you're comfortable looking at the hugging face hub, looking at models and data sets and spaces.
And you can run code using Google Colab.
So today we're going to look at Hugging Face Transformers library and discuss the fact that there are
two different types of API, two different levels that you can work with transformers at one level,
the higher level API is called pipelines, and that's what we'll be working with mostly today, including
generating text, images and sound using pipelines.
So let's just talk for a moment about these two different API levels.
So there are these two modes of interacting with the hugging face code.
One of them is if you want to carry out a standard, everyday typical task in what we'd call inference,
or running a model at runtime given an input to get an output.
And hugging face has wonderfully packaged this up into a high level interface that's super easy to use,
and that provides you with a rapid way to get going, generating text, and doing a number of everyday
functions.
But if you want to get deeper into the code, if you want to be looking in more detail at things like
how how you are tokenizing your text at which models and which parameters you're using to run a model,
or if you're actually going to go as far as training and be fine tuning your own model to carry out
specialist tasks with extra knowledge or nuance.
At that point, you need to look at the deeper APIs, the lower level APIs, working with Tokenizers
and models in Hugging Face.
Today we're going to be looking at pipelines.
And then after that we're going to turn to the Tokenizers and models.
So what can you do with these pipelines?
So essentially it allows you to take instant advantage of models on the Hugging face hub with two lines
of code.
It's as simple as that.
And I'm going to give you lots of examples and lots of things you can take away so that you can use
it yourself to carry out every day inference tasks.
So one classic example, which is one of the easiest ones to start with, is what they call sentiment
analysis.
Given a sentence saying what is the emotion conveyed by this sentence?
Uh, then classification, of course, is one of those very traditional machine learning tasks of putting
things into buckets.
Named entity recognition is when you can take a sentence and tag the words in that sentence as things
like whether they are people or whether they are locations or things and so on.
Question answering is when you have some context and you want to be able to ask questions about the
context that you provide.
Summarization, of course, is when you have a block of text and you want to turn it into a summary
translation.
Another classic AI task translating between one language and another.
So what if I told you that all of these things can be done with two lines of code each?
Hopefully you would be amazed and you will see it in a moment.
There are some other things you can do as well that become perhaps slightly more advanced.
Text generation actually isn't advanced at all.
It's still just two lines of code.
It's still super simple, and it's another thing that you will marvel at.
But generating images is also very simple, as is audio.
It becomes a little bit more than two lines, but it's still very simple and I can't wait to show you.
I think that's enough preamble.
Let's get straight to it.
Let's go to Google Colab.