コード例 #1
0
def test_tc_test():
    happy_tc = HappyTextClassification(
        model_type="DISTILBERT",
        model_name="distilbert-base-uncased-finetuned-sst-2-english")

    result = happy_tc.test("../data/tc/test.csv")
    answer = [
        TextClassificationResult(label='POSITIVE', score=0.9998401999473572),
        TextClassificationResult(label='NEGATIVE', score=0.9772131443023682),
        TextClassificationResult(label='NEGATIVE', score=0.9966067671775818),
        TextClassificationResult(label='POSITIVE', score=0.9792295098304749)
    ]
    assert result == answer
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
def example_2_4():
    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!
    result = happy_tc.test("../../data/tc/test.csv")
    print(type(result))  # <class 'list'>
    print(
        result
    )  # [TextClassificationResult(label='LABEL_1', score=0.9998401999473572), TextClassificationResult(label='LABEL_0', score=0.9772131443023682)...
    print(
        type(result[0])
    )  # <class 'happytransformer.happy_text_classification.TextClassificationResult'>
    print(
        result[0]
    )  # TextClassificationResult(label='LABEL_1', score=0.9998401999473572)
    print(result[0].label)  # LABEL_1