rxnn 0.1.64__py3-none-any.whl → 0.1.65__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rxnn/training/dataset.py
CHANGED
@@ -14,6 +14,8 @@ class BaseDataset(Dataset):
|
|
14
14
|
tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast],
|
15
15
|
max_seq_len: int = 1024,
|
16
16
|
hf_field: str = 'text',
|
17
|
+
cache_tokenized: bool = False,
|
18
|
+
cache_remove_text: bool = False,
|
17
19
|
*args,
|
18
20
|
**kwargs
|
19
21
|
):
|
@@ -22,27 +24,56 @@ class BaseDataset(Dataset):
|
|
22
24
|
self.max_seq_len = max_seq_len
|
23
25
|
self.texts = texts
|
24
26
|
self.hf_field = hf_field
|
27
|
+
self.is_pre_tokenized = False
|
28
|
+
self.cache_tokenized = cache_tokenized
|
29
|
+
self.cache_remove_text = cache_remove_text
|
30
|
+
self.inputs = [] if self.cache_tokenized else None
|
25
31
|
|
26
32
|
def get_tokenized_text(self, idx: int):
|
27
|
-
if
|
28
|
-
|
33
|
+
if self.is_pre_tokenized:
|
34
|
+
return self.inputs[idx]
|
29
35
|
else:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
inputs['input_ids'][0]
|
44
|
-
|
45
|
-
|
36
|
+
if isinstance(self.texts, list):
|
37
|
+
text = self.texts[idx]
|
38
|
+
else:
|
39
|
+
text = self.texts[idx][self.hf_field]
|
40
|
+
|
41
|
+
inputs = self.tokenizer(
|
42
|
+
text,
|
43
|
+
max_length=self.max_seq_len,
|
44
|
+
truncation=True,
|
45
|
+
padding='max_length',
|
46
|
+
return_tensors='pt',
|
47
|
+
return_attention_mask=True
|
48
|
+
)
|
49
|
+
if not (inputs['input_ids'][0] < self.tokenizer.vocab_size).all():
|
50
|
+
inputs['input_ids'][0][(inputs['input_ids'][0] >= self.tokenizer.vocab_size)] = self.tokenizer.unk_token_id
|
51
|
+
if not (inputs['input_ids'][0] >= 0).all():
|
52
|
+
inputs['input_ids'][0][inputs['input_ids'][0] < 0] = self.tokenizer.unk_token_id
|
53
|
+
|
54
|
+
if self.cache_tokenized:
|
55
|
+
self.inputs.append(inputs)
|
56
|
+
if len(self.inputs) == len(self.texts):
|
57
|
+
self.is_pre_tokenized = True
|
58
|
+
if self.cache_remove_text:
|
59
|
+
del self.texts
|
60
|
+
self.texts = None
|
61
|
+
|
62
|
+
return inputs
|
63
|
+
|
64
|
+
def get_subset(self, size: float, from_start: bool = False, use_hf_select: bool = False, **kwargs) -> "BaseDataset":
|
65
|
+
split_point = int(len(self.texts) * ((1 - size) if not from_start else size))
|
66
|
+
subset = self.texts.select(range(split_point, len(self.texts))) if use_hf_select and not isinstance(self.texts, list) else self.texts[:split_point]
|
67
|
+
self.texts = self.texts.select(range(split_point)) if use_hf_select and not isinstance(self.texts, list) else self.texts[split_point:]
|
68
|
+
return self.__class__(subset, self.tokenizer, self.max_seq_len, self.hf_field, **kwargs)
|
69
|
+
|
70
|
+
def pre_tokenize(self, remove_texts: bool = True):
|
71
|
+
if not self.is_pre_tokenized:
|
72
|
+
self.inputs = list(map(lambda idx: self.get_tokenized_text(idx), range(len(self.texts))))
|
73
|
+
self.is_pre_tokenized = True
|
74
|
+
if remove_texts:
|
75
|
+
del self.texts
|
76
|
+
self.texts = None
|
46
77
|
|
47
78
|
@classmethod
|
48
79
|
def from_hf_hub(
|
@@ -132,6 +163,7 @@ class BaseDataset(Dataset):
|
|
132
163
|
return cls(hf_dataset, tokenizer, max_seq_len=max_seq_len, hf_field=target_field, **kwargs)
|
133
164
|
|
134
165
|
|
166
|
+
|
135
167
|
class JointLMDataset(BaseDataset):
|
136
168
|
def __init__(
|
137
169
|
self,
|
@@ -12,7 +12,7 @@ rxnn/training/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
rxnn/training/base.py,sha256=xPMA2Bg9-oUZvSZg67ls2p7Gk9pZ9IHUiIJwUzSe2K8,11766
|
13
13
|
rxnn/training/bml.py,sha256=S1ZaXTybzeJH7uVFamCr4TPl2bLyZ5xmn_lSsjThTiM,19162
|
14
14
|
rxnn/training/callbacks.py,sha256=_YfMKY_eFdc-tubhO9nYH2PXDZDQwlSI74FVOoCXpQg,22108
|
15
|
-
rxnn/training/dataset.py,sha256=
|
15
|
+
rxnn/training/dataset.py,sha256=fKTNtDOAMSuRPbSl0yy0-k_xQ5o-AF6pqwKw9tC-7Mw,11328
|
16
16
|
rxnn/training/scheduler.py,sha256=ow6oALzWjWQmHSpcJEjv6tg4g4CDMvr73TypxfcefMc,712
|
17
17
|
rxnn/training/tokenizer.py,sha256=umaLByMBx_NMrQElA45HLm9gkuzyKWDTFaKVd-CjXl0,8344
|
18
18
|
rxnn/transformers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -25,7 +25,7 @@ rxnn/transformers/moe.py,sha256=j6jEx6Ip0zttlUZKKn82azxo95lkLZs-H2GLSMD88hY,5859
|
|
25
25
|
rxnn/transformers/positional.py,sha256=2l38RS0Dini3f6Z3LUHr3XwWzg1UK7fO2C6wazWDAYU,4292
|
26
26
|
rxnn/transformers/sampler.py,sha256=poWBpxg1iuK5gEJtxHkk5VVfS9V48hs2Olqdhy_Gw8c,6548
|
27
27
|
rxnn/utils.py,sha256=d5U8i5ukovgDyqiycc2AoxObTz_eF_bgo2MKvdtJ98s,467
|
28
|
-
rxnn-0.1.
|
29
|
-
rxnn-0.1.
|
30
|
-
rxnn-0.1.
|
31
|
-
rxnn-0.1.
|
28
|
+
rxnn-0.1.65.dist-info/LICENSE,sha256=C8coDFIUYuOcke4JLPwTqahQUCyXyGq6WOaigOkx8tY,11275
|
29
|
+
rxnn-0.1.65.dist-info/METADATA,sha256=wFv7U3aEMscWvxERWl2x-qHO2aBc5LPF79uV9RUzbyQ,16579
|
30
|
+
rxnn-0.1.65.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
31
|
+
rxnn-0.1.65.dist-info/RECORD,,
|
File without changes
|
File without changes
|