File size: 7,406 Bytes
c93c142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4164169
 
 
 
 
 
 
2cc13ba
 
 
100bf33
2cc13ba
100bf33
 
2cc13ba
a0e8332
2cc13ba
4164169
 
 
 
 
a0e8332
4164169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100bf33
 
 
 
 
 
a0e8332
100bf33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0e8332
4963014
 
 
 
 
 
 
 
100bf33
 
 
 
 
 
 
 
a0e8332
100bf33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4164169
 
 
 
 
 
 
 
 
 
 
a0e8332
 
 
 
 
4164169
100bf33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0e8332
100bf33
4164169
 
a0e8332
 
4164169
 
a0e8332
 
4164169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0e8332
 
 
 
 
 
4164169
a0e8332
 
 
 
 
4164169
 
a0e8332
 
4164169
 
a0e8332
 
100bf33
 
 
 
 
 
 
 
a0e8332
 
2cc13ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
---
language:
- ar
pretty_name: TypePrediction
task_categories:
- token-classification
tags:
- named-entity-recognition
- arabic
- wojood
- entity-typing
size_categories:
- 100K<n<1M
---

# TypePrediction

Unified mention-level type prediction data built from all available local Wojood NER datasets except `WojoodRelations`.

## Main file

- `type_predictor_data.jsonl`
- `type_predictor_train.jsonl`
- `type_predictor_val.jsonl`
- `type_predictor_test.jsonl`
- `summary.json`
- `split_summary.json`
- `build_type_prediction_dataset.py`
- `push_to_hf.py`
- `split_data.py`
- `artifacts/ambiguous_span_type_conflicts.jsonl`
- `artifacts/split_assignments.jsonl`

Each row contains:

```json
{
  "id": "tp_000001",
  "entity": "النص",
  "type": "ORG",
  "sentence": "الجملة الكاملة",
  "start_token": 0,
  "end_token": 1,
  "start_char": 0,
  "end_char": 10,
  "raw_types": ["ORG", "NONGOV"],
  "sources": [
    {"dataset": "WojoodFine", "split": "train"},
    {"dataset": "Wojood1_1_nested", "split": "train"}
  ]
}
```

## Stored row examples

Simple flat/coarse example:

```json
{
  "id": "tp_000001",
  "entity": "عبد الحميد عبد العاطي",
  "type": "PERS",
  "sentence": "! ! ! تم النشر قبل بواسطة عبد الحميد عبد العاطي ازهقنا .",
  "start_token": 7,
  "end_token": 10,
  "start_char": 26,
  "end_char": 47,
  "raw_types": ["PERS"],
  "sources": [{"dataset": "WojoodFine", "split": "train"}]
}
```

Example where a fine label is mapped to a coarse label:

```json
{
  "id": "tp_001001",
  "entity": "للعراقيين",
  "type": "NORP",
  "sentence": ", أثارت محاكمات 11 مشتبها بهم فرنسيين في العراق في مايو / أيار هذه المخاوف ، ليس فقط للمشتبه بهم الأجانب بل للعراقيين أيضا .",
  "start_token": 22,
  "end_token": 22,
  "start_char": 108,
  "end_char": 117,
  "raw_types": ["NORP"],
  "sources": [{"dataset": "WojoodFine", "split": "train"}]
}
```

Example merged across multiple source datasets:

```json
{
  "id": "tp_050001",
  "entity": "مصر",
  "type": "GPE",
  "sentence": "بعدما أطاح به آية الله الخميني وبنظامه ، حيث توجه بداية إلى مصر قبل أن يستقر به الأمر في المغرب ، ,",
  "start_token": 12,
  "end_token": 12,
  "start_char": 60,
  "end_char": 63,
  "raw_types": ["GPE", "COUNTRY"],
  "sources": [
    {"dataset": "Wojood1_1_flat", "split": "test"},
    {"dataset": "Wojood1_1_nested", "split": "test"},
    {"dataset": "WojoodFine-Flat", "split": "split20"}
  ]
}
```

## Construction

1. Parse all sentence-separated CoNLL-style files from:
   - `Wojood1_1_flat`
   - `Wojood1_1_nested`
   - `WojoodFine`
   - `WojoodFine-Flat`
2. Extract every entity span, including nested spans when multiple BIO tags are present on the same token sequence.
3. Map fine labels to coarse labels using `wojood_ontology.json`.
4. Reconstruct full sentence text and both token and character spans.
5. Deduplicate by `(sentence, entity, type, start_token, end_token)` and merge provenance.
6. Remove exact span/type conflicts from the main file:
   - conflict key: `(sentence, entity, start_token, end_token, start_char, end_char)`
   - if the same exact span has more than one coarse type, all candidate rows for that span are written to `artifacts/ambiguous_span_type_conflicts.jsonl`
   - the main `type_predictor_data.jsonl` keeps only unambiguous rows
