Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Fix BerSumAbs Notebook #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def preprocess(self, story_lines, summary_lines=None):
if len(line) <= 0:
continue
story_lines_token_ids.append(
self.tokenizer.encode(line, max_length=self.max_src_len)
self.tokenizer.encode(line, truncation=True, max_length=self.max_src_len)
)
except:
print(line)
Expand All @@ -333,7 +333,7 @@ def preprocess(self, story_lines, summary_lines=None):
if len(line) <= 0:
continue
summary_lines_token_ids.append(
self.tokenizer.encode(line, max_length=self.max_tgt_len)
self.tokenizer.encode(line, truncation=True, max_length=self.max_tgt_len)
)
except:
print(line)
Expand Down
8 changes: 4 additions & 4 deletions utils_nlp/models/transformers/bertsum/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _fast_translate_batch(self, src, segs, mask_src, max_length, min_length=0):
topk_log_probs = topk_scores * length_penalty

# Resolve beam origin and true word ids.
topk_beam_index = topk_ids.div(vocab_size)
topk_beam_index = topk_ids.true_divide(vocab_size)
topk_ids = topk_ids.fmod(vocab_size)

# Map beam_index to batch_index in the flat representation.
Expand All @@ -267,7 +267,7 @@ def _fast_translate_batch(self, src, segs, mask_src, max_length, min_length=0):

# Append last prediction.
alive_seq = torch.cat(
[alive_seq.index_select(0, select_indices), topk_ids.view(-1, 1)], -1
[alive_seq.index_select(0, select_indices.view(-1).long()), topk_ids.view(-1, 1)], -1
)

is_finished = topk_ids.eq(self.end_token)
Expand Down Expand Up @@ -310,9 +310,9 @@ def _fast_translate_batch(self, src, segs, mask_src, max_length, min_length=0):
)
# Reorder states.
select_indices = batch_index.view(-1)
src_features = src_features.index_select(0, select_indices)
src_features = src_features.index_select(0, select_indices.view(-1).long())
dec_states.map_batch_fn(
lambda state, dim: state.index_select(dim, select_indices)
lambda state, dim: state.index_select(dim, select_indices.view(-1).long())
)

empty_output = [len(results["predictions"][b]) <= 0 for b in batch_offset]
Expand Down