Download run_example.py from NodeNestor/bifrost-flash-430m: direct link, hf CLI and curl.
- Browser
- Download file 683 Bytes
-
https://huggingface.co/NodeNestor/bifrost-flash-430m/resolve/main/run_example.py
- Command line
-
hf download hf://NodeNestor/bifrost-flash-430m/run_example.py
-
curl -L -o run_example.py https://huggingface.co/NodeNestor/bifrost-flash-430m/resolve/main/run_example.py
683 Bytes
| """Minimal example. Usage: python run_example.py "Hello, how are you?" sv""" | |
| import sys, os, torch, sentencepiece as spm | |
| from modeling_flash import NordicFlash | |
| H = os.path.dirname(__file__) | |
| LANG = {"en":65000,"sv":65001,"da":65002,"nb":65003,"nn":65004,"fi":65005,"is":65006} | |
| text = sys.argv[1] if len(sys.argv) > 1 else "Hello, how are you today?" | |
| tgt = sys.argv[2] if len(sys.argv) > 2 else "sv" | |
| sp = spm.SentencePieceProcessor(); sp.load(H + "/nordic_unigram_65k.model") | |
| m = NordicFlash.from_checkpoint(H + "/model.safetensors", device="cuda" if torch.cuda.is_available() else "cpu") | |
| out = m.translate(sp.encode(text, out_type=int), LANG[tgt]) | |
| print(f"[{tgt}] {sp.decode(out)}") | |