Views
No views yet

1from transformers import AutoModelForSeq2SeqLM
2from huggingface_hub import hf_hub_download
3import sentencepiece as spm
4import torch
5
6model = AutoModelForSeq2SeqLM.from_pretrained("amaury-delille/phogpt-0.13b", trust_remote_code=True)
7
8en_spm_path = hf_hub_download("amaury-delille/phogpt-0.13b", "tokenizer_en/spm.model")
9vi_spm_path = hf_hub_download("amaury-delille/phogpt-0.13b", "tokenizer_vi/spm.model")
10
11en_tokenizer = spm.SentencePieceProcessor(en_spm_path)
12vi_tokenizer = spm.SentencePieceProcessor(vi_spm_path)
13
14text = "Hello, how are you?"
15encoded = en_tokenizer.Encode(text)
16encoded.append(3)
17max_len = 128
18encoded = encoded + [0] * (max_len - len(encoded))
19input_ids = torch.tensor([encoded[:max_len]], dtype=torch.long)
20
21model.eval()
22outputs = model.generate(input_ids, max_length=128)
23
24out_tokens = [t for t in outputs[0].tolist() if t not in [0, 2, 3]]
25translation = vi_tokenizer.Decode(out_tokens)
26print(f"English: {text}")
27print(f"Vietnamese: {translation}")1@inproceedings{vaswani2017attention,
2title = {Attention is All You Need},
3author = {Vaswani, Ashish and Shazeer, Noam and Parmar, Niki and Uszkoreit, Jakob and Jones, Llion and Gomez, Aidan N and Kaiser, Lukasz and Polosukhin, Illia},
4booktitle = {Advances in Neural Information Processing Systems},
5year = {2017}
6}
7
8@article{su2021roformer,
9title = {RoFormer: Enhanced Transformer with Rotary Position Embedding},
10author = {Su, Jianlin and Lu, Yu and Pan, Shengfeng and Murtadha, Ahmed and Wen, Bo and Liu, Yunfeng},
11journal = {arXiv preprint arXiv:2104.09864},
12year = {2021}
13}
14
15@inproceedings{PhoMT,
16title = {{PhoMT: A High-Quality and Large-Scale Benchmark Dataset for Vietnamese-English Machine Translation}},
17author = {Long Doan and Linh The Nguyen and Nguyen Luong Tran and Thai Hoang and Dat Quoc Nguyen},
18booktitle = {Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing},
19year = {2021}
20}