INNER CODE UNIT · Python
_encode_qa
AMontgomerie/question_generator · questiongenerator.py:367
def _encode_qa(self, question: str, answer: str) -> torch.tensor:
"""Concatenates a question and answer, and then tokenizes them. Returns a tensor of
input ids corresponding to indices in the vocab.
"""
if type(answer) is list:
for a in answer:
if a["correct"]:
correct_answer = a["answer"]
else:
correct_answer = answer
return self.qae_tokenizer(
text=question,
text_pair=correct_answer,
padding="max_length",
max_length=self.SEQ_LENGTH,
truncation=True,
return_tensors="pt",