traintest
Browse files
batch_finetune_eu_jav_base_test.sh
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
PROJECT_DIR=${HOME}"/models/eu-jav-categorisation"
|
2 |
+
export PYTHONPATH=${PROJECT_DIR}
|
3 |
+
INITIAL_CHECKPOINT_PATH=\"gs://t5-data/pretrained_models/t5x/mt5_base/checkpoint_1000000\"
|
4 |
+
TRAIN_STEPS=1002000
|
5 |
+
|
6 |
+
python3 ../../t5x/t5x/train.py --gin_search_paths="./" --gin.TRAIN_STEPS=${TRAIN_STEPS} --gin_file="finetune_classification_base_test.gin" --gin.INITIAL_CHECKPOINT_PATH=${INITIAL_CHECKPOINT_PATH} --gin.MIXTURE_OR_TASK_NAME=\"classify_tweets\" --gin.MODEL_DIR=\"gs://eu-jav-t5x/finetuned/italian_tweets/traintest_classify_tweets_base_v1\" &&
|
7 |
+
python3 ../../t5x/t5x/train.py --gin_search_paths="./" --gin.TRAIN_STEPS=${TRAIN_STEPS} --gin_file="finetune_classification_base_test.gin" --gin.INITIAL_CHECKPOINT_PATH=${INITIAL_CHECKPOINT_PATH} --gin.MIXTURE_OR_TASK_NAME=\"classify_tweets\" --gin.MODEL_DIR=\"gs://eu-jav-t5x/finetuned/italian_tweets/traintest_classify_tweets_base_2\" &&
|
8 |
+
|
finetune_classification_base.gin
CHANGED
@@ -11,7 +11,7 @@ include "t5x/examples/t5/mt5/base.gin"
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
-
TASK_FEATURE_LENGTHS = {"inputs":
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
+
TASK_FEATURE_LENGTHS = {"inputs": 256, "targets": 2}
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
finetune_classification_base_test.gin
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __gin__ import dynamic_registration
|
2 |
+
import tasks_test
|
3 |
+
|
4 |
+
import __main__ as train_script
|
5 |
+
from t5.data import mixtures
|
6 |
+
from t5x import models
|
7 |
+
from t5x import partitioning
|
8 |
+
from t5x import utils
|
9 |
+
|
10 |
+
include "t5x/examples/t5/mt5/base.gin"
|
11 |
+
include "t5x/configs/runs/finetune.gin"
|
12 |
+
|
13 |
+
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
+
TASK_FEATURE_LENGTHS = {"inputs": 256, "targets": 2}
|
15 |
+
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
+
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
+
USE_CACHED_TASKS = False
|
18 |
+
DROPOUT_RATE = 0.1
|
19 |
+
RANDOM_SEED = 0
|
20 |
+
|
21 |
+
#Fixing a small error
|
22 |
+
infer_eval/utils.DatasetConfig:
|
23 |
+
task_feature_lengths = %TASK_FEATURE_LENGTHS
|
24 |
+
|
25 |
+
#Saving every 1000 steps
|
26 |
+
utils.SaveCheckpointConfig:
|
27 |
+
period = 100
|
28 |
+
|
29 |
+
|
30 |
+
# Pere: Only necessary if we load a t5 model. We can start with an t5x model here
|
31 |
+
# `LOSS_NORMALIZING_FACTOR`: When fine-tuning a model that was pre-trained
|
32 |
+
# using Mesh Tensorflow (e.g. the public T5 / mT5 / ByT5 models), this should be
|
33 |
+
# set to `pretraining batch_size` * `target_token_length`. For T5 and T5.1.1:
|
34 |
+
# `2048 * 114`. For mT5: `1024 * 229`. For ByT5: `1024 * 189`.
|
35 |
+
# LOSS_NORMALIZING_FACTOR = 234496
|
36 |
+
|
37 |
+
# Might have to ba changed based on architecture
|
38 |
+
# partitioning.PjitPartitioner.num_partitions = 1
|
39 |
+
|
finetune_classification_large.gin
CHANGED
@@ -11,13 +11,12 @@ include "t5x/examples/t5/mt5/large.gin"
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
-
TASK_FEATURE_LENGTHS = {"inputs":
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
18 |
DROPOUT_RATE = 0.1
|
19 |
RANDOM_SEED = 0
|
20 |
-
BATCH_SIZE = 32
|
21 |
|
22 |
#Fixing a small error
|
23 |
infer_eval/utils.DatasetConfig:
|
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
+
TASK_FEATURE_LENGTHS = {"inputs": 256, "targets": 2}
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
18 |
DROPOUT_RATE = 0.1
|
19 |
RANDOM_SEED = 0
|
|
|
20 |
|
21 |
#Fixing a small error
|
22 |
infer_eval/utils.DatasetConfig:
|
finetune_classification_small.gin
CHANGED
@@ -11,7 +11,7 @@ include "t5x/examples/t5/mt5/small.gin"
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
-
TASK_FEATURE_LENGTHS = {"inputs":
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
|
|
11 |
include "t5x/configs/runs/finetune.gin"
|
12 |
|
13 |
MIXTURE_OR_TASK_NAME = %gin.REQUIRED
|
14 |
+
TASK_FEATURE_LENGTHS = {"inputs": 256, "targets": 2}
|
15 |
INITIAL_CHECKPOINT_PATH = %gin.REQUIRED
|
16 |
TRAIN_STEPS = %gin.REQUIRED # 1000000 pre-trained steps + 10000 fine-tuning steps.
|
17 |
USE_CACHED_TASKS = False
|
tasks_test.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# /home/perk/mymodel/categorisation-mt5x/tasks.py
|
2 |
+
|
3 |
+
import functools
|
4 |
+
import seqio
|
5 |
+
import tensorflow_datasets as tfds
|
6 |
+
from t5.evaluation import metrics
|
7 |
+
import my_metrics
|
8 |
+
from t5.data import preprocessors
|
9 |
+
import t5
|
10 |
+
import tensorflow.compat.v1 as tf
|
11 |
+
|
12 |
+
tsv_path = {
|
13 |
+
"train": "gs://eu-jav-t5x/corpus/labeled/datasetA_train_3categories.tsv",
|
14 |
+
"validation": "gs://eu-jav-t5x/corpus/labeled/datasetA_train_3categories.tsv",
|
15 |
+
"test": "gs://eu-jav-t5x/corpus/labeled/ datasetA_test_3categories.tsv"
|
16 |
+
}
|
17 |
+
|
18 |
+
vocabulary = seqio.SentencePieceVocabulary(
|
19 |
+
'gs://t5-data/vocabs/mc4.250000.100extra/sentencepiece.model', extra_ids=0)
|
20 |
+
|
21 |
+
DEFAULT_OUTPUT_FEATURES = {
|
22 |
+
"inputs":
|
23 |
+
seqio.Feature(
|
24 |
+
vocabulary=vocabulary, add_eos=True),
|
25 |
+
"targets":
|
26 |
+
seqio.Feature(
|
27 |
+
vocabulary=vocabulary, add_eos=True)
|
28 |
+
}
|
29 |
+
|
30 |
+
def categorise_preprocessor(ds):
|
31 |
+
def normalize_text(text):
|
32 |
+
"""Lowercase and remove quotes from a TensorFlow string."""
|
33 |
+
text = tf.strings.regex_replace(text,"'(.*)'", r"\1")
|
34 |
+
return text
|
35 |
+
|
36 |
+
def to_inputs_and_targets(ex):
|
37 |
+
"""Map {"source": ..., "source": ...}->{"target": ..., "target": ...}."""
|
38 |
+
return {
|
39 |
+
"inputs":
|
40 |
+
tf.strings.join(
|
41 |
+
[normalize_text(ex["source"])]),
|
42 |
+
"targets":
|
43 |
+
tf.strings.join(
|
44 |
+
[normalize_text(ex["target"])]),
|
45 |
+
}
|
46 |
+
return ds.map(to_inputs_and_targets,
|
47 |
+
num_parallel_calls=tf.data.experimental.AUTOTUNE)
|
48 |
+
|
49 |
+
|
50 |
+
seqio.TaskRegistry.add(
|
51 |
+
"classify_tweets",
|
52 |
+
source=seqio.TextLineDataSource(
|
53 |
+
split_to_filepattern=tsv_path,
|
54 |
+
#num_input_examples=num_nq_examples
|
55 |
+
),
|
56 |
+
preprocessors=[
|
57 |
+
functools.partial(
|
58 |
+
t5.data.preprocessors.parse_tsv,
|
59 |
+
field_names=["annotator1","annotator2","annotator3","target","source","id"]),
|
60 |
+
categorise_preprocessor,
|
61 |
+
seqio.preprocessors.tokenize_and_append_eos,
|
62 |
+
],
|
63 |
+
metric_fns=[metrics.accuracy,my_metrics.f1_macro],
|
64 |
+
output_features=DEFAULT_OUTPUT_FEATURES,
|
65 |
+
)
|
66 |
+
|
67 |
+
seqio.TaskRegistry.add(
|
68 |
+
"classify_tweets_a1",
|
69 |
+
source=seqio.TextLineDataSource(
|
70 |
+
split_to_filepattern=tsv_path,
|
71 |
+
#num_input_examples=num_nq_examples
|
72 |
+
),
|
73 |
+
preprocessors=[
|
74 |
+
functools.partial(
|
75 |
+
t5.data.preprocessors.parse_tsv,
|
76 |
+
field_names=["target","annotator2","annotator3","placeholder","source","id"]),
|
77 |
+
categorise_preprocessor,
|
78 |
+
seqio.preprocessors.tokenize_and_append_eos,
|
79 |
+
],
|
80 |
+
metric_fns=[metrics.accuracy,my_metrics.f1_macro],
|
81 |
+
output_features=DEFAULT_OUTPUT_FEATURES,
|
82 |
+
)
|
83 |
+
|
84 |
+
seqio.TaskRegistry.add(
|
85 |
+
"classify_tweets_a2",
|
86 |
+
source=seqio.TextLineDataSource(
|
87 |
+
split_to_filepattern=tsv_path,
|
88 |
+
#num_input_examples=num_nq_examples
|
89 |
+
),
|
90 |
+
preprocessors=[
|
91 |
+
functools.partial(
|
92 |
+
t5.data.preprocessors.parse_tsv,
|
93 |
+
field_names=["annotator1","target","annotator3","placeholder","source","id"]),
|
94 |
+
categorise_preprocessor,
|
95 |
+
seqio.preprocessors.tokenize_and_append_eos,
|
96 |
+
],
|
97 |
+
metric_fns=[metrics.accuracy,my_metrics.f1_macro],
|
98 |
+
output_features=DEFAULT_OUTPUT_FEATURES,
|
99 |
+
)
|
100 |
+
|
101 |
+
seqio.TaskRegistry.add(
|
102 |
+
"classify_tweets_a3",
|
103 |
+
source=seqio.TextLineDataSource(
|
104 |
+
split_to_filepattern=tsv_path,
|
105 |
+
#num_input_examples=num_nq_examples
|
106 |
+
),
|
107 |
+
preprocessors=[
|
108 |
+
functools.partial(
|
109 |
+
t5.data.preprocessors.parse_tsv,
|
110 |
+
field_names=["annotator1","annotator2","target","placeholder","source","id"]),
|
111 |
+
categorise_preprocessor,
|
112 |
+
seqio.preprocessors.tokenize_and_append_eos,
|
113 |
+
],
|
114 |
+
metric_fns=[metrics.accuracy,my_metrics.f1_macro],
|
115 |
+
output_features=DEFAULT_OUTPUT_FEATURES,
|
116 |
+
)
|