{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3fcd5f6c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting transformers\n", " Downloading transformers-4.28.1-py3-none-any.whl (7.0 MB)\n", " ---------------------------------------- 7.0/7.0 MB 722.4 kB/s eta 0:00:00\n", "Requirement already satisfied: numpy>=1.17 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (1.24.3)\n", "Collecting huggingface-hub<1.0,>=0.11.0\n", " Downloading huggingface_hub-0.14.1-py3-none-any.whl (224 kB)\n", " ------------------------------------ 224.5/224.5 kB 762.4 kB/s eta 0:00:00\n", "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (6.0)\n", "Requirement already satisfied: filelock in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (3.12.0)\n", "Requirement already satisfied: packaging>=20.0 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (21.3)\n", "Requirement already satisfied: regex!=2019.12.17 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (2022.7.9)\n", "Collecting tokenizers!=0.11.3,<0.14,>=0.11.1\n", " Downloading tokenizers-0.13.3-cp39-cp39-win_amd64.whl (3.5 MB)\n", " ---------------------------------------- 3.5/3.5 MB 738.0 kB/s eta 0:00:00\n", "Requirement already satisfied: tqdm>=4.27 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (4.64.1)\n", "Requirement already satisfied: requests in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from transformers) (2.28.1)\n", "Requirement already satisfied: fsspec in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from huggingface-hub<1.0,>=0.11.0->transformers) (2022.7.1)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from huggingface-hub<1.0,>=0.11.0->transformers) (4.3.0)\n", "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from packaging>=20.0->transformers) (3.0.9)\n", "Requirement already satisfied: colorama in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from tqdm>=4.27->transformers) (0.4.5)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from requests->transformers) (3.3)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from requests->transformers) (2022.12.7)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from requests->transformers) (1.26.11)\n", "Requirement already satisfied: charset-normalizer<3,>=2 in c:\\users\\atharva\\anaconda3\\lib\\site-packages (from requests->transformers) (2.0.4)\n", "Installing collected packages: tokenizers, huggingface-hub, transformers\n", "Successfully installed huggingface-hub-0.14.1 tokenizers-0.13.3 transformers-4.28.1\n" ] } ], "source": [ "!pip install transformers" ] }, { "cell_type": "code", "execution_count": 2, "id": "9b7e3e88", "metadata": {}, "outputs": [], "source": [ "from transformers import pipeline" ] }, { "cell_type": "code", "execution_count": null, "id": "bf785b14", "metadata": {}, "outputs": [], "source": [ "##BART -LARGE-MNLI" ] }, { "cell_type": "code", "execution_count": 3, "id": "ac57b4d0", "metadata": { "scrolled": true }, "outputs": [], "source": [ "classifier_pipeline=pipeline(\"zero-shot-classification\",model=\"facebook/bart-large-mnli\",)" ] }, { "cell_type": "code", "execution_count": 4, "id": "8b1d9736", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'sequence': 'I love travelling',\n", " 'labels': ['travelling', 'entertainment', 'technology', 'dancing', 'cooking'],\n", " 'scores': [0.930633544921875,\n", " 0.057743728160858154,\n", " 0.004555718973278999,\n", " 0.004288351628929377,\n", " 0.0027786651626229286]}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "input_sequences=\"I love travelling\"\n", "label_candidates=[\"travelling\",\"cooking\",\"entertainment\",\"dancing\",\"technology\"]\n", "classifier_pipeline(input_sequences,label_candidates)\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "80d56ec0", "metadata": { "scrolled": true }, "outputs": [], "source": [ "import pickle\n", "pickle_out=open(\"classfier_pipeline.pkl\",\"wb\")\n", "pickle.dump=(classifier_pipeline,pickle_out)\n", "pickle_out.close()\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "19f74f84", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }