laurabernardy commited on
Commit
f8ddb6c
·
verified ·
1 Parent(s): c7ef246

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ epstein_190_24k.jsonl filter=lfs diff=lfs merge=lfs -text
37
+ epstein_190_24k_bio.jsonl filter=lfs diff=lfs merge=lfs -text
38
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
biotag.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ import os
4
+ from typing import List
5
+ from tqdm import tqdm
6
+
7
+ def normalize(text: str):
8
+ text = text.lower()
9
+ text = re.sub(r"[^\w\s]", " ", text)
10
+ text = re.sub(r"\s+", " ", text).strip()
11
+ return text
12
+
13
+ def tokenize_with_spans(text: str):
14
+ tokens = []
15
+ spans = []
16
+
17
+ for match in re.finditer(r"\w+|[^\w\s]", text):
18
+ tokens.append(match.group())
19
+ spans.append((match.start(), match.end()))
20
+
21
+ return tokens, spans
22
+
23
+ def map_norm_to_original(sentence: str):
24
+ norm = normalize(sentence)
25
+
26
+ mapping = []
27
+ j = 0
28
+
29
+ for i, char in enumerate(sentence):
30
+ if re.match(r"\w", char.lower()):
31
+ while j < len(norm) and norm[j] == " ":
32
+ j += 1
33
+ mapping.append(j)
34
+ j += 1
35
+ else:
36
+ mapping.append(None)
37
+
38
+ return mapping, norm
39
+
40
+ def label_tokens(sentence: str, locations: List[str]):
41
+ tokens, token_spans = tokenize_with_spans(sentence)
42
+
43
+ labels = ["O"] * len(tokens)
44
+
45
+ if not locations:
46
+ return tokens, labels
47
+
48
+ mapping, norm_sentence = map_norm_to_original(sentence)
49
+
50
+ for loc in locations:
51
+ norm_loc = normalize(loc)
52
+
53
+ # skip empty or garbage locations
54
+ if not norm_loc or len(norm_loc) < 2:
55
+ continue
56
+
57
+ start = 0
58
+ while True:
59
+ idx = norm_sentence.find(norm_loc, start)
60
+ if idx == -1:
61
+ break
62
+
63
+ norm_start = idx
64
+ norm_end = idx + len(norm_loc)
65
+
66
+ orig_positions = [
67
+ i for i, m in enumerate(mapping)
68
+ if m is not None and norm_start <= m < norm_end
69
+ ]
70
+
71
+ if not orig_positions:
72
+ start = norm_end
73
+ continue
74
+
75
+ start_char = min(orig_positions)
76
+ end_char = max(orig_positions) + 1
77
+
78
+ inside = False
79
+ for i, (t_start, t_end) in enumerate(token_spans):
80
+ if t_end <= start_char:
81
+ continue
82
+ if t_start >= end_char:
83
+ break
84
+
85
+ if not inside:
86
+ labels[i] = "B-ADDR"
87
+ inside = True
88
+ else:
89
+ labels[i] = "I-ADDR"
90
+
91
+ start = norm_end
92
+
93
+ return tokens, labels
94
+
95
+ def count_lines(file_path):
96
+ with open(file_path, "r", encoding="utf-8") as f:
97
+ return sum(1 for _ in f)
98
+
99
+ def clean_filename(path):
100
+ if not path:
101
+ return None
102
+ path = path.replace("\\", "/")
103
+ return os.path.basename(path)
104
+
105
+ def process_jsonl(input_path, output_path):
106
+ total_lines = count_lines(input_path)
107
+
108
+ with open(input_path, "r", encoding="utf-8") as infile, \
109
+ open(output_path, "w", encoding="utf-8") as outfile:
110
+
111
+ for line in tqdm(infile, total=total_lines, desc="Processing JSONL"):
112
+ try:
113
+ entry = json.loads(line)
114
+ except json.JSONDecodeError:
115
+ continue
116
+
117
+ sentence = entry.get("sentence", "")
118
+ filename = clean_filename(entry.get("filename"))
119
+
120
+ labels_data = entry.get("labels") or {}
121
+
122
+ locations = [
123
+ loc.get("text", "")
124
+ for loc in labels_data.get("locations", [])
125
+ if isinstance(loc, dict)
126
+ ]
127
+
128
+ tokens, labels = label_tokens(sentence, locations)
129
+
130
+ output_entry = {
131
+ "filename": filename,
132
+ "tokens": tokens,
133
+ "labels": labels
134
+ }
135
+
136
+ outfile.write(json.dumps(output_entry) + "\n")
137
+
138
+ if __name__ == "__main__":
139
+ input_file = "/home/laura/rueberta/runs/24k/epstein_190_24k.jsonl"
140
+ output_file = "/home/laura/rueberta/runs/24k/epstein_190_24k_bio.jsonl"
141
+
142
+ process_jsonl(input_file, output_file)
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "XLMRobertaForMaskedLM"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "dtype": "float32",
10
+ "eos_token_id": 2,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "is_decoder": false,
17
+ "layer_norm_eps": 1e-05,
18
+ "max_position_embeddings": 514,
19
+ "model_type": "xlm-roberta",
20
+ "num_attention_heads": 12,
21
+ "num_hidden_layers": 12,
22
+ "output_past": true,
23
+ "pad_token_id": 1,
24
+ "position_embedding_type": "absolute",
25
+ "tie_word_embeddings": true,
26
+ "transformers_version": "5.14.1",
27
+ "type_vocab_size": 1,
28
+ "use_cache": true,
29
+ "vocab_size": 250002
30
+ }
epstein_190_24k.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b15c5b27ba587d63bb729bde38bb6820db1917885d9a6f8a3be18a67db924d2a
3
+ size 16953341
epstein_190_24k_bio.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62a7615d1aa40f043ef22dc8d843ff8b5dd009d33bc3563d13bc5305782d4749
3
+ size 27409146
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba1ebd808265070c7759f1d919ddf277ea1e5b9c832374d36090d12bcb7c0bc6
3
+ size 1112269331
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a04dec98c0804beeedde93263778442d924081d88090d4ac3db097205fa959bd
3
+ size 17098351
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": true,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<s>",
5
+ "cls_token": "<s>",
6
+ "eos_token": "</s>",
7
+ "is_local": false,
8
+ "local_files_only": false,
9
+ "mask_token": "<mask>",
10
+ "model_max_length": 512,
11
+ "pad_token": "<pad>",
12
+ "sep_token": "</s>",
13
+ "tokenizer_class": "XLMRobertaTokenizer",
14
+ "unk_token": "<unk>"
15
+ }