File size: 1,335 Bytes
adb7bab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#!/usr/bin/env python3
"""
Example usage of Braille256-v1 model.
"""
import torch
from braille256_model import Braille256Model, Braille256Config
from braille256_tokenizer import Braille256Tokenizer
def main():
# Load model and tokenizer
model_path = "." # or path to downloaded model
config = Braille256Config.from_pretrained(model_path)
model = Braille256Model.from_pretrained(model_path, config=config)
tokenizer = Braille256Tokenizer.from_pretrained(model_path)
model.eval()
print(f"Model loaded: {sum(p.numel() for p in model.parameters()):,} parameters")
# Example: Generate from Braille prompt
prompts = [
("⠞⠓⠑", "the"),
("⠁⠝⠙", "and"),
("⠋⠕⠗", "for"),
]
print("\nGeneration examples:")
print("-" * 50)
for braille_prompt, english in prompts:
tokens = tokenizer.encode(braille_prompt, add_special_tokens=True)
input_ids = torch.tensor([tokens])
with torch.no_grad():
output = model.generate(input_ids, max_length=50, temperature=0.7)
generated = tokenizer.decode(output[0].tolist())
print(f"Prompt: {english} ({braille_prompt})")
print(f"Generated: {generated[:60]}...")
print()
if __name__ == "__main__":
main()
|