def main(): # Be careful not to commit the csv files to the rep train_csv_path = "train.csv" eval_csv_path = "eval.csv" train_dataset = load_dataset('squad', split='train[0:499]') eval_dataset = load_dataset('squad', split='validation[0:99]') generate_csv(train_csv_path, train_dataset) generate_csv(eval_csv_path, eval_dataset) happy_qa = HappyQuestionAnswering(model_type="BERT", model_name="bert-base-uncased") before_loss = happy_qa.eval(eval_csv_path) happy_qa.train(train_csv_path) after_loss = happy_qa.eval(eval_csv_path) print("Before loss: ", before_loss.loss) print("After loss: ", after_loss.loss)
def test_qa_test(): happy_qa = HappyQuestionAnswering() results = happy_qa.test("../data/qa/test.csv") assert results[0].answer == 'October 31st' assert results[1].answer == 'November 23rd'
def test_qa_eval(): happy_qa = HappyQuestionAnswering( model_type='DISTILBERT', model_name='distilbert-base-cased-distilled-squad') result = happy_qa.eval("../data/qa/train-eval.csv") assert result.loss == approx(0.11738169193267822, 0.001)
def test_qa_train(): happy_qa = HappyQuestionAnswering( model_type='DISTILBERT', model_name='distilbert-base-cased-distilled-squad') result = happy_qa.train("../data/qa/train-eval.csv")