deeplotx 0.4.11__py3-none-any.whl → 0.4.12b0__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.
- deeplotx/encoder/long_text_encoder.py +3 -3
- deeplotx/trainer/text_binary_classification_trainer.py +4 -2
- {deeplotx-0.4.11.dist-info → deeplotx-0.4.12b0.dist-info}/METADATA +1 -1
- {deeplotx-0.4.11.dist-info → deeplotx-0.4.12b0.dist-info}/RECORD +7 -7
- {deeplotx-0.4.11.dist-info → deeplotx-0.4.12b0.dist-info}/WHEEL +0 -0
- {deeplotx-0.4.11.dist-info → deeplotx-0.4.12b0.dist-info}/licenses/LICENSE +0 -0
- {deeplotx-0.4.11.dist-info → deeplotx-0.4.12b0.dist-info}/top_level.txt +0 -0
@@ -28,7 +28,7 @@ class LongTextEncoder(BertEncoder):
|
|
28
28
|
def postprocess(tensors: list[torch.Tensor], _flatten: bool) -> torch.Tensor:
|
29
29
|
if not _flatten:
|
30
30
|
return torch.stack(tensors, dim=0).squeeze()
|
31
|
-
_fin_emb_tensor = torch.tensor([], dtype=tensors[0].dtype)
|
31
|
+
_fin_emb_tensor = torch.tensor([], dtype=tensors[0].dtype, device=self.device)
|
32
32
|
for _emb in tensors:
|
33
33
|
_fin_emb_tensor = torch.cat((_fin_emb_tensor.detach().clone(), _emb.detach().clone()), dim=-1)
|
34
34
|
return _fin_emb_tensor.squeeze()
|
@@ -55,8 +55,8 @@ class LongTextEncoder(BertEncoder):
|
|
55
55
|
for i in range(num_chunks):
|
56
56
|
_tmp_left = max(i * self._chunk_size - self._overlapping, 0)
|
57
57
|
_tmp_right = (i + 1) * self._chunk_size + self._overlapping
|
58
|
-
chunks.append((i, torch.tensor([_text_to_input_ids[_tmp_left: _tmp_right]], dtype=torch.int),
|
59
|
-
torch.tensor([_text_to_input_ids_att_mask[_tmp_left: _tmp_right]], dtype=torch.int)))
|
58
|
+
chunks.append((i, torch.tensor([_text_to_input_ids[_tmp_left: _tmp_right]], dtype=torch.int, device=self.device),
|
59
|
+
torch.tensor([_text_to_input_ids_att_mask[_tmp_left: _tmp_right]], dtype=torch.int, device=self.device)))
|
60
60
|
with ThreadPoolExecutor(max_workers=min(num_chunks + 1, 3)) as executor:
|
61
61
|
embeddings = list(executor.map(self.__chunk_embedding, chunks))
|
62
62
|
embeddings.sort(key=lambda x: x[0])
|
@@ -16,6 +16,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
16
16
|
def __init__(self, long_text_encoder: LongTextEncoder, batch_size: int = 2, train_ratio: float = 0.8):
|
17
17
|
super().__init__(batch_size=batch_size, train_ratio=train_ratio)
|
18
18
|
self._long_text_encoder = long_text_encoder
|
19
|
+
self.device = self._long_text_encoder.device
|
19
20
|
|
20
21
|
@override
|
21
22
|
def train(self, positive_texts: list[str], negative_texts: list[str],
|
@@ -27,8 +28,8 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
27
28
|
positive_texts = positive_texts[:min_length]
|
28
29
|
negative_texts = negative_texts[:min_length]
|
29
30
|
all_texts = positive_texts + negative_texts
|
30
|
-
labels = ([torch.tensor([1.0], dtype=torch.float32) for _ in range(len(positive_texts))]
|
31
|
-
+ [torch.tensor([0.0], dtype=torch.float32) for _ in range(len(negative_texts))])
|
31
|
+
labels = ([torch.tensor([1.0], dtype=torch.float32, device=self.device) for _ in range(len(positive_texts))]
|
32
|
+
+ [torch.tensor([0.0], dtype=torch.float32, device=self.device) for _ in range(len(negative_texts))])
|
32
33
|
text_embeddings = [self._long_text_encoder.encode(x) for x in all_texts]
|
33
34
|
feature_dim = text_embeddings[0].shape[-1]
|
34
35
|
inputs = torch.stack(text_embeddings)
|
@@ -44,6 +45,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
44
45
|
self.model = None
|
45
46
|
if self.model is None:
|
46
47
|
self.model = LogisticRegression(input_dim=feature_dim, output_dim=1)
|
48
|
+
self.model.to(self.device)
|
47
49
|
loss_function = nn.BCELoss()
|
48
50
|
optimizer = optim.Adamax(self.model.parameters(), lr=learning_rate)
|
49
51
|
for epoch in range(num_epochs):
|
@@ -1,7 +1,7 @@
|
|
1
1
|
deeplotx/__init__.py,sha256=wMN_AI14V-0BPbQghYpvd2y7eUGfhr7jKTTuur-5Upg,1002
|
2
2
|
deeplotx/encoder/__init__.py,sha256=EM-xrTsHoGaiiFpj-iFAxilMHXC_sQKWYrcq1qCnI3U,138
|
3
3
|
deeplotx/encoder/bert_encoder.py,sha256=IZsmkcmK6ulwTS4zubljW5uvq2r1Ik03nYG6jqcgQL8,2441
|
4
|
-
deeplotx/encoder/long_text_encoder.py,sha256=
|
4
|
+
deeplotx/encoder/long_text_encoder.py,sha256=hl_O8kR9o1kcII9YfSx2rf_Pk0l_Rv7LNbsS9UsTU0c,3373
|
5
5
|
deeplotx/encoder/longformer_encoder.py,sha256=vsDIiS9kLzvAalDnCGfTuAd2gfqDBgKUqPj6tPgF-BM,1886
|
6
6
|
deeplotx/nn/__init__.py,sha256=oQ-vYXyuaGelfCOs2im_gZXAiiBlCCVXh1uw9yjvRMs,253
|
7
7
|
deeplotx/nn/auto_regression.py,sha256=o82C9TREZbhGdj2knSVGTXhjJne0LGEqc7BllByJJWE,449
|
@@ -16,12 +16,12 @@ deeplotx/similarity/set.py,sha256=zhGFxtSIXlWqvipBYzoiPahp4g0boAIoUiMfG0wl07A,68
|
|
16
16
|
deeplotx/similarity/vector.py,sha256=WVbDHqykt-fvuILVrhUCtIFAOEjY_zvttrXGM9eylG0,1125
|
17
17
|
deeplotx/trainer/__init__.py,sha256=Fl5DR9UecQc5VtBcczU9sx_HtPNoFohpuELOh-Jrsks,77
|
18
18
|
deeplotx/trainer/base_trainer.py,sha256=z0MeAT-rRYmjeBXt0ckt7J1itYArR0Cx02wHesXUoZE,385
|
19
|
-
deeplotx/trainer/text_binary_classification_trainer.py,sha256=
|
19
|
+
deeplotx/trainer/text_binary_classification_trainer.py,sha256=NhLFndk4I1PViSfat4XadDV-vSUGPOZ0RabfhQ5FLKY,4210
|
20
20
|
deeplotx/util/__init__.py,sha256=JxqAK_WOOHcYVSTHBT1-WuBwWrPEVDTV3titeVWvNUM,74
|
21
21
|
deeplotx/util/hash.py,sha256=wwsC6kOQvbpuvwKsNQOARd78_wePmW9i3oaUuXRUnpc,352
|
22
22
|
deeplotx/util/read_file.py,sha256=ptzouvEQeeW8KU5BrWNJlXw-vFXVrpS9SkAUxsu6A8A,612
|
23
|
-
deeplotx-0.4.
|
24
|
-
deeplotx-0.4.
|
25
|
-
deeplotx-0.4.
|
26
|
-
deeplotx-0.4.
|
27
|
-
deeplotx-0.4.
|
23
|
+
deeplotx-0.4.12b0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
|
24
|
+
deeplotx-0.4.12b0.dist-info/METADATA,sha256=2JQcCaNV4WQ2jYDw50dIT5aLcwoEBkkjrvDAOCrcdbM,6287
|
25
|
+
deeplotx-0.4.12b0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
26
|
+
deeplotx-0.4.12b0.dist-info/top_level.txt,sha256=hKg4pVDXZ-WWxkRfJFczRIll1Sv7VyfKCmzHLXbuh1U,9
|
27
|
+
deeplotx-0.4.12b0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|