Unable to retrieve URL from context
Hi All,Im trying question answer for one of the usecase, Im unable to retrieve URLs from context using tranformers model, below is the code snippet for reference. please help me in resolving the issue.import pandas as pdimport jsonimport torchfrom transformers import AutoTokenizer, AutoModelForQuestionAnsweringdata = pd.read_csv(r’C:\Users\anvitha.haviligi\Downloads\threatmodel.csv’)questions = data[‘question’].tolist()contexts = data[‘context’].tolist()tokenizer = AutoTokenizer.from_pretrained(‘bert-large-uncased-whole-word-masking-finetuned-squad’)model = AutoModelForQuestionAnswering.from_pretrained(‘bert-large-uncased-whole-word-masking-finetuned-squad’)def predict_answer(question, context):inputs = tokenizer.encode_plus(question, context, add_special_tokens=True, return_tensors=‘pt’)input_ids = inputs[‘input_ids’]attention_mask = inputs[‘attention_mask’]outputs = model(input_ids=input_ids, attention_mask=attention_mask)
answer_start_scores = outputs.start_logits
answer_end_scores = outputs.end_logits

# Find the top-k start and end indices
start_indices = torch.topk(answer_start_scores, k=1, dim=1)[1].squeeze()
end_indices = torch.topk(answer_end_scores, k=1, dim=1)[1].squeeze()

# Convert the indices to token IDs and decode the answer
input_ids = input_ids.squeeze()
answer = tokenizer.decode(input_ids[start_indices: end_indices+1])

return answerfor i in range(len(questions)):question = questions[i]context = contexts[i]answer = predict_answer(question, context)print(“Question:”, question)print(“Context:”, context)print(“Answer:”, answer)print(“—”)question = What is the method used for threat modelling?Threat modelling methodology:https://rak.box.com/s/d15qngm7xp6haqacyk6e1phcht1mzz011Thanks in advance