{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:18:55.033345Z","iopub.status.busy":"2024-06-03T11:18:55.032642Z","iopub.status.idle":"2024-06-03T11:19:13.773777Z","shell.execute_reply":"2024-06-03T11:19:13.772989Z","shell.execute_reply.started":"2024-06-03T11:18:55.033313Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["2024-06-03 11:19:02.256736: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-03 11:19:02.256864: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-03 11:19:02.368948: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"]}],"source":["from transformers import (\n"," AutoModelForSeq2SeqLM,\n"," AutoTokenizer,\n"," DataCollatorForSeq2Seq,\n"," Seq2SeqTrainer,\n"," Seq2SeqTrainingArguments,\n"," pipeline,\n",")\n","\n","from datasets import load_dataset\n","\n","model_name = \"google/umt5-small\""]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:19:13.775904Z","iopub.status.busy":"2024-06-03T11:19:13.775364Z","iopub.status.idle":"2024-06-03T11:19:14.356839Z","shell.execute_reply":"2024-06-03T11:19:14.355976Z","shell.execute_reply.started":"2024-06-03T11:19:13.775878Z"},"trusted":true},"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"fdd37b65a44d42b2931bdc0db8229fa7","version_major":2,"version_minor":0},"text/plain":["Generating train split: 0 examples [00:00, ? examples/s]"]},"metadata":{},"output_type":"display_data"},{"data":{"text/plain":["DatasetDict({\n"," train: Dataset({\n"," features: ['mr', 'ref'],\n"," num_rows: 18564\n"," })\n"," test: Dataset({\n"," features: ['mr', 'ref'],\n"," num_rows: 2063\n"," })\n","})"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["dataset = load_dataset('csv', data_files='/kaggle/input/ngl-data/nlg_data.csv', split='train').train_test_split(test_size=0.1)\n","dataset"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:19:14.358052Z","iopub.status.busy":"2024-06-03T11:19:14.357803Z","iopub.status.idle":"2024-06-03T11:19:24.614600Z","shell.execute_reply":"2024-06-03T11:19:24.613696Z","shell.execute_reply.started":"2024-06-03T11:19:14.358030Z"},"trusted":true},"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"9418d01ad2124c74bcd05cc4d41b9b1d","version_major":2,"version_minor":0},"text/plain":["tokenizer_config.json: 0%| | 0.00/6.84k [00:00"]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["Run data is saved locally in /kaggle/working/wandb/run-20240603_111947-zd4tutif"],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["Syncing run /kaggle/working to Weights & Biases (docs)
"],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":[" View project at https://wandb.ai/filnow42/huggingface"],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":[" View run at https://wandb.ai/filnow42/huggingface/runs/zd4tutif"],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["\n","
\n"," \n"," \n"," [6963/6963 38:47, Epoch 3/3]\n","
\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
EpochTraining LossValidation Loss
10.7329000.331611
20.3731000.246366
30.3269000.231167

"],"text/plain":[""]},"metadata":{},"output_type":"display_data"},{"name":"stderr","output_type":"stream","text":["There were missing keys in the checkpoint model loaded: ['encoder.embed_tokens.weight', 'decoder.embed_tokens.weight'].\n"]},{"data":{"text/plain":["TrainOutput(global_step=6963, training_loss=1.0388871652717377, metrics={'train_runtime': 2359.6292, 'train_samples_per_second': 23.602, 'train_steps_per_second': 2.951, 'total_flos': 7499132383002624.0, 'train_loss': 1.0388871652717377, 'epoch': 3.0})"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["trainer.train()"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:58:53.891952Z","iopub.status.busy":"2024-06-03T11:58:53.891542Z","iopub.status.idle":"2024-06-03T11:58:53.897775Z","shell.execute_reply":"2024-06-03T11:58:53.896741Z","shell.execute_reply.started":"2024-06-03T11:58:53.891924Z"},"trusted":true},"outputs":[],"source":["nlg = pipeline('summarization', model=model, tokenizer=tokenizer)"]},{"cell_type":"code","execution_count":8,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:58:53.899234Z","iopub.status.busy":"2024-06-03T11:58:53.898928Z","iopub.status.idle":"2024-06-03T11:59:05.979970Z","shell.execute_reply":"2024-06-03T11:59:05.978805Z","shell.execute_reply.started":"2024-06-03T11:58:53.899195Z"},"trusted":true},"outputs":[{"data":{"text/plain":["'Nie mamy tatar w menu. Cena wynosi 50. Sk艂adnik to owoce.'"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: dish[tatar], price[50], ingredient[wolowina]')[0]['summary_text']"]},{"cell_type":"code","execution_count":9,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:05.981585Z","iopub.status.busy":"2024-06-03T11:59:05.981291Z","iopub.status.idle":"2024-06-03T11:59:06.533378Z","shell.execute_reply":"2024-06-03T11:59:06.532379Z","shell.execute_reply.started":"2024-06-03T11:59:05.981559Z"},"trusted":true},"outputs":[{"data":{"text/plain":["'Nie obs艂ugujemy p艂atno艣ci gotowka. Cena wynosi 150. Oczywi艣cie, dostarczymy na ulica Dluga 5.'"]},"execution_count":9,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: payment_methods[gotowka], price[150], addresses[ulica Dluga 5]')[0]['summary_text']"]},{"cell_type":"code","execution_count":10,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:06.538123Z","iopub.status.busy":"2024-06-03T11:59:06.537427Z","iopub.status.idle":"2024-06-03T11:59:06.938435Z","shell.execute_reply":"2024-06-03T11:59:06.937299Z","shell.execute_reply.started":"2024-06-03T11:59:06.538081Z"},"trusted":true},"outputs":[{"data":{"text/plain":["'Nie mamy tiramisu w menu. Sk艂adnik mleko jest dost臋pny. Nie zawiera alergenu laktoza.'"]},"execution_count":10,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: dish[tiramisu], ingredient[mleko], allergy[laktoza]')[0]['summary_text']"]},{"cell_type":"code","execution_count":11,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:06.940331Z","iopub.status.busy":"2024-06-03T11:59:06.939929Z","iopub.status.idle":"2024-06-03T11:59:07.132913Z","shell.execute_reply":"2024-06-03T11:59:07.131901Z","shell.execute_reply.started":"2024-06-03T11:59:06.940292Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["Your max_length is set to 20, but your input_length is only 10. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=5)\n"]},{"data":{"text/plain":["'Zamkni臋te o dziesiata.'"]},"execution_count":11,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: time[dziesiata]')[0]['summary_text']"]},{"cell_type":"code","execution_count":12,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:07.134671Z","iopub.status.busy":"2024-06-03T11:59:07.134067Z","iopub.status.idle":"2024-06-03T11:59:07.405347Z","shell.execute_reply":"2024-06-03T11:59:07.404117Z","shell.execute_reply.started":"2024-06-03T11:59:07.134642Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["Your max_length is set to 20, but your input_length is only 14. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=7)\n"]},{"data":{"text/plain":["'Nie mamy spaghetti w menu. Sk艂adnik ser jest dost臋pny.'"]},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: dish[spaghetti], ingredient[ser]')[0]['summary_text']"]},{"cell_type":"code","execution_count":13,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:07.410442Z","iopub.status.busy":"2024-06-03T11:59:07.407270Z","iopub.status.idle":"2024-06-03T11:59:07.697634Z","shell.execute_reply":"2024-06-03T11:59:07.695355Z","shell.execute_reply.started":"2024-06-03T11:59:07.410396Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["Your max_length is set to 20, but your input_length is only 16. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=8)\n"]},{"data":{"text/plain":["'Nie mamy pierogi w menu. Sk艂adnik to koti ser.'"]},"execution_count":13,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: dish[pierogi], ingredient[kozi ser]')[0]['summary_text']"]},{"cell_type":"code","execution_count":14,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:07.699269Z","iopub.status.busy":"2024-06-03T11:59:07.698906Z","iopub.status.idle":"2024-06-03T11:59:08.138934Z","shell.execute_reply":"2024-06-03T11:59:08.137833Z","shell.execute_reply.started":"2024-06-03T11:59:07.699233Z"},"trusted":true},"outputs":[{"data":{"text/plain":["'Zamkni臋te o 23:00. Nie dostarczamy na ulica Kr贸tka 256.'"]},"execution_count":14,"metadata":{},"output_type":"execute_result"}],"source":["nlg(f'generate text: time[23:00], adres[ul Kr贸tka 256]')[0]['summary_text']"]},{"cell_type":"code","execution_count":15,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T11:59:08.140718Z","iopub.status.busy":"2024-06-03T11:59:08.140399Z","iopub.status.idle":"2024-06-03T11:59:11.078579Z","shell.execute_reply":"2024-06-03T11:59:11.077378Z","shell.execute_reply.started":"2024-06-03T11:59:08.140689Z"},"trusted":true},"outputs":[],"source":["model.save_pretrained(\"/kaggle/working\")"]},{"cell_type":"code","execution_count":18,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T12:03:34.284674Z","iopub.status.busy":"2024-06-03T12:03:34.283930Z","iopub.status.idle":"2024-06-03T12:03:34.468881Z","shell.execute_reply":"2024-06-03T12:03:34.467812Z","shell.execute_reply.started":"2024-06-03T12:03:34.284637Z"},"trusted":true},"outputs":[],"source":["from kaggle_secrets import UserSecretsClient\n","user_secrets = UserSecretsClient()\n","secret_value_0 = user_secrets.get_secret(\"huggingface-write\")"]},{"cell_type":"code","execution_count":19,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T12:03:38.980042Z","iopub.status.busy":"2024-06-03T12:03:38.979682Z","iopub.status.idle":"2024-06-03T12:03:39.119457Z","shell.execute_reply":"2024-06-03T12:03:39.118367Z","shell.execute_reply.started":"2024-06-03T12:03:38.980011Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n","Token is valid (permission: write).\n","Your token has been saved to /root/.cache/huggingface/token\n","Login successful\n"]}],"source":["from huggingface_hub import login\n","login(secret_value_0)"]},{"cell_type":"code","execution_count":20,"metadata":{"execution":{"iopub.execute_input":"2024-06-03T12:03:45.290131Z","iopub.status.busy":"2024-06-03T12:03:45.289755Z","iopub.status.idle":"2024-06-03T12:04:24.555639Z","shell.execute_reply":"2024-06-03T12:04:24.554427Z","shell.execute_reply.started":"2024-06-03T12:03:45.290099Z"},"trusted":true},"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"bc999b688b0b4163b518f7047380dc7d","version_major":2,"version_minor":0},"text/plain":["events.out.tfevents.1717413574.743112a2decd.34.0: 0%| | 0.00/9.10k [00:00