File size: 1,002 Bytes
03d39cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
code for using this model

from huggingface_hub import snapshot_download
import json
import torch
from downloaded_model.main_model import Seq2Seq , generate_answer

# Download model files from Hugging Face Hub
snapshot_download(repo_id="DP27/test-ma-model", local_dir="downloaded_model")


with open("./downloaded_model/config.json", "r") as f:
    config = json.load(f)

vocab_size = config["vocab_size"]
embedding_dim = config["embedding_dim"]
hidden_dim = config["hidden_dim"]
max_len = config["max_len"]

# Initialize Model
model = Seq2Seq(vocab_size, embedding_dim, hidden_dim)
model.load_state_dict(torch.load("./downloaded_model/seq2seq_model.pth",weights_only=True))
model.eval()  # Set model to evaluation mode

with open("./downloaded_model/ma_vocab.json", "r") as f:
    vocab = json.load(f)

# Create mappings
word2idx = vocab
idx2word = {idx: word for word, idx in vocab.items()}


question = "what is MA?"
answer = generate_answer(model, question, vocab=word2idx)
print("Answer:", answer)