к каталогу
#5топнужен почти всегда

🤖 transformers/ huggingface

Библиотека Transformers предоставляет тысячи предобученных моделей для обработки естественного языка, компьютерного зрения, аудио и мультимодальных задач. Она поддерживает интеграцию с PyTorch, TensorFlow и JAX, позволяя как запускать модели, так и обучать их. Благодаря единому API разработчики могут легко загружать, дообучать и развертывать современные модели.

Открыть на GitHubобновлён 8ч назад
Звёзды
162.0k
Форки
33.7k
За неделю
За месяц
Рост %
Язык
Python

Установка и запуск

Installation

Transformers works with Python 3.10+, and PyTorch 2.4+.

Create and activate a virtual environment with venv or uv, a fast Rust-based Python package and project manager.

# venv
python -m venv .my-env
source .my-env/bin/activate
# uv
uv venv .my-env
source .my-env/bin/activate

Install Transformers in your virtual environment.

# pip
pip install "transformers[torch]"

# uv
uv pip install "transformers[torch]"

Install Transformers from source if you want the latest changes in the library or are interested in contributing. However, the latest version may not be stable. Feel free to open an issue if you encounter an error.

git clone https://github.com/huggingface/transformers.git
cd transformers

# pip
pip install '.[torch]'

# uv
uv pip install '.[torch]'

Quickstart

Get started with Transformers right away with the Pipeline API. The Pipeline is a high-level inference class that supports text, audio, vision, and multimodal tasks. It handles preprocessing the input and returns the appropriate output.

Instantiate a pipeline and specify model to use for text generation. The model is downloaded and cached so you can easily reuse it again. Finally, pass some text to prompt the model.

from transformers import pipeline

pipeline = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")
pipeline("the secret to baking a really good cake is ")
[{'generated_text': 'the secret to baking a really good cake is 1) to use the right ingredients and 2) to follow the recipe exactly. the recipe for the cake is as follows: 1 cup of sugar, 1 cup of flour, 1 cup of milk, 1 cup of butter, 1 cup of eggs, 1 cup of chocolate chips. if you want to make 2 cakes, how much sugar do you need? To make 2 cakes, you will need 2 cups of sugar.'}]

To chat with a model, the usage pattern is the same. The only difference is you need to construct a chat history (the input to Pipeline) between you and the system.

[!TIP] You can also chat with a model directly from the command line, as long as transformers serve is running.

transformers chat Qwen/Qwen2.5-0.5B-Instruct
import torch
from transformers import pipeline

chat = [
    {"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
    {"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
]

…

## Example models

You can test most of our models directly on their [Hub model pages](https://huggingface.co/models).

Expand each modality below to see a few example models for various use cases.

<details>
<summary>Audio</summary>

- Audio classification with [CLAP](https://huggingface.co/laion/clap-htsat-fused)
- Automatic speech recognition with [Parakeet](https://huggingface.co/nvidia/parakeet-ctc-1.1b#transcribing-using-transformers-%F0%9F%A4%97), [Whisper](https://huggingface.co/openai/whisper-large-v3-turbo), [GLM-ASR](https://huggingface.co/zai-org/GLM-ASR-Nano-2512) and [Moonshine-Streaming](https://huggingface.co/UsefulSensors/moonshine-streaming-medium)
- Keyword spotting with [Wav2Vec2](https://huggingface.co/superb/wav2vec2-base-superb-ks)
- Speech to speech generation with [Moshi](https://huggingface.co/kyutai/moshiko-pytorch-bf16)
- Text to audio with [MusicGen](https://huggingface.co/facebook/musicgen-large)
- Text to speech with [CSM](https://huggingface.co/sesame/csm-1b)

</details>

<details>
<summary>Computer vision</summary>

…

Из README репозитория · полный README на GitHub

Категории

Теги

audiodeep-learningdeepseekgemmaglmhacktoberfestllmmachine-learningmodel-hubnatural-language-processingnlppretrained-modelspythonpytorchpytorch-transformersqwenspeech-recognitiontransformervlm

Анонс

🚀 Hugging Face Transformers — must-have для любого ML-разработчика! Эта библиотека даёт доступ к тысячам предобученных моделей: от BERT до GPT-4, от YOLO до Stable Diffusion. Поддерживает PyTorch, TensorFlow и JAX. Можно использовать для инференса и дообучения. Установка одной командой: pip install transformers. Попробуйте прямо сейчас! 🔥