wolof-translate 0.0.2__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.
Files changed (141) hide show
  1. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/PKG-INFO +1 -1
  2. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/setup.py +1 -1
  3. wolof_translate-0.0.3/wolof_translate/utils/bucket_iterator.py +212 -0
  4. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate.egg-info/PKG-INFO +1 -1
  5. wolof_translate-0.0.2/wolof_translate/utils/bucket_iterator.py +0 -138
  6. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/setup.cfg +0 -0
  7. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/__init__.py +0 -0
  8. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-310.pyc +0 -0
  9. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/__pycache__/__init__.cpython-311.pyc +0 -0
  10. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/__pycache__/dataset_v1.cpython-310.pyc +0 -0
  11. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/__pycache__/sent_transformers.cpython-310.pyc +0 -0
  12. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__init__.py +0 -0
  13. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/__init__.cpython-310.pyc +0 -0
  14. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/__init__.cpython-311.pyc +0 -0
  15. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v1.cpython-310.pyc +0 -0
  16. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v2.cpython-310.pyc +0 -0
  17. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v3.cpython-310.pyc +0 -0
  18. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v3.cpython-311.pyc +0 -0
  19. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v4.cpython-310.pyc +0 -0
  20. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/__pycache__/dataset_v4.cpython-311.pyc +0 -0
  21. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v1.py +0 -0
  22. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v2.py +0 -0
  23. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v3.py +0 -0
  24. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v3_2.py +0 -0
  25. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v4.py +0 -0
  26. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/data/dataset_v5.py +0 -0
  27. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/__init__.py +0 -0
  28. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/__pycache__/__init__.cpython-310.pyc +0 -0
  29. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/__pycache__/__init__.cpython-311.pyc +0 -0
  30. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2idf.txt +0 -0
  31. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/french/tfidfaug_w2tfidf.txt +0 -0
  32. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__init__.py +0 -0
  33. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/__init__.cpython-310.pyc +0 -0
  34. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/__init__.cpython-311.pyc +0 -0
  35. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/main.cpython-310.pyc +0 -0
  36. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/main.cpython-311.pyc +0 -0
  37. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/optimization.cpython-310.pyc +0 -0
  38. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/optimization.cpython-311.pyc +0 -0
  39. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/position.cpython-310.pyc +0 -0
  40. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/position.cpython-311.pyc +0 -0
  41. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/size.cpython-310.pyc +0 -0
  42. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/__pycache__/size.cpython-311.pyc +0 -0
  43. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/main.py +0 -0
  44. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/main_2.py +0 -0
  45. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/optimization.py +0 -0
  46. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/position.py +0 -0
  47. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/transformers/size.py +0 -0
  48. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2idf.txt +0 -0
  49. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/models/wolof/tfidfaug_w2tfidf.txt +0 -0
  50. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/pipe/__init__.py +0 -0
  51. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/pipe/__pycache__/__init__.cpython-310.pyc +0 -0
  52. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/pipe/__pycache__/nlp_pipeline.cpython-310.pyc +0 -0
  53. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/pipe/nlp_pipeline.py +0 -0
  54. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/__init__.py +0 -0
  55. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/__pycache__/__init__.cpython-310.pyc +0 -0
  56. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/adverse_tokenizer.json +0 -0
  57. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v3.json +0 -0
  58. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v3_2.json +0 -0
  59. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/bart_tokenizers/tokenizer_v5.json +0 -0
  60. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v3.model +0 -0
  61. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v3.vocab +0 -0
  62. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v4.model +0 -0
  63. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v4.vocab +0 -0
  64. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v5.model +0 -0
  65. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v5.vocab +0 -0
  66. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v6.model +0 -0
  67. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v6.vocab +0 -0
  68. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v7.model +0 -0
  69. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v7.vocab +0 -0
  70. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v8.model +0 -0
  71. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v8.vocab +0 -0
  72. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v9.model +0 -0
  73. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers/tokenizer_v9.vocab +0 -0
  74. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/t5_tokenizers.zip +0 -0
  75. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v1.json +0 -0
  76. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/tokenizer_v3_2.json +0 -0
  77. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v4.subwords +0 -0
  78. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v5.subwords +0 -0
  79. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v6.subwords +0 -0
  80. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/tokenizers/trax/sentencepiece_tokenizer_v7.subwords +0 -0
  81. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__init__.py +0 -0
  82. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/__init__.cpython-310.pyc +0 -0
  83. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/__init__.cpython-311.pyc +0 -0
  84. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer.cpython-310.pyc +0 -0
  85. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer.cpython-311.pyc +0 -0
  86. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_custom.cpython-310.pyc +0 -0
  87. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_ml.cpython-310.pyc +0 -0
  88. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/__pycache__/transformer_trainer_ml_.cpython-310.pyc +0 -0
  89. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer.py +0 -0
  90. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_custom.py +0 -0
  91. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml.py +0 -0
  92. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/trainers/transformer_trainer_ml_.py +0 -0
  93. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__init__.py +0 -0
  94. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  95. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  96. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/bucket_iterator.cpython-310.pyc +0 -0
  97. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/database_manager.cpython-310.pyc +0 -0
  98. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/display_predictions.cpython-310.pyc +0 -0
  99. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/download_model.cpython-310.pyc +0 -0
  100. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluate_custom.cpython-310.pyc +0 -0
  101. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluation.cpython-310.pyc +0 -0
  102. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/evaluation.cpython-311.pyc +0 -0
  103. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/extract_new_sentences.cpython-310.pyc +0 -0
  104. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/recuperate_datasets.cpython-310.pyc +0 -0
  105. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_corrections.cpython-310.pyc +0 -0
  106. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_corrections.cpython-311.pyc +0 -0
  107. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_transformers.cpython-310.pyc +0 -0
  108. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_transformers.cpython-311.pyc +0 -0
  109. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/sent_unification.cpython-310.pyc +0 -0
  110. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/split_with_valid.cpython-310.pyc +0 -0
  111. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/split_with_valid.cpython-311.pyc +0 -0
  112. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/tokenize_text.cpython-310.pyc +0 -0
  113. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/__pycache__/training.cpython-310.pyc +0 -0
  114. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/database_manager.py +0 -0
  115. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/display_predictions.py +0 -0
  116. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/download_model.py +0 -0
  117. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/evaluate_custom.py +0 -0
  118. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/evaluation.py +0 -0
  119. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/extract_new_sentences.py +0 -0
  120. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/extract_poems.py +0 -0
  121. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/extract_sentences.py +0 -0
  122. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__init__.py +0 -0
  123. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/__init__.cpython-310.pyc +0 -0
  124. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/__init__.cpython-311.pyc +0 -0
  125. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/end_marks.cpython-310.pyc +0 -0
  126. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/__pycache__/end_marks.cpython-311.pyc +0 -0
  127. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/improvements/end_marks.py +0 -0
  128. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets.py +0 -0
  129. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/recuperate_datasets_trunc.py +0 -0
  130. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/send_model.py +0 -0
  131. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/sent_corrections.py +0 -0
  132. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/sent_transformers.py +0 -0
  133. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/sent_unification.py +0 -0
  134. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/split_with_valid.py +0 -0
  135. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/tokenize_text.py +0 -0
  136. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/training.py +0 -0
  137. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate/utils/trunc_hg_training.py +0 -0
  138. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate.egg-info/SOURCES.txt +0 -0
  139. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate.egg-info/dependency_links.txt +0 -0
  140. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate.egg-info/requires.txt +0 -0
  141. {wolof_translate-0.0.2 → wolof_translate-0.0.3}/wolof_translate.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wolof_translate
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Contain function and classes to process corpora for making translation between wolof text and other languages.
5
5
  Author: Oumar Kane
