## Hugging Face

All functionality related to the [Hugging Face Platform](https://huggingface.co/).

## Chat models[​](#chat-models "Direct link to Chat models")

### Models from Hugging Face[​](#models-from-hugging-face "Direct link to Models from Hugging Face")

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

We need to install several python packages.

```
pip install huggingface_hubpip install transformers
```

See a [usage example](https://python.langchain.com/docs/integrations/chat/huggingface/).

```
from langchain_community.chat_models.huggingface import ChatHuggingFace
```

## LLMs[​](#llms "Direct link to LLMs")

### Hugging Face Local Pipelines[​](#hugging-face-local-pipelines "Direct link to Hugging Face Local Pipelines")

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

We need to install `transformers` python package.

See a [usage example](https://python.langchain.com/docs/integrations/llms/huggingface_pipelines/).

```
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
```

To use the OpenVINO backend in local pipeline wrapper, please install the optimum library and set HuggingFacePipeline's backend as `openvino`:

```
pip install --upgrade-strategy eager "optimum[openvino,nncf]"
```

See a [usage example](https://python.langchain.com/docs/integrations/llms/huggingface_pipelines/)

To export your model to the OpenVINO IR format with the CLI:

```
optimum-cli export openvino --model gpt2 ov_model
```

To apply [weight-only quantization](https://github.com/huggingface/optimum-intel?tab=readme-ov-file#export) when exporting your model.

## Embedding Models[​](#embedding-models "Direct link to Embedding Models")

### Hugging Face Hub[​](#hugging-face-hub "Direct link to Hugging Face Hub")

> The [Hugging Face Hub](https://huggingface.co/docs/hub/index) is a platform with over 350k models, 75k datasets, and 150k demo apps (Spaces), all open source and publicly available, in an online platform where people can easily collaborate and build ML together. The Hub works as a central place where anyone can explore, experiment, collaborate, and build technology with Machine Learning.

We need to install the `sentence_transformers` python package.

```
pip install sentence_transformers
```

#### HuggingFaceEmbeddings[​](#huggingfaceembeddings "Direct link to HuggingFaceEmbeddings")

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/huggingfacehub/).

```
from langchain_community.embeddings import HuggingFaceEmbeddings
```

#### HuggingFaceInstructEmbeddings[​](#huggingfaceinstructembeddings "Direct link to HuggingFaceInstructEmbeddings")

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/instruct_embeddings/).

```
from langchain_community.embeddings import HuggingFaceInstructEmbeddings
```

#### HuggingFaceBgeEmbeddings[​](#huggingfacebgeembeddings "Direct link to HuggingFaceBgeEmbeddings")

> [BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard). BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). `BAAI` is a private non-profit organization engaged in AI research and development.

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/bge_huggingface/).

```
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
```

### Hugging Face Text Embeddings Inference (TEI)[​](#hugging-face-text-embeddings-inference-tei "Direct link to Hugging Face Text Embeddings Inference (TEI)")

> [Hugging Face Text Embeddings Inference (TEI)](https://huggingface.co/docs/text-generation-inference/index) 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](https://python.langchain.com/docs/integrations/text_embedding/text_embeddings_inference/).

```
from langchain_community.embeddings import HuggingFaceHubEmbeddings
```

## Document Loaders[​](#document-loaders "Direct link to Document Loaders")

### Hugging Face dataset[​](#hugging-face-dataset "Direct link to Hugging Face dataset")

> [Hugging Face Hub](https://huggingface.co/docs/hub/index) is home to over 75,000 [datasets](https://huggingface.co/docs/hub/index#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.

See a [usage example](https://python.langchain.com/docs/integrations/document_loaders/hugging_face_dataset/).

```
from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader
```

### Hugging Face Hub Tools[​](#hugging-face-hub-tools "Direct link to Hugging Face Hub Tools")

> [Hugging Face Tools](https://huggingface.co/docs/transformers/v4.29.0/en/custom_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](https://python.langchain.com/docs/integrations/tools/huggingface_tools/).

```
from langchain.agents import load_huggingface_tool
```