Files changed (1) hide show
  1. README.md +20 -0
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: openrail
3
+ ---
4
+ import torch
5
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering
6
+ tokenizer = AutoTokenizer.from_pretrained("atharvamundada99/bert-large-question-answering-finetuned-legal",cache_dir="/E/HUG_Models")
7
+ model = AutoModelForQuestionAnswering.from_pretrained("atharvamundada99/bert-large-question-answering-finetuned-legal", cache_dir="/E/HUG_Models")
8
+
9
+ def get_answer( question, context):
10
+ inputs = tokenizer(question, context, return_tensors="pt")
11
+ with torch.no_grad():
12
+ outputs = model(**inputs)
13
+ answer_start_index = outputs.start_logits.argmax()
14
+ answer_end_index = outputs.end_logits.argmax()
15
+
16
+ predict_answer_tokens = inputs.input_ids[0, answer_start_index: answer_end_index + 1]
17
+ answer=tokenizer.decode(predict_answer_tokens, skip_special_tokens=True)
18
+ return answer
19
+ print(get_answer("What is your name","My name is JACK"))
20
+ #output JACK