Instructions to use hanzceo/JOSS-dev1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hanzceo/JOSS-dev1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="hanzceo/JOSS-dev1")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("hanzceo/JOSS-dev1") model = AutoModelForSequenceClassification.from_pretrained("hanzceo/JOSS-dev1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload train.ipynb
Browse files- train.ipynb +446 -0
train.ipynb
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "6cc7d98d-23c5-4fb3-86eb-4e0665382bb1",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"\u001b[2mInstalled \u001b[1mPython 3.13.8\u001b[0m \u001b[2min 696ms\u001b[0m\u001b[0m\n",
|
| 14 |
+
" \u001b[32m+\u001b[39m \u001b[1mcpython-3.13.8-linux-x86_64-gnu\u001b[0m (python3.13)\n",
|
| 15 |
+
"\u001b[1m\u001b[33mwarning\u001b[39m\u001b[0m\u001b[1m:\u001b[0m \u001b[1m`\u001b[36m/root/.local/bin\u001b[39m` is not on your PATH. To use installed Python executables, run `\u001b[32mexport PATH=\"/root/.local/bin:$PATH\"\u001b[39m` or `\u001b[32muv python update-shell\u001b[39m`.\u001b[0m\n",
|
| 16 |
+
"Pinned `\u001b[36m.python-version\u001b[39m` to `\u001b[32m3.13\u001b[39m`\n"
|
| 17 |
+
]
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"source": [
|
| 21 |
+
"!uv python install 313\n",
|
| 22 |
+
"!uv python pin 313"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"cell_type": "code",
|
| 27 |
+
"execution_count": 2,
|
| 28 |
+
"id": "2d741065-01e2-4551-8a7e-70fecca6759e",
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"outputs": [
|
| 31 |
+
{
|
| 32 |
+
"name": "stdout",
|
| 33 |
+
"output_type": "stream",
|
| 34 |
+
"text": [
|
| 35 |
+
"Using CPython \u001b[36m3.13.8\u001b[39m\n",
|
| 36 |
+
"Creating virtual environment at: \u001b[36m.venv\u001b[39m\n",
|
| 37 |
+
"Activate with: \u001b[32msource .venv/bin/activate\u001b[39m\n",
|
| 38 |
+
"\u001b[2K\u001b[2mResolved \u001b[1m30 packages\u001b[0m \u001b[2min 63ms\u001b[0m\u001b[0m \u001b[0m\n",
|
| 39 |
+
"\u001b[2K\u001b[2mPrepared \u001b[1m30 packages\u001b[0m \u001b[2min 703ms\u001b[0m\u001b[0m \n",
|
| 40 |
+
"\u001b[2K\u001b[2mInstalled \u001b[1m30 packages\u001b[0m \u001b[2min 110ms\u001b[0m\u001b[0m \u001b[0m\n",
|
| 41 |
+
" \u001b[32m+\u001b[39m \u001b[1masttokens\u001b[0m\u001b[2m==3.0.2\u001b[0m\n",
|
| 42 |
+
" \u001b[32m+\u001b[39m \u001b[1mcomm\u001b[0m\u001b[2m==0.2.3\u001b[0m\n",
|
| 43 |
+
" \u001b[32m+\u001b[39m \u001b[1mdebugpy\u001b[0m\u001b[2m==1.8.21\u001b[0m\n",
|
| 44 |
+
" \u001b[32m+\u001b[39m \u001b[1mdecorator\u001b[0m\u001b[2m==5.3.1\u001b[0m\n",
|
| 45 |
+
" \u001b[32m+\u001b[39m \u001b[1mexecuting\u001b[0m\u001b[2m==2.2.1\u001b[0m\n",
|
| 46 |
+
" \u001b[32m+\u001b[39m \u001b[1mipykernel\u001b[0m\u001b[2m==7.3.0\u001b[0m\n",
|
| 47 |
+
" \u001b[32m+\u001b[39m \u001b[1mipython\u001b[0m\u001b[2m==9.15.0\u001b[0m\n",
|
| 48 |
+
" \u001b[32m+\u001b[39m \u001b[1mipython-pygments-lexers\u001b[0m\u001b[2m==1.1.1\u001b[0m\n",
|
| 49 |
+
" \u001b[32m+\u001b[39m \u001b[1mjedi\u001b[0m\u001b[2m==0.20.0\u001b[0m\n",
|
| 50 |
+
" \u001b[32m+\u001b[39m \u001b[1mjupyter-client\u001b[0m\u001b[2m==8.9.1\u001b[0m\n",
|
| 51 |
+
" \u001b[32m+\u001b[39m \u001b[1mjupyter-core\u001b[0m\u001b[2m==5.9.1\u001b[0m\n",
|
| 52 |
+
" \u001b[32m+\u001b[39m \u001b[1mmatplotlib-inline\u001b[0m\u001b[2m==0.2.2\u001b[0m\n",
|
| 53 |
+
" \u001b[32m+\u001b[39m \u001b[1mnest-asyncio2\u001b[0m\u001b[2m==1.7.2\u001b[0m\n",
|
| 54 |
+
" \u001b[32m+\u001b[39m \u001b[1mpackaging\u001b[0m\u001b[2m==26.2\u001b[0m\n",
|
| 55 |
+
" \u001b[32m+\u001b[39m \u001b[1mparso\u001b[0m\u001b[2m==0.8.7\u001b[0m\n",
|
| 56 |
+
" \u001b[32m+\u001b[39m \u001b[1mpexpect\u001b[0m\u001b[2m==4.9.0\u001b[0m\n",
|
| 57 |
+
" \u001b[32m+\u001b[39m \u001b[1mplatformdirs\u001b[0m\u001b[2m==4.11.0\u001b[0m\n",
|
| 58 |
+
" \u001b[32m+\u001b[39m \u001b[1mprompt-toolkit\u001b[0m\u001b[2m==3.0.53\u001b[0m\n",
|
| 59 |
+
" \u001b[32m+\u001b[39m \u001b[1mpsutil\u001b[0m\u001b[2m==7.2.2\u001b[0m\n",
|
| 60 |
+
" \u001b[32m+\u001b[39m \u001b[1mptyprocess\u001b[0m\u001b[2m==0.7.0\u001b[0m\n",
|
| 61 |
+
" \u001b[32m+\u001b[39m \u001b[1mpure-eval\u001b[0m\u001b[2m==0.2.3\u001b[0m\n",
|
| 62 |
+
" \u001b[32m+\u001b[39m \u001b[1mpygments\u001b[0m\u001b[2m==2.20.0\u001b[0m\n",
|
| 63 |
+
" \u001b[32m+\u001b[39m \u001b[1mpython-dateutil\u001b[0m\u001b[2m==2.9.0.post0\u001b[0m\n",
|
| 64 |
+
" \u001b[32m+\u001b[39m \u001b[1mpyzmq\u001b[0m\u001b[2m==27.1.0\u001b[0m\n",
|
| 65 |
+
" \u001b[32m+\u001b[39m \u001b[1msix\u001b[0m\u001b[2m==1.17.0\u001b[0m\n",
|
| 66 |
+
" \u001b[32m+\u001b[39m \u001b[1mstack-data\u001b[0m\u001b[2m==0.6.3\u001b[0m\n",
|
| 67 |
+
" \u001b[32m+\u001b[39m \u001b[1mtornado\u001b[0m\u001b[2m==6.5.7\u001b[0m\n",
|
| 68 |
+
" \u001b[32m+\u001b[39m \u001b[1mtraitlets\u001b[0m\u001b[2m==5.15.1\u001b[0m\n",
|
| 69 |
+
" \u001b[32m+\u001b[39m \u001b[1mtyping-extensions\u001b[0m\u001b[2m==4.16.0\u001b[0m\n",
|
| 70 |
+
" \u001b[32m+\u001b[39m \u001b[1mwcwidth\u001b[0m\u001b[2m==0.8.2\u001b[0m\n",
|
| 71 |
+
"Installed kernelspec uv-kernel in /root/.local/share/jupyter/kernels/uv-kernel\n"
|
| 72 |
+
]
|
| 73 |
+
}
|
| 74 |
+
],
|
| 75 |
+
"source": [
|
| 76 |
+
"!uv venv --clear\n",
|
| 77 |
+
"!uv pip install ipykernel\n",
|
| 78 |
+
"!uv run python -m ipykernel install --user --name=uv-kernel --display-name \"Python (uv venv)\""
|
| 79 |
+
]
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"cell_type": "code",
|
| 83 |
+
"execution_count": 4,
|
| 84 |
+
"id": "ae35bf68-b4b1-435e-8a79-61bd140bc77e",
|
| 85 |
+
"metadata": {},
|
| 86 |
+
"outputs": [
|
| 87 |
+
{
|
| 88 |
+
"name": "stdout",
|
| 89 |
+
"output_type": "stream",
|
| 90 |
+
"text": [
|
| 91 |
+
"\u001b[2mAudited \u001b[1m10 packages\u001b[0m \u001b[2min 10ms\u001b[0m\u001b[0m\n"
|
| 92 |
+
]
|
| 93 |
+
}
|
| 94 |
+
],
|
| 95 |
+
"source": [
|
| 96 |
+
"!uv pip install transformers huggingface_hub datasets fastrand torch sentencepiece protobuf evaluate scikit-learn accelerate>1.1.0"
|
| 97 |
+
]
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"cell_type": "code",
|
| 101 |
+
"execution_count": 1,
|
| 102 |
+
"id": "345615b8-726e-4c9a-ab56-deb322632c82",
|
| 103 |
+
"metadata": {},
|
| 104 |
+
"outputs": [
|
| 105 |
+
{
|
| 106 |
+
"name": "stderr",
|
| 107 |
+
"output_type": "stream",
|
| 108 |
+
"text": [
|
| 109 |
+
"/workspace/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 110 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 111 |
+
]
|
| 112 |
+
}
|
| 113 |
+
],
|
| 114 |
+
"source": [
|
| 115 |
+
"import numpy as np\n",
|
| 116 |
+
"import torch\n",
|
| 117 |
+
"from datasets import load_dataset\n",
|
| 118 |
+
"from transformers import (\n",
|
| 119 |
+
" AutoTokenizer, \n",
|
| 120 |
+
" AutoModelForSequenceClassification, \n",
|
| 121 |
+
" TrainingArguments, \n",
|
| 122 |
+
" Trainer,\n",
|
| 123 |
+
" DataCollatorWithPadding\n",
|
| 124 |
+
")\n",
|
| 125 |
+
"from huggingface_hub import notebook_login\n",
|
| 126 |
+
"import evaluate"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"cell_type": "code",
|
| 131 |
+
"execution_count": 2,
|
| 132 |
+
"id": "033f1b47-2771-48ff-b89f-fcc3d93ab47d",
|
| 133 |
+
"metadata": {},
|
| 134 |
+
"outputs": [],
|
| 135 |
+
"source": [
|
| 136 |
+
"notebook_login()"
|
| 137 |
+
]
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"cell_type": "code",
|
| 141 |
+
"execution_count": 3,
|
| 142 |
+
"id": "f0ff7440-f91c-4705-9d32-d37ac1089239",
|
| 143 |
+
"metadata": {},
|
| 144 |
+
"outputs": [
|
| 145 |
+
{
|
| 146 |
+
"name": "stderr",
|
| 147 |
+
"output_type": "stream",
|
| 148 |
+
"text": [
|
| 149 |
+
"[transformers] `torch_dtype` is deprecated! Use `dtype` instead!\n",
|
| 150 |
+
"Loading weights: 100%|ββββββββββ| 172/172 [00:00<00:00, 1366.64it/s]\n",
|
| 151 |
+
"[transformers] \u001b[1mModernBertForSequenceClassification LOAD REPORT\u001b[0m from: jhu-clsp/ettin-encoder-1b\n",
|
| 152 |
+
"Key | Status | \n",
|
| 153 |
+
"------------------+------------+-\n",
|
| 154 |
+
"decoder.bias | UNEXPECTED | \n",
|
| 155 |
+
"decoder.weight | UNEXPECTED | \n",
|
| 156 |
+
"classifier.weight | MISSING | \n",
|
| 157 |
+
"classifier.bias | MISSING | \n",
|
| 158 |
+
"\n",
|
| 159 |
+
"Notes:\n",
|
| 160 |
+
"- UNEXPECTED:\tcan be ignored when loading from different task/architecture; not ok if you expect identical arch.\n",
|
| 161 |
+
"- MISSING:\tthose params were newly initialized because missing from the checkpoint. Consider training on your downstream task.\n"
|
| 162 |
+
]
|
| 163 |
+
}
|
| 164 |
+
],
|
| 165 |
+
"source": [
|
| 166 |
+
"# 1. Load tokenizer and model for classification\n",
|
| 167 |
+
"model_name = \"jhu-clsp/ettin-encoder-1b\"\n",
|
| 168 |
+
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
|
| 169 |
+
"model = AutoModelForSequenceClassification.from_pretrained(\n",
|
| 170 |
+
" model_name, num_labels=2,\n",
|
| 171 |
+
" torch_dtype=torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16\n",
|
| 172 |
+
") # Adjust num_labels"
|
| 173 |
+
]
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"cell_type": "code",
|
| 177 |
+
"execution_count": 4,
|
| 178 |
+
"id": "46b5f750-1b36-4437-b7cb-26331d92c595",
|
| 179 |
+
"metadata": {},
|
| 180 |
+
"outputs": [],
|
| 181 |
+
"source": [
|
| 182 |
+
"# 2. Load and tokenize dataset (example using IMDb for binary classification)\n",
|
| 183 |
+
"dataset = load_dataset(\"hanzceo/JOSS-data-L2\")[\"train\"]"
|
| 184 |
+
]
|
| 185 |
+
},
|
| 186 |
+
{
|
| 187 |
+
"cell_type": "code",
|
| 188 |
+
"execution_count": 5,
|
| 189 |
+
"id": "37f80b16-499f-4002-93c5-a534c4f7b289",
|
| 190 |
+
"metadata": {},
|
| 191 |
+
"outputs": [],
|
| 192 |
+
"source": [
|
| 193 |
+
"dataset = dataset.train_test_split(test_size=0.2)"
|
| 194 |
+
]
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"cell_type": "code",
|
| 198 |
+
"execution_count": 6,
|
| 199 |
+
"id": "4a8f8b10-e197-4d58-a818-2f5e8ba77d0e",
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"outputs": [
|
| 202 |
+
{
|
| 203 |
+
"data": {
|
| 204 |
+
"text/plain": [
|
| 205 |
+
"DatasetDict({\n",
|
| 206 |
+
" train: Dataset({\n",
|
| 207 |
+
" features: ['sentence1', 'score'],\n",
|
| 208 |
+
" num_rows: 1600\n",
|
| 209 |
+
" })\n",
|
| 210 |
+
" test: Dataset({\n",
|
| 211 |
+
" features: ['sentence1', 'score'],\n",
|
| 212 |
+
" num_rows: 400\n",
|
| 213 |
+
" })\n",
|
| 214 |
+
"})"
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
"execution_count": 6,
|
| 218 |
+
"metadata": {},
|
| 219 |
+
"output_type": "execute_result"
|
| 220 |
+
}
|
| 221 |
+
],
|
| 222 |
+
"source": [
|
| 223 |
+
"dataset"
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": 7,
|
| 229 |
+
"id": "fa7253f7-05a7-40a4-9727-d107adac325e",
|
| 230 |
+
"metadata": {},
|
| 231 |
+
"outputs": [
|
| 232 |
+
{
|
| 233 |
+
"name": "stderr",
|
| 234 |
+
"output_type": "stream",
|
| 235 |
+
"text": [
|
| 236 |
+
"Map: 100%|ββββββββββ| 1600/1600 [00:01<00:00, 1399.51 examples/s]\n",
|
| 237 |
+
"Map: 100%|ββββββββββ| 400/400 [00:00<00:00, 1632.19 examples/s]\n"
|
| 238 |
+
]
|
| 239 |
+
}
|
| 240 |
+
],
|
| 241 |
+
"source": [
|
| 242 |
+
"def tokenize_function(examples):\n",
|
| 243 |
+
" return tokenizer(examples[\"sentence1\"], truncation=True)\n",
|
| 244 |
+
"tokenized_datasets = dataset.map(tokenize_function, batched=True)\n",
|
| 245 |
+
"data_collator = DataCollatorWithPadding(tokenizer=tokenizer)"
|
| 246 |
+
]
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
"cell_type": "code",
|
| 250 |
+
"execution_count": 8,
|
| 251 |
+
"id": "49744185-47ff-460a-9a1b-90f33f2bc991",
|
| 252 |
+
"metadata": {},
|
| 253 |
+
"outputs": [
|
| 254 |
+
{
|
| 255 |
+
"data": {
|
| 256 |
+
"text/plain": [
|
| 257 |
+
"DatasetDict({\n",
|
| 258 |
+
" train: Dataset({\n",
|
| 259 |
+
" features: ['sentence1', 'labels', 'input_ids', 'attention_mask'],\n",
|
| 260 |
+
" num_rows: 1600\n",
|
| 261 |
+
" })\n",
|
| 262 |
+
" test: Dataset({\n",
|
| 263 |
+
" features: ['sentence1', 'labels', 'input_ids', 'attention_mask'],\n",
|
| 264 |
+
" num_rows: 400\n",
|
| 265 |
+
" })\n",
|
| 266 |
+
"})"
|
| 267 |
+
]
|
| 268 |
+
},
|
| 269 |
+
"execution_count": 8,
|
| 270 |
+
"metadata": {},
|
| 271 |
+
"output_type": "execute_result"
|
| 272 |
+
}
|
| 273 |
+
],
|
| 274 |
+
"source": [
|
| 275 |
+
"tokenized_datasets = tokenized_datasets.rename_column(\"score\", \"labels\")\n",
|
| 276 |
+
"\n",
|
| 277 |
+
"tokenized_datasets"
|
| 278 |
+
]
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"cell_type": "code",
|
| 282 |
+
"execution_count": 9,
|
| 283 |
+
"id": "93531513-4e7f-4d16-8292-8cecb44e0aa3",
|
| 284 |
+
"metadata": {},
|
| 285 |
+
"outputs": [],
|
| 286 |
+
"source": [
|
| 287 |
+
"# 3. Setup evaluation metrics\n",
|
| 288 |
+
"metric = evaluate.load(\"accuracy\")\n",
|
| 289 |
+
"def compute_metrics(eval_pred):\n",
|
| 290 |
+
" logits, labels = eval_pred\n",
|
| 291 |
+
" predictions = np.argmax(logits, axis=-1)\n",
|
| 292 |
+
" return metric.compute(predictions=predictions, references=labels)"
|
| 293 |
+
]
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"cell_type": "code",
|
| 297 |
+
"execution_count": 10,
|
| 298 |
+
"id": "b663bbee-15cb-44a9-9393-a78cf051c0fc",
|
| 299 |
+
"metadata": {},
|
| 300 |
+
"outputs": [],
|
| 301 |
+
"source": [
|
| 302 |
+
"# 4. Define Training Arguments\n",
|
| 303 |
+
"training_args = TrainingArguments(\n",
|
| 304 |
+
" output_dir=\"models/ettin-classification\",\n",
|
| 305 |
+
" eval_strategy=\"epoch\",\n",
|
| 306 |
+
" learning_rate=2e-5,\n",
|
| 307 |
+
" per_device_train_batch_size=2,\n",
|
| 308 |
+
" per_device_eval_batch_size=2,\n",
|
| 309 |
+
" num_train_epochs=3,\n",
|
| 310 |
+
" weight_decay=0.01,\n",
|
| 311 |
+
" bf16=True\n",
|
| 312 |
+
")"
|
| 313 |
+
]
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"cell_type": "code",
|
| 317 |
+
"execution_count": null,
|
| 318 |
+
"id": "685b3f75-3a68-4965-bf28-ba3e70b97618",
|
| 319 |
+
"metadata": {},
|
| 320 |
+
"outputs": [
|
| 321 |
+
{
|
| 322 |
+
"data": {
|
| 323 |
+
"text/html": [
|
| 324 |
+
"\n",
|
| 325 |
+
" <div>\n",
|
| 326 |
+
" \n",
|
| 327 |
+
" <progress value='2401' max='2400' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
|
| 328 |
+
" [2400/2400 17:50, Epoch 3/3]\n",
|
| 329 |
+
" </div>\n",
|
| 330 |
+
" <table border=\"1\" class=\"dataframe\">\n",
|
| 331 |
+
" <thead>\n",
|
| 332 |
+
" <tr style=\"text-align: left;\">\n",
|
| 333 |
+
" <th>Epoch</th>\n",
|
| 334 |
+
" <th>Training Loss</th>\n",
|
| 335 |
+
" <th>Validation Loss</th>\n",
|
| 336 |
+
" <th>Accuracy</th>\n",
|
| 337 |
+
" </tr>\n",
|
| 338 |
+
" </thead>\n",
|
| 339 |
+
" <tbody>\n",
|
| 340 |
+
" <tr>\n",
|
| 341 |
+
" <td>1</td>\n",
|
| 342 |
+
" <td>0.423433</td>\n",
|
| 343 |
+
" <td>0.226460</td>\n",
|
| 344 |
+
" <td>0.947500</td>\n",
|
| 345 |
+
" </tr>\n",
|
| 346 |
+
" <tr>\n",
|
| 347 |
+
" <td>2</td>\n",
|
| 348 |
+
" <td>0.217008</td>\n",
|
| 349 |
+
" <td>0.211006</td>\n",
|
| 350 |
+
" <td>0.947500</td>\n",
|
| 351 |
+
" </tr>\n",
|
| 352 |
+
" </tbody>\n",
|
| 353 |
+
"</table><p>\n",
|
| 354 |
+
" <div>\n",
|
| 355 |
+
" \n",
|
| 356 |
+
" <progress value='119' max='200' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
|
| 357 |
+
" [119/200 00:14 < 00:09, 8.22 it/s]\n",
|
| 358 |
+
" </div>\n",
|
| 359 |
+
" "
|
| 360 |
+
],
|
| 361 |
+
"text/plain": [
|
| 362 |
+
"<IPython.core.display.HTML object>"
|
| 363 |
+
]
|
| 364 |
+
},
|
| 365 |
+
"metadata": {},
|
| 366 |
+
"output_type": "display_data"
|
| 367 |
+
},
|
| 368 |
+
{
|
| 369 |
+
"name": "stderr",
|
| 370 |
+
"output_type": "stream",
|
| 371 |
+
"text": [
|
| 372 |
+
"Writing model shards: 100%|ββββββββββ| 1/1 [00:00<00:00, 1.30it/s]\n",
|
| 373 |
+
"Writing model shards: 100%|ββββββββββ| 1/1 [00:00<00:00, 1.85it/s]\n",
|
| 374 |
+
"Writing model shards: 100%|ββββββββββ| 1/1 [00:00<00:00, 1.28it/s]\n",
|
| 375 |
+
"Writing model shards: 100%|ββββββββββ| 1/1 [00:00<00:00, 1.39it/s]\n",
|
| 376 |
+
"Writing model shards: 100%|ββββββββββ| 1/1 [00:00<00:00, 1.28it/s]\n"
|
| 377 |
+
]
|
| 378 |
+
}
|
| 379 |
+
],
|
| 380 |
+
"source": [
|
| 381 |
+
"# 5. Train\n",
|
| 382 |
+
"trainer = Trainer(\n",
|
| 383 |
+
" model=model,\n",
|
| 384 |
+
" args=training_args,\n",
|
| 385 |
+
" data_collator=data_collator,\n",
|
| 386 |
+
" train_dataset=tokenized_datasets[\"train\"].shuffle(seed=42),\n",
|
| 387 |
+
" eval_dataset=tokenized_datasets[\"test\"].shuffle(seed=42),\n",
|
| 388 |
+
" compute_metrics=compute_metrics,\n",
|
| 389 |
+
")\n",
|
| 390 |
+
"\n",
|
| 391 |
+
"trainer.train()"
|
| 392 |
+
]
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"cell_type": "code",
|
| 396 |
+
"execution_count": null,
|
| 397 |
+
"id": "250248f5-021e-4247-8b2d-1d1098cf8a31",
|
| 398 |
+
"metadata": {},
|
| 399 |
+
"outputs": [],
|
| 400 |
+
"source": [
|
| 401 |
+
"model"
|
| 402 |
+
]
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"cell_type": "code",
|
| 406 |
+
"execution_count": null,
|
| 407 |
+
"id": "91374ca9-04ca-4ab7-a136-a5b329071426",
|
| 408 |
+
"metadata": {},
|
| 409 |
+
"outputs": [],
|
| 410 |
+
"source": [
|
| 411 |
+
"model.push_to_hub(\"hanzceo/JOSS-dev1\")"
|
| 412 |
+
]
|
| 413 |
+
},
|
| 414 |
+
{
|
| 415 |
+
"cell_type": "code",
|
| 416 |
+
"execution_count": null,
|
| 417 |
+
"id": "ed10d1ca-ada0-43db-ac78-357a865d2b4a",
|
| 418 |
+
"metadata": {},
|
| 419 |
+
"outputs": [],
|
| 420 |
+
"source": [
|
| 421 |
+
"tokenizer.push_to_hub(\"hanzceo/JOSS-dev1\")"
|
| 422 |
+
]
|
| 423 |
+
}
|
| 424 |
+
],
|
| 425 |
+
"metadata": {
|
| 426 |
+
"kernelspec": {
|
| 427 |
+
"display_name": "Python (uv venv)",
|
| 428 |
+
"language": "python",
|
| 429 |
+
"name": "uv-kernel"
|
| 430 |
+
},
|
| 431 |
+
"language_info": {
|
| 432 |
+
"codemirror_mode": {
|
| 433 |
+
"name": "ipython",
|
| 434 |
+
"version": 3
|
| 435 |
+
},
|
| 436 |
+
"file_extension": ".py",
|
| 437 |
+
"mimetype": "text/x-python",
|
| 438 |
+
"name": "python",
|
| 439 |
+
"nbconvert_exporter": "python",
|
| 440 |
+
"pygments_lexer": "ipython3",
|
| 441 |
+
"version": "3.13.8"
|
| 442 |
+
}
|
| 443 |
+
},
|
| 444 |
+
"nbformat": 4,
|
| 445 |
+
"nbformat_minor": 5
|
| 446 |
+
}
|