|  | 
| 189 | 189 |    ] | 
| 190 | 190 |   }, | 
| 191 | 191 |   { | 
| 192 |  | -   "metadata": {}, | 
| 193 | 192 |    "cell_type": "markdown", | 
| 194 |  | -   "source": "## Initializing TMaRCo", | 
| 195 |  | -   "id": "1eb7719e30054304" | 
|  | 193 | +   "id": "1eb7719e30054304", | 
|  | 194 | +   "metadata": {}, | 
|  | 195 | +   "source": [ | 
|  | 196 | +    "## Initializing TMaRCo" | 
|  | 197 | +   ] | 
| 196 | 198 |   }, | 
| 197 | 199 |   { | 
| 198 | 200 |    "cell_type": "code", | 
|  | 
| 205 | 207 |    ] | 
| 206 | 208 |   }, | 
| 207 | 209 |   { | 
| 208 |  | -   "metadata": {}, | 
| 209 | 210 |    "cell_type": "markdown", | 
|  | 211 | +   "id": "3e16ee305f4983d9", | 
|  | 212 | +   "metadata": {}, | 
| 210 | 213 |    "source": [ | 
| 211 | 214 |     "This will initialize `TMaRCo` using the default models, taken from HuggingFace.\n", | 
| 212 | 215 |     "<div class=\"alert alert-info\">\n", | 
| 213 |  | -    "To use local models with TMaRCo, we need to have them in a local storage, accessible to TMaRCo, initialize separately, and pass them to TMaRCo's constructor.\n", | 
|  | 216 | +    "To use local models with TMaRCo, we need to have the pre-initialized models in a local storage that is accessible to TMaRCo.\n", | 
| 214 | 217 |     "</div>\n", | 
| 215 | 218 |     "For instance, to use the default `facebook/bart-large` model, but locally. First, we would need to retrieve the model:" | 
| 216 |  | -   ], | 
| 217 |  | -   "id": "3e16ee305f4983d9" | 
|  | 219 | +   ] | 
| 218 | 220 |   }, | 
| 219 | 221 |   { | 
| 220 |  | -   "metadata": {}, | 
| 221 | 222 |    "cell_type": "code", | 
| 222 |  | -   "outputs": [], | 
| 223 | 223 |    "execution_count": null, | 
|  | 224 | +   "id": "614c9ff6f46a0ea9", | 
|  | 225 | +   "metadata": {}, | 
|  | 226 | +   "outputs": [], | 
| 224 | 227 |    "source": [ | 
| 225 | 228 |     "from huggingface_hub import snapshot_download\n", | 
| 226 | 229 |     "\n", | 
| 227 | 230 |     "snapshot_download(repo_id=\"facebook/bart-large\", local_dir=\"models/bart\")" | 
| 228 |  | -   ], | 
| 229 |  | -   "id": "614c9ff6f46a0ea9" | 
|  | 231 | +   ] | 
| 230 | 232 |   }, | 
| 231 | 233 |   { | 
| 232 |  | -   "metadata": {}, | 
| 233 | 234 |    "cell_type": "markdown", | 
| 234 |  | -   "source": "We now initialize the base model and tokenizer from local files and pass them to `TMaRCo`:", | 
| 235 |  | -   "id": "95bd792e757205d6" | 
|  | 235 | +   "id": "95bd792e757205d6", | 
|  | 236 | +   "metadata": {}, | 
|  | 237 | +   "source": [ | 
|  | 238 | +    "We now initialize the base model and tokenizer from local files and pass them to `TMaRCo`:" | 
|  | 239 | +   ] | 
| 236 | 240 |   }, | 
| 237 | 241 |   { | 
| 238 |  | -   "metadata": {}, | 
| 239 | 242 |    "cell_type": "code", | 
|  | 243 | +   "execution_count": null, | 
|  | 244 | +   "id": "f0f24485822a7c3f", | 
|  | 245 | +   "metadata": {}, | 
|  | 246 | +   "outputs": [], | 
| 240 | 247 |    "source": [ | 
| 241 | 248 |     "from transformers import BartForConditionalGeneration, BartTokenizer\n", | 
| 242 | 249 |     "\n", | 
| 243 | 250 |     "tokenizer = BartTokenizer.from_pretrained(\n", | 
| 244 |  | -    "    \"models/bart\", # Or directory where the local model is stored \n", | 
|  | 251 | +    "    \"models/bart\", # Or directory where the local model is stored\n", | 
| 245 | 252 |     "    is_split_into_words=True, add_prefix_space=True\n", | 
| 246 | 253 |     ")\n", | 
| 247 | 254 |     "\n", | 
|  | 
| 255 | 262 |     "\n", | 
| 256 | 263 |     "# Initialize TMaRCo with local models\n", | 
| 257 | 264 |     "tmarco = TMaRCo(tokenizer=tokenizer, base_model=base)" | 
| 258 |  | -   ], | 
| 259 |  | -   "id": "f0f24485822a7c3f", | 
| 260 |  | -   "outputs": [], | 
| 261 |  | -   "execution_count": null | 
|  | 265 | +   ] | 
| 262 | 266 |   }, | 
| 263 | 267 |   { | 
| 264 | 268 |    "cell_type": "code", | 
|  | 
| 286 | 290 |    ] | 
| 287 | 291 |   }, | 
| 288 | 292 |   { | 
| 289 |  | -   "metadata": {}, | 
| 290 | 293 |    "cell_type": "markdown", | 
|  | 294 | +   "id": "c113208c527c342e", | 
|  | 295 | +   "metadata": {}, | 
| 291 | 296 |    "source": [ | 
| 292 | 297 |     "<div class=\"alert alert-info\">\n", | 
| 293 |  | -    "To use local expert/anti-expert models with TMaRCo, we need to have them in a local storage, accessible to TMaRCo, as previously.\n", | 
|  | 298 | +    "To use local expert/anti-expert models with TMaRCo, we need to have them in a local storage that is accessible to TMaRCo, as previously.\n", | 
|  | 299 | +    "\n", | 
| 294 | 300 |     "However, we don't need to initialize them separately, and can pass the directory directly.\n", | 
| 295 | 301 |     "</div>\n", | 
| 296 | 302 |     "If we want to use local models with `TMaRCo` (in this case the same default `gminus`/`gplus`):\n" | 
| 297 |  | -   ], | 
| 298 |  | -   "id": "c113208c527c342e" | 
|  | 303 | +   ] | 
| 299 | 304 |   }, | 
| 300 | 305 |   { | 
| 301 |  | -   "metadata": {}, | 
| 302 | 306 |    "cell_type": "code", | 
| 303 |  | -   "outputs": [], | 
| 304 | 307 |    "execution_count": null, | 
|  | 308 | +   "id": "dfa288dcb60102c", | 
|  | 309 | +   "metadata": {}, | 
|  | 310 | +   "outputs": [], | 
| 305 | 311 |    "source": [ | 
| 306 | 312 |     "snapshot_download(repo_id=\"trustyai/gminus\", local_dir=\"models/gminus\")\n", | 
| 307 | 313 |     "snapshot_download(repo_id=\"trustyai/gplus\", local_dir=\"models/gplus\")\n", | 
| 308 | 314 |     "\n", | 
| 309 | 315 |     "tmarco.load_models([\"models/gminus\", \"models/gplus\"])" | 
| 310 |  | -   ], | 
| 311 |  | -   "id": "dfa288dcb60102c" | 
|  | 316 | +   ] | 
| 312 | 317 |   }, | 
| 313 | 318 |   { | 
| 314 | 319 |    "cell_type": "code", | 
|  | 
| 450 | 455 |    ] | 
| 451 | 456 |   }, | 
| 452 | 457 |   { | 
| 453 |  | -   "metadata": {}, | 
| 454 | 458 |    "cell_type": "markdown", | 
| 455 |  | -   "source": "As noted previously, to use local models, simply pass the initialized tokenizer and base model to the constructor, and the local path as the expert/anti-expert:", | 
| 456 |  | -   "id": "b0738c324227f57" | 
|  | 459 | +   "id": "b0738c324227f57", | 
|  | 460 | +   "metadata": {}, | 
|  | 461 | +   "source": [ | 
|  | 462 | +    "As noted previously, to use local models, simply pass the initialized tokenizer and base model to the constructor, and the local path as the expert/anti-expert:" | 
|  | 463 | +   ] | 
| 457 | 464 |   }, | 
| 458 | 465 |   { | 
| 459 |  | -   "metadata": {}, | 
| 460 | 466 |    "cell_type": "code", | 
| 461 |  | -   "outputs": [], | 
| 462 | 467 |    "execution_count": null, | 
|  | 468 | +   "id": "b929e21a97ea914e", | 
|  | 469 | +   "metadata": {}, | 
|  | 470 | +   "outputs": [], | 
| 463 | 471 |    "source": [ | 
| 464 | 472 |     "tmarco = TMaRCo(tokenizer=tokenizer, base_model=base)\n", | 
| 465 | 473 |     "tmarco.load_models([\"models/gminus\", \"models/gplus\"])" | 
| 466 |  | -   ], | 
| 467 |  | -   "id": "b929e21a97ea914e" | 
|  | 474 | +   ] | 
| 468 | 475 |   }, | 
| 469 | 476 |   { | 
| 470 | 477 |    "cell_type": "markdown", | 
|  | 
0 commit comments