wolof-translate 0.0.1__tar.gz → 0.0.3__tar.gz
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.
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/PKG-INFO +1 -1
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/setup.py +1 -1
- wolof_translate-0.0.3/wolof_translate/utils/bucket_iterator.py +212 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/PKG-INFO +1 -1
- wolof_translate-0.0.1/wolof_translate/utils/bucket_iterator.py +0 -143
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/setup.cfg +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/dataset_v1.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/sent_transformers.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v1.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v2.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v3.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v3.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v4.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v4.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v1.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v2.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v3.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v3_2.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v4.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v5.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2idf.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2tfidf.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/main.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/main.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/optimization.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/optimization.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/position.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/position.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/size.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/size.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/main.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/main_2.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/optimization.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/position.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/size.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2idf.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2tfidf.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/pipe/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/pipe/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/pipe/__pycache__/nlp_pipeline.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/pipe/nlp_pipeline.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/adverse_tokenizer.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v3.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v3_2.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v5.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v3.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v3.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v4.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v4.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v5.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v5.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v6.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v6.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v7.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v7.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v8.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v8.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v9.model +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v9.vocab +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers.zip +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v1.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v3_2.json +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v4.subwords +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v5.subwords +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v6.subwords +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v7.subwords +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_custom.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_ml.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_ml_.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_custom.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml_.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/bucket_iterator.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/database_manager.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/display_predictions.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/download_model.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluate_custom.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluation.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluation.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/extract_new_sentences.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/recuperate_datasets.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_corrections.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_corrections.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_transformers.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_transformers.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_unification.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/split_with_valid.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/split_with_valid.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/tokenize_text.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/training.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/database_manager.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/display_predictions.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/download_model.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/evaluate_custom.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/evaluation.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/extract_new_sentences.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/extract_poems.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/extract_sentences.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__init__.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/__init__.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/__init__.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/end_marks.cpython-310.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/end_marks.cpython-311.pyc +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/end_marks.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets_trunc.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/send_model.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/sent_corrections.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/sent_transformers.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/sent_unification.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/split_with_valid.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/tokenize_text.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/training.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/trunc_hg_training.py +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/SOURCES.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/dependency_links.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/requires.txt +0 -0
- {wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ from setuptools import setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="wolof_translate",
|
|
5
|
-
version="0.0.
|
|
5
|
+
version="0.0.3",
|
|
6
6
|
author="Oumar Kane",
|
|
7
7
|
author_email="oumar.kane@univ-thies.sn",
|
|
8
8
|
description="Contain function and classes to process corpora for making translation between wolof text and other languages.",
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from typing import Optional, List, Iterator, Union
|
|
3
|
+
from torch.utils.data import Sampler
|
|
4
|
+
from math import ceil
|
|
5
|
+
from tqdm import tqdm
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
class SequenceLengthBatchSampler(Sampler[List[int]]):
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
dataset,
|
|
12
|
+
boundaries: List[int],
|
|
13
|
+
batch_sizes: List[int],
|
|
14
|
+
input_key: Optional[int] = None,
|
|
15
|
+
label_key: Optional[int] = None,
|
|
16
|
+
drop_unique: bool = True,
|
|
17
|
+
):
|
|
18
|
+
self.dataset = dataset
|
|
19
|
+
self.boundaries = boundaries
|
|
20
|
+
self.batch_sizes = batch_sizes
|
|
21
|
+
self.drop_unique = drop_unique
|
|
22
|
+
|
|
23
|
+
start_time = time.time()
|
|
24
|
+
tqdm.write("Computing sequence lengths...")
|
|
25
|
+
|
|
26
|
+
# Compute lengths with tqdm progress bar
|
|
27
|
+
self.lengths = np.array([
|
|
28
|
+
max(len(data[0]), len(data[2])) if input_key is None or label_key is None
|
|
29
|
+
else max(len(data[input_key]), len(data[label_key]))
|
|
30
|
+
for data in tqdm(dataset, desc="Lengths", unit="seq")
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
tqdm.write(f"Sequence lengths computed in {time.time() - start_time:.2f} seconds.")
|
|
34
|
+
|
|
35
|
+
start_time = time.time()
|
|
36
|
+
tqdm.write("Assigning buckets...")
|
|
37
|
+
|
|
38
|
+
# Assign bucket ids using digitize (vectorized)
|
|
39
|
+
self.bucket_ids = np.digitize(self.lengths, bins=self.boundaries, right=True)
|
|
40
|
+
|
|
41
|
+
# Create buckets of indices
|
|
42
|
+
self.buckets = [np.where(self.bucket_ids == i)[0] for i in range(len(boundaries) + 1)]
|
|
43
|
+
|
|
44
|
+
tqdm.write(f"Buckets assigned in {time.time() - start_time:.2f} seconds.")
|
|
45
|
+
|
|
46
|
+
start_time = time.time()
|
|
47
|
+
tqdm.write("Preparing batches...")
|
|
48
|
+
|
|
49
|
+
# Prepare batches from buckets
|
|
50
|
+
self.batches = []
|
|
51
|
+
for bucket, batch_size in zip(self.buckets, self.batch_sizes):
|
|
52
|
+
bucket = bucket.copy()
|
|
53
|
+
np.random.shuffle(bucket)
|
|
54
|
+
|
|
55
|
+
n_full_batches = len(bucket) // batch_size
|
|
56
|
+
leftover = len(bucket) % batch_size
|
|
57
|
+
|
|
58
|
+
for i in range(n_full_batches):
|
|
59
|
+
batch = bucket[i * batch_size : (i + 1) * batch_size].tolist()
|
|
60
|
+
self.batches.append(batch)
|
|
61
|
+
|
|
62
|
+
if leftover > 0 and (leftover != 1 or not self.drop_unique):
|
|
63
|
+
batch = bucket[-leftover:].tolist()
|
|
64
|
+
self.batches.append(batch)
|
|
65
|
+
|
|
66
|
+
self.length = len(self.batches)
|
|
67
|
+
tqdm.write(f"Batches prepared in {time.time() - start_time:.2f} seconds.")
|
|
68
|
+
|
|
69
|
+
def __iter__(self) -> Iterator[List[int]]:
|
|
70
|
+
# Shuffle all batches globally to add randomness between buckets
|
|
71
|
+
np.random.shuffle(self.batches)
|
|
72
|
+
for batch in self.batches:
|
|
73
|
+
yield batch
|
|
74
|
+
|
|
75
|
+
def __len__(self) -> int:
|
|
76
|
+
return self.length
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# class SequenceLengthBatchSampler(Sampler[List[int]]):
|
|
82
|
+
# def __init__(
|
|
83
|
+
# self,
|
|
84
|
+
# dataset,
|
|
85
|
+
# boundaries: List[int],
|
|
86
|
+
# batch_sizes: List[int],
|
|
87
|
+
# input_key: Optional[int] = None,
|
|
88
|
+
# label_key: Optional[int] = None,
|
|
89
|
+
# drop_unique: bool = True,
|
|
90
|
+
# ):
|
|
91
|
+
# self.dataset = dataset
|
|
92
|
+
# self.boundaries = boundaries
|
|
93
|
+
# self.batch_sizes = batch_sizes
|
|
94
|
+
# self.drop_unique = drop_unique
|
|
95
|
+
# self.data_info = {}
|
|
96
|
+
|
|
97
|
+
# # Extract lengths
|
|
98
|
+
# for i in range(len(dataset)):
|
|
99
|
+
# data = dataset[i]
|
|
100
|
+
# if input_key is None or label_key is None:
|
|
101
|
+
# length = max(len(data[0]), len(data[2]))
|
|
102
|
+
# else:
|
|
103
|
+
# length = max(len(data[input_key]), len(data[label_key]))
|
|
104
|
+
# self.data_info[i] = {"index": i, "length": length}
|
|
105
|
+
|
|
106
|
+
# self.calculate_length()
|
|
107
|
+
|
|
108
|
+
# def calculate_length(self):
|
|
109
|
+
# self.batches = []
|
|
110
|
+
# sorted_indices = sorted(self.data_info.keys(), key=lambda i: self.data_info[i]["length"])
|
|
111
|
+
|
|
112
|
+
# prev_boundary = 0
|
|
113
|
+
# for boundary in self.boundaries:
|
|
114
|
+
# batch = [i for i in sorted_indices if prev_boundary < self.data_info[i]["length"] <= boundary]
|
|
115
|
+
# self.batches.append(batch)
|
|
116
|
+
# sorted_indices = [i for i in sorted_indices if i not in batch]
|
|
117
|
+
# prev_boundary = boundary
|
|
118
|
+
|
|
119
|
+
# # Remaining sequences > last boundary
|
|
120
|
+
# self.batches.append(sorted_indices)
|
|
121
|
+
|
|
122
|
+
# total_batches = 0
|
|
123
|
+
# for batch, batch_size in zip(self.batches, self.batch_sizes):
|
|
124
|
+
# n_full_batches = len(batch) // batch_size
|
|
125
|
+
# leftover = len(batch) % batch_size
|
|
126
|
+
# total_batches += n_full_batches
|
|
127
|
+
# if leftover > 0 and (leftover != 1 or not self.drop_unique):
|
|
128
|
+
# total_batches += 1
|
|
129
|
+
# self.length = total_batches
|
|
130
|
+
|
|
131
|
+
# def __iter__(self) -> Iterator[List[int]]:
|
|
132
|
+
# for batch_indices, batch_size in zip(self.batches, self.batch_sizes):
|
|
133
|
+
# num_batches = len(batch_indices) // batch_size
|
|
134
|
+
|
|
135
|
+
# for i in range(num_batches):
|
|
136
|
+
# current_bucket = batch_indices[i * batch_size: (i + 1) * batch_size]
|
|
137
|
+
# np.random.shuffle(current_bucket)
|
|
138
|
+
# yield [self.data_info[idx]["index"] for idx in current_bucket]
|
|
139
|
+
|
|
140
|
+
# remaining = len(batch_indices) % batch_size
|
|
141
|
+
# if remaining > 0 and (remaining != 1 or not self.drop_unique):
|
|
142
|
+
# current_bucket = batch_indices[-remaining:]
|
|
143
|
+
# np.random.shuffle(current_bucket)
|
|
144
|
+
# yield [self.data_info[idx]["index"] for idx in current_bucket]
|
|
145
|
+
|
|
146
|
+
# def __len__(self) -> int:
|
|
147
|
+
# return self.length
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class BucketSampler(Sampler):
|
|
152
|
+
def __init__(self, dataset, batch_size, sort_key=lambda x, index_1, index_2: max(len(x[index_1]), len(x[index_2])), input_key: Union[str, int] = 0, label_key: Union[str, int] = 1):
|
|
153
|
+
self.dataset = dataset
|
|
154
|
+
self.batch_size = batch_size
|
|
155
|
+
self.sort_key = sort_key
|
|
156
|
+
self.index_1 = input_key
|
|
157
|
+
self.index_2 = label_key
|
|
158
|
+
indices = np.argsort([self.sort_key(self.dataset[i], self.index_1, self.index_2) for i in range(len(self.dataset))])
|
|
159
|
+
self.batches = [indices[i:i + self.batch_size] for i in range(0, len(indices), self.batch_size)]
|
|
160
|
+
|
|
161
|
+
def __iter__(self):
|
|
162
|
+
if self.batch_size > 1:
|
|
163
|
+
np.random.shuffle(self.batches)
|
|
164
|
+
for batch in self.batches:
|
|
165
|
+
yield batch.tolist()
|
|
166
|
+
|
|
167
|
+
def __len__(self):
|
|
168
|
+
return ceil(len(self.dataset) / self.batch_size)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def collate_fn(batch):
|
|
172
|
+
from torch.nn.utils.rnn import pad_sequence
|
|
173
|
+
# Separate the input sequences, target sequences, and attention masks
|
|
174
|
+
input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
|
|
175
|
+
|
|
176
|
+
# Pad the input sequences to have the same length
|
|
177
|
+
padded_input_seqs = pad_sequence(input_seqs, batch_first=True)
|
|
178
|
+
|
|
179
|
+
# Pad the target sequences to have the same length
|
|
180
|
+
padded_target_seqs = pad_sequence(target_seqs, batch_first=True)
|
|
181
|
+
|
|
182
|
+
# Pad the input masks to have the same length
|
|
183
|
+
padded_input_masks = pad_sequence(input_masks, batch_first=True)
|
|
184
|
+
|
|
185
|
+
# Pad the labels masks to have the same length
|
|
186
|
+
padded_target_masks = pad_sequence(target_masks, batch_first=True)
|
|
187
|
+
|
|
188
|
+
return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks
|
|
189
|
+
|
|
190
|
+
def collate_fn_trunc(batch, max_len, eos_token_id, pad_token_id):
|
|
191
|
+
from torch.nn.utils.rnn import pad_sequence
|
|
192
|
+
# Separate the input sequences, target sequences, and attention masks
|
|
193
|
+
input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
|
|
194
|
+
|
|
195
|
+
# Pad the input sequences to have the same length
|
|
196
|
+
padded_input_seqs = pad_sequence(input_seqs, batch_first=True)[:,:max_len]
|
|
197
|
+
|
|
198
|
+
# Pad the target sequences to have the same length
|
|
199
|
+
padded_target_seqs = pad_sequence(target_seqs, batch_first=True)[:,:max_len]
|
|
200
|
+
|
|
201
|
+
# add eos_token id if pad token id is not visible
|
|
202
|
+
padded_input_seqs[:, -1:][(padded_input_seqs[:, -1:] != eos_token_id) & (padded_input_seqs[:, -1:] != pad_token_id)] = eos_token_id
|
|
203
|
+
|
|
204
|
+
padded_target_seqs[:, -1:][(padded_target_seqs[:, -1:] != eos_token_id) & (padded_target_seqs[:, -1:] != pad_token_id)] = eos_token_id
|
|
205
|
+
|
|
206
|
+
# Pad the input masks to have the same length
|
|
207
|
+
padded_input_masks = pad_sequence(input_masks, batch_first=True)[:,:max_len]
|
|
208
|
+
|
|
209
|
+
# Pad the labels masks to have the same length
|
|
210
|
+
padded_target_masks = pad_sequence(target_masks, batch_first=True)[:,:max_len]
|
|
211
|
+
|
|
212
|
+
return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import torch
|
|
3
|
-
import numpy as np
|
|
4
|
-
from typing import *
|
|
5
|
-
from torch.utils.data import Sampler
|
|
6
|
-
from torch.nn.utils.rnn import pad_sequence
|
|
7
|
-
from math import ceil
|
|
8
|
-
|
|
9
|
-
class SequenceLengthBatchSampler(Sampler):
|
|
10
|
-
def __init__(self, dataset, boundaries, batch_sizes, input_key = None, label_key = None, drop_unique = True):
|
|
11
|
-
self.dataset = dataset
|
|
12
|
-
self.boundaries = boundaries
|
|
13
|
-
self.batch_sizes = batch_sizes
|
|
14
|
-
self.data_info = {}
|
|
15
|
-
self.drop_unique = drop_unique
|
|
16
|
-
|
|
17
|
-
# Initialize dictionary with indices and element lengths
|
|
18
|
-
for i in range(len(dataset)):
|
|
19
|
-
data = dataset[i]
|
|
20
|
-
length = (
|
|
21
|
-
max(len(data[0]), len(data[2]))
|
|
22
|
-
if (input_key is None and label_key is None)
|
|
23
|
-
else max(len(data[input_key]), len(data[label_key]))
|
|
24
|
-
)
|
|
25
|
-
self.data_info[i] = {"index": i, "length": length}
|
|
26
|
-
|
|
27
|
-
self.calculate_length()
|
|
28
|
-
|
|
29
|
-
def calculate_length(self):
|
|
30
|
-
self.batches = []
|
|
31
|
-
|
|
32
|
-
# Sort indices based on element length
|
|
33
|
-
sorted_indices = sorted(self.data_info.keys(), key=lambda i: self.data_info[i]["length"])
|
|
34
|
-
|
|
35
|
-
# Group indices into batches of sequences with the same length
|
|
36
|
-
for boundary in self.boundaries:
|
|
37
|
-
batch = [i for i in sorted_indices if self.data_info[i]["length"] <= boundary] # Filter indices based on length boundary
|
|
38
|
-
self.batches.append(batch)
|
|
39
|
-
sorted_indices = [i for i in sorted_indices if i not in batch] # Remove processed indices
|
|
40
|
-
|
|
41
|
-
# Add remaining indices to the last batch
|
|
42
|
-
self.batches.append(sorted_indices)
|
|
43
|
-
|
|
44
|
-
# Calculate the total length of the data loader
|
|
45
|
-
self.length = sum(ceil(len(batch) / batch_size) for batch, batch_size in zip(self.batches, self.batch_sizes) if len(batch) % batch_size != 1 or not self.drop_unique)
|
|
46
|
-
|
|
47
|
-
def __iter__(self):
|
|
48
|
-
# indices = list(self.data_info.keys()) # Get indices from the data_info dictionary
|
|
49
|
-
# np.random.shuffle(indices) # Shuffle the indices
|
|
50
|
-
|
|
51
|
-
# Yield batches with the corresponding batch sizes
|
|
52
|
-
for batch_indices, batch_size in zip(self.batches, self.batch_sizes):
|
|
53
|
-
num_batches = len(batch_indices) // batch_size
|
|
54
|
-
|
|
55
|
-
for i in range(num_batches):
|
|
56
|
-
# Recuperate the current bucket
|
|
57
|
-
current_bucket = batch_indices[i * batch_size: (i + 1) * batch_size]
|
|
58
|
-
|
|
59
|
-
# Shuffle the current bucket
|
|
60
|
-
np.random.shuffle(current_bucket)
|
|
61
|
-
|
|
62
|
-
# Yield the current bucket
|
|
63
|
-
yield [self.data_info[i]["index"] for i in current_bucket]
|
|
64
|
-
|
|
65
|
-
remaining_indices = len(batch_indices) % batch_size
|
|
66
|
-
|
|
67
|
-
if remaining_indices > 0 and remaining_indices != 1 or not self.drop_unique:
|
|
68
|
-
|
|
69
|
-
# Recuperate the current bucket
|
|
70
|
-
current_bucket = batch_indices[-remaining_indices:]
|
|
71
|
-
|
|
72
|
-
# Shuffle the current bucket
|
|
73
|
-
np.random.shuffle(current_bucket)
|
|
74
|
-
|
|
75
|
-
# Yield the current bucket
|
|
76
|
-
yield [self.data_info[i]["index"] for i in batch_indices[-remaining_indices:]]
|
|
77
|
-
|
|
78
|
-
def __len__(self):
|
|
79
|
-
return self.length
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
class BucketSampler(Sampler):
|
|
83
|
-
def __init__(self, dataset, batch_size, sort_key=lambda x, index_1, index_2: max(len(x[index_1]), len(x[index_2])), input_key: Union[str, int] = 0, label_key: Union[str, int] = 1):
|
|
84
|
-
self.dataset = dataset
|
|
85
|
-
self.batch_size = batch_size
|
|
86
|
-
self.sort_key = sort_key
|
|
87
|
-
self.index_1 = input_key
|
|
88
|
-
self.index_2 = label_key
|
|
89
|
-
indices = np.argsort([self.sort_key(self.dataset[i], self.index_1, self.index_2) for i in range(len(self.dataset))])
|
|
90
|
-
self.batches = [indices[i:i + self.batch_size] for i in range(0, len(indices), self.batch_size)]
|
|
91
|
-
|
|
92
|
-
def __iter__(self):
|
|
93
|
-
if self.batch_size > 1:
|
|
94
|
-
np.random.shuffle(self.batches)
|
|
95
|
-
for batch in self.batches:
|
|
96
|
-
yield batch.tolist()
|
|
97
|
-
|
|
98
|
-
def __len__(self):
|
|
99
|
-
return ceil(len(self.dataset) / self.batch_size)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def collate_fn(batch):
|
|
103
|
-
from torch.nn.utils.rnn import pad_sequence
|
|
104
|
-
# Separate the input sequences, target sequences, and attention masks
|
|
105
|
-
input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
|
|
106
|
-
|
|
107
|
-
# Pad the input sequences to have the same length
|
|
108
|
-
padded_input_seqs = pad_sequence(input_seqs, batch_first=True)
|
|
109
|
-
|
|
110
|
-
# Pad the target sequences to have the same length
|
|
111
|
-
padded_target_seqs = pad_sequence(target_seqs, batch_first=True)
|
|
112
|
-
|
|
113
|
-
# Pad the input masks to have the same length
|
|
114
|
-
padded_input_masks = pad_sequence(input_masks, batch_first=True)
|
|
115
|
-
|
|
116
|
-
# Pad the labels masks to have the same length
|
|
117
|
-
padded_target_masks = pad_sequence(target_masks, batch_first=True)
|
|
118
|
-
|
|
119
|
-
return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks
|
|
120
|
-
|
|
121
|
-
def collate_fn_trunc(batch, max_len, eos_token_id, pad_token_id):
|
|
122
|
-
from torch.nn.utils.rnn import pad_sequence
|
|
123
|
-
# Separate the input sequences, target sequences, and attention masks
|
|
124
|
-
input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
|
|
125
|
-
|
|
126
|
-
# Pad the input sequences to have the same length
|
|
127
|
-
padded_input_seqs = pad_sequence(input_seqs, batch_first=True)[:,:max_len]
|
|
128
|
-
|
|
129
|
-
# Pad the target sequences to have the same length
|
|
130
|
-
padded_target_seqs = pad_sequence(target_seqs, batch_first=True)[:,:max_len]
|
|
131
|
-
|
|
132
|
-
# add eos_token id if pad token id is not visible
|
|
133
|
-
padded_input_seqs[:, -1:][(padded_input_seqs[:, -1:] != eos_token_id) & (padded_input_seqs[:, -1:] != pad_token_id)] = eos_token_id
|
|
134
|
-
|
|
135
|
-
padded_target_seqs[:, -1:][(padded_target_seqs[:, -1:] != eos_token_id) & (padded_target_seqs[:, -1:] != pad_token_id)] = eos_token_id
|
|
136
|
-
|
|
137
|
-
# Pad the input masks to have the same length
|
|
138
|
-
padded_input_masks = pad_sequence(input_masks, batch_first=True)[:,:max_len]
|
|
139
|
-
|
|
140
|
-
# Pad the labels masks to have the same length
|
|
141
|
-
padded_target_masks = pad_sequence(target_masks, batch_first=True)[:,:max_len]
|
|
142
|
-
|
|
143
|
-
return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-310.pyc
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-311.pyc
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2idf.txt
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2tfidf.txt
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/main_2.py
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/optimization.py
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/transformers/position.py
RENAMED
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2idf.txt
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2tfidf.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/adverse_tokenizer.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers.zip
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v1.json
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v3_2.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer.py
RENAMED
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml.py
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml_.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/display_predictions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/extract_new_sentences.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/end_marks.py
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets.py
RENAMED
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets_trunc.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{wolof_translate-0.0.1 → wolof_translate-0.0.3}/wolof_translate.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|