7. Assign deterministic ids in final sorted order: `tp_000001`, `tp_000002`, ...

## Parsing details and edge cases

- `Wojood1_1_flat` uses simple space-separated `token tag` rows.
- `Wojood1_1_nested` uses space-separated rows with multiple BIO tags on the same token when nested annotations exist.
- `WojoodFine` and `WojoodFine-Flat` use tab-separated rows.
- Some `WojoodFine` rows place multiple tags inside a single tab field, for example:
  - `نبيه\tI-OCC B-PERS\t\t\t`
  The builder normalizes this by splitting tag cells on internal whitespace.
- Some fine labels appear with alias spellings that differ from the ontology ids, for example:
  - `GPE-ORG` -> `GPE_ORG`
  - `Cluster` -> `CLUSTER`
  - `Path` -> `PATH`
  The builder canonicalizes these before mapping to coarse parents.
- Sentence boundaries are read from blank lines in the CoNLL files.
- Character spans are reconstructed after joining sentence tokens with single spaces.
- The main file is single-label by construction. Ambiguous multi-type spans are excluded rather than guessed.

## Summary

- total rows: `125996`
- unique sentences: `33933`
- raw extracted mentions before dedupe: `408035`
- rows merged by dedupe: `275272`
- ambiguous span groups excluded: `3383`
- candidate rows excluded by ambiguity filtering: `6767`

## Source breakdown

- `Wojood1_1_flat/test`: 14573 mentions from 6606 sentences
- `Wojood1_1_flat/train`: 49959 mentions from 23125 sentences
- `Wojood1_1_flat/val`: 7143 mentions from 3304 sentences
- `Wojood1_1_nested/test`: 18045 mentions from 6606 sentences
- `Wojood1_1_nested/train`: 62377 mentions from 23125 sentences
- `Wojood1_1_nested/val`: 8944 mentions from 3304 sentences
- `WojoodFine/test`: 27848 mentions from 5748 sentences
- `WojoodFine/train`: 96188 mentions from 19484 sentences
- `WojoodFine/val`: 13800 mentions from 2828 sentences
- `WojoodFine-Flat/split10`: 10859 mentions from 3304 sentences
- `WojoodFine-Flat/split20`: 22208 mentions from 6606 sentences
- `WojoodFine-Flat/split70`: 76091 mentions from 23125 sentences

## Top coarse types

- `GPE`: 26902
- `ORG`: 26593
- `DATE`: 19762
- `PERS`: 10712
- `NORP`: 10217
- `ORDINAL`: 7807
- `OCC`: 7696
- `EVENT`: 3769
- `CARDINAL`: 3724
- `LOC`: 2388
- `WEBSITE`: 1478
- `FAC`: 1296
- `LAW`: 904
- `TIME`: 871
- `MONEY`: 420
- `CURR`: 411
- `LANGUAGE`: 332
- `PERCENT`: 312
- `PRODUCT`: 190
- `QUANTITY`: 106

## Validation performed

- verified that all four non-relation Wojood sources were included
- verified nested extraction is enabled when multiple tags occur on one token
- verified fine-to-coarse mapping uses the repo's `wojood_ontology.json`
- verified `sentence[start_char:end_char] == entity` across the built file
- verified deduped rows merge provenance rather than silently dropping it
- verified no exact span in the main file has more than one coarse type
- verified ids are unique and deterministic

## Split files

The repo also includes a mention-level stratified split built from `type_predictor_data.jsonl`:

- `type_predictor_train.jsonl`
- `type_predictor_val.jsonl`
- `type_predictor_test.jsonl`
- `split_summary.json`
- `artifacts/split_assignments.jsonl`
- `split_data.py`

Split policy:

1. Start from the clean `type_predictor_data.jsonl`.
2. Perform a stratified `80/20` split by the `type` column with `random_state = 42`.
3. Split the holdout pool again, stratified by `type`, into equal halves.
4. Keep sentence overlap allowed across splits.
5. Preserve all original fields.
6. Add `evaluation_category` only to validation and test rows:
   - `unseen_sentence`
   - `seen_sentence_new_entity`

Current split sizes:

- train: `100,796`
- validation: `12,600`
- test: `12,600`

Current evaluation-category counts:

- validation `seen_sentence_new_entity`: `11,661`
- validation `unseen_sentence`: `939`
- test `seen_sentence_new_entity`: `11,606`
- test `unseen_sentence`: `994`