Skip to content

Commit

Permalink
Exception to alert user of possible mistake when providing label and …
Browse files Browse the repository at this point in the history
…label candidate (facebookresearch#232)
  • Loading branch information
Belbs authored Jul 24, 2017
1 parent 9cd7065 commit 3fe358c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions parlai/core/dialog_teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,30 +228,35 @@ def _load(self, data_loader):
new_entry.append(None)
if len(entry) > 1:
# process labels if available
if entry[1] is not None:
if entry[1] is None:
new_entry.append(None)
elif hasattr(entry[1], '__iter__') and type(entry[1]) is not str:
# make sure iterable over labels, not single string
new_entry.append(tuple(sys.intern(e) for e in entry[1]))
else:
new_entry.append(None)
raise TypeError('Must provide iterable over labels, not a single string.')
if len(entry) > 2:
# process reward if available
if entry[2] is not None:
new_entry.append(sys.intern(entry[2]))
else:
new_entry.append(None)
if len(entry) > 3:
if entry[3] is not None:
# process label candidates if available
if last_cands and entry[3] is last_cands:
# if cands are shared, say "same" so we
# don't store them again
new_entry.append(
sys.intern('same as last time'))
else:
last_cands = entry[3]
new_entry.append(tuple(
sys.intern(e) for e in entry[3]))
else:
# process label candidates if available
if entry[3] is None:
new_entry.append(None)
elif last_cands and entry[3] is last_cands:
# if cands are shared, say "same" so we
# don't store them again
new_entry.append(
sys.intern('same as last time'))
elif hasattr(entry[3], '__iter__') and type(entry[3]) is not str:
# make sure iterable over candidates, not single string
last_cands = entry[3]
new_entry.append(tuple(
sys.intern(e) for e in entry[3]))
else:
raise TypeError('Must provide iterable over label candidates, not a single string.')
if len(entry) > 4 and entry[4] is not None:
new_entry.append(sys.intern(entry[4]))

Expand Down

0 comments on commit 3fe358c

Please sign in to comment.