cleaner, plus check if < 0
@@ -264,13 +264,13 @@ class TorchAgent(Agent):
'-tr', '--truncate', default=-1, type=int,
help='Truncate input lengths to increase speed / use less memory.')
agent.add_argument(
- '--left-truncate', type=int,
- help='LHS truncation length: if not specified, this will default '
- 'to `truncate`'
+ '--text-truncate', type=int,
+ help='Text input truncation length: if not specified, this will '
+ 'default to `truncate`'
)
agent.add_argument(
- '--right-truncate', type=int,
- help='RHS truncation length: if not specified, this will default '
+ '--label-truncate', type=int,
+ help='Label truncation length: if not specified, this will default '
'to `truncate`'
)
agent.add_argument(
@@ -361,10 +361,10 @@ class TorchAgent(Agent):
self.history = deque(maxlen=self.histsz)
# truncate == 0 might give funny behavior
self.truncate = opt['truncate'] if opt['truncate'] >= 0 else None
- self.left_truncate = (self.truncate if not opt.get('left_truncate')
- else opt['left_truncate'])
- self.right_truncate = (self.truncate if not opt.get('right_truncate')
- else opt['right_truncate'])
+ text_truncate = opt.get('text_truncate') or opt['truncate']
+ self.text_truncate = text_truncate if text_truncate >= 0 else None
+ label_truncate = opt.get('label_truncate') or opt['truncate']
+ self.label_truncate = label_truncate if label_truncate >= 0 else None
self.rank_candidates = opt['rank_candidates']
self.add_person_tokens = opt.get('person_tokens', False)
@@ -837,9 +837,9 @@ class TorchAgent(Agent):
:return: the input observation, with 'text_vec', 'label_vec', and
'cands_vec' fields added.
"""
- self._set_text_vec(obs, self.left_truncate, split_lines)
- self._set_label_vec(obs, add_start, add_end, self.right_truncate)
- self._set_label_cands_vec(obs, add_start, add_end, self.right_truncate)
+ self._set_text_vec(obs, self.text_truncate, split_lines)
+ self._set_label_vec(obs, add_start, add_end, self.label_truncate)
+ self._set_label_cands_vec(obs, add_start, add_end, self.label_truncate)
return obs
def batchify(self, obs_batch, sort=False,
