GitHub repo xịn · Vui Coding chọn
huggingface/transformers
Huggingface/transformers là thư viện mã nguồn mở cung cấp các mô hình pretrained cho xử lý ngôn ngữ tự nhiên, thị giác, âm thanh và đa phương tiện, hỗ trợ inference và training. Nó giúp đơn giản hóa việc sử dụng, tùy chỉnh và triển khai các mô hình trạng thái nghệ thuật trong nhiều lĩnh vực AI.
Tóm tắt nhanh
Repo này làm được gì?
Huggingface/transformers là thư viện mã nguồn mở cung cấp các mô hình pretrained cho xử lý ngôn ngữ tự nhiên, thị giác, âm thanh và đa phương tiện, hỗ trợ inference và training. Nó giúp đơn giản hóa việc sử dụng, tùy chỉnh và triển khai các mô hình trạng thái nghệ thuật trong nhiều lĩnh vực AI.
Mô tả từ GitHub
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
Bắt đầu với repo
Cài đặt và sử dụng
Hướng dẫn cài đặt
Tạo môi trường ảo: - venv:
python -m venv .my-env
source .my-env/bin/activate- uv:
uv venv .my-env
source .my-env/bin/activateCài đặt thư viện:
pip install "transformers[torch]"hoặc
uv pip install "transformers[torch]". Nếu muốn cài từ source:
git clone https://github.com/huggingface/transformers.git
cd transformers
pip install '.[torch]'hoặc
uv pip install '.[torch]'.
Hướng dẫn sử dụng
Sử dụng cơ bản: - Nhập thư viện:
from transformers import pipeline- Khởi tạo pipeline:
pipeline = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")- Gửi prompt:
pipeline("the secret to baking a really good cake is ")- Kết quả: {'generated_text': 'the secret to baking a really good cake is 1) to use ...'} Ví dụ chat hệ thống:
pipeline = pipeline(task="text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct")
response = pipeline(chat, max_new_tokens=512)
print(response[0]['generated_text'])