{ "cells": [ { "cell_type": "markdown", "id": "7b73f12d-1104-4eea-ac08-3716aa9af45b", "metadata": {}, "source": [ "**Zero shot classification**" ] }, { "cell_type": "code", "execution_count": 7, "id": "966c6d6a-c2d7-405c-bf9b-1e1f1415234e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"sequence\": \"I just bought a new laptop, and it works amazing!\",\n", " \"labels\": [\n", " \"technology\",\n", " \"health\",\n", " \"sports\",\n", " \"politics\"\n", " ],\n", " \"scores\": [\n", " 0.970917284488678,\n", " 0.014999152161180973,\n", " 0.008272469975054264,\n", " 0.005811101291328669\n", " ]\n", "}\n" ] } ], "source": [ "from dotenv import load_dotenv\n", "import os\n", "import requests\n", "import json\n", "\n", "load_dotenv() # Load environment variables from .env file, contains personal access token (HF_API_TOKEN=your_token)\n", "headers = {\"Authorization\": f\"Bearer {os.getenv('HF_API_TOKEN')}\"}\n", "\n", "candidate_labels = [\"technology\", \"sports\", \"politics\", \"health\"]\n", "\n", "def query(model, input_text):\n", " API_URL = f\"https://router.huggingface.co/hf-inference/models/{model}\"\n", " payload = {\n", " \"inputs\": input_text,\n", " \"parameters\": {\"candidate_labels\": candidate_labels}\n", " }\n", " response = requests.post(API_URL, headers=headers, json=payload)\n", " return response.json()\n", "\n", "input_text = \"I just bought a new laptop, and it works amazing!\"\n", "\n", "output = query(\"facebook/bart-large-mnli\", input_text)\n", "print(json.dumps(output, indent=4))" ] }, { "cell_type": "markdown", "id": "edf44387-d166-4e0f-a8ad-621230aee115", "metadata": {}, "source": [ "**Try to run a model locally**" ] }, { "cell_type": "code", "execution_count": 35, "id": "1d01a363-572b-450c-8fce-0721234f9a1a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First trip: 7-Day Island Beach Holiday in Greece (Summer). I am planning a trip to Greece with my boyfriend, where we will visit two islands. We have booked an apartment on each island for a few days and plan to spend most of our time relaxing. Our main goals are to enjoy the beach, try delicious local food, and possibly go on a hike—if it’s not too hot. We will be relying solely on public transport. We’re in our late 20s and traveling from the Netherlands. \n", "\n", "Packing list: ['bathing suit', 'beach towel', 'beach bag', 'sandals', 'comfortable walking shoes', 'light jacket', 'sunscreen', 'sunglasses', 'sunhat', 'entertainment for downtime (e.g. book/ebook, games, laptop, journal)', 'short pants/skirts', 't-shirts/tops']\n" ] } ], "source": [ "# Prerequisites\n", "from tabulate import tabulate\n", "from transformers import pipeline\n", "import json\n", "\n", "# input text\n", "input_text = \"I like to cycle and I burn easily. I also love culture and like to post on social media about my food. I will go on a trip to italy in july.\"\n", "\n", "# Load labels from a txt file\n", "with open(\"labels.txt\", \"r\", encoding=\"utf-8\") as f:\n", " class_labels = [line.strip() for line in f if line.strip()]\n", "\n", "# Load test data (in dictionary)\n", "with open(\"test_data.json\", \"r\") as file:\n", " packing_data = json.load(file)\n", "# Get a list of trip descriptions (keys)\n", "trips = list(packing_data.keys())\n", "# Access the first trip description\n", "first_trip = trips[0]\n", "# Get the packing list for the secondfirst trip\n", "first_trip_items = packing_data[first_trip]\n", "\n", "print(f\"First trip: {first_trip} \\n\")\n", "print(f\"Packing list: {first_trip_items}\")" ] }, { "cell_type": "markdown", "id": "88aa1d7e-8a32-4530-9ddd-60fa38e4a342", "metadata": {}, "source": [ "Load classifiers" ] }, { "cell_type": "code", "execution_count": 36, "id": "d0d8f7c0-c2d9-4fbe-b1a7-699a5b99466c", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Some weights of BartForSequenceClassification were not initialized from the model checkpoint at facebook/bart-base and are newly initialized: ['classification_head.dense.bias', 'classification_head.dense.weight', 'classification_head.out_proj.bias', 'classification_head.out_proj.weight']\n", "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n", "Hardware accelerator e.g. GPU is available in the environment, but no `device` argument is passed to the `Pipeline` object. Model will be on CPU.\n", "Failed to determine 'entailment' label id from the label2id mapping in the model config. Setting to -1. Define a descriptive label2id mapping in the model config to ensure correct outputs.\n" ] } ], "source": [ "# Load smaller the model and create a pipeline for zero-shot classification (1min loading + classifying with 89 labels)\n", "classifier_bart_base = pipeline(\"zero-shot-classification\", model=\"facebook/bart-base\")" ] }, { "cell_type": "code", "execution_count": 37, "id": "a971ca1c-d478-489f-9592-bc243d587eb4", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Hardware accelerator e.g. GPU is available in the environment, but no `device` argument is passed to the `Pipeline` object. Model will be on CPU.\n" ] } ], "source": [ "# Load larger the model and create a pipeline for zero-shot classification (5min loading model + classifying with 89 labels)\n", "classifier_bart_large_mnli = pipeline(\"zero-shot-classification\", model=\"facebook/bart-large-mnli\")" ] }, { "cell_type": "markdown", "id": "38805499-9919-40fe-9d42-de6869ba01dc", "metadata": {}, "source": [ "Try classifiers" ] }, { "cell_type": "code", "execution_count": 38, "id": "abb13524-71c6-448d-948d-fb22a0e0ceeb", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.\n" ] } ], "source": [ "# Run the classification (ca 30 seconds classifying)\n", "result_bart_base = classifier_bart_base(first_trip, class_labels)" ] }, { "cell_type": "code", "execution_count": 39, "id": "116c7ee3-2b59-4623-a416-162c487aab70", "metadata": {}, "outputs": [], "source": [ "# Run the classification (ca 1 minute classifying)\n", "result_bart_large_mnli = classifier_bart_large_mnli(first_trip, class_labels)" ] }, { "cell_type": "code", "execution_count": 40, "id": "8591425b-ce55-4a36-a4b6-70974e8d4e59", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| bart_base | bart_large_mnli |\n", "+======================================================================+======================================================================+\n", "| bandana | travel adapter |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| lip balm | travel journal |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| hand warmers | light jacket |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sim card | sim card |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| neck wallet | bathing suit |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| tent | multi-tool |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| poncho | dry bag |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| gloves | travel pillow |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| painkiller | base layers |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| pen | day pack |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| thin scarf | entertainment for downtime (e.g. book/ebook, games, laptop, journal) |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| wallet | passport |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sleeping bag | thin scarf |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| dry bag | comfortable shoes |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| gifts | lightweight backpack |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| fanny pack | beach bag |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| beach towel | swimsuit |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| underwear | short pants/skirts |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| swimsuit | quick-dry towel |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| blanket | sunhat |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| laptop | local currency |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| quick-dry towel | tickets |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| ski jacket | wallet |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| emergency roadside kit | cardigan/sweater |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| passport | refillable water bottle |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| necessary medication | fanny pack |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| snacks for the journey | poncho |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| snow boots | thermal clothing |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sunglasses | laptop |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| flip-flops | pen |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| phone and charger | big backpack/suitcase |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| socks | beach towel |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| local currency | currency |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| t-shirts/tops | blanket |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| bathing suit | compass |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| currency | beanie |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| cardigan/sweater | sunscreen |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| snowboard | phone and charger |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| visa documents | reusable coffee mug |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| shirts | power bank |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| headphones | personal toiletries (e.g. toothbrush, toothpaste) |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| pants | packable rain jacket |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| refillable water bottle | bandana |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| beach bag | short pants |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| big backpack/suitcase | business attire |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| multi-tool | sleeping bag |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sandals | flashlight |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| tickets | t-shirts/tops |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| thermal clothing | waterproof phone case |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| short pants/skirts | long pants |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| light jacket | travel-sized toiletries |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| base layers | visa documents |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| snacks | sandals |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| comfortable shoes | hand warmers |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| lightweight backpack | hostel lock |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| winter shoes | headphones |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| dress shoes | emergency roadside kit |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| power bank | ski jacket |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| packable rain jacket | shirts |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| first aid kit | first aid kit |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| water filter | reusable shopping bags |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| short pants | flip-flops |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| ski goggles | camping stove |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| waterproof phone case | water filter |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sunhat | gloves |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| flashlight | dress shoes |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| earplugs | tent |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| beanie | sunglasses |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| hostel lock | pants |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| personal toiletries (e.g. toothbrush, toothpaste) | charging cables |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| travel journal | snacks |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| reusable coffee mug | neck wallet |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sunscreen | snacks for the journey |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| travel pillow | ski goggles |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| trekking poles | mosquito repellant |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| business attire | snorkel gear |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| snorkel gear | bug spray |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| reusable shopping bags | earplugs |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| sleep wear | travel insurance documents |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| camping stove | painkiller |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| travel-sized toiletries | hiking boots |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| hiking boots | necessary medication |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| travel insurance documents | socks |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| long pants | underwear |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| charging cables | trekking poles |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| entertainment for downtime (e.g. book/ebook, games, laptop, journal) | sleep wear |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| bug spray | gifts |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| day pack | lip balm |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| travel adapter | snowboard |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| malaria medication | malaria medication |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| compass | snow boots |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n", "| mosquito repellant | winter shoes |\n", "+----------------------------------------------------------------------+----------------------------------------------------------------------+\n" ] } ], "source": [ "# Creating a table\n", "table = zip(result_bart_base[\"labels\"], \n", " result_bart_large_mnli[\"labels\"])\n", "headers = [\"bart_base\", \"bart_large_mnli\"]\n", "\n", "print(tabulate(table, headers=headers, tablefmt=\"grid\"))\n" ] }, { "cell_type": "markdown", "id": "21a35d0c-9451-433a-b14c-87e8dac21d68", "metadata": {}, "source": [ "**Try simple prompt engineering**" ] }, { "cell_type": "code", "execution_count": 12, "id": "ee734de6-bbcb-427d-8987-ab41286f7907", "metadata": {}, "outputs": [], "source": [ "# No prompt\n", "no_prompt = input_text\n", "no_result = classifier(no_prompt, class_labels)\n", "\n", "# Simple prompt\n", "simple_prompt = \"Classify the following text: \" + input_text\n", "simple_result = classifier(simple_prompt, class_labels)\n", "\n", "# Primed prompt\n", "primed_prompt = input_text + \"What are the most important things to pack for the trip?\"\n", "primed_result = classifier(primed_prompt, class_labels)" ] }, { "cell_type": "code", "execution_count": 13, "id": "96deb877-b3b0-4048-9960-d8b0b0d56cd0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| no_prompt | no_prompt | simple_prompt | simple_prompt | primed_prompt | primed_prompt |\n", "+============================+=============+============================+=================+============================+=================+\n", "| Travel-sized toiletries | 0.0141621 | Beanie | 0.0126489 | First aid kit | 0.0126422 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Refillable water bottle | 0.013635 | Baby wipes | 0.0125994 | Work ID badge | 0.0125781 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Aloe vera gel | 0.0135288 | Bandana | 0.0125701 | Travel insurance documents | 0.0125387 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Snorkel gear | 0.0135229 | Blanket | 0.0125266 | Business attire | 0.0124256 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Waterproof phone case | 0.0135219 | Sunglasses | 0.0123896 | Baby wipes | 0.012401 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Packable rain jacket | 0.0133905 | Sunglasses | 0.0123896 | Blanket | 0.0122619 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Reusable shopping bags | 0.0133134 | Laptop | 0.0123645 | Lightweight backpack | 0.0122291 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Reusable coffee mug | 0.012921 | Snacks | 0.0123038 | Sunglasses | 0.0121536 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Reusable water bottle | 0.012695 | Sunscreen | 0.0122985 | Sunglasses | 0.0121536 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| First aid kit | 0.0124969 | Pen | 0.0122703 | Laptop | 0.0121034 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Travel insurance documents | 0.0124186 | Cooler | 0.0122299 | Passport | 0.0121023 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Work ID badge | 0.0123513 | Snowboard | 0.012205 | Beanie | 0.0120397 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Lightweight backpack | 0.0122867 | Passport | 0.0121188 | Baby clothes | 0.0120325 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Presentation materials | 0.0121707 | Visa documents | 0.0121176 | Snacks | 0.0119757 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Flip-flops | 0.0121665 | Swimsuit | 0.0120711 | Packable rain jacket | 0.011946 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Charging cables | 0.0121361 | Flashlight | 0.0120105 | Baby food | 0.0119228 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Hiking boots | 0.0121118 | Stroller | 0.0119368 | Baby blanket | 0.0118852 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Comfortable shoes | 0.0120349 | Map | 0.01193 | Dress shoes | 0.0118458 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Fanny pack | 0.011914 | First aid kit | 0.0119121 | Bug spray | 0.0118403 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Trekking poles | 0.0118607 | Notebook | 0.0118809 | Travel journal | 0.0118067 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Visa documents | 0.0118408 | Hat | 0.011833 | Travel pillow | 0.0118006 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Baby wipes | 0.0117297 | Currency | 0.0118279 | Visa documents | 0.0117734 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Quick-dry towel | 0.0116303 | Work ID badge | 0.0117867 | Emergency roadside kit | 0.0117412 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Baby blanket | 0.011586 | Travel insurance documents | 0.01168 | SIM card | 0.0117407 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Hostel lock | 0.0115573 | Business attire | 0.0116774 | Cooler | 0.0117317 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Blanket | 0.0114867 | Compass | 0.0116575 | Snowboard | 0.0117232 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Business attire | 0.0114801 | Playlist | 0.0116254 | Diapers | 0.0117056 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Laptop | 0.0112665 | Bug spray | 0.0115941 | Notebook | 0.011676 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Beanie | 0.0112438 | Tent | 0.0115531 | Bandana | 0.0116441 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Bug spray | 0.0112397 | Tent | 0.0115531 | Pen | 0.011614 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Travel pillow | 0.0111955 | Diapers | 0.0115231 | Flashlight | 0.011587 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Baby clothes | 0.0111946 | Travel journal | 0.0114808 | Playlist | 0.0115787 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Passport | 0.0111815 | Hiking boots | 0.0114734 | Sunscreen | 0.0115577 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Earplugs | 0.0111681 | Reusable shopping bags | 0.0114722 | Swimsuit | 0.0115468 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Camping stove | 0.0111419 | SIM card | 0.0114319 | Reusable coffee mug | 0.0115091 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Travel journal | 0.01114 | Toys | 0.0114257 | Trekking poles | 0.011476 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Emergency roadside kit | 0.011128 | Dress shoes | 0.0113439 | Sleeping bag | 0.0114472 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Baby food | 0.0110848 | Waterproof phone case | 0.0113438 | Hiking boots | 0.0114388 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Pen | 0.0110799 | Travel pillow | 0.0113271 | Snorkel gear | 0.0114219 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Bandana | 0.0110713 | Refillable water bottle | 0.0113269 | Reusable shopping bags | 0.0113664 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Dress shoes | 0.0110698 | Fanny pack | 0.0113193 | Portable charger | 0.0113632 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Snacks | 0.0110153 | Baby blanket | 0.0113175 | Fanny pack | 0.011333 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Travel crib | 0.0110133 | Aloe vera gel | 0.0113123 | Headphones | 0.0113156 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Sunscreen | 0.0109995 | Snorkel gear | 0.011283 | Currency | 0.0112893 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Ski goggles | 0.010981 | Pacifier | 0.0112826 | Travel adapter | 0.0112652 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Sunglasses | 0.0109759 | Headphones | 0.0112543 | Travel crib | 0.011224 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Sunglasses | 0.0109759 | Packable rain jacket | 0.0112416 | Presentation materials | 0.0112228 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Stroller | 0.0109661 | Poncho | 0.0112411 | Waterproof phone case | 0.0112181 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Lip balm | 0.0109645 | Nursing cover | 0.0112323 | Nursing cover | 0.0111811 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Notebook | 0.0109306 | Comfortable shoes | 0.0112138 | Beach bag | 0.0111739 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Glow sticks | 0.0108928 | Reusable coffee mug | 0.0112081 | Stroller | 0.0111447 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Cooler | 0.0108527 | Travel crib | 0.0111724 | Car charger | 0.0110935 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Snowboard | 0.0108444 | Baby clothes | 0.0111683 | Neck wallet | 0.0110586 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Map | 0.0108275 | Presentation materials | 0.0111555 | Lip balm | 0.0110534 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Thermal clothing | 0.0108054 | Baby food | 0.0111165 | Comfortable shoes | 0.0110398 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Neck wallet | 0.0107892 | Sleeping bag | 0.0110978 | Poncho | 0.0109919 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Water filter | 0.0107846 | Lightweight backpack | 0.011038 | Reusable water bottle | 0.0109792 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Travel adapter | 0.0107792 | Gloves | 0.010946 | Energy bars | 0.0109684 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Currency | 0.010762 | Portable charger | 0.0108962 | Map | 0.0109623 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Nursing cover | 0.0107438 | Trekking poles | 0.0108781 | Hostel lock | 0.0109603 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Snow boots | 0.0107272 | Charging cables | 0.0108504 | Power bank | 0.0109483 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Pacifier | 0.0107227 | Reusable water bottle | 0.0108255 | Thermal clothing | 0.0109311 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Sleeping bag | 0.0106966 | Neck wallet | 0.0108161 | Earplugs | 0.0109061 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Car charger | 0.0106959 | Beach bag | 0.0108042 | Charging cables | 0.0108819 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Diapers | 0.010669 | Travel-sized toiletries | 0.0107921 | Toys | 0.0108427 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Flashlight | 0.0106647 | Travel adapter | 0.0107415 | Ski jacket | 0.0108272 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Ski jacket | 0.0106418 | Hostel lock | 0.0106021 | Base layers | 0.0107343 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Portable charger | 0.0106307 | Thermal clothing | 0.0105911 | Glow sticks | 0.0106845 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Playlist | 0.0106083 | Car charger | 0.0105783 | Beach towel | 0.010634 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Swimsuit | 0.0105832 | Ski goggles | 0.0105752 | Water filter | 0.0106173 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Tent | 0.010549 | Ski jacket | 0.0105524 | Festival tickets | 0.0106124 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Tent | 0.010549 | Water filter | 0.010523 | Dry bag | 0.0105999 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| SIM card | 0.0105225 | Festival tickets | 0.0105077 | Hat | 0.010555 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Compass | 0.0105095 | Dry bag | 0.0104999 | Tent | 0.0105432 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Multi-tool | 0.0104697 | Glow sticks | 0.0104861 | Tent | 0.0105432 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Hat | 0.0104314 | Beach towel | 0.0104595 | Refillable water bottle | 0.0105226 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Base layers | 0.0104078 | Earplugs | 0.0104484 | Language phrasebook | 0.0104878 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Energy bars | 0.0103765 | Emergency roadside kit | 0.01042 | Aloe vera gel | 0.0104495 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Toys | 0.0103667 | Energy bars | 0.010328 | Compass | 0.0102844 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Power bank | 0.010329 | Flip-flops | 0.010279 | Pacifier | 0.0102553 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Dry bag | 0.0102989 | Power bank | 0.0102667 | Flip-flops | 0.0102396 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Beach towel | 0.0102733 | Base layers | 0.0102346 | Ski goggles | 0.010229 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Beach bag | 0.0102259 | Multi-tool | 0.0101584 | Multi-tool | 0.0100441 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Poncho | 0.0100634 | Lip balm | 0.0101392 | Gloves | 0.0100095 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Headphones | 0.010053 | Snow boots | 0.0101161 | Hand warmers | 0.00999101 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Gloves | 0.010049 | Camping stove | 0.00999308 | Camping stove | 0.00982307 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Festival tickets | 0.00984126 | Language phrasebook | 0.00958238 | Travel-sized toiletries | 0.0097547 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Hand warmers | 0.00967844 | Quick-dry towel | 0.00957849 | Snow boots | 0.00964112 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n", "| Language phrasebook | 0.0093065 | Hand warmers | 0.00916433 | Quick-dry towel | 0.00960495 |\n", "+----------------------------+-------------+----------------------------+-----------------+----------------------------+-----------------+\n" ] } ], "source": [ "# Creating a table\n", "table = zip(no_result[\"labels\"], no_result[\"scores\"], \n", " simple_result[\"labels\"], simple_result[\"scores\"], \n", " primed_result[\"labels\"], primed_result[\"scores\"])\n", "headers = [\"no_prompt\", \"no_prompt\", \"simple_prompt\", \"simple_prompt\", \"primed_prompt\", \"primed_prompt\"]\n", "\n", "print(tabulate(table, headers=headers, tablefmt=\"grid\"))\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python (huggingface_env)", "language": "python", "name": "huggingface_env" }, "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.20" } }, "nbformat": 4, "nbformat_minor": 5 }