Update README.md
Browse files
README.md
CHANGED
@@ -32,6 +32,52 @@ CTranslate2 is one of the most performant ways of hosting translation models at
|
|
32 |
|
33 |
The project is production-oriented and comes with backward compatibility guarantees, but it also includes experimental features related to model compression and inference acceleration.
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
### Licensing information
|
37 |
This work is licensed under a [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
|
|
32 |
|
33 |
The project is production-oriented and comes with backward compatibility guarantees, but it also includes experimental features related to model compression and inference acceleration.
|
34 |
|
35 |
+
# CTranslate2 Installation
|
36 |
+
```bash
|
37 |
+
pip install hf-hub-ctranslate2>=1.0.0 ctranslate2>=3.13.0
|
38 |
+
```
|
39 |
+
### ct2-transformers-converter Command Used:
|
40 |
+
```bash
|
41 |
+
ct2-transformers-converter --model Helsinki-NLP/opus-mt-cau-en --output_dir ./ctranslate2/opus-mt-cau-en-ctranslate2 --force --copy_files README.md generation_config.json tokenizer_config.json vocab.json source.spm .gitattributes target.spm --quantization float16
|
42 |
+
```
|
43 |
+
# CTranslate2 Converted Checkpoint Information:
|
44 |
+
**Compatible With:**
|
45 |
+
- [ctranslate2](https://github.com/OpenNMT/CTranslate2)
|
46 |
+
- [hf-hub-ctranslate2](https://github.com/michaelfeil/hf-hub-ctranslate2)
|
47 |
+
|
48 |
+
**Compute Type:**
|
49 |
+
- `compute_type=int8_float16` for `device="cuda"`
|
50 |
+
- `compute_type=int8` for `device="cpu"`
|
51 |
+
|
52 |
+
# Sample Code - ctranslate2
|
53 |
+
#### Clone the repository to the working directory or wherever you wish to store the model artifacts. ####
|
54 |
+
```bash
|
55 |
+
git clone https://huggingface.co/gaudi/opus-mt-cau-en-ctranslate2
|
56 |
+
```
|
57 |
+
|
58 |
+
#### Take the python code below and update the 'model_dir' variable to the location of the cloned repository. ####
|
59 |
+
|
60 |
+
```python
|
61 |
+
from ctranslate2 import Translator
|
62 |
+
import transformers
|
63 |
+
|
64 |
+
model_dir = "./mt-hitz-en-eu-ct2" # Path to model directory.
|
65 |
+
translator = Translator(
|
66 |
+
model_path=model_dir,
|
67 |
+
device="cuda", # cpu, cuda, or auto.
|
68 |
+
inter_threads=1, # Maximum number of parallel translations.
|
69 |
+
intra_threads=4, # Number of OpenMP threads per translator.
|
70 |
+
compute_type="int8_float16", # int8 for cpu or int8_float16 for cuda.
|
71 |
+
)
|
72 |
+
|
73 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_dir)
|
74 |
+
|
75 |
+
source = tokenizer.convert_ids_to_tokens(tokenizer.encode("Hello, world!"))
|
76 |
+
results = translator.translate_batch([source])
|
77 |
+
target = results[0].hypotheses[0]
|
78 |
+
|
79 |
+
print(tokenizer.decode(tokenizer.convert_tokens_to_ids(target)))
|
80 |
+
```
|
81 |
|
82 |
### Licensing information
|
83 |
This work is licensed under a [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|