Skip to content

Commit 8a34e8e

Browse files
authored
Merge pull request #190 from kermitt2/feature/remove-elmo
Remove ELMo support :'(
2 parents 6d89f27 + 64030d0 commit 8a34e8e

22 files changed

Lines changed: 44 additions & 3567 deletions

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DeLFT has three main purposes:
2222

2323
Some contributions include:
2424

25-
* A variety of modern NLP architectures and tasks to be used following the same API and input formats, including RNN, ELMo and transformers.
25+
* A variety of modern NLP architectures and tasks to be used following the same API and input formats, including RNN and transformers.
2626

2727
* Reduction of the size of RNN models, in particular by removing word embeddings from them. For instance, the model for the toxic comment classifier went down from a size of 230 MB with embeddings to 1.8 MB. In practice the size of all the models of DeLFT is less than 2 MB, except for Ontonotes 5.0 NER model which is 4.7 MB.
2828

delft/applications/datasetTagger.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def configure(architecture, output_path=None, max_sequence_length=-1,
1515
batch_size=-1, embeddings_name=None,
16-
max_epoch=-1, use_ELMo=False, patience=-1, early_stop=None):
16+
max_epoch=-1, patience=-1, early_stop=None):
1717
"""
1818
Set up the default parameters based on the model type.
1919
"""
@@ -46,10 +46,7 @@ def configure(architecture, output_path=None, max_sequence_length=-1,
4646
multiprocessing = False
4747

4848
model_name += '-' + architecture
49-
50-
if use_ELMo:
51-
model_name += '-with_ELMo'
52-
49+
5350
if batch_size == -1:
5451
batch_size = 20
5552

@@ -72,7 +69,7 @@ def configure(architecture, output_path=None, max_sequence_length=-1,
7269
def train(embeddings_name=None, architecture='BidLSTM_CRF', transformer=None,
7370
input_path=None, output_path=None, fold_count=1,
7471
features_indices=None, max_sequence_length=-1,
75-
batch_size=-1, use_ELMo=False,
72+
batch_size=-1,
7673
max_epoch=-1,
7774
patience=-1,
7875
learning_rate=None,
@@ -107,7 +104,6 @@ def train(embeddings_name=None, architecture='BidLSTM_CRF', transformer=None,
107104
batch_size,
108105
embeddings_name,
109106
max_epoch,
110-
use_ELMo,
111107
patience,
112108
early_stop)
113109
model = Sequence(model_name,
@@ -120,7 +116,6 @@ def train(embeddings_name=None, architecture='BidLSTM_CRF', transformer=None,
120116
fold_number=fold_count,
121117
features_indices=features_indices,
122118
max_epoch=max_epoch,
123-
use_ELMo=use_ELMo,
124119
multiprocessing=multiprocessing,
125120
early_stop=early_stop,
126121
patience=patience,
@@ -142,7 +137,7 @@ def train(embeddings_name=None, architecture='BidLSTM_CRF', transformer=None,
142137
# split data, train a model and evaluate it
143138
def train_eval(embeddings_name=None, architecture='BidLSTM_CRF', transformer=None,
144139
input_path=None, output_path=None, fold_count=1,
145-
features_indices=None, max_sequence_length=-1, batch_size=-1, use_ELMo=False,
140+
features_indices=None, max_sequence_length=-1, batch_size=-1,
146141
max_epoch=-1,
147142
patience=-1,
148143
learning_rate=None,
@@ -179,7 +174,6 @@ def train_eval(embeddings_name=None, architecture='BidLSTM_CRF', transformer=Non
179174
batch_size,
180175
embeddings_name,
181176
max_epoch,
182-
use_ELMo,
183177
patience=patience,
184178
early_stop=early_stop)
185179
model = Sequence(model_name,
@@ -192,7 +186,6 @@ def train_eval(embeddings_name=None, architecture='BidLSTM_CRF', transformer=Non
192186
fold_number=fold_count,
193187
features_indices=features_indices,
194188
max_epoch=max_epoch,
195-
use_ELMo=use_ELMo,
196189
multiprocessing=multiprocessing,
197190
early_stop=early_stop,
198191
patience=patience,
@@ -224,14 +217,12 @@ def eval_(input_path=None, architecture=None):
224217

225218

226219
# annotate a list of texts
227-
def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=None, use_ELMo=False, multi_gpu=False):
220+
def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=None, multi_gpu=False):
228221
annotations = []
229222

230223
# load model
231224
model_name = 'datasets'
232225
model_name += '-'+architecture
233-
if use_ELMo:
234-
model_name += '-with_ELMo'
235226

236227
model = Sequence(model_name)
237228
model.load()
@@ -323,7 +314,6 @@ def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=Non
323314
max_sequence_length = args.max_sequence_length
324315
batch_size = args.batch_size
325316
transformer = args.transformer
326-
use_ELMo = args.use_ELMo
327317
patience = args.patience
328318
learning_rate = args.learning_rate
329319
max_epoch = args.max_epoch
@@ -342,7 +332,6 @@ def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=Non
342332
output_path=output,
343333
max_sequence_length=max_sequence_length,
344334
batch_size=batch_size,
345-
use_ELMo=use_ELMo,
346335
patience=patience,
347336
learning_rate=learning_rate,
348337
max_epoch=max_epoch,
@@ -368,7 +357,6 @@ def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=Non
368357
fold_count=args.fold_count,
369358
max_sequence_length=max_sequence_length,
370359
batch_size=batch_size,
371-
use_ELMo=use_ELMo,
372360
patience=patience,
373361
learning_rate=learning_rate,
374362
max_epoch=max_epoch,
@@ -383,7 +371,7 @@ def annotate_text(texts, output_format, architecture='BidLSTM_CRF', features=Non
383371
someTexts.append("We also compare ShanghaiTechRGBD with other RGB-D crowd counting datasets in , and we can see that ShanghaiTechRGBD is the most challenging RGB-D crowd counting dataset in terms of the number of images and heads.")
384372
someTexts.append("Insulin levels of all samples were measured by ELISA kit (Mercodia)")
385373

386-
result = annotate_text(someTexts, "json", architecture=architecture, use_ELMo=use_ELMo, multi_gpu=multi_gpu)
374+
result = annotate_text(someTexts, "json", architecture=architecture, multi_gpu=multi_gpu)
387375
print(json.dumps(result, sort_keys=False, indent=4, ensure_ascii=False))
388376

389377

0 commit comments

Comments
 (0)