Skip to content

Commit 1b0b07c

Browse files
committed
ELMoEmbedding
1 parent 2c37330 commit 1b0b07c

File tree

19 files changed

+194
-34
lines changed

19 files changed

+194
-34
lines changed

docs/source/modules/transformer.rst renamed to docs/source/modules/pretrained.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
Transformer Layers
22
================================================================
33

4-
.. currentmodule:: supar.modules.transformer
4+
.. currentmodule:: supar.modules.pretrained
55

66
TransformerEmbedding
77
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
.. autoclass:: TransformerEmbedding
99
:members:
1010

11+
ELMoEmbedding
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
.. autoclass:: ELMoEmbedding
14+
:members:
15+
1116
ScalarMix
1217
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1318
.. autoclass:: ScalarMix

supar/cmds/biaffine_dep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1616
# train
1717
subparser = subparsers.add_parser('train', help='Train a parser.')
18-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
18+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
1919
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
2020
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
2121
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/biaffine_sdp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main():
1212
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1313
# train
1414
subparser = subparsers.add_parser('train', help='Train a parser.')
15-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'lemma', 'bert'], nargs='+', help='features to use')
15+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'lemma', 'elmo', 'bert'], nargs='+', help='features to use')
1616
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
1717
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
1818
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/crf2o_dep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1717
# train
1818
subparser = subparsers.add_parser('train', help='Train a parser.')
19-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
19+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
2020
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
2121
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
2222
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/crf_con.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main():
1313
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1414
# train
1515
subparser = subparsers.add_parser('train', help='Train a parser.')
16-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
16+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
1717
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
1818
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
1919
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/crf_dep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1717
# train
1818
subparser = subparsers.add_parser('train', help='Train a parser.')
19-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
19+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
2020
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
2121
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
2222
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/vi_con.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main():
1212
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1313
# train
1414
subparser = subparsers.add_parser('train', help='Train a parser.')
15-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
15+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
1616
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
1717
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
1818
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/vi_dep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1616
# train
1717
subparser = subparsers.add_parser('train', help='Train a parser.')
18-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'bert'], nargs='+', help='features to use')
18+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'elmo', 'bert'], nargs='+', help='features to use')
1919
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
2020
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
2121
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/cmds/vi_sdp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main():
1212
subparsers = parser.add_subparsers(title='Commands', dest='mode')
1313
# train
1414
subparser = subparsers.add_parser('train', help='Train a parser.')
15-
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'lemma', 'bert'], nargs='+', help='features to use')
15+
subparser.add_argument('--feat', '-f', choices=['tag', 'char', 'lemma', 'elmo', 'bert'], nargs='+', help='features to use')
1616
subparser.add_argument('--build', '-b', action='store_true', help='whether to build the model first')
1717
subparser.add_argument('--checkpoint', action='store_true', help='whether to load a checkpoint to restore training')
1818
subparser.add_argument('--encoder', choices=['lstm', 'bert'], default='lstm', help='encoder to use')

supar/models/con.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class CRFConstituencyModel(Model):
4646
The size of hidden states of CharLSTM, required if using CharLSTM. Default: 100.
4747
char_pad_index (int):
4848
The index of the padding token in the character vocabulary, required if using CharLSTM. Default: 0.
49+
elmo (str):
50+
Name of the pretrained ELMo registered in `ELMoEmbedding.OPTION`. Default: ``'original_5b'``.
51+
elmo_bos_eos (tuple[bool]):
52+
A tuple of two boolean values indicating whether to keep start/end boundaries of elmo outputs.
53+
Default: ``(True, False)``.
4954
bert (str):
5055
Specifies which kind of language model to use, e.g., ``'bert-base-cased'``.
5156
This is required if ``encoder='bert'`` or using BERT features. The full list can be found in `transformers`_.
@@ -101,6 +106,8 @@ def __init__(self,
101106
n_char_embed=50,
102107
n_char_hidden=100,
103108
char_pad_index=0,
109+
elmo='original_5b',
110+
elmo_bos_eos=(True, True),
104111
bert=None,
105112
n_bert_layers=4,
106113
mix_dropout=.0,
@@ -247,6 +254,11 @@ class VIConstituencyModel(CRFConstituencyModel):
247254
The size of hidden states of CharLSTM, required if using CharLSTM. Default: 100.
248255
char_pad_index (int):
249256
The index of the padding token in the character vocabulary, required if using CharLSTM. Default: 0.
257+
elmo (str):
258+
Name of the pretrained ELMo registered in `ELMoEmbedding.OPTION`. Default: ``'original_5b'``.
259+
elmo_bos_eos (tuple[bool]):
260+
A tuple of two boolean values indicating whether to keep start/end boundaries of elmo outputs.
261+
Default: ``(True, False)``.
250262
bert (str):
251263
Specifies which kind of language model to use, e.g., ``'bert-base-cased'``.
252264
This is required if ``encoder='bert'`` or using BERT features. The full list can be found in `transformers`_.
@@ -310,6 +322,8 @@ def __init__(self,
310322
n_char_embed=50,
311323
n_char_hidden=100,
312324
char_pad_index=0,
325+
elmo='original_5b',
326+
elmo_bos_eos=(True, True),
313327
bert=None,
314328
n_bert_layers=4,
315329
mix_dropout=.0,

0 commit comments

Comments
 (0)