Spaces:
Runtime error
Runtime error
File size: 3,285 Bytes
f3ae72f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
{
"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": []
}
]
} |