liveBook · Manning

Transformers

As explained in Data Analysis with LLMs

Hugging Face Transformers is an open-source library providing pretrained Transformer models and tools for natural-language, vision, and multimodal machine-learning tasks.

Hugging Face Transformers is a Python library and model hub for trying pretrained Transformer models locally. It offers models for tasks such as sentiment classification, image captioning, visual question answering, and speech-to-text. section 8.4.1 section 8.4.2

A practical workflow is:

  • Browse the model repository and filter models by the task you need. section 8.4.1
  • Read a model’s description, associated papers, code samples, and hardware guidance before trying it. section 8.4.1
  • Install Transformers and its PyTorch dependency, then import the library with import transformers. section 8.4.2
  • Use a pipeline to connect a selected model with an input and obtain a task-specific result. section 8.4.2

Classify a review

A sentiment pipeline can use Cardiff University’s RoBERTa model: create the pipeline with model='cardiffnlp/twitter-roberta-base-sentiment-latest', pass it a review, and print the result. Running it on “This movie was really awful!” produces a negative label with a score of about 0.94. The first run automatically downloads the model from the public repository. section 8.4.2

Figure 8.4 Overview of Hugging Face Transformer models. Click the Tasks filters to narrow the selec-tion. Click models in the Models list to see details.
figure

Use the model browser to narrow a very large catalog by task and inspect candidate models. section 8.4.1

How Data Analysis with LLMs covers it

How deep it goes
Demonstrates installation, pipeline creation, inference, and output inspection, while stopping short of comprehensive library features or model training.
Examples
Uses task filters, a Salesforce BLIP image-captioning model, and Cardiff University’s RoBERTa sentiment-classification model.
What it assumes
Assumes a Python environment and requires PyTorch alongside the Transformers installation.
What you can do after
Apply it via Python to download and run a pretrained model through a task pipeline.
How it connects
Connects pretrained models with model repositories, task pipelines, PyTorch, and sentiment classification.

Also explained in

Compare how 6 books explain transformers →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.