| import json |
| import torch |
|
|
| |
| with open('config.json', 'r') as f: |
| config = json.load(f) |
|
|
| |
| with open('tokenizer_config.json', 'r', encoding='utf-8') as f: |
| tokenizer_data = json.load(f) |
| stoi = tokenizer_data['stoi'] |
| itos = {i: ch for ch, i in stoi.items()} |
|
|
| def encode(s): return [stoi.get(c, stoi[" "]) for c in s] |
| def decode(l): return "".join([itos.get(i, "") for i in l]) |
|
|
| |
| model = MedicalMasterAI(config) |
|
|
| |
| random_string = "LنIBkيظقcظزSرoIeD!OxMعه*kDNO]وzOبXقآلt(بdأfk." |
| encoded_ids = encode(random_string) |
| print(f"Encoded IDs: {encoded_ids}") |
| print(f"Decoded Text: {decode(encoded_ids)}") |
|
|
| |
| input_tensor = torch.tensor([encoded_ids]) |
| with torch.no_grad(): |
| logits = model(input_tensor) |
| print(f"Output shape (Batch, Seq, Vocab): {logits.shape}") |