{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "blender-agent.ipynb", "private_outputs": true, "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "rJ-QA0ODU4x9" }, "source": [ "# Install Dependancies" ] }, { "cell_type": "code", "metadata": { "id": "Bx20ocfPWAYS" }, "source": [ "#install pytorch\n", "!pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "UcY5FPNHY72K" }, "source": [ "#install transformers\n", "!pip install transformers" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "DKilCO-TU_s0" }, "source": [ "# Import Model" ] }, { "cell_type": "code", "metadata": { "id": "VU33RjeOc8eG" }, "source": [ "#import model class and tokenizer\n", "from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "6LZEzJXpc8pg" }, "source": [ "#download and setup the model and tokenizer\n", "model_name = 'facebook/blenderbot-400M-distill'\n", "tokenizer = BlenderbotTokenizer.from_pretrained(model_name)\n", "model = BlenderbotForConditionalGeneration.from_pretrained(model_name)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "_T9nRG5eVENY" }, "source": [ "# make conversation" ] }, { "cell_type": "code", "metadata": { "id": "AkrWBF3af8Ns" }, "source": [ "#making an utterance \n", "utterance = \"My name is gold, I like football and coding\"" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "JDDDJ2V3f8QT" }, "source": [ "#tokenize the utterance\n", "inputs = tokenizer(utterance, return_tensors=\"pt\")\n", "inputs" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "-QYclYycf8TN" }, "source": [ "#generate model results\n", "result = model.generate(**inputs)\n", "result" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "syB3F_iyf8Vt" }, "source": [ "tokenizer.decode(result[0])" ], "execution_count": null, "outputs": [] } ] }