Update attribute names
Browse files
funsd.py
CHANGED
@@ -61,7 +61,7 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
61 |
features=datasets.Features(
|
62 |
{
|
63 |
"id": datasets.Value("string"),
|
64 |
-
"
|
65 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
66 |
"ner_tags": datasets.Sequence(
|
67 |
datasets.features.ClassLabel(
|
@@ -93,7 +93,7 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
93 |
ann_dir = os.path.join(filepath, "annotations")
|
94 |
img_dir = os.path.join(filepath, "images")
|
95 |
for guid, file in enumerate(sorted(os.listdir(ann_dir))):
|
96 |
-
|
97 |
bboxes = []
|
98 |
ner_tags = []
|
99 |
file_path = os.path.join(ann_dir, file)
|
@@ -103,21 +103,21 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
103 |
image_path = image_path.replace("json", "png")
|
104 |
image, size = load_image(image_path)
|
105 |
for item in data["form"]:
|
106 |
-
|
107 |
-
|
108 |
-
if len(
|
109 |
continue
|
110 |
if label == "other":
|
111 |
-
for w in
|
112 |
-
|
113 |
ner_tags.append("O")
|
114 |
bboxes.append(normalize_bbox(w["box"], size))
|
115 |
else:
|
116 |
-
|
117 |
ner_tags.append("B-" + label.upper())
|
118 |
-
bboxes.append(normalize_bbox(
|
119 |
-
for w in
|
120 |
-
|
121 |
ner_tags.append("I-" + label.upper())
|
122 |
bboxes.append(normalize_bbox(w["box"], size))
|
123 |
-
yield guid, {"id": str(guid), "
|
|
|
61 |
features=datasets.Features(
|
62 |
{
|
63 |
"id": datasets.Value("string"),
|
64 |
+
"words": datasets.Sequence(datasets.Value("string")),
|
65 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
66 |
"ner_tags": datasets.Sequence(
|
67 |
datasets.features.ClassLabel(
|
|
|
93 |
ann_dir = os.path.join(filepath, "annotations")
|
94 |
img_dir = os.path.join(filepath, "images")
|
95 |
for guid, file in enumerate(sorted(os.listdir(ann_dir))):
|
96 |
+
words = []
|
97 |
bboxes = []
|
98 |
ner_tags = []
|
99 |
file_path = os.path.join(ann_dir, file)
|
|
|
103 |
image_path = image_path.replace("json", "png")
|
104 |
image, size = load_image(image_path)
|
105 |
for item in data["form"]:
|
106 |
+
words_example, label = item["words"], item["label"]
|
107 |
+
words_example = [w for w in words_example if w["text"].strip() != ""]
|
108 |
+
if len(words_example) == 0:
|
109 |
continue
|
110 |
if label == "other":
|
111 |
+
for w in words_example:
|
112 |
+
words.append(w["text"])
|
113 |
ner_tags.append("O")
|
114 |
bboxes.append(normalize_bbox(w["box"], size))
|
115 |
else:
|
116 |
+
words.append(words_example[0]["text"])
|
117 |
ner_tags.append("B-" + label.upper())
|
118 |
+
bboxes.append(normalize_bbox(words_example[0]["box"], size))
|
119 |
+
for w in words_example[1:]:
|
120 |
+
words.append(w["text"])
|
121 |
ner_tags.append("I-" + label.upper())
|
122 |
bboxes.append(normalize_bbox(w["box"], size))
|
123 |
+
yield guid, {"id": str(guid), "words": words, "bboxes": bboxes, "ner_tags": ner_tags, "image_path": image_path}
|