Skip to content

Transformers

State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow

pip3 install transformers
pip3 install transformers

NLP Course

pipeline

python
from transformers import pipeline

classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")
from transformers import pipeline

classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")
shell
[{'label': 'POSITIVE', 'score': 0.9598047137260437}]
[{'label': 'POSITIVE', 'score': 0.9598047137260437}]

By default, this pipeline selects a particular pretained model that has been fine-tuned for sentiment analysis in English. The model is downloaded and cached when you create the classifier object. If you rerun the command, the cached model will be used instead and there is no need to download the model again.

The cache folder is .cache/huggingface by default. You can customize your cache folder by setting the HF_HOME environment variable.

There are three main steps involved when you pass some text to a pipeline:

  1. The text is preprocessed into a format the model can understand.
  2. The preprocessed inputs are passed to the model.
  3. The predictions of the model are post-processed, so you can make sense of them.

Some of the currently available pipelines are:

  • feature-extraction (get the vector representative of a text)
  • fill-mask
  • ner (named entity recognition)
  • question-answering
  • sentiment-analysis
  • summarization
  • text-generation
  • translation
  • zero-shot-classification

Transformers-Tutorials

Transformers-Tutorials is a collection of demons with the Transformers library by HuggingFace.

table-transformer

https://github.com/microsoft/table-transformer

https://huggingface.co/microsoft/table-transformer-detectionhttps://huggingface.co/microsoft/table-transformer-structure-recognition

Hugging Face Serverless Inference API

The Serverless Inference API offers a fast and free way to explore thousands of models for a variety of tasks. Whether you’re prototyping a new application or experimenting with ML capabilities, this API gives you instant access to high-performing models across multiple domains.

PyTorch Model Format

model.safetensors and pytorch_model.bin.

References