DP27 commited on
Commit
03d39cc
·
verified ·
1 Parent(s): c66a046

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ code for using this model
2
+
3
+ from huggingface_hub import snapshot_download
4
+ import json
5
+ import torch
6
+ from downloaded_model.main_model import Seq2Seq , generate_answer
7
+
8
+ # Download model files from Hugging Face Hub
9
+ snapshot_download(repo_id="DP27/test-ma-model", local_dir="downloaded_model")
10
+
11
+
12
+ with open("./downloaded_model/config.json", "r") as f:
13
+ config = json.load(f)
14
+
15
+ vocab_size = config["vocab_size"]
16
+ embedding_dim = config["embedding_dim"]
17
+ hidden_dim = config["hidden_dim"]
18
+ max_len = config["max_len"]
19
+
20
+ # Initialize Model
21
+ model = Seq2Seq(vocab_size, embedding_dim, hidden_dim)
22
+ model.load_state_dict(torch.load("./downloaded_model/seq2seq_model.pth",weights_only=True))
23
+ model.eval() # Set model to evaluation mode
24
+
25
+ with open("./downloaded_model/ma_vocab.json", "r") as f:
26
+ vocab = json.load(f)
27
+
28
+ # Create mappings
29
+ word2idx = vocab
30
+ idx2word = {idx: word for word, idx in vocab.items()}
31
+
32
+
33
+ question = "what is MA?"
34
+ answer = generate_answer(model, question, vocab=word2idx)
35
+ print("Answer:", answer)