Views
No views yet
| Model | Average of 4 domains | General Scientific | ||||
|---|---|---|---|---|---|---|
| SacreBLEU | chrF2++ | COMET | SacreBLEU | chrF2++ | COMET | |
| Base | 46 | 68.3 | 66.7 | 44.9 | 67.7 | 66.3 |
| Fine-Tuned | 48.4 | 69.9 | 67.3 | 47.3 | 69.1 | 67.8 |
| Improvement | +2.4 | +1.6 | +0.9 | +2.4 | +1.4 | +1.5 |
pip install ctranslate2 sentencepiece huggingface_hub1import ctranslate2
2import sentencepiece as spm
3from huggingface_hub import snapshot_download
4
5repo_id = "ilsp/opus-mt-pt-en_ct2_ft-SciLake"
6
7# REPLACE WITH ACTUAL LOCAL DIRECTORY WHERE THE MODEL WILL BE DOWNLOADED
8local_dir = ""
9
10model_path = snapshot_download(repo_id=repo_id, local_dir=local_dir)
11
12translator = ctranslate2.Translator(model_path, compute_type="auto")
13
14sp_enc = spm.SentencePieceProcessor()
15sp_enc.load(f"{model_path}/source.spm")
16
17sp_dec = spm.SentencePieceProcessor()
18sp_dec.load(f"{model_path}/target.spm")
19
20def translate_text(input_text, sp_enc=sp_enc, sp_dec=sp_dec, translator=translator, beam_size=6):
21 input_tokens = sp_enc.encode(input_text, out_type=str)
22 results = translator.translate_batch([input_tokens],
23 beam_size=beam_size,
24 length_penalty=0,
25 max_decoding_length=512,
26 replace_unknowns=True)
27 output_tokens = results[0].hypotheses[0]
28 output_text = sp_dec.decode(output_tokens)
29 return output_text
30
31input_text = "Na osteoartríte (OA) a degeneração progressiva das estruturas articulares activa continuamente nociceptores levando ao desenvolvimento de dor crónica e a déficits emocionais e cognitivos."
32translate_text(input_text)
33
34# OUTPUT
35# In osteoarthritis (OA), progressive degeneration of articular structures continuously activates nociceptors leading to the development of chronic pain and emotional and cognitive deficits.