Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Fairseq
Commits
386847ee
Commit
386847ee
authored
May 25, 2018
by
Myle Ott
Browse files
Generalize eval_str_list
parent
09379ad8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
8 deletions
+9
-8
fairseq/models/fconv.py
fairseq/models/fconv.py
+2
-3
fairseq/options.py
fairseq/options.py
+7
-5
No files found.
fairseq/models/fconv.py
View file @
386847ee
...
@@ -10,7 +10,7 @@ import torch
...
@@ -10,7 +10,7 @@ import torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
from
fairseq
import
utils
from
fairseq
import
options
,
utils
from
fairseq.data.consts
import
LEFT_PAD_SOURCE
,
LEFT_PAD_TARGET
from
fairseq.data.consts
import
LEFT_PAD_SOURCE
,
LEFT_PAD_TARGET
from
fairseq.modules
import
BeamableMM
,
GradMultiply
,
LearnedPositionalEmbedding
,
LinearizedConvolution
,
AdaptiveSoftmax
from
fairseq.modules
import
BeamableMM
,
GradMultiply
,
LearnedPositionalEmbedding
,
LinearizedConvolution
,
AdaptiveSoftmax
...
@@ -139,8 +139,7 @@ class FConvLanguageModel(FairseqLanguageModel):
...
@@ -139,8 +139,7 @@ class FConvLanguageModel(FairseqLanguageModel):
max_positions
=
args
.
max_target_positions
,
max_positions
=
args
.
max_target_positions
,
share_embed
=
False
,
share_embed
=
False
,
positional_embeddings
=
False
,
positional_embeddings
=
False
,
adaptive_softmax_cutoff
=
list
(
adaptive_softmax_cutoff
=
options
.
eval_str_list
(
args
.
adaptive_softmax_cutoff
,
type
=
int
),
map
(
int
,
args
.
adaptive_softmax_cutoff
.
split
(
','
)))
if
args
.
adaptive_softmax_cutoff
else
None
,
normalization_constant
=
args
.
normalization_constant
,
normalization_constant
=
args
.
normalization_constant
,
)
)
return
FConvLanguageModel
(
decoder
)
return
FConvLanguageModel
(
decoder
)
...
...
fairseq/options.py
View file @
386847ee
...
@@ -34,13 +34,15 @@ def get_generation_parser(interactive=False):
...
@@ -34,13 +34,15 @@ def get_generation_parser(interactive=False):
return
parser
return
parser
def
_eval_float_list
(
x
):
def
eval_str_list
(
x
,
type
=
float
):
if
x
is
None
:
return
None
if
isinstance
(
x
,
str
):
if
isinstance
(
x
,
str
):
x
=
eval
(
x
)
x
=
eval
(
x
)
try
:
try
:
return
list
(
x
)
return
list
(
map
(
type
,
x
)
)
except
:
except
:
return
[
float
(
x
)]
return
[
type
(
x
)]
def
get_eval_lm_parser
():
def
get_eval_lm_parser
():
...
@@ -75,8 +77,8 @@ def parse_args_and_arch(parser, input_args=None):
...
@@ -75,8 +77,8 @@ def parse_args_and_arch(parser, input_args=None):
args
=
parser
.
parse_args
(
input_args
)
args
=
parser
.
parse_args
(
input_args
)
# Post-process args.
# Post-process args.
args
.
lr
=
_
eval_
float
_list
(
args
.
lr
)
args
.
lr
=
eval_
str
_list
(
args
.
lr
,
type
=
float
)
args
.
update_freq
=
_
eval_
float
_list
(
args
.
update_freq
)
args
.
update_freq
=
eval_
str
_list
(
args
.
update_freq
,
type
=
int
)
if
args
.
max_sentences_valid
is
None
:
if
args
.
max_sentences_valid
is
None
:
args
.
max_sentences_valid
=
args
.
max_sentences
args
.
max_sentences_valid
=
args
.
max_sentences
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment