{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "aa7a358a", "metadata": {}, "outputs": [], "source": [ "from transformers import CamembertTokenizer, CamembertForMaskedLM" ] }, { "cell_type": "code", "execution_count": 2, "id": "c7e39f7f", "metadata": {}, "outputs": [], "source": [ "tokenizer = CamembertTokenizer.from_pretrained(\"camembert-base\")\n", "model = CamembertForMaskedLM.from_pretrained(\"camembert-base\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "30ca41f5", "metadata": {}, "outputs": [], "source": [ "model.save_pretrained(\"./\")" ] }, { "cell_type": "code", "execution_count": 1, "id": "fff6346c", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import notebook_login" ] }, { "cell_type": "code", "execution_count": 2, "id": "3b8b1722", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Login successful\n", "Your token has been saved to C:\\Users\\1seba/.huggingface/token\n", "\u001b[1m\u001b[31mAuthenticated through git-credential store but this isn't the helper defined on your machine.\n", "You might have to re-authenticate when pushing to the Hugging Face Hub. Run the following command in your terminal in case you want to set this credential helper as the default\n", "\n", "git config --global credential.helper store\u001b[0m\n" ] } ], "source": [ "notebook_login()" ] }, { "cell_type": "code", "execution_count": 4, "id": "e50eaa96", "metadata": {}, "outputs": [], "source": [ "from transformers import TrainingArguments" ] }, { "cell_type": "code", "execution_count": 5, "id": "abdb0496", "metadata": {}, "outputs": [], "source": [ "# training_args = TrainingArguments(\n", "# \"bert-finetuned-mrpc\", save_strategy=\"epoch\", push_to_hub=True, hub_model_id=\"SebastianS/dummy\"\n", "# )" ] }, { "cell_type": "code", "execution_count": 6, "id": "33d7f045", "metadata": {}, "outputs": [], "source": [ "from transformers import AutoModelForMaskedLM, AutoTokenizer\n", "checkpoint = \"camembert-base\"\n", "model = AutoModelForMaskedLM.from_pretrained(checkpoint)\n", "tokenizer = AutoTokenizer.from_pretrained(checkpoint)" ] }, { "cell_type": "code", "execution_count": 7, "id": "7ce0651f", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Anaconda\\envs\\AI\\lib\\site-packages\\huggingface_hub\\hf_api.py:723: FutureWarning: `create_repo` now takes `token` as an optional positional argument. Be sure to adapt your code!\n", " warnings.warn(\n", "Cloning https://huggingface.co/SebastianS/dummy-model into local empty directory.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2dc66be4581641e2992f3fd5821d4147", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Upload file pytorch_model.bin: 0%| | 32.0k/422M [00:00 main\n", "\n" ] } ], "source": [ "model.push_to_hub(\"dummy-model\", token=\"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\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "ed8312cb", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import (\n", " # User management\n", " login,\n", " logout,\n", " whoami,\n", "\n", " # Repository creation and management\n", " create_repo,\n", " delete_repo,\n", " update_repo_visibility,\n", "\n", " # And some methods to retrieve/change information about the content\n", " list_models,\n", " list_datasets,\n", " list_metrics,\n", " list_repo_files,\n", " upload_file,\n", " delete_file,\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "71af81a5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://huggingface.co/SebastianS/dummy-model'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "create_repo(\"dummy-model\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "1d5fd185", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://huggingface.co/SebastianS/dummy-model/blob/main/ch3.ipynb'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "upload_file(\"./ch3.ipynb\", path_in_repo=\"ch3.ipynb\", repo_id=\"SebastianS/dummy-model\")\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "02a3cc53", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import Repository" ] }, { "cell_type": "code", "execution_count": 2, "id": "5122830e", "metadata": {}, "outputs": [], "source": [ "repo = Repository(\"../sharing\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "06ef92c9", "metadata": {}, "outputs": [], "source": [ "repo.git_pull()" ] }, { "cell_type": "code", "execution_count": 4, "id": "3442a913", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "To https://huggingface.co/SebastianS/dummy-model\n", " 91d9c6c..bc13ef6 main -> main\n", "\n" ] }, { "data": { "text/plain": [ "'https://huggingface.co/SebastianS/dummy-model/commit/bc13ef64436e852b999af0315b661eebf6fd6a42'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "repo.git_add()\n", "repo.git_commit(\"added this file\")\n", "repo.git_push()" ] }, { "cell_type": "code", "execution_count": null, "id": "f036dfdd", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "AI", "language": "python", "name": "ai" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }