nielsr HF staff commited on
Commit
cc411ad
1 Parent(s): f515662

Update attribute names

Browse files
Files changed (1) hide show
  1. funsd.py +12 -12
funsd.py CHANGED
@@ -61,7 +61,7 @@ class Funsd(datasets.GeneratorBasedBuilder):
61
  features=datasets.Features(
62
  {
63
  "id": datasets.Value("string"),
64
- "tokens": datasets.Sequence(datasets.Value("string")),
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
- tokens = []
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
- words, label = item["words"], item["label"]
107
- words = [w for w in words if w["text"].strip() != ""]
108
- if len(words) == 0:
109
  continue
110
  if label == "other":
111
- for w in words:
112
- tokens.append(w["text"])
113
  ner_tags.append("O")
114
  bboxes.append(normalize_bbox(w["box"], size))
115
  else:
116
- tokens.append(words[0]["text"])
117
  ner_tags.append("B-" + label.upper())
118
- bboxes.append(normalize_bbox(words[0]["box"], size))
119
- for w in words[1:]:
120
- tokens.append(w["text"])
121
  ner_tags.append("I-" + label.upper())
122
  bboxes.append(normalize_bbox(w["box"], size))
123
- yield guid, {"id": str(guid), "tokens": tokens, "bboxes": bboxes, "ner_tags": ner_tags, "image_path": image_path}
 
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}