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

GH-921: fine-tune FlairEmbeddings #922

Merged
merged 3 commits into from
Jul 22, 2019
Merged

GH-921: fine-tune FlairEmbeddings #922

merged 3 commits into from
Jul 22, 2019

Conversation

alanakbik
Copy link
Collaborator

@alanakbik alanakbik commented Jul 22, 2019

Closes #921

This PR makes FlairEmbeddings task-trainable. This allows users to (a) fine-tune an existing language model on task data and (b) train a new model only on task data.

  • You can fine-tune an existing LM by simply passing the fine_tune parameter in the FlairEmbeddings constructor, like this:
embeddings = FlairEmbeddings('news-foward', fine_tune=True)
  • You can task-train a wholly new language model by passing an empty LanguageModel to the FlairEmbeddings constructor and the fine_tune parameter, like this:
# make an empty language model
language_model = LanguageModel(
    Dictionary.load('chars'),
    is_forward_lm=True,
    hidden_size=256,
    nlayers=1)

# init FlairEmbeddings to task-train this model
embeddings = FlairEmbeddings(language_model, fine_tune=True)

@alanakbik alanakbik changed the title Gh 921 fune tune flair GH-921: fine-tune FlairEmbeddings Jul 22, 2019
@yosipk
Copy link
Collaborator

yosipk commented Jul 22, 2019

👍

1 similar comment
@alanakbik
Copy link
Collaborator Author

👍

@alanakbik alanakbik merged commit 9f49d09 into master Jul 22, 2019
@alanakbik alanakbik deleted the GH-921-fune-tune-flair branch July 22, 2019 15:14
@jasminesjlee
Copy link

For clarification -- what exactly does it mean to "task-train a wholly new language model"? Is this different from training a LM on this data from scratch?

@alanakbik
Copy link
Collaborator Author

Hello @jasminesjlee yes this would be different since the training objective is different. A standard language model is trained to predict the next character given the previous characters. However, what we do here is wrap it into FlairEmbeddings and train it on a downstream task (such as NER). So we train a character-level RNN to produce useful features specifically for the downstream task (see the paper by Liu et al. who originally proposed this). Due to the different objective, such an LM cannot be used to generate text.

@jasminesjlee
Copy link

Ah, I understand. Thank you @alanakbik ! :)

@DecentMakeover
Copy link

@alanakbik What branch should i be in to access these changes i am currently on

      origin/GH-538-attention
  origin/GH-822-xlnet
  origin/GH-873-pytorch-transformers
  origin/HEAD -> remotes/origin/master
  origin/SimilarityLearner
  origin/master
  origin/release-0.4.1

Thanks

@pommedeterresautee
Copy link
Contributor

As this PR is merged it is available on master

@DecentMakeover
Copy link

@pommedeterresautee Thanks .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants