training¶
topic_segmentation.training
Fine-tune, evaluate, and predict topic segmentation with the Hugging Face Trainer.
python -m topic_segmentation.training --model_name_or_path MODEL --dataset_name news --output_dir OUT \
--do_train True --do_eval True --do_predict True ...
scripts/run_news_finetuning.py, run_mind_adaptation.py, and run_clinical_transfer.py build the full commands.
ModelArguments
dataclass
¶
Initial checkpoint and training objectives.
Source code in src/topic_segmentation/training.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
model_name_or_path: str = field(metadata={'help': 'Initial checkpoint'})
class-attribute
instance-attribute
¶
do_da_ts: bool = field(default=False, metadata={'help': 'Also train topic segmentation on the augmented view'})
class-attribute
instance-attribute
¶
do_tssp: bool = field(default=False, metadata={'help': 'Encode the augmented view for TSSP'})
class-attribute
instance-attribute
¶
ts_loss_weight: float = field(default=1.0, metadata={'help': 'Topic segmentation loss weight'})
class-attribute
instance-attribute
¶
cl_loss_weight: float = field(default=0.0, metadata={'help': 'CSSL loss weight; 0 disables CSSL'})
class-attribute
instance-attribute
¶
cl_temp: float = field(default=1, metadata={'help': 'CSSL cosine-similarity temperature'})
class-attribute
instance-attribute
¶
cl_positive_k: int = field(default=1, metadata={'help': 'CSSL positives per anchor from the same topic'})
class-attribute
instance-attribute
¶
cl_negative_k: int = field(default=1, metadata={'help': 'CSSL negatives per anchor from the following topics'})
class-attribute
instance-attribute
¶
tssp_loss_weight: float = field(default=0.0, metadata={'help': 'TSSP loss weight'})
class-attribute
instance-attribute
¶
DataTrainingArguments
dataclass
¶
Dataset, windowing, and evaluation schedule.
Source code in src/topic_segmentation/training.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
dataset_name: str = field(metadata={'help': 'Selects data/<name> and names the prediction files'})
class-attribute
instance-attribute
¶
data_dir: Optional[str] = field(default=None, metadata={'help': 'Directory with train/val/test JSONL splits'})
class-attribute
instance-attribute
¶
train_file: Optional[str] = field(default=None, metadata={'help': 'Training JSONL instead of data_dir'})
class-attribute
instance-attribute
¶
validation_file: Optional[str] = field(default=None, metadata={'help': 'Validation JSONL instead of data_dir'})
class-attribute
instance-attribute
¶
test_file: Optional[str] = field(default=None, metadata={'help': 'Test JSONL instead of data_dir'})
class-attribute
instance-attribute
¶
test_data_name: Optional[str] = field(default=None, metadata={'help': 'Test-set name in prediction files'})
class-attribute
instance-attribute
¶
dataset_cache_dir: Optional[str] = field(default='./cache', metadata={'help': 'Dataset and tokenization cache'})
class-attribute
instance-attribute
¶
preprocessing_num_workers: Optional[int] = field(default=None, metadata={'help': 'Tokenization processes'})
class-attribute
instance-attribute
¶
max_seq_length: int = field(default=4096, metadata={'help': 'Tokens per window'})
class-attribute
instance-attribute
¶
eval_cnt: int = field(default=50, metadata={'help': 'Evaluations per training run'})
class-attribute
instance-attribute
¶
configure_logging(args)
¶
Configure stdout logging at the current process log level.
Source code in src/topic_segmentation/training.py
70 71 72 73 74 75 76 77 78 79 80 | |
load_model(model_args, max_length)
¶
Load the tokenizer and model, then configure the objectives and boundary tokens.
Source code in src/topic_segmentation/training.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
make_windows(data_args, args, tokenizer)
¶
Return windows for the requested splits and test documents when predicting.
Source code in src/topic_segmentation/training.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
build_trainer(model, tokenizer, args, windows, evaluations)
¶
Build a Trainer with boundary F1 for evaluation.
Step-based evaluation and saving use max(total_steps // evaluations, 40) steps.
Source code in src/topic_segmentation/training.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
train(trainer, windows)
¶
Source code in src/topic_segmentation/training.py
150 151 152 153 154 | |
evaluate(trainer, windows)
¶
Source code in src/topic_segmentation/training.py
157 158 | |
report(trainer, name, metrics)
¶
Source code in src/topic_segmentation/training.py
161 162 163 | |
predict(trainer, documents, windows, data_args)
¶
Save document predictions and return their scores on the main process.
Write predict_<test>_max_seq<length>_ts_score_lt.txt; other ranks return None.
Source code in src/topic_segmentation/training.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
record(model_args, data_args, args, scores)
¶
Append run settings and test scores to results.jsonl beside the run directory.
Source code in src/topic_segmentation/training.py
199 200 201 202 203 204 205 | |
main()
¶
Source code in src/topic_segmentation/training.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |