sheikh commited on
Commit
9049fff
·
1 Parent(s): d8c00a8

Update lmv3.py

Browse files
Files changed (1) hide show
  1. lmv3.py +23 -22
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=["O", "B-HEADER", "I-HEADER", "B-QUESTION", "I-QUESTION", "B-ANSWER", "I-ANSWER"]
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 item in data["form"]:
121
- cur_line_bboxes = []
122
- words, label = item["words"], item["label"]
123
- words = [w for w in words if w["text"].strip() != ""]
124
- if len(words) == 0:
125
- continue
126
- if label == "other":
127
- for w in words:
128
- tokens.append(w["text"])
129
- ner_tags.append("O")
130
- cur_line_bboxes.append(normalize_bbox(w["box"], size))
131
- else:
132
- tokens.append(words[0]["text"])
133
- ner_tags.append("B-" + label.upper())
134
- cur_line_bboxes.append(normalize_bbox(words[0]["box"], size))
135
- for w in words[1:]:
136
- tokens.append(w["text"])
137
- ner_tags.append("I-" + label.upper())
138
- cur_line_bboxes.append(normalize_bbox(w["box"], size))
139
- cur_line_bboxes = self.get_line_bbox(cur_line_bboxes)
140
- bboxes.extend(cur_line_bboxes)
 
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}