Esempio n. 1
0
def test_tc_train_effectiveness():
    """assert that training decreases the loss"""
    happy_tc = HappyTextClassification(model_type="DISTILBERT",
                                       model_name="distilbert-base-uncased")
    before_loss = happy_tc.eval("../data/tc/train-eval.csv").loss
    happy_tc.train("../data/tc/train-eval.csv")
    after_loss = happy_tc.eval("../data/tc/train-eval.csv").loss
    assert after_loss < before_loss
Esempio n. 2
0
def test_tc_train_effectiveness_multi():

    happy_tc = HappyTextClassification(model_type="DISTILBERT",
                                       model_name="distilbert-base-uncased",
                                       num_labels=3)
    before_loss = happy_tc.eval("../data/tc/train-eval-multi.csv").loss
    happy_tc.train("../data/tc/train-eval-multi.csv")
    after_loss = happy_tc.eval("../data/tc/train-eval-multi.csv").loss
    assert after_loss < before_loss
Esempio n. 3
0
def example_2_5():
    happy_tc = HappyTextClassification(
        model_type="DISTILBERT",
        model_name="distilbert-base-uncased-finetuned-sst-2-english",
        num_labels=2)  # Don't forget to set num_labels!
    before_loss = happy_tc.eval("../../data/tc/train-eval.csv").loss
    happy_tc.train("../../data/tc/train-eval.csv")
    after_loss = happy_tc.eval("../../data/tc/train-eval.csv").loss
    print("Before loss: ", before_loss)  # 0.007262040860950947
    print("After loss: ", after_loss)  # 0.000162081079906784
Esempio n. 4
0
def test_tc_with_dataclass():

    happy_tc = HappyTextClassification()
    train_args = TCTrainArgs(learning_rate=0.01, num_train_epochs=1)

    happy_tc.train("../data/tc/train-eval.csv", args=train_args)

    eval_args = TCEvalArgs()

    result_eval = happy_tc.eval("../data/tc/train-eval.csv", args=eval_args)

    test_args = TCTestArgs()

    result_test = happy_tc.test("../data/tc/test.csv", args=test_args)
Esempio n. 5
0
def test_tc_with_dic():

    happy_tc = HappyTextClassification()
    train_args = {'learning_rate': 0.01, "num_train_epochs": 1}

    happy_tc.train("../data/tc/train-eval.csv", args=train_args)

    eval_args = {}

    result_eval = happy_tc.eval("../data/tc/train-eval.csv", args=eval_args)

    test_args = {}

    result_test = happy_tc.test("../data/tc/test.csv", args=test_args)
Esempio n. 6
0
def test_tc_train():
    happy_tc = HappyTextClassification(
        model_type="DISTILBERT",
        model_name="distilbert-base-uncased-finetuned-sst-2-english")
    results = happy_tc.train("../data/tc/train-eval.csv")
Esempio n. 7
0
def example_2_2():
    happy_tc = HappyTextClassification(
        model_type="DISTILBERT",
        model_name="distilbert-base-uncased-finetuned-sst-2-english",
        num_labels=2)  # Don't forget to set num_labels!
    happy_tc.train("../../data/tc/train-eval.csv")