Update lmv3.py
Browse files
lmv3.py
CHANGED
|
@@ -69,7 +69,7 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
| 69 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
| 70 |
"ner_tags": datasets.Sequence(
|
| 71 |
datasets.features.ClassLabel(
|
| 72 |
-
names=["
|
| 73 |
)
|
| 74 |
),
|
| 75 |
"image": datasets.features.Image(),
|
|
@@ -117,26 +117,27 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
| 117 |
image_path = os.path.join(img_dir, file)
|
| 118 |
image_path = image_path.replace("json", "png")
|
| 119 |
image, size = load_image(image_path)
|
| 120 |
-
for
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
| 141 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags,
|
| 142 |
"image": image}
|
|
|
|
| 69 |
"bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
| 70 |
"ner_tags": datasets.Sequence(
|
| 71 |
datasets.features.ClassLabel(
|
| 72 |
+
names=["DATEISSUED","LOANTERM","PURPOSE","PRODUCT","PROPERTY","LOANAMOUNT","INTERESTRATE","MONTHLYPR","PREPENALTY","BALLOONPAYMENT","ESTMONTHLY","ESTTAXES"]
|
| 73 |
)
|
| 74 |
),
|
| 75 |
"image": datasets.features.Image(),
|
|
|
|
| 117 |
image_path = os.path.join(img_dir, file)
|
| 118 |
image_path = image_path.replace("json", "png")
|
| 119 |
image, size = load_image(image_path)
|
| 120 |
+
for state in data:
|
| 121 |
+
for item in state["form"]:
|
| 122 |
+
cur_line_bboxes = []
|
| 123 |
+
words, label = item["words"], item["label"]
|
| 124 |
+
words = [w for w in words if w["text"].strip() != ""]
|
| 125 |
+
if len(words) == 0:
|
| 126 |
+
continue
|
| 127 |
+
if label == "other":
|
| 128 |
+
for w in words:
|
| 129 |
+
tokens.append(w["text"])
|
| 130 |
+
ner_tags.append("O")
|
| 131 |
+
cur_line_bboxes.append(normalize_bbox(w["box"], size))
|
| 132 |
+
else:
|
| 133 |
+
tokens.append(words[0]["text"])
|
| 134 |
+
ner_tags.append("B-" + label.upper())
|
| 135 |
+
cur_line_bboxes.append(normalize_bbox(words[0]["box"], size))
|
| 136 |
+
for w in words[1:]:
|
| 137 |
+
tokens.append(w["text"])
|
| 138 |
+
ner_tags.append("I-" + label.upper())
|
| 139 |
+
cur_line_bboxes.append(normalize_bbox(w["box"], size))
|
| 140 |
+
cur_line_bboxes = self.get_line_bbox(cur_line_bboxes)
|
| 141 |
+
bboxes.extend(cur_line_bboxes)
|
| 142 |
yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags,
|
| 143 |
"image": image}
|