nicholasKluge
commited on
Commit
·
28c8f56
1
Parent(s):
1bb59a6
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- ruanchaves/faquad-nli
|
5 |
+
language:
|
6 |
+
- pt
|
7 |
+
metrics:
|
8 |
+
- accuracy
|
9 |
+
library_name: transformers
|
10 |
+
pipeline_tag: text-classification
|
11 |
+
tags:
|
12 |
+
- textual-entailment
|
13 |
+
---
|
14 |
+
|
15 |
+
## neuralmind/bert-base-portuguese-cased
|
16 |
+
|
17 |
+
| Epoch | Training Loss | Validation Loss | Accuracy |
|
18 |
+
|-------|----------------|------------------|----------|
|
19 |
+
| 1 | 0.123456 | 0.241125 | 0.921538 |
|
20 |
+
| 2 | 0.234567 | 0.246445 | 0.927692 |
|
21 |
+
| 3 | 0.345678 | 0.287228 | 0.930769 |
|
22 |
+
|
23 |
+
## nicholasKluge/Teeny-tiny-llama-162m-faquad
|
24 |
+
|
25 |
+
| Epoch | Training Loss | Validation Loss | Accuracy |
|
26 |
+
|-------|----------------|------------------|----------|
|
27 |
+
| 1 | 0.123456 | 0.307782 | 0.893846 |
|
28 |
+
| 2 | 0.234567 | 0.317620 | 0.883077 |
|
29 |
+
| 3 | 0.345678 | 0.340426 | 0.900000 |
|
30 |
+
|
31 |
+
## pierreguillou/gpt2-small-portuguese
|
32 |
+
|
33 |
+
| Epoch | Training Loss | Validation Loss | Accuracy |
|
34 |
+
|-------|----------------|------------------|----------|
|
35 |
+
| 1 | 0.123456 | 0.410291 | 0.820000 |
|
36 |
+
| 2 | 0.234567 | 0.424272 | 0.847692 |
|
37 |
+
| 3 | 0.345678 | 0.410154 | 0.864615 |
|
38 |
+
|
39 |
+
|
40 |
+
```python
|
41 |
+
# Faquad-nli
|
42 |
+
! pip install transformers datasets evaluate accelerate -q
|
43 |
+
|
44 |
+
import evaluate
|
45 |
+
import numpy as np
|
46 |
+
from huggingface_hub import login
|
47 |
+
from datasets import load_dataset, Dataset, DatasetDict
|
48 |
+
from transformers import AutoTokenizer, DataCollatorWithPadding
|
49 |
+
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
|
50 |
+
|
51 |
+
# Basic fine-tuning arguments
|
52 |
+
token="your_token"
|
53 |
+
task="ruanchaves/faquad-nli"
|
54 |
+
model_name="nicholasKluge/Teeny-tiny-llama-162m"
|
55 |
+
output_dir="checkpoint"
|
56 |
+
learning_rate=4e-5
|
57 |
+
per_device_train_batch_size=16
|
58 |
+
per_device_eval_batch_size=16
|
59 |
+
num_train_epochs=3
|
60 |
+
weight_decay=0.01
|
61 |
+
evaluation_strategy="epoch"
|
62 |
+
save_strategy="epoch"
|
63 |
+
hub_model_id="nicholasKluge/Teeny-tiny-llama-162m-faquad"
|
64 |
+
|
65 |
+
# Login on the hub to load and push
|
66 |
+
login(token=token)
|
67 |
+
|
68 |
+
# Load the task
|
69 |
+
dataset = load_dataset(task)
|
70 |
+
|
71 |
+
# Create a `ModelForSequenceClassification`
|
72 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
73 |
+
model_name,
|
74 |
+
num_labels=2,
|
75 |
+
id2label={0: "UNSUITABLE", 1: "SUITABLE"},
|
76 |
+
label2id={"UNSUITABLE": 0, "SUITABLE": 1}
|
77 |
+
)
|
78 |
+
|
79 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
80 |
+
|
81 |
+
# If model does not have a pad_token, we need to add it
|
82 |
+
#tokenizer.pad_token = tokenizer._eos_token
|
83 |
+
#model.config.pad_token_id = model.config.eos_token_id
|
84 |
+
|
85 |
+
# Preprocess if needed
|
86 |
+
train = dataset['train'].to_pandas()
|
87 |
+
train['text'] = train['question'] + tokenizer.bos_token + train['answer'] + tokenizer.eos_token
|
88 |
+
train = train[['text', 'label']]
|
89 |
+
train.labels = train.label.astype(int)
|
90 |
+
train = Dataset.from_pandas(train)
|
91 |
+
|
92 |
+
test = dataset['test'].to_pandas()
|
93 |
+
test['text'] = test['question'] + tokenizer.bos_token + test['answer'] + tokenizer.eos_token
|
94 |
+
test = test[['text', 'label']]
|
95 |
+
test.labels = test.label.astype(int)
|
96 |
+
test = Dataset.from_pandas(test)
|
97 |
+
|
98 |
+
dataset = DatasetDict({
|
99 |
+
"train": train,
|
100 |
+
"test": test
|
101 |
+
})
|
102 |
+
|
103 |
+
# Pre process the dataset
|
104 |
+
def preprocess_function(examples):
|
105 |
+
return tokenizer(examples["text"], truncation=True)
|
106 |
+
|
107 |
+
dataset_tokenized = dataset.map(preprocess_function, batched=True)
|
108 |
+
|
109 |
+
# Create a simple data collactor
|
110 |
+
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
|
111 |
+
|
112 |
+
# Use accuracy as evaluation metric
|
113 |
+
accuracy = evaluate.load("accuracy")
|
114 |
+
|
115 |
+
# Function to compute accuracy
|
116 |
+
def compute_metrics(eval_pred):
|
117 |
+
predictions, labels = eval_pred
|
118 |
+
predictions = np.argmax(predictions, axis=1)
|
119 |
+
return accuracy.compute(predictions=predictions, references=labels)
|
120 |
+
|
121 |
+
# Define training arguments
|
122 |
+
training_args = TrainingArguments(
|
123 |
+
output_dir=output_dir,
|
124 |
+
learning_rate=learning_rate,
|
125 |
+
per_device_train_batch_size=per_device_train_batch_size,
|
126 |
+
per_device_eval_batch_size=per_device_eval_batch_size,
|
127 |
+
num_train_epochs=num_train_epochs,
|
128 |
+
weight_decay=weight_decay,
|
129 |
+
evaluation_strategy=evaluation_strategy,
|
130 |
+
save_strategy=save_strategy,
|
131 |
+
load_best_model_at_end=True,
|
132 |
+
push_to_hub=True,
|
133 |
+
hub_token=token,
|
134 |
+
hub_private_repo=True,
|
135 |
+
hub_model_id=hub_model_id,
|
136 |
+
tf32=True,
|
137 |
+
)
|
138 |
+
|
139 |
+
# Define the Trainer
|
140 |
+
trainer = Trainer(
|
141 |
+
model=model,
|
142 |
+
args=training_args,
|
143 |
+
train_dataset=dataset_tokenized["train"],
|
144 |
+
eval_dataset=dataset_tokenized["test"],
|
145 |
+
tokenizer=tokenizer,
|
146 |
+
data_collator=data_collator,
|
147 |
+
compute_metrics=compute_metrics,
|
148 |
+
)
|
149 |
+
|
150 |
+
# Train!
|
151 |
+
trainer.train()
|
152 |
+
|
153 |
+
```
|