Skip to main content

Hugging Face

All functionality related to the Hugging Face Platform.

Installationโ€‹

Most of the Hugging Face integrations are available in the langchain-huggingface package.

pip install langchain-huggingface

Chat modelsโ€‹

Models from Hugging Faceโ€‹

We can use the Hugging Face LLM classes or directly use the ChatHuggingFace class.

See a usage example.

from langchain_huggingface import ChatHuggingFace
API Reference:ChatHuggingFace

LLMsโ€‹

Hugging Face Local Pipelinesโ€‹

Hugging Face models can be run locally through the HuggingFacePipeline class.

See a usage example.

from langchain_huggingface import HuggingFacePipeline
API Reference:HuggingFacePipeline

Embedding Modelsโ€‹

HuggingFaceEmbeddingsโ€‹

See a usage example.

from langchain_huggingface import HuggingFaceEmbeddings
API Reference:HuggingFaceEmbeddings

HuggingFaceInstructEmbeddingsโ€‹

See a usage example.

from langchain_community.embeddings import HuggingFaceInstructEmbeddings

HuggingFaceBgeEmbeddingsโ€‹

BGE models on the HuggingFace are the best open-source embedding models. BGE model is created by the Beijing Academy of Artificial Intelligence (BAAI). BAAI is a private non-profit organization engaged in AI research and development.

See a usage example.

from langchain_community.embeddings import HuggingFaceBgeEmbeddings

Hugging Face Text Embeddings Inference (TEI)โ€‹

Hugging Face Text Embeddings Inference (TEI) is a toolkit for deploying and serving open-source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5.

We need to install huggingface-hub python package.

pip install huggingface-hub

See a usage example.

from langchain_community.embeddings import HuggingFaceHubEmbeddings

Document Loadersโ€‹

Hugging Face datasetโ€‹

Hugging Face Hub is home to over 75,000 datasets in more than 100 languages that can be used for a broad range of tasks across NLP, Computer Vision, and Audio. They used for a diverse range of tasks such as translation, automatic speech recognition, and image classification.

We need to install datasets python package.

pip install datasets

See a usage example.

from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader

Toolsโ€‹

Hugging Face Hub Toolsโ€‹

Hugging Face Tools support text I/O and are loaded using the load_huggingface_tool function.

We need to install several python packages.

pip install transformers huggingface_hub

See a usage example.

from langchain.agents import load_huggingface_tool
API Reference:load_huggingface_tool

Was this page helpful?


You can also leave detailed feedback on GitHub.