Skip to content

HuggingFace Hello World!

Table of Contents

Overview

Hugging Face Platform is a collaboration platform for machine learning where the community can share, discover, and experiment with open-source models, datasets, and applications.

Applications

  • The platform hosts over 300k models, 100k applications, and 50k datasets in various domains such as natural language processing, computer vision, and speech recognition.
  • The platform allows users to easily host a demo app to show their machine learning work with Spaces, a web-based IDE for creating and deploying machine learning applications.
  • The platform also provides paid Compute and Enterprise solutions for deploying models on optimized inference endpoints, training models automatically with AutoTrain, and collaborating securely with enterprise-grade security and access controls.

Tools & Frameworks

  • The platform is built on top of the Hugging Face open source stack, which includes state-of-the-art libraries and frameworks for machine learning such as Transformers, Diffusers, SafeTensors, and Hub Python Library.
  • The platform also supports collaborative features such as pull requests, discussions, model cards, and versioning to improve the machine learning workflow and enable peer reviews on models, datasets, and Spaces.
  • The platform is compliant with GDPR and SOC 2 Type 2, and allows users to pick their storage region for compliance and performance.

Hello World!

Here is a code snippet that shows how to use the Transformers library to load a pre-trained model from the Hugging Face Hub and generate text with it:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load a pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")

# Encode some input text
input_ids = tokenizer.encode("Hello world!", return_tensors="pt")

# Generate text with the model
output_ids = model.generate(input_ids, max_length=20)

# Decode the output text
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print(output_text)

References