longformer-large-4096 ajustado para responder RACE
potsawee
Pregunta y respuesta
El modelo Longformer-large-4096 está ajustado al conjunto de datos RACE para la respuesta de preguntas de opción múltiple. El modelo toma como entrada una concatenación de contexto + pregunta + opción y produce una probabilidad sobre las opciones. Este es el componente de respuesta a preguntas (QA) en nuestro artículo MQAG. Para más detalles, refiérase al repositorio de GitHub de este proyecto.
Como usar
Como usar el modelo:
import torch
import numpy as np
from transformers import LongformerTokenizer, LongformerForMultipleChoice
tokenizer = LongformerTokenizer.from_pretrained('potsawee/longformer-large-4096-answering-race')
model = LongformerForMultipleChoice.from_pretrained('potsawee/longformer-large-4096-answering-race')
context = '''Chelsea's mini-revival continued with a third victory in a row as they consigned struggling Leicester City to a fifth consecutive defeat.
Buoyed by their Champions League win over Borussia Dortmund, Chelsea started brightly and Ben Chilwell volleyed in from a tight angle against his old club.
Chelsea's Joao Felix and Leicester's Kiernan Dewsbury-Hall hit the woodwork in the space of two minutes, then Felix had a goal ruled out by the video assistant referee for offside.
Patson Daka rifled home an excellent equaliser after Ricardo Pereira won the ball off the dawdling Felix outside the box.
But Kai Havertz pounced six minutes into first-half injury time with an excellent dinked finish from Enzo Fernandez's clever aerial ball.
Mykhailo Mudryk thought he had his first goal for the Blues after the break but his effort was disallowed for offside.
Mateo Kovacic sealed the win as he volleyed in from Mudryk's header.
The sliding Foxes, who ended with 10 men following Wout Faes' late dismissal for a second booking, now just sit one point outside the relegation zone.'''.replace('\n', ' ')
question = 'Who had a goal ruled out for offside?'
options = ['Ricardo Pereira', 'Ben Chilwell', 'Joao Felix', 'The Foxes']
inputs = prepare_answering_input(
tokenizer=tokenizer, question=question,
options=options, context=context,
)
outputs = model(**inputs)
prob = torch.softmax(outputs.logits, dim=-1)[0].tolist()
selected_answer = options[np.argmax(prob)]
print(prob)
[0.00145158, 0.00460851, 0.99049687, 0.00344302]
print(selected_answer)
Joao Felix
# Función para preparar la entrada
def prepare_answering_input(
tokenizer, # longformer_tokenizer
question, # str
options, # List[str]
context, # str
max_seq_length=4096,
):
c_plus_q = context + ' ' + tokenizer.bos_token + ' ' + question
c_plus_q_4 = [c_plus_q] * len(options)
tokenized_examples = tokenizer(
c_plus_q_4, options,
max_length=max_seq_length,
padding='longest',
truncation=True,
return_tensors='pt',
)
input_ids = tokenized_examples['input_ids'].unsqueeze(0)
attention_mask = tokenized_examples['attention_mask'].unsqueeze(0)
example_encoded = {
'input_ids': input_ids,
'attention_mask': attention_mask,
}
return example_encoded
Funcionalidades
- Entrenado en el conjunto de datos RACE
- Responde preguntas de opción múltiple
- Utiliza la arquitectura Longformer
- Produce logit (o probabilidad) sobre las opciones
Casos de uso
- Responde preguntas de opción múltiple basadas en contexto
- Generación y respuesta a preguntas para evaluar la consistencia de la información en resúmenes
- Aplicaciones educativas y evaluaciones automatizadas