nicholasKluge commited on
Commit
196b6e6
1 Parent(s): 25f906f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +171 -12
README.md CHANGED
@@ -1,18 +1,177 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
- ## nicholasKluge/TeenyTinyLlama-162m-AgNews
5
- | Epoch | Training Loss | Validation Loss | Accuracy |
6
- |-------|---------------|------------------|----------|
7
- | 1 | 0.195400 | 0.189048 | 0.939211 |
8
- | 2 | 0.106300 | 0.209798 | 0.940526 |
9
- | 3 | 0.036400 | 0.277067 | 0.936579 |
10
 
11
- ## neuralmind/bert-base-portuguese-cased
12
 
13
- | Epoch | Training Loss | Validation Loss | Accuracy |
14
- |-------|---------------|------------------|----------|
15
- | 1 | 0.231100 | 0.212624 | 0.936711 |
16
- | 2 | 0.156000 | 0.216593 | 0.940789 |
17
- | 3 | 0.091800 | 0.258803 | 0.941974 |
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ datasets:
4
+ - maritaca-ai/ag_news_pt
5
+ language:
6
+ - pt
7
+ metrics:
8
+ - accuracy
9
+ library_name: transformers
10
+ pipeline_tag: text-classification
11
+ tags:
12
+ - hate-speech
13
+ widget:
14
+ - text: "Os preços do petróleo do Tearway, derrubar registros e forçar carteiras, apresentam uma nova ameaça econômica apenas três meses antes das eleições presidenciais dos EUA."
15
+ example_title: Exemplo
16
+ - text: "Quando falamos de Inteligência Artificial, hoje em dia existem já vários sistemas que começam a ganhar popularidade, embora nenhum seja ainda tão conhecido como o ChatGPT da OpenAI."
17
+ example_title: Exemplo
18
+ - text: "O Sport Club Internacional comunica a permanência do seu Diretor Esportivo, Márcio Rodrigues, o Magrão. Com novas atribuições, liderando os setores de trabalho do Departamento de Futebol, e a interligação com as categorias de base, exercendo uma função de gestão e suporte ao trabalho desempenhado pela comissão técnica, grupo de jogadores e staff do Clube."
19
+ example_title: Exemplo
20
+ - text: "Uma conferência da ONU terminou no início do sábado com um plano vago para novas negociações informais sobre como diminuir o aquecimento global, mas sem um compromisso dos EUA com negociações multilaterais sobre os próximos passos, incluindo controles de emissões."
21
+ example_title: Exemplo
22
  ---
23
+ # TeenyTinyLlama-162m-AgNews
 
 
 
 
 
24
 
25
+ TeenyTinyLlama is a series of small foundational models trained in Brazilian Portuguese.
26
 
