This is a character-level Transformer model trained for English → Telugu translation.
1import torch
2import json
3from model import Transformer # make sure you have this definition
4
5# Load config
6with open("config.json", "r", encoding="utf-8") as f:
7 config = json.load(f)
8
9# Load vocab
10with open("english_vocabulary.json", "r", encoding="utf-8") as f:
11 en_vocab = json.load(f)
12with open("telugu_vocabulary.json", "r", encoding="utf-8") as f:
13 te_vocab = json.load(f)
14
15# Reverse vocab for decoding
16idx2telugu = {i: ch for i, ch in enumerate(te_vocab)}
17telugu2idx = {ch: i for i, ch in enumerate(te_vocab)}
18
19# Load model
20model = Transformer(
21 config["d_model"],
22 config["ffn_hidden"],
23 config["num_heads"],
24 config["drop_prob"],
25 config["num_layers"],
26 len(en_vocab),
27 len(te_vocab),
28 config["max_sequence_length"]
29)
30model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
31model.eval()
32
33# Translate a sentence
34def translate(sentence):
35 # Implement encoding → model inference → decoding
36 pass # Replace with your tokenization + inference code
37
38print(translate("i love my country."))