Are you searching for a quick way to use machine learning models, all in just a few lines of code? Are you interested in utilizing machine learning models without requiring an extensive understanding of the intricacies of machine learning?
I have always been interested in artificial intelligence and have always wanted to learn how it works and develop my own AI applications. But considering the fact that AI is a very technical field it can be very difficult sometimes to know where to start.
I have been on Hugging Face for some time now but a few weeks back I came across their learning hub, started learning from there, and discovered their pipeline function and since then it has proved to be by far the easiest way to use ML models, IMHO.
Hugging Face pipelines provide a convenient and straightforward method for utilizing models in inference. So these pipelines allow you to use models that are hosted on Hugging Face without you knowing the intricacies of how the model works. These pipelines provide APIs for tasks such as Sentiment Analysis, Text Generation, and Named Entity Recognition. Too much of me talking, let’s get our hands dirty.
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
classifier("I feel not so good today")
[{'label': 'NEGATIVE', 'score': 0.999760091304779}]
In a few lines of code, three to be precise, we were able to use a sentiment analysis model using the high-level API pipeline function and didn’t need to worry about the intricacies of the whole thing. Let’s see another example of how to use a pipeline to generate text.
from transformers import pipeline
generator = pipeline("text-generation")
generator("Let's come together and")
[{'generated_text': 'Let's come together and help build an emergency medical service
for families that need help. In a place like California, that's a major concern right now."'}]
For text generation, you provide a prompt and the model will generate the remaining text.
There’s nothing more fulfilling than being able, from the get-go, to write a few lines of code and see it do its magic when learning a new technology. This is not meant to be a Pipeline tutorial. I just want to share what I have been learning and tools that make things easy for me, hopefully, it will help someone looking for where to start. For further learning just go to https://huggingface.co/learn