6
6
  Author-email: oumar.kane@univ-thies.sn
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name="wolof_translate",
5
- version="0.0.2",
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wolof-translate
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Contain function and classes to process corpora for making translation between wolof text and other languages.
5
5
  Author: Oumar Kane
6
6
  Author-email: oumar.kane@univ-thies.sn
@@ -1,138 +0,0 @@
1
- import torch
2
- import numpy as np
3
- from typing import Optional, List, Iterator
4
- from torch.utils.data import Sampler
5
- from math import ceil
6
-
7
- class SequenceLengthBatchSampler(Sampler[List[int]]):
8
- def __init__(
9
- self,
10
- dataset,
11
- boundaries: List[int],
12
- batch_sizes: List[int],
13
- input_key: Optional[int] = None,
14
- label_key: Optional[int] = None,
15
- drop_unique: bool = True,
16
- ):
17
- self.dataset = dataset
18
- self.boundaries = boundaries
19
- self.batch_sizes = batch_sizes
20
- self.drop_unique = drop_unique
21
- self.data_info = {}
22
-
23
- # Extract lengths
24
- for i in range(len(dataset)):
25
- data = dataset[i]
26
- if input_key is None or label_key is None:
27
- length = max(len(data[0]), len(data[2]))
28
- else:
29
- length = max(len(data[input_key]), len(data[label_key]))
30
- self.data_info[i] = {"index": i, "length": length}
31
-
32
- self.calculate_length()
33
-
34
- def calculate_length(self):
35
- self.batches = []
36
- sorted_indices = sorted(self.data_info.keys(), key=lambda i: self.data_info[i]["length"])
37
-
38
- prev_boundary = 0
39
- for boundary in self.boundaries:
40
- batch = [i for i in sorted_indices if prev_boundary < self.data_info[i]["length"] <= boundary]
41
- self.batches.append(batch)
42
- sorted_indices = [i for i in sorted_indices if i not in batch]
43
- prev_boundary = boundary
44
-
45
- # Remaining sequences > last boundary
46
- self.batches.append(sorted_indices)
47
-
48
- total_batches = 0
49
- for batch, batch_size in zip(self.batches, self.batch_sizes):
50
- n_full_batches = len(batch) // batch_size
51
- leftover = len(batch) % batch_size
52
- total_batches += n_full_batches
53
- if leftover > 0 and (leftover != 1 or not self.drop_unique):
54
- total_batches += 1
55
- self.length = total_batches
56
-
57
- def __iter__(self) -> Iterator[List[int]]:
58
- for batch_indices, batch_size in zip(self.batches, self.batch_sizes):
59
- num_batches = len(batch_indices) // batch_size
60
-
61
- for i in range(num_batches):
62
- current_bucket = batch_indices[i * batch_size: (i + 1) * batch_size]
63
- np.random.shuffle(current_bucket)
64
- yield [self.data_info[idx]["index"] for idx in current_bucket]
65
-
66
- remaining = len(batch_indices) % batch_size
67
- if remaining > 0 and (remaining != 1 or not self.drop_unique):
68
- current_bucket = batch_indices[-remaining:]
69
- np.random.shuffle(current_bucket)
70
- yield [self.data_info[idx]["index"] for idx in current_bucket]
71
-
72
- def __len__(self) -> int:
73
- return self.length
74
-
75
-
76
-
77
- class BucketSampler(Sampler):
78
- 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):
79
- self.dataset = dataset
80
- self.batch_size = batch_size
81
- self.sort_key = sort_key
82
- self.index_1 = input_key
83
- self.index_2 = label_key
84
- indices = np.argsort([self.sort_key(self.dataset[i], self.index_1, self.index_2) for i in range(len(self.dataset))])
85
- self.batches = [indices[i:i + self.batch_size] for i in range(0, len(indices), self.batch_size)]
86
-
87
- def __iter__(self):
88
- if self.batch_size > 1:
89
- np.random.shuffle(self.batches)
90
- for batch in self.batches:
91
- yield batch.tolist()
92
-
93
- def __len__(self):
94
- return ceil(len(self.dataset) / self.batch_size)
95
-
96
-
97
- def collate_fn(batch):
98
- from torch.nn.utils.rnn import pad_sequence
99
- # Separate the input sequences, target sequences, and attention masks
100
- input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
101
-
102
- # Pad the input sequences to have the same length
103
- padded_input_seqs = pad_sequence(input_seqs, batch_first=True)
104
-
105
- # Pad the target sequences to have the same length
106
- padded_target_seqs = pad_sequence(target_seqs, batch_first=True)
107
-
108
- # Pad the input masks to have the same length
109
- padded_input_masks = pad_sequence(input_masks, batch_first=True)
110
-
111
- # Pad the labels masks to have the same length
112
- padded_target_masks = pad_sequence(target_masks, batch_first=True)
113
-
114
- return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks
115
-
116
- def collate_fn_trunc(batch, max_len, eos_token_id, pad_token_id):
117
- from torch.nn.utils.rnn import pad_sequence
118
- # Separate the input sequences, target sequences, and attention masks
119
- input_seqs, input_masks, target_seqs, target_masks = zip(*batch)
120
-
121
- # Pad the input sequences to have the same length
122
- padded_input_seqs = pad_sequence(input_seqs, batch_first=True)[:,:max_len]
123
-
124
- # Pad the target sequences to have the same length
125
- padded_target_seqs = pad_sequence(target_seqs, batch_first=True)[:,:max_len]
126
-
127
- # add eos_token id if pad token id is not visible
128
- padded_input_seqs[:, -1:][(padded_input_seqs[:, -1:] != eos_token_id) & (padded_input_seqs[:, -1:] != pad_token_id)] = eos_token_id
129
-
130
- padded_target_seqs[:, -1:][(padded_target_seqs[:, -1:] != eos_token_id) & (padded_target_seqs[:, -1:] != pad_token_id)] = eos_token_id
131
-
132
- # Pad the input masks to have the same length
133
- padded_input_masks = pad_sequence(input_masks, batch_first=True)[:,:max_len]
134
-
135
- # Pad the labels masks to have the same length
136
- padded_target_masks = pad_sequence(target_masks, batch_first=True)[:,:max_len]
137
-
138
- return padded_input_seqs, padded_input_masks, padded_target_seqs, padded_target_masks