harbor run -t openthoughts/tasktrove-mix-h11-single-skill-only-v2-mix-h11-single-skill-2320
harbor download openthoughts/tasktrove-mix-h11-single-skill-only-v2-mix-h11-single-skill-2320
solution file
import torch from omegaconf import DictConfig from transformers import AutoConfig, AutoModelForQuestionAnswering, PretrainedConfig, PreTrainedModel from transformers.modeling_outputs import QuestionAnsweringModelOutput from datamodule.datasets.jsquad import JSQuADDataset from metrics import JSQuADMetric from modules.base import BaseModule class JSQuADModule(BaseModule): MODEL_ARGS = ["input_ids", "attention_mask", "token_type_ids", "start_positions", "end_positions"] def __init__(self, hparams: DictConfig) -> None: super().__init__(hparams) config: PretrainedConfig = AutoConfig.from_pretrained( hparams.model_name_or_path, finetuning_task="JSQuAD", ) self.model: PreTrainedModel = AutoModelForQuestionAnswering.from_pretrained( hparams.model_name_or_path, config=config, ) self.metric = JSQuADMetric() def forward(self, batch: dict[str, torch.Tensor]) -> QuestionAnsweringModelOutput: return self.model(**{k: v for k, v in batch.items() if k in self.MODEL_ARGS}) def training_step(self, batch: dict[str, torch.Tensor], batch_idx: int) -> torch.Tensor: out: QuestionAnsweringModelOutput = self(batch) self.log("train/loss", out.loss) return out.loss def validation_step(self, batch: dict[str, torch.Tensor], batch_idx: int) -> None: out: QuestionAnsweringModelOutput = self(batch) dataset: JSQuADDataset = self.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py
/app/solution.py