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
c6831d3b
Unverified
Commit
c6831d3b
authored
Nov 12, 2017
by
Myle Ott
Committed by
GitHub
Nov 12, 2017
Browse files
Merge pull request #56 from facebookresearch/python3
Remove Python 3.6 format strings (fixes #55)
parents
7b086021
3524b661
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
fairseq/data.py
fairseq/data.py
+3
-3
fairseq/progress_bar.py
fairseq/progress_bar.py
+7
-6
No files found.
fairseq/data.py
View file @
c6831d3b
...
@@ -21,7 +21,7 @@ from fairseq.indexed_dataset import IndexedDataset, IndexedInMemoryDataset, Inde
...
@@ -21,7 +21,7 @@ from fairseq.indexed_dataset import IndexedDataset, IndexedInMemoryDataset, Inde
def
has_binary_files
(
data_dir
,
splits
):
def
has_binary_files
(
data_dir
,
splits
):
for
split
in
splits
:
for
split
in
splits
:
if
len
(
glob
.
glob
(
os
.
path
.
join
(
data_dir
,
f
'
{
split
}
.*-*.*.bin'
)))
<
2
:
if
len
(
glob
.
glob
(
os
.
path
.
join
(
data_dir
,
'{}.*-*.*.bin'
.
format
(
split
)
)))
<
2
:
return
False
return
False
return
True
return
True
...
@@ -107,8 +107,8 @@ def load_raw_text_dataset(path, load_splits, src=None, dst=None):
...
@@ -107,8 +107,8 @@ def load_raw_text_dataset(path, load_splits, src=None, dst=None):
# Load dataset from raw text files
# Load dataset from raw text files
for
split
in
load_splits
:
for
split
in
load_splits
:
src_path
=
os
.
path
.
join
(
path
,
f
'
{
split
}
.
{
src
}
'
)
src_path
=
os
.
path
.
join
(
path
,
'{
}.{}'
.
format
(
split
,
src
)
)
dst_path
=
os
.
path
.
join
(
path
,
f
'
{
split
}
.
{
dst
}
'
)
dst_path
=
os
.
path
.
join
(
path
,
'{
}.{}'
.
format
(
split
,
dst
)
)
dataset
.
splits
[
split
]
=
LanguagePairDataset
(
dataset
.
splits
[
split
]
=
LanguagePairDataset
(
IndexedRawTextDataset
(
src_path
,
src_dict
),
IndexedRawTextDataset
(
src_path
,
src_dict
),
IndexedRawTextDataset
(
dst_path
,
dst_dict
),
IndexedRawTextDataset
(
dst_path
,
dst_dict
),
...
...
fairseq/progress_bar.py
View file @
c6831d3b
...
@@ -27,9 +27,9 @@ class progress_bar(object):
...
@@ -27,9 +27,9 @@ class progress_bar(object):
self
.
epoch
=
epoch
self
.
epoch
=
epoch
self
.
prefix
=
''
self
.
prefix
=
''
if
epoch
is
not
None
:
if
epoch
is
not
None
:
self
.
prefix
+=
f
'| epoch
{
epoch
:
03
d
}
'
self
.
prefix
+=
'| epoch {:03d}'
.
format
(
epoch
)
if
prefix
is
not
None
:
if
prefix
is
not
None
:
self
.
prefix
+=
f
' |
{
prefix
}
'
self
.
prefix
+=
' | {
}'
.
format
(
prefix
)
def
__enter__
(
self
):
def
__enter__
(
self
):
return
self
return
self
...
@@ -90,7 +90,7 @@ class json_progress_bar(progress_bar):
...
@@ -90,7 +90,7 @@ class json_progress_bar(progress_bar):
self
.
log_interval
is
not
None
and
i
%
self
.
log_interval
==
0
:
self
.
log_interval
is
not
None
and
i
%
self
.
log_interval
==
0
:
update
=
self
.
epoch
+
float
(
i
/
size
)
if
self
.
epoch
is
not
None
else
None
update
=
self
.
epoch
+
float
(
i
/
size
)
if
self
.
epoch
is
not
None
else
None
stats
=
self
.
_format_stats
(
self
.
stats
,
epoch
=
self
.
epoch
,
update
=
update
)
stats
=
self
.
_format_stats
(
self
.
stats
,
epoch
=
self
.
epoch
,
update
=
update
)
print
(
"
sweep_log:
"
+
json
.
dumps
(
stats
),
flush
=
True
)
print
(
'
sweep_log:
'
+
json
.
dumps
(
stats
),
flush
=
True
)
def
log
(
self
,
stats
):
def
log
(
self
,
stats
):
"""Log intermediate stats according to log_interval."""
"""Log intermediate stats according to log_interval."""
...
@@ -152,7 +152,8 @@ class simple_progress_bar(progress_bar):
...
@@ -152,7 +152,8 @@ class simple_progress_bar(progress_bar):
if
self
.
stats
is
not
None
and
i
>
0
and
\
if
self
.
stats
is
not
None
and
i
>
0
and
\
self
.
log_interval
is
not
None
and
i
%
self
.
log_interval
==
0
:
self
.
log_interval
is
not
None
and
i
%
self
.
log_interval
==
0
:
postfix
=
self
.
_str_commas
(
self
.
stats
)
postfix
=
self
.
_str_commas
(
self
.
stats
)
print
(
f
'
{
self
.
prefix
}
:
{
i
:
5
d
}
/
{
size
:
d
}
{
postfix
}
'
,
flush
=
True
)
print
(
'{}: {:5d} / {:d} {}'
.
format
(
self
.
prefix
,
i
,
size
,
postfix
),
flush
=
True
)
def
log
(
self
,
stats
):
def
log
(
self
,
stats
):
"""Log intermediate stats according to log_interval."""
"""Log intermediate stats according to log_interval."""
...
@@ -161,7 +162,7 @@ class simple_progress_bar(progress_bar):
...
@@ -161,7 +162,7 @@ class simple_progress_bar(progress_bar):
def
print
(
self
,
stats
):
def
print
(
self
,
stats
):
"""Print end-of-epoch stats."""
"""Print end-of-epoch stats."""
postfix
=
self
.
_str_pipes
(
self
.
_format_stats
(
stats
))
postfix
=
self
.
_str_pipes
(
self
.
_format_stats
(
stats
))
print
(
f
'
{
self
.
prefix
}
|
{
postfix
}
'
,
flush
=
True
)
print
(
'{
} | {}'
.
format
(
self
.
prefix
,
postfix
)
,
flush
=
True
)
class
tqdm_progress_bar
(
progress_bar
):
class
tqdm_progress_bar
(
progress_bar
):
...
@@ -181,4 +182,4 @@ class tqdm_progress_bar(progress_bar):
...
@@ -181,4 +182,4 @@ class tqdm_progress_bar(progress_bar):
def
print
(
self
,
stats
):
def
print
(
self
,
stats
):
"""Print end-of-epoch stats."""
"""Print end-of-epoch stats."""
postfix
=
self
.
_str_pipes
(
self
.
_format_stats
(
stats
))
postfix
=
self
.
_str_pipes
(
self
.
_format_stats
(
stats
))
self
.
tqdm
.
write
(
f
'
{
self
.
tqdm
.
desc
}
|
{
postfix
}
'
)
self
.
tqdm
.
write
(
'{
} | {}'
.
format
(
self
.
tqdm
.
desc
,
postfix
)
)
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