Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug of label dimension smaller than 1 #3238

Merged
merged 2 commits into from
Sep 9, 2022
Merged
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
8 changes: 5 additions & 3 deletions model_zoo/uie/data_distill/data_collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def __call__(

bs = batch[0].shape[0]
if self.task_type == "entity_extraction":
max_ent_num = max([len(lb["ent_labels"]) for lb in labels])
# Ensure the dimension is greater or equal to 1
max_ent_num = max(max([len(lb["ent_labels"]) for lb in labels]), 1)
num_ents = len(self.label_maps["entity2id"])
batch_entity_labels = paddle.zeros(
shape=[bs, num_ents, max_ent_num, 2], dtype="int64")
Expand All @@ -67,8 +68,9 @@ def __call__(

batch.append([batch_entity_labels])
else:
max_ent_num = max([len(lb["ent_labels"]) for lb in labels])
max_spo_num = max([len(lb["rel_labels"]) for lb in labels])
# Ensure the dimension is greater or equal to 1
max_ent_num = max(max([len(lb["ent_labels"]) for lb in labels]), 1)
max_spo_num = max(max([len(lb["rel_labels"]) for lb in labels]), 1)
num_ents = len(self.label_maps["entity2id"])
if "relation2id" in self.label_maps.keys():
num_rels = len(self.label_maps["relation2id"])
Expand Down