"
],
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [55/55 05:56, Epoch 5/5]\n",
"
\n",
" \n",
" \n",
" \n",
" Epoch | \n",
" Training Loss | \n",
" Validation Loss | \n",
"
\n",
" \n",
" \n",
" \n",
" 1 | \n",
" No log | \n",
" 21.553352 | \n",
"
\n",
" \n",
" 2 | \n",
" No log | \n",
" 18.918873 | \n",
"
\n",
" \n",
" 3 | \n",
" No log | \n",
" 17.439026 | \n",
"
\n",
" \n",
" 4 | \n",
" No log | \n",
" 16.559143 | \n",
"
\n",
" \n",
" 5 | \n",
" No log | \n",
" 16.236048 | \n",
"
\n",
" \n",
"
"
]
},
"metadata": {}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"TrainOutput(global_step=55, training_loss=20.093738902698863, metrics={'train_runtime': 358.3321, 'train_samples_per_second': 1.158, 'train_steps_per_second': 0.153, 'total_flos': 284174301265920.0, 'train_loss': 20.093738902698863, 'epoch': 5.0})"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "markdown",
"source": [
"# Evaluate"
],
"metadata": {
"id": "O9FOXSXcn-NQ"
}
},
{
"cell_type": "code",
"source": [
"\n",
"# Evaluate the model on the evaluation dataset\n",
"metrics = trainer.evaluate()\n",
"\n",
"# Print the evaluation metrics\n",
"print(metrics)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 74
},
"id": "N3gC3Dpgn9_q",
"outputId": "5156ee46-ca9f-48ff-a700-8e8952576cd2"
},
"execution_count": 21,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
""
],
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [116/116 04:28]\n",
"
\n",
" "
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'eval_loss': 16.236047744750977, 'eval_runtime': 53.0288, 'eval_samples_per_second': 17.443, 'eval_steps_per_second': 2.187, 'epoch': 5.0}\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Summary Function"
],
"metadata": {
"id": "Fj1gIkoUoUsH"
}
},
{
"cell_type": "code",
"source": [
"\n",
"def summarize(text):\n",
" # Tokenize the input text and move it to the correct device\n",
" inputs = tokenizer(text, return_tensors=\"pt\", max_length=512, truncation=True).to(device)\n",
"\n",
" # Generate the summary using the fine-tuned model\n",
" summary_ids = model.generate(inputs[\"input_ids\"], max_length=128, num_beams=4, early_stopping=True)\n",
"\n",
" # Decode the generated summary back into text and return it\n",
" return tokenizer.decode(summary_ids[0], skip_special_tokens=True)"
],
"metadata": {
"id": "egbdnsPOoWgW"
},
"execution_count": 22,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Test"
],
"metadata": {
"id": "p8Cg3fuooXkk"
}
},
{
"cell_type": "code",
"source": [
"print(summarize(\n",
" \"\"\"\n",
"Person A: Hey, did you hear about the new project management software our company is planning to implement?\n",
"\n",
"Person B: Yeah, I heard a bit about it. What’s the deal with it?\n",
"\n",
"Person A: It’s called \"TaskFlow.\" The management thinks it’s going to streamline our workflow, especially with remote teams. It’s supposed to integrate all the tools we use, like Slack, Trello, and Google Drive, into one platform.\n",
"\n",
"Person B: That sounds interesting. But I’m a bit concerned about the learning curve. Is it user-friendly?\n",
"\n",
"Person A: From what I’ve seen, it looks pretty intuitive. They’re also planning to run a couple of training sessions to get everyone up to speed. The first one is next Monday.\n",
"\n",
"Person B: Okay, that helps. I guess I’ll have to attend that session. How does it compare to what we’re using now?\n",
"\n",
"Person A: It’s supposed to be much more efficient. We’ll be able to track project progress more easily and get real-time updates. Plus, it has built-in analytics to help us with performance tracking.\n",
"\n",
"Person B: That sounds promising. I just hope it doesn’t come with too many bugs at launch.\n",
"\n",
"Person A: Yeah, that’s always a concern with new software. But they’ve been testing it for a while now, so fingers crossed it goes smoothly.\n",
"\n",
"Person B: Let’s hope for the best. Thanks for the info!\n",
"\n",
"Person A: No problem. See you at the training!\n",
"\"\"\"\n",
"))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "199TVy5xoYtW",
"outputId": "386857dd-d19a-4488-8b5e-3de84b84160c"
},
"execution_count": 23,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Person B is excited about the new project management software \"TaskFlow\" that the company is planning to implement.\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"As expected, the model is very concise on the summarization but woud leave some details."
],
"metadata": {
"id": "n_wDFtFQ2rn0"
}
}
]
}