Update README.md
Browse files123---license: apache-2.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521---license: cc-by-nc-4.0language:- en- vitags:- translation- machine-translation- english-to-vietnamese- vietnamese- onnx- seq2seq- bartpipeline_tag: translation---# AnViMt**AnViMt** là mô hình dịch máy **English → Vietnamese** được fine-tune để dịch cả văn bản thông thường lẫn nội dung kỹ thuật, hệ thống, lập trình và hội thoại.Tên model:> **An** = English> **Vi** = Vietnamese> **Mt** = Machine TranslationModel được export sang **ONNX** để chạy inference nhẹ và không cần cài toàn bộ Hugging Face Transformers.## ✨ Điểm nổi bật- 🇬🇧 English → 🇻🇳 Vietnamese- ⚡ ONNX Runtime inference- 📱 Có thể chạy trên Android / Termux- 💻 Có thể chạy trên CPU- 🧠 Kiến trúc Seq2Seq encoder-decoder- 🔧 Hỗ trợ khá tốt nội dung kỹ thuật- 💬 Có dữ liệu hội thoại và nhiều cách xưng hô tiếng Việt- 🖥️ Có dữ liệu về Linux, hệ điều hành, kernel, system calls, process, memory, networking- 🤖 Có dữ liệu AI / machine learning / inference- 📦 Runtime package tối giản---# Model filesBản ONNX runtime chỉ cần 3 file:```textAnViMt/├── encoder_model.onnx├── decoder_model.onnx└── spm.modelencoder_model.onnxEncoder nhận câu tiếng Anh đã được tokenize.English text↓Tokenizer↓Token IDs↓encoder_model.onnx↓Encoder hidden statesEncoder xử lý toàn bộ câu nguồn và tạo hidden states dùng cho decoder.---decoder_model.onnxDecoder sinh câu tiếng Việt theo từng token.Encoder hidden states+Previous generated tokens↓decoder_model.onnx↓Next token logits↓Select next token↓Repeat until EOSQuá trình dịch là autoregressive generation.---spm.modelTokenizer SentencePiece.File này chịu trách nhiệm:Text↓SentencePiece↓Token IDs↓ONNX model↓Generated token IDs↓SentencePiece decode↓Vietnamese translation---ArchitectureAnViMt sử dụng kiến trúc Transformer Seq2Seq encoder-decoder.SOURCEEnglish sentence│▼SentencePiece│▼Token IDs│▼┌─────────────────────────┐│ ENCODER ││ encoder_model.onnx │└─────────────────────────┘│▼Hidden states│▼┌─────────────────────────┐│ DECODER ││ decoder_model.onnx │└─────────────────────────┘│▼Output logits│▼Next token│└───────┐│Repeat│▼Vietnamese textModel thuộc nhóm encoder-decoder neural machine translation.---ParametersAnViMt được export từ checkpoint fine-tuned sang ONNX.Các tham số của model được lưu trực tiếp bên trong:encoder_model.onnxdecoder_model.onnxRuntime package ONNX không yêu cầu:config.jsonHugging Face TransformersPyTorchSafetensorsInference chỉ cần:onnxruntimenumpysentencepiece---InstallationPythonpip install onnxruntime numpy sentencepieceTermuxNếu đã có Python:pip install onnxruntime numpy sentencepiece---Quick StartĐặt 3 file:project/├── main.py├── encoder_model.onnx├── decoder_model.onnx└── spm.modelSau đó chạy:python main.py---main.pyVí dụ inference tối giản:import numpy as npimport onnxruntime as ortimport sentencepiece as spmENCODER_MODEL = "encoder_model.onnx"DECODER_MODEL = "decoder_model.onnx"TOKENIZER_MODEL = "spm.model"sp = spm.SentencePieceProcessor()sp.load(TOKENIZER_MODEL)encoder = ort.InferenceSession(ENCODER_MODEL,providers=["CPUExecutionProvider"])decoder = ort.InferenceSession(DECODER_MODEL,providers=["CPUExecutionProvider"])def translate(text, max_length=128):# Tokenize inputinput_ids = sp.encode(text,out_type=int)input_ids = np.array([input_ids],dtype=np.int64)attention_mask = np.ones_like(input_ids,dtype=np.int64)# Encoderencoder_outputs = encoder.run(None,{encoder.get_inputs()[0].name: input_ids,encoder.get_inputs()[1].name: attention_mask,})encoder_hidden_states = encoder_outputs[0]# Decoder start tokendecoder_ids = np.array([[sp.bos_id()]],dtype=np.int64)# Generatefor _ in range(max_length):decoder_inputs = {}for inp in decoder.get_inputs():name = inp.nameif "input_ids" in name:decoder_inputs[name] = decoder_idselif "encoder_hidden_states" in name:decoder_inputs[name] = encoder_hidden_stateselif "attention_mask" in name:decoder_inputs[name] = attention_maskoutputs = decoder.run(None,decoder_inputs)logits = outputs[0]next_token = np.argmax(logits[:, -1, :],axis=-1)decoder_ids = np.concatenate([decoder_ids,next_token[:, None]],axis=1)if int(next_token[0]) == sp.eos_id():breaktokens = decoder_ids[0].tolist()# Remove special tokenstokens = [x for x in tokensif x not in {sp.bos_id(),sp.eos_id(),sp.pad_id()}]return sp.decode(tokens)if __name__ == "__main__":while True:text = input("\nEN > ").strip()if not text:continueif text.lower() in {"exit","quit","q"}:breakresult = translate(text)print("VI >", result)---ExampleInput:The system automatically restarts the failed service after detecting an unexpected process crash.Output:Hệ thống tự động khởi động lại dịch vụ gặp lỗi sau khi phát hiện tiến trình bị sập bất ngờ.---Another exampleInput:The application uses asynchronous I/O so network requests do not block the main execution thread.Expected translation style:Ứng dụng sử dụng I/O bất đồng bộ để các yêu cầu mạng không chặn luồng thực thi chính.---Technical examplesInput:The kernel schedules CPU time according to process priority and current system load.The database transaction was rolled back because a constraint violation occurred during the update.Gradient accumulation allows the model to simulate a larger effective batch size when GPU memory is limited.The inference engine reuses cached key-value states to avoid recomputing previous attention activations.---Conversation examplesInput:Hey bro, can you help me fix this problem? I have been stuck on it for hours.Input:Don't worry, I'll take a look at the logs and see what caused the crash.Input:Could you please restart the service and check whether the error still occurs?AnViMt được train thêm dữ liệu hội thoại để hỗ trợ cách diễn đạt tự nhiên và nhiều phong cách xưng hô tiếng Việt.---Runtime dependenciesAnViMt ONNX runtime chỉ sử dụng 3 thư viện Python:onnxruntimenumpysentencepieceLibrary Purposeonnxruntime Chạy encoder và decoder ONNXnumpy Xử lý tensor / token IDssentencepiece Tokenization và decodingKhông cần:torchtransformersoptimumtensorflow---Supported environmentAnViMt có thể chạy trên:LinuxWindowsmacOSAndroid TermuxCPU environmentsTùy phiên bản ONNX Runtime, có thể sử dụng execution provider khác nếu môi trường hỗ trợ.---LimitationsModel tập trung vào English → Vietnamese.Chất lượng có thể giảm với câu cực dài hoặc cấu trúc hiếm.Một số thuật ngữ chuyên ngành mới có thể được giữ nguyên tiếng Anh.Tên riêng và thuật ngữ kỹ thuật có thể cần hậu kiểm.Bản ONNX runtime này ưu tiên inference đơn giản và nhẹ.---LicenseThis model is released under:CC BY-NC 4.0You are allowed to:DownloadUseShareModifyFine-tuneYou are not allowed to use this model for commercial purposes without permission.Commercial use includes using the model to generate revenue, provide paid services, or integrate it into commercial products.---AuthorPhitran21Model: AnViMtEnglish → Vietnamese Machine Translation
README.md+519-1