Skip to main content

Connecting Transfromers on HuggingfaceHub with Ctranslate2

Project description

hf_hub_ctranslate2

Connecting Transfromers on HuggingfaceHub with Ctranslate2 - a small utility for keeping tokenizer and model around Huggingface Hub.

codecovCI pytest

Read the docs

Contributors Forks Stargazers Issues MIT License LinkedIn


Usage:

Decoder-only Transformer:

# download ctranslate.Generator repos from Huggingface Hub (GPT-J, ..)
from hf_hub_ctranslate2 import TranslatorCT2fromHfHub, GeneratorCT2fromHfHub

model_name_1="michaelfeil/ct2fast-pythia-160m"
model = GeneratorCT2fromHfHub(
    # load in int8 on CPU
    model_name_or_path=model_name_1, device="cpu", compute_type="int8"
)
outputs = model.generate(
    text=["How do you call a fast Flan-ingo?", "User: How are you doing?"]
    # add arguments specifically to ctranslate2.Generator here
)

Encoder-Decoder:

# download ctranslate.Translator repos from Huggingface Hub (T5, ..)
model_name_2 = "michaelfeil/ct2fast-flan-alpaca-base"
model = TranslatorCT2fromHfHub(
        # load in int8 on CUDA
        model_name_or_path=model_name_2, device="cuda", compute_type="int8_float16"
)
outputs = model.generate(
    text=["How do you call a fast Flan-ingo?", "Translate to german: How are you doing?"],
    # use arguments specifically to ctranslate2.Translator below:
    min_decoding_length=8,
    max_decoding_length=16,
    max_input_length=512,
    beam_size=3
)
print(outputs)

Encoder-Decoder for multilingual translations (m2m-100):

model = MultiLingualTranslatorCT2fromHfHub(
    model_name_or_path="michaelfeil/ct2fast-m2m100_418M", device="cpu", compute_type="int8",
    tokenizer=AutoTokenizer.from_pretrained(f"facebook/m2m100_418M")
)

outputs = model.generate(
    ["How do you call a fast Flamingo?", "Wie geht es dir?"],
    src_lang=["en", "de"],
    tgt_lang=["de", "fr"]
)

PYPI Install

pip install hf-hub-ctranslate2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hf_hub_ctranslate2-2.0.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hf_hub_ctranslate2-2.0.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file hf_hub_ctranslate2-2.0.3.tar.gz.

File metadata

  • Download URL: hf_hub_ctranslate2-2.0.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for hf_hub_ctranslate2-2.0.3.tar.gz
Algorithm Hash digest
SHA256 1c06973a04c8cc3da5881992d70be61cb3a0db1ff4cb38e2b3d6fe78d0ce13c8
MD5 0a569a9dc3033bf64714437d454fea87
BLAKE2b-256 fddd4b561828c83f0cb64285f923d232843066d6b4348e3b86a7b48e28033baf

See more details on using hashes here.

File details

Details for the file hf_hub_ctranslate2-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for hf_hub_ctranslate2-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ead1a5cf25bc2f3ed8a9133cadf4276137f5561e492ad74e63c1f92c52a10eec
MD5 e564a325d60ca46bf2b76148ee095db0
BLAKE2b-256 47e5bbe201058c1cc892af7277df71bd17b0fea356a31d5e840127f181c0ad01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page