27
+ This repository contains a version of [TeenyTinyLlama-162m](https://huggingface.co/nicholasKluge/TeenyTinyLlama-162m) (`TeenyTinyLlama-162m-AgNews`) fine-tuned on the [AgNews dataset](https://huggingface.co/datasets/maritaca-ai/ag_news_pt).
 
 
 
 
28
 
29
+ ## Details
30
+
31
+ - **Number of Epochs:** 3
32
+ - **Batch size:** 16
33
+ - **Optimizer:** `torch.optim.AdamW` (learning_rate = 4e-5, epsilon = 1e-8)
34
+ - **GPU:** 1 NVIDIA A100-SXM4-40GB
35
+
36
+ ## Usage
37
+
38
+ Using `transformers.pipeline`:
39
+
40
+ ```python
41
+ from transformers import pipeline
42
+
43
+ text = "Quando falamos de Inteligência Artificial, hoje em dia existem já vários sistemas que começam a ganhar popularidade,\
44
+ embora nenhum seja ainda tão conhecido como o ChatGPT da OpenAI."
45
+
46
+ classifier = pipeline("text-classification", model="nicholasKluge/TeenyTinyLlama-162m-AgNews")
47
+ classifier(text)
48
+
49
+ # >>>
50
+ ```
51
+
52
+ ## Reproducing
53
+
54
+ To reproduce the fine-tuning process, use the following code snippet:
55
+
56
+ ```python
57
+
58
+ # AgNews
59
+ !pip install transformers datasets evaluate accelerate -q
60
+
61
+ import evaluate
62
+ import numpy as np
63
+ from datasets import load_dataset, Dataset, DatasetDict
64
+ from transformers import AutoTokenizer, DataCollatorWithPadding
65
+ from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
66
+
67
+ # Load the task
68
+ dataset = load_dataset("maritaca-ai/ag_news_pt")
69
+
70
+ # Create a `ModelForSequenceClassification`
71
+ model = AutoModelForSequenceClassification.from_pretrained(
72
+ "nicholasKluge/TeenyTinyLlama-162m",
73
+ num_labels=4,
74
+ id2label={0: "MUNDO", 1: "ESPORTES", 2: "NEGÓCIOS", 3: "TECNOLOGIA"},
75
+ label2id={"MUNDO": 0, "ESPORTES": 1, "NEGÓCIOS": 2, "TECNOLOGIA": 3}
76
+ )
77
+
78
+ tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/TeenyTinyLlama-162m")
79
+
80
+ # Format the dataset
81
+ train = dataset['train'].to_pandas()
82
+ train["text"] = train["title"] + "\n\n" + train["text"]
83
+ train.label = train.label.astype(int)
84
+ train = Dataset.from_pandas(train)
85
+
86
+ test = dataset['test'].to_pandas()
87
+ test["text"] = test["title"] + "\n\n" + test["text"]
88
+ test.label = test.label.astype(int)
89
+ test = Dataset.from_pandas(test)
90
+
91
+ dataset = DatasetDict({
92
+ "train": train,
93
+ "test": test
94
+ })
95
+
96
+ # Preprocess the dataset
97
+ def preprocess_function(examples):
98
+ return tokenizer(examples["text"], truncation=True, max_length=256)
99
+
100
+ dataset_tokenized = dataset.map(preprocess_function, batched=True)
101
+
102
+ # Create a simple data collactor
103
+ data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
104
+
105
+ # Use accuracy as an evaluation metric
106
+ accuracy = evaluate.load("accuracy")
107
+
108
+ # Function to compute accuracy
109
+ def compute_metrics(eval_pred):
110
+ predictions, labels = eval_pred
111
+ predictions = np.argmax(predictions, axis=1)
112
+ return accuracy.compute(predictions=predictions, references=labels)
113
+
114
+ # Define training arguments
115
+ training_args = TrainingArguments(
116
+ output_dir="checkpoints",
117
+ learning_rate=4e-5,
118
+ per_device_train_batch_size=16,
119
+ per_device_eval_batch_size=16,
120
+ num_train_epochs=3,
121
+ weight_decay=0.01,
122
+ evaluation_strategy="epoch",
123
+ save_strategy="epoch",
124
+ load_best_model_at_end=True,
125
+ push_to_hub=True,
126
+ hub_token="your_token_here",
127
+ hub_model_id="username/model-ID",
128
+ )
129
+
130
+ # Define the Trainer
131
+ trainer = Trainer(
132
+ model=model,
133
+ args=training_args,
134
+ train_dataset=dataset_tokenized["train"],
135
+ eval_dataset=dataset_tokenized["test"],
136
+ tokenizer=tokenizer,
137
+ data_collator=data_collator,
138
+ compute_metrics=compute_metrics,
139
+ )
140
+
141
+ # Train!
142
+ trainer.train()
143
+
144
+ ```
145
+
146
+ ## Fine-Tuning Comparisons
147
+
148
+ | Models | [AgNews](https://huggingface.co/datasets/maritaca-ai/ag_news_pt) |
149
+ |--------------------------------------------------------------------------------------------|------------------------------------------------------------------|
150
+ | [Teeny Tiny Llama 162m](https://huggingface.co/nicholasKluge/TeenyTinyLlama-162m) | 94.05 |
151
+ | [Bert-base-portuguese-cased](https://huggingface.co/neuralmind/bert-base-portuguese-cased) | 94.19 |
152
+ | [Bert-large-portuguese-cased](https://huggingface.co/neuralmind/bert-base-portuguese-cased)| xx.xx |
153
+ | [Gpt2-small-portuguese](https://huggingface.co/pierreguillou/gpt2-small-portuguese) | 94.07 |
154
+
155
+ ## Cite as 🤗
156
+
157
+ ```latex
158
+
159
+ @misc{nicholas22llama,
160
+ doi = {10.5281/zenodo.6989727},
161
+ url = {https://huggingface.co/nicholasKluge/TeenyTinyLlama-162m},
162
+ author = {Nicholas Kluge Corrêa},
163
+ title = {TeenyTinyLlama},
164
+ year = {2023},
165
+ publisher = {HuggingFace},
166
+ journal = {HuggingFace repository},
167
+ }
168
+
169
+ ```
170
+
171
+ ## Funding
172
+
173
+ This repository was built as part of the RAIES ([Rede de Inteligência Artificial Ética e Segura](https://www.raies.org/)) initiative, a project supported by FAPERGS - ([Fundação de Amparo à Pesquisa do Estado do Rio Grande do Sul](https://fapergs.rs.gov.br/inicial)), Brazil.
174
+
175
+ ## License
176
+
177
+ TeenyTinyLlama-162m-AgNews is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for more details.