Major refactoring of Model classes (Step 2) #2351
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As we are now adding many more types of models to Flair (see #2333) we are refactoring the logic of Flair model classes to remove many redundancies and make the code hopefully easier to read.
This PR is the second step in this refactoring process and mainly adds the new
DefaultClassifier
base class to Flair. It contains all logic that is shared by models that do classification, so that these models use the same (1) evaluation code, (2) prediction code and (3) loss computation code. Any Flair model that inherits fromDefaultClassifier
now only has to implement theforward_pass()
method - all the rest is then supplied by the parent class.With this refactoring, the
TextClassifier
, theRelationExtractor
, theTextPairClassifier
and theSimpleSequenceTagger
now inherits fromDefaultClassifier
. Accordingly, much redundant code has disappeared. TheSequenceTagger
still inherits fromClassifier
, but this will change as a major refactoring here is planned as well.In addition, the TARS classes (
TARSClassifier
andTARSTagger
) were broadly refactored so thatt they inherit from the new base classFewshotClassifier
and share most of the TARS logic through the super class. This removed many redundancies. The implementation ofTARSClassifier
is now slightly different from before as single-label predictions are no longer enforced.In addition, many small changes were made:
batch_size
parameter inTransformerDocumentEmbeddings
has been removed since it is very counterintuitive and caused speed losses if not used correctly. The default behavior is not to batch over all sentences in a given mini-batch.Dictionary
with the methodremove_item()
make_label_dictionary()
method of theCorpus
now requires you to specify alabel_type
. To make this change easier, it now prints a list of all available label types when a dictionary is computedGO_EMOTIONS
dataset is renamed to 'emotion'TextPairClassifier
now resides in its own moduleflair.nn
module was split into a folder structure