Transformers Library

Hello there! (Imagine I'm saying this in Obi-Wan Kenobi’s voice :D)
I'm writing this newsletter while listening to a wonderful piece by Yann Tiersen. I'll tell you why I chose this song in the music section. Even if you haven't heard of Yann Tiersen, you might recognize his music from the movie Amelie.
As you know, we're all riding the AI train, and it's still moving full speed ahead. There are many tools, models, and websites to explore and learn about.
Recently, I came across HuggingFace's Agents course, but after some digging, I realized it would be better to start with their NLP course first, then move on to Agents. By the way, all of these courses are completely free!
I've completed the first two chapters of the NLP course, and today I'd like to introduce you to HuggingFace's Transformers library, specifically the pipeline() function.
If you're not familiar with HuggingFace, think of it as the GitHub for the AI world. People share their models there, and you can find pre-trained models ready to use. It also has great communities, datasets, forums, and educational courses.
Check it out here: https://huggingface.co
Technical Section
Transformers is a comprehensive library from HuggingFace, and today we'll discuss the pipeline() function.
This function conveniently combines a model's preprocessing and postprocessing steps, meaning we just provide the input text, and it handles the rest—tokenizers, input IDs, softmax, and more. I'll talk about these details in future newsletters.
To run Python code, you have a couple of easy options:
The simplest is Google Colab: https://colab.research.google.com
Or you can set up a local Python environment, which is what I prefer. Here's a guide: Transformers Installation
Once we've created our notebook file, we can run our first code cell:
In this example, we used sentiment analysis without specifying a model, so the default model (distilbert-base-uncased-finetuned-sst-2-english) was chosen automatically. You can find the details here: distilbert model
Result:
[{'label': 'POSITIVE', 'score': 0.9998801946640015}]
As you can see, the pipeline function took care of all the details for us.
Here's another pipeline type: Zero-Shot Classification
This is a powerful model since it doesn't require labeled training data:
Result:
{'sequence': 'Superman is from Krypton, he is the savior of humanity', 'labels': ['hero', 'villian'], 'scores': [0.997347891330719, 0.0026521203108131886]}
Text Generation
This time, we're using a specific model called TinyLlama. Details here: TinyLlama
Result:
[{'generated_text': "Batman is a detective who is known for his quick thinking and his ability to solve complex cases. He is known for his ability to read people and understand their motivations, which has helped him solve some of the most challenging cases in Gotham City.\n\n2. Robin: Robin is a young boy who is trained by Batman to be his sidekick. He is known for his bravery and his ability to use his superhuman strength to help Batman in his missions.\n\n3. Nightwing: Nightwing is a former member of the Batman's team who is now working as a vigilante in Gotham City. He is known for his quick thinking and his ability to take down criminals with his arsenal of weapons.\n\n4. Red Hood: Red Hood is a former member of the Batman's team who is now working as a vigilante in Gotham City. He is known for his ability to take down criminals with his arsenal of weapons and his ability to use his superhuman strength to overcome obstacles.\n\n5. Harley Quinn: Harley Quinn is a criminal who has been hired by the Joker to be his personal assistant. She is known for her wit, her ability to use her sharp tongue to get what she wants, and her ability to use her superhuman strength to take down criminals.\n\nThese are just a few examples of the many characters that make up the Batman universe. Each character has their own unique abilities, motivations, and backstory, making the Batman universe a rich and diverse world to explore."}]
Fill Mask
Here, we're filling in missing words using the distilbert-base-uncased model. Seems like this model isn't sure where Superman is from!!!
Named Entity Recognition (NER)
NER identifies entities like people and locations in text. It correctly recognized "Fırat" as a person and "Istanbul" as a location.
Result:
[{'entity_group': 'PER', 'score': np.float32(0.9811023), 'word': 'Fırat', 'start': 11, 'end': 16}, {'entity_group': 'LOC', 'score': np.float32(0.9994142), 'word': 'Istanbul', 'start': 57, 'end': 65}]
Summarization
This summarization model neatly summarized a Wikipedia paragraph about "The Dark Knight Returns":
Result:
[{'summary_text': ' The Dark Knight Returns is a 1986 four-issue comic book miniseries . It tells an alternative story of Batman who, at 55 years old, returns from a decade of retirement to fight crime . The story also features the return of classic foes Two-Face and the Joker . A direct adaptation of the story was released as a two-part film across 2012 and 2013 .'}]
This text that I gave is from Wikipedia of The Dark Knight Returns, which is a classic Batman comic book, and it has an animation movie as well ❤️
We talked about the pipeline() function of the Transformers library, but this is just the tip of the iceberg. you can explore the rest of the library from their documentation: https://huggingface.co/docs/transformers/en/quicktour
Here is the codebase: https://github.com/MehmetFiratKomurcu/Newsletter/blob/master/huggingface-transformers-pipeline/transformers-pipeline.ipynb
As you can see in the models section of HuggingFace, there are a lot of models, and there is the Inference API of HuggingFace, which you can test some models from UI directly.
Not all models support it, but popular ones do.
Here is an example of one Deepseek model: https://huggingface.co/deepseek-ai/DeepSeek-V3-0324
You can see the Inference section on the right side.
Music 🎶
Today, we're listening to "Le Jour D'avant" by Yann Tiersen.
This week, my tap dance class created a small choreography to this lovely piece.
Movies & Series 🎬
This week's recommendation is the legendary two-part series: The Dark Knight Returns.
This classic comic book set the tone for Batman as we know him today.
Truly iconic!
That’s it for today, my friends.
Thanks for reading!
May the Force be with you ❤️



