INNER CODE UNIT · Python
_encode_qg_input
AMontgomerie/question_generator · questiongenerator.py:275
def _encode_qg_input(self, qg_input: str) -> torch.tensor:
"""Tokenizes a string and returns a tensor of input ids corresponding to indices of tokens in
the vocab.
"""
return self.qg_tokenizer(
qg_input,
padding='max_length',
max_length=self.SEQ_LENGTH,
truncation=True,
return_tensors="pt",
).to(self.device)
def _get_ranked_qa_pairs(
self, generated_questions: List[str], qg_answers: List[str], scores, num_questions: int = 10
) -> List[Mapping[str, str]]:
"""Ranks generated questions according to scores, and returns the top num_questions examples.
"""
if num_questions > len(scores):