Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextPair regression model #3202

Merged
merged 4 commits into from
Apr 21, 2023
Merged

Add TextPair regression model #3202

merged 4 commits into from
Apr 21, 2023

Conversation

plonerma
Copy link
Collaborator

@plonerma plonerma commented Apr 19, 2023

The STS-B task (added in #3201) of the glue benchmark requires a regression model which operates on sentence pairs. The added model can be used to solve this task, e.g. using following training script (this should result in a spearman correlation of ~0.8730):

import sys
from pathlib import Path

import flair
from flair.datasets import GLUE_STSB
from flair.embeddings import TransformerDocumentEmbeddings
from flair.models import TextPairRegressor
from flair.trainers import ModelTrainer


def train(device, seed=0):
    flair.device = device
    flair.set_seed(seed)

    corpus = GLUE_STSB()

    label_type: str = "similarity"

    embeddings = TransformerDocumentEmbeddings("bert-base-uncased", layers="-1", fine_tune=True)

    model = TextPairRegressor(embeddings=embeddings, label_type=label_type)

    trainer = ModelTrainer(model, corpus)

    trainer.fine_tune(
        Path("resources/regression/stsb_model"),
        learning_rate=5e-5,
        mini_batch_size=32,
        max_epochs=5,
        warmup_fraction=0.06,
        main_evaluation_metric=("correlation", "pearson"),
        weight_decay=0.1,
    )


if __name__ == "__main__":
    assert len(sys.argv) == 2, "Pass a device to train on."
    train(sys.argv[1])

@alanakbik
Copy link
Collaborator

Merged with #3211

@alanakbik alanakbik deleted the textpair_regression_model branch April 21, 2023 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants