Download main.py from echodict/rosa-plus: direct link, hf CLI and curl.
- Browser
- Download file 887 Bytes
-
https://huggingface.co/datasets/echodict/rosa-plus/resolve/main/main.py
- Command line
-
hf download hf://datasets/echodict/rosa-plus/main.py
-
curl -L -o main.py https://huggingface.co/datasets/echodict/rosa-plus/resolve/main/main.py
887 Bytes
| from rosaplus import ROSAPlus | |
| # import requests | |
| # # Train on Shakespare | |
| # url = "https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt" | |
| # # Download the text | |
| # response = requests.get(url) | |
| # text = response.text | |
| # print("Downloaded text.") | |
| # m2 = ROSAPlus.load("rosa-model.json") | |
| # prompt = "ROMEO:" # Novel text | |
| # max_tokens = 256 | |
| # print(prompt + m2.generate(prompt, steps=max_tokens)) | |
| with open('tinyshakespeare.txt', "r", encoding='UTF-8') as f: | |
| text = f.read() | |
| # Initialize model | |
| m = ROSAPlus(max_order=1048576, use_eot=False, seed=0) | |
| m.train_example(text) # Train ROSA | |
| m.build_lm() # Train fallback predictor | |
| # Prompting | |
| prompt = "ROMEO:" # Novel text | |
| max_tokens = 256 | |
| # Eval mode | |
| print(prompt + m.generate(prompt, steps=max_tokens)) | |
| # Saving model | |
| m.save("rosa-model.json") | |
| m2 = ROSAPlus.load("rosa-model.json") # Loading model | |