edemgold commited on
Commit
f3ae72f
1 Parent(s): 5393e6f

adding code

Browse files
Files changed (2) hide show
  1. blender_bot.ipynb +148 -0
  2. requirements.txt +3 -0
blender_bot.ipynb ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "name": "blender-agent.ipynb",
7
+ "private_outputs": true,
8
+ "provenance": [],
9
+ "collapsed_sections": []
10
+ },
11
+ "kernelspec": {
12
+ "name": "python3",
13
+ "display_name": "Python 3"
14
+ },
15
+ "language_info": {
16
+ "name": "python"
17
+ },
18
+ "accelerator": "GPU"
19
+ },
20
+ "cells": [
21
+ {
22
+ "cell_type": "markdown",
23
+ "metadata": {
24
+ "id": "rJ-QA0ODU4x9"
25
+ },
26
+ "source": [
27
+ "# Install Dependancies"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "metadata": {
33
+ "id": "Bx20ocfPWAYS"
34
+ },
35
+ "source": [
36
+ "#install pytorch\n",
37
+ "!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"
38
+ ],
39
+ "execution_count": null,
40
+ "outputs": []
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "metadata": {
45
+ "id": "UcY5FPNHY72K"
46
+ },
47
+ "source": [
48
+ "#install transformers\n",
49
+ "!pip install transformers"
50
+ ],
51
+ "execution_count": null,
52
+ "outputs": []
53
+ },
54
+ {
55
+ "cell_type": "markdown",
56
+ "metadata": {
57
+ "id": "DKilCO-TU_s0"
58
+ },
59
+ "source": [
60
+ "# Import Model"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "metadata": {
66
+ "id": "VU33RjeOc8eG"
67
+ },
68
+ "source": [
69
+ "#import model class and tokenizer\n",
70
+ "from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration"
71
+ ],
72
+ "execution_count": null,
73
+ "outputs": []
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "metadata": {
78
+ "id": "6LZEzJXpc8pg"
79
+ },
80
+ "source": [
81
+ "#download and setup the model and tokenizer\n",
82
+ "model_name = 'facebook/blenderbot-400M-distill'\n",
83
+ "tokenizer = BlenderbotTokenizer.from_pretrained(model_name)\n",
84
+ "model = BlenderbotForConditionalGeneration.from_pretrained(model_name)"
85
+ ],
86
+ "execution_count": null,
87
+ "outputs": []
88
+ },
89
+ {
90
+ "cell_type": "markdown",
91
+ "metadata": {
92
+ "id": "_T9nRG5eVENY"
93
+ },
94
+ "source": [
95
+ "# make conversation"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "metadata": {
101
+ "id": "AkrWBF3af8Ns"
102
+ },
103
+ "source": [
104
+ "#making an utterance \n",
105
+ "utterance = \"My name is gold, I like football and coding\""
106
+ ],
107
+ "execution_count": null,
108
+ "outputs": []
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "metadata": {
113
+ "id": "JDDDJ2V3f8QT"
114
+ },
115
+ "source": [
116
+ "#tokenize the utterance\n",
117
+ "inputs = tokenizer(utterance, return_tensors=\"pt\")\n",
118
+ "inputs"
119
+ ],
120
+ "execution_count": null,
121
+ "outputs": []
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "metadata": {
126
+ "id": "-QYclYycf8TN"
127
+ },
128
+ "source": [
129
+ "#generate model results\n",
130
+ "result = model.generate(**inputs)\n",
131
+ "result"
132
+ ],
133
+ "execution_count": null,
134
+ "outputs": []
135
+ },
136
+ {
137
+ "cell_type": "code",
138
+ "metadata": {
139
+ "id": "syB3F_iyf8Vt"
140
+ },
141
+ "source": [
142
+ "tokenizer.decode(result[0])"
143
+ ],
144
+ "execution_count": null,
145
+ "outputs": []
146
+ }
147
+ ]
148
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch