bobboyms commited on
Commit
26dfd91
·
verified ·
1 Parent(s): 7cd29f4

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
README.md CHANGED
@@ -1,3 +1,33 @@
1
- ---
2
- license: cc-by-sa-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ features:
4
+ - name: text
5
+ dtype: string
6
+ - name: word_count
7
+ dtype: int32
8
+ splits:
9
+ - name: train
10
+ num_examples: 2883231
11
+ dataset_size: 4395542393
12
+ configs:
13
+ - config_name: default
14
+ data_files:
15
+ - split: train
16
+ path: "temp/*.parquet"
17
+
18
+ license: apache-2.0
19
+ task_categories:
20
+ - text2text-generation
21
+ - text-generation
22
+ language:
23
+ - pt
24
+ pretty_name: 'Subset Corpus Itau-Unibanco/aroeira: 1B tokens (portuguese PT-BR)'
25
+ size_categories:
26
+ - 1K<n<10K
27
+ ---
28
+
29
+ # **Subset Corpus Itau-Unibanco/aroeira: 1B tokens (portuguese PT-BR)**
30
+
31
+ Subset Corpus Itau-Unibanco/aroeira: 1B tokens (portuguese PT-BR)
32
+
33
+ subset-Itau-Unibanco-aroeira-1B-tokens
aroeira_subset.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+ import pyarrow as pa
4
+ import pyarrow.parquet as pq
5
+ from datasets import load_dataset
6
+
7
+ # Configuração de logging
8
+ logging.basicConfig(
9
+ level=logging.INFO,
10
+ format="%(asctime)s - %(levelname)s - %(message)s"
11
+ )
12
+
13
+ # Threshold de palavras
14
+ WORD_THRESHOLD = 4_000_000_000 # 3 bilhão
15
+
16
+
17
+ def count_words(text: str) -> int:
18
+ """
19
+ Conta a quantidade de palavras em `text` de forma eficiente,
20
+ usando contagem de espaços para evitar alocações de lista.
21
+
22
+ Args:
23
+ text (str): Texto a ser analisado.
24
+
25
+ Returns:
26
+ int: Número de palavras.
27
+ """
28
+ return text.count(" ") + 1 if text else 0
29
+
30
+
31
+ def process_and_write(
32
+ dataset,
33
+ output_folder: str,
34
+ batch_size: int = 100_000
35
+ ) -> None:
36
+ """
37
+ Itera em um `IterableDataset` streaming registro a registro, agrupa em batches,
38
+ conta palavras e escreve cada batch em um arquivo Parquet separado.
39
+ Para evitar gerar arquivos além do limite, interrompe ao alcançar 1 bilhão de palavras.
40
+
41
+ Args:
42
+ dataset: HuggingFace streaming Dataset.
43
+ output_folder (str): Diretório onde serão salvos os arquivos .parquet.
44
+ batch_size (int): Número de registros por batch.
45
+ """
46
+ # Garante que a pasta exista
47
+ os.makedirs(output_folder, exist_ok=True)
48
+
49
+ batch_records = []
50
+ batch_idx = 0
51
+ cumulative_words = 0
52
+ stop_processing = False
53
+
54
+ for record in dataset:
55
+ batch_records.append(record)
56
+ # Ao atingir o tamanho do batch, processa e escreve
57
+ if len(batch_records) >= batch_size:
58
+ batch_idx += 1
59
+ texts = [rec["text"] for rec in batch_records]
60
+ word_counts = [count_words(t) for t in texts]
61
+ batch_word_sum = sum(word_counts)
62
+
63
+ table = pa.Table.from_pydict({
64
+ "text": texts,
65
+ "word_count": word_counts,
66
+ })
67
+
68
+ # Define caminho do arquivo para este batch
69
+ file_path = os.path.join(output_folder, f"batch_{batch_idx}.parquet")
70
+ pq.write_table(table, file_path)
71
+ cumulative_words += batch_word_sum
72
+ logging.info(
73
+ f"Batch {batch_idx} salvo em '{file_path}': "
74
+ f"{len(texts)} registros, {batch_word_sum} palavras, total acumulado: {cumulative_words}"
75
+ )
76
+
77
+ # Verifica threshold
78
+ if cumulative_words >= WORD_THRESHOLD:
79
+ logging.info(
80
+ f"Limite de {WORD_THRESHOLD} palavras atingido. "
81
+ f"Parando processamento.")
82
+ stop_processing = True
83
+ break
84
+
85
+ batch_records = []
86
+
87
+ # Processa o lote restante, se houver e se não interrompido
88
+ if not stop_processing and batch_records:
89
+ batch_idx += 1
90
+ texts = [rec["text"] for rec in batch_records]
91
+ word_counts = [count_words(t) for t in texts]
92
+ batch_word_sum = sum(word_counts)
93
+
94
+ table = pa.Table.from_pydict({
95
+ "text": texts,
96
+ "word_count": word_counts,
97
+ })
98
+
99
+ file_path = os.path.join(output_folder, f"batch_{batch_idx}.parquet")
100
+ pq.write_table(table, file_path)
101
+ cumulative_words += batch_word_sum
102
+ logging.info(
103
+ f"Batch {batch_idx} (restante) salvo em '{file_path}': "
104
+ f"{len(texts)} registros, {batch_word_sum} palavras, total acumulado: {cumulative_words}"
105
+ )
106
+
107
+ logging.info(f"Processamento finalizado. Total de batches: {batch_idx}, palavras totais: {cumulative_words}")
108
+
109
+
110
+ def main() -> None:
111
+ """
112
+ Ponto de entrada: carrega o dataset em streaming e chama o processamento.
113
+ """
114
+ logging.info("Iniciando processamento e escrita de dados em streaming...")
115
+ ds = load_dataset("Itau-Unibanco/aroeira", split="train", streaming=True)
116
+
117
+ script_dir = os.path.dirname(os.path.abspath(__file__))
118
+ output_folder = os.path.join(script_dir, "data")
119
+
120
+ process_and_write(ds, output_folder)
121
+ logging.info("Processamento concluído com sucesso.")
122
+
123
+
124
+ if __name__ == "__main__":
125
+ main()
data/batch_1.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e56025063ed37ee9fef37ce755c62aaaa8b88827e5ad9daecde0fb72eb229f2
3
+ size 161970581
data/batch_10.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c52cf3e77dd7ab9fb6253c6c38ce0e75fbe32c56acd84d686d6f972fb5e602c7
3
+ size 150502460
data/batch_100.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ddb800a6662e7af2eeb6dd1ee157838a3397cd8a678c5f25509d0f866dc73d6
3
+ size 146993509
data/batch_101.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edaaa853bf8f7950b8a479d7e04add6b074243af82e37d260d38208b95950d11
3
+ size 147496878
data/batch_102.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1d0aa3ff9b455cd87304490c5939c2f1418676ad25e4e7e25353d7ce354738f
3
+ size 147426839
data/batch_103.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c3683aa8bd50ec1ecc7b8ee9841f6372fa61bdad1de61f4e2a12e061e57498a
3
+ size 146656083
data/batch_104.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae45d167464fe72c26d9cea74333300bc34c6784252a6b39b29b8d0910482073
3
+ size 148750118
data/batch_105.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0f542efee6488048ad193c941ca3b5e4a4b212c9441f9842d2947f5190f3579
3
+ size 147225586
data/batch_106.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0497b839b6d9d0acfc556b684acc2fb4c74670b717736211e665ebad873d1aa2
3
+ size 147551571
data/batch_107.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a74a03461dab206fd2e8dde74559db5ba84a46ebac9d1110e0ef6cdeb094579a
3
+ size 147597767
data/batch_108.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62ef2e185a4f475a535bbd3530adb533b4246ef95eebdce3a0324f5bce5e474f
3
+ size 147892353
data/batch_109.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5dec40446673ea8eb03ab39efdcae5e272b4f320393f3603370fa1823149ef47
3
+ size 147832782
data/batch_11.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2800fcc0769d9277b7bef0930cac033d2ab787cebff8d54b7228ace9eee2f49
3
+ size 123371165
data/batch_110.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc759823173614dfb07e0e790c69fe71b565141d53ee66e3743b2c3c3e84971b
3
+ size 147468575
data/batch_12.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1607aa01a63f90a7a20a6fec9aed51c3ea0e00eb6db3757939e24f9add4ef2d
3
+ size 124721389
data/batch_13.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:995270a086eeb498482f3da44d9392a6747189ee98e5078a9186348afdaa40d9
3
+ size 128241633
data/batch_14.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ab12952c9ce796b635fbaedfdb96e2eeed7043b74aba9bb07c4aebea96baab4
3
+ size 128427021
data/batch_15.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2c578b5150940ecfc47c0e7bcdf3c71d0a9ac9e72bd24ab256797389d9a0266
3
+ size 130228780
data/batch_16.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8dd88ee01a65039531b520804d3aac94f681c1a352f3a1ffe3b9b7e0d95e3eae
3
+ size 130688539
data/batch_17.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b15cdb064f38bdb17165e66aca9080b59e459bdd2d91f90ad965ae42f979ed0e
3
+ size 133420209
data/batch_18.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89e71bdfd5e82a005a84d78c58788f29b99d4e8db593907cb9029a632002d90b
3
+ size 134931040
data/batch_19.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5694a49939c9241652902d66d47efb5b207842e6bef791c61e23101b8d8cbb1
3
+ size 141729812
data/batch_2.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a4da3f429ca53fae814138522b9cc74e708f75828c680ca85a4776a93b1d6d2
3
+ size 157655555
data/batch_20.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3eb14bce2c1f8913e1439ab4b158ea4eec21b21abd6bf8ccefb185c7e487302
3
+ size 146977519
data/batch_21.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:468b0745b79dcbff1387381802a13eb240a3115828c8ec9c26649b74d8d71854
3
+ size 147493118
data/batch_22.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8890d610315322d1fe9ba54b0e4dcb9c7c83768f406aaa4636709a4bd04f09a2
3
+ size 153472310
data/batch_23.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:756fdbae2400f437fea5ce30ed86f1d37074866d65a1ede24541604a44bbf33a
3
+ size 153518839
data/batch_24.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a2b34548d0619e59b93309c8e1d9c5860d1a97da303f701197eecffc9f4241f
3
+ size 152635817
data/batch_25.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee3624c1e373a55979c23ea34922d63bc9e1b84cd4581ec1b569ec2bb91dfddf
3
+ size 150468246
data/batch_26.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:313fd94231e1c7936c117d96df29eb2d062823c81bbdca942f3ca491ae788af5
3
+ size 150374704
data/batch_27.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:754799628d0c75643c8a518170ef204f4c1d8740460e706cf25d7a0f6135386d
3
+ size 151113726
data/batch_28.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:308ecf4fa0c60c4f8613fa9201912b9f1dab823cf2017406f2857f063c2459c4
3
+ size 151046758
data/batch_29.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d8d944abde4227b20a37b0803cda81bf3bcd1001182ea82d6385cce6b53304c
3
+ size 150967441
data/batch_3.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f6fc89d17484a1086cfd50837335ee2d0c046660ec793b750760089a610424f
3
+ size 157925452
data/batch_30.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92dbad584dc4cb943667f55f354b91e2d8aa024b9c96c0ccf6a22a41ead81a57
3
+ size 152464235
data/batch_31.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa59def5f755dc8f9303fe687ec519a055d756d9ded909845912c0bbd16870dd
3
+ size 152952896
data/batch_32.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee0ac841d949e72c0e2f291272b2dbb31be2857a404d16e58003d0e17c6fcdf0
3
+ size 150829658
data/batch_33.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fac175205fdad8d2c83d1a6599a08cf1adc88c46806dceecfaa4e636e5ff78e7
3
+ size 149736238
data/batch_34.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f39a41016088dee83f8e2d8bd90ad7451d0a997c06e1f55d4400017a344dcec
3
+ size 150080133
data/batch_35.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9135958f16a09af24db8f9460c63e873d9348a232dfc71bb58e059e3089f21ea
3
+ size 150177327
data/batch_36.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff1dffb963e27ad4b6853070b597d233d1860e2f737e17543ea096184eefa3d4
3
+ size 148790412
data/batch_37.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:642234995dd5fff1465c6cf43b0820adb20c777cb22b41630da88d4a8aa1748c
3
+ size 148663076
data/batch_38.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba1174a7d36456cf5cdb26848d5d18b0ea1c94a1d9daeeb33e930520ec680ea8
3
+ size 149445457
data/batch_39.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2482a6b42176f73df58a46cbb2847c058a99ebc8f9872da44dfd42bbf1f603d1
3
+ size 148330416
data/batch_4.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:379d4bbed7cad0e7b2b58158c1ae98301e9525b581a04c3f0bd26b2c67f28bd5
3
+ size 159768482
data/batch_40.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1334fbd7a1ac54a4caaeff92be786ff199c4328cd3ed41c152f5f72575da8acf
3
+ size 149562742
data/batch_41.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f4d1c6c2e2bfb25511d5d2ceba36abeebbcd9b952bfe35f3c2ab3079de24041
3
+ size 149531170
data/batch_42.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65c7bf70a3ecf57d46326e4dcf68fcad481e37988e1aefc6519b66ec10586418
3
+ size 149769197