lsacy
commited on
Commit
·
0a5800f
1
Parent(s):
ee3489d
minor update
Browse files- .DS_Store +0 -0
- requirements.txt~ +0 -7
- streamlit_app.py +6 -4
- test.ipynb +128 -63
- twilio.py +0 -20
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
requirements.txt~
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
Flask==2.2.2
|
2 |
-
openai==0.26.4
|
3 |
-
python-dotenv==0.21.1
|
4 |
-
streamlit==1.17.0
|
5 |
-
streamlit_chat==0.0.2.1
|
6 |
-
transformers==4.25.1
|
7 |
-
torch==1.13.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streamlit_app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import openai
|
2 |
-
openai.
|
|
|
3 |
import streamlit as st
|
4 |
from streamlit_chat import message
|
5 |
from transformers import pipeline
|
@@ -62,7 +63,9 @@ def analyze_sentiment(chat_log):
|
|
62 |
sentiment = sentiment_task(chat_log)
|
63 |
return sentiment
|
64 |
|
65 |
-
|
|
|
|
|
66 |
|
67 |
|
68 |
|
@@ -91,8 +94,7 @@ def main():
|
|
91 |
summary = summarizer(chat_log, max_length=100, min_length=30, do_sample=False)
|
92 |
st.write(summary)
|
93 |
user_sentiment = st.session_state['past']
|
94 |
-
user_sentiment =
|
95 |
-
user_sentiment = clean_chat_log(user_sentiment)
|
96 |
st.write(sentiment_task(user_sentiment))
|
97 |
st.session_state['generated'] = [start_message]
|
98 |
st.session_state['past'] = []
|
|
|
1 |
import openai
|
2 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
3 |
+
|
4 |
import streamlit as st
|
5 |
from streamlit_chat import message
|
6 |
from transformers import pipeline
|
|
|
63 |
sentiment = sentiment_task(chat_log)
|
64 |
return sentiment
|
65 |
|
66 |
+
def remove_backslashN(chat_log: list) -> list:
|
67 |
+
chat_log = [i.replace('\n', ' ') for i in chat_log]
|
68 |
+
return chat_log
|
69 |
|
70 |
|
71 |
|
|
|
94 |
summary = summarizer(chat_log, max_length=100, min_length=30, do_sample=False)
|
95 |
st.write(summary)
|
96 |
user_sentiment = st.session_state['past']
|
97 |
+
user_sentiment = remove_backslashN(user_sentiment)
|
|
|
98 |
st.write(sentiment_task(user_sentiment))
|
99 |
st.session_state['generated'] = [start_message]
|
100 |
st.session_state['past'] = []
|
test.ipynb
CHANGED
@@ -2,20 +2,9 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
-
"outputs": [
|
8 |
-
{
|
9 |
-
"data": {
|
10 |
-
"text/plain": [
|
11 |
-
"528"
|
12 |
-
]
|
13 |
-
},
|
14 |
-
"execution_count": 9,
|
15 |
-
"metadata": {},
|
16 |
-
"output_type": "execute_result"
|
17 |
-
}
|
18 |
-
],
|
19 |
"source": [
|
20 |
"test = ''' Cancer of the womb (uterus) is a common cancer that affects the female reproductive system. It's also called uterine cancer and endometrial cancer.\n",
|
21 |
"\n",
|
@@ -60,23 +49,78 @@
|
|
60 |
"\n",
|
61 |
"\n",
|
62 |
" '''\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
"\n",
|
64 |
-
"
|
65 |
-
"# count the number of words in test string\n",
|
66 |
-
"\n",
|
67 |
-
"test2 = test.split()\n",
|
68 |
-
"len(test2)"
|
69 |
]
|
70 |
},
|
71 |
{
|
72 |
"cell_type": "code",
|
73 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
"metadata": {},
|
75 |
"outputs": [
|
76 |
{
|
77 |
"name": "stderr",
|
78 |
"output_type": "stream",
|
79 |
"text": [
|
|
|
|
|
|
|
80 |
"Some weights of the model checkpoint at cardiffnlp/twitter-roberta-base-sentiment-latest were not used when initializing RobertaForSequenceClassification: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']\n",
|
81 |
"- This IS expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
|
82 |
"- This IS NOT expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n"
|
@@ -87,32 +131,23 @@
|
|
87 |
"from transformers import AutoModelForSequenceClassification\n",
|
88 |
"from transformers import TFAutoModelForSequenceClassification\n",
|
89 |
"from transformers import AutoTokenizer, AutoConfig\n",
|
|
|
90 |
"MODEL = \"cardiffnlp/twitter-roberta-base-sentiment-latest\"\n",
|
91 |
"\n",
|
92 |
"tokenizer = AutoTokenizer.from_pretrained(MODEL)\n",
|
93 |
"config = AutoConfig.from_pretrained(MODEL)\n",
|
94 |
"model = AutoModelForSequenceClassification.from_pretrained(MODEL)\n",
|
95 |
"\n",
|
96 |
-
"\n"
|
97 |
-
"\n"
|
98 |
]
|
99 |
},
|
100 |
{
|
101 |
"cell_type": "code",
|
102 |
-
"execution_count":
|
103 |
"metadata": {},
|
104 |
-
"outputs": [
|
105 |
-
{
|
106 |
-
"name": "stdout",
|
107 |
-
"output_type": "stream",
|
108 |
-
"text": [
|
109 |
-
"2865\n"
|
110 |
-
]
|
111 |
-
}
|
112 |
-
],
|
113 |
"source": [
|
114 |
-
"
|
115 |
-
"len(test3)\n",
|
116 |
"def clean_chat_log(chat_log):\n",
|
117 |
" chat_log = ' '.join(chat_log)\n",
|
118 |
" # find the first /n\n",
|
@@ -120,30 +155,73 @@
|
|
120 |
" chat_log = chat_log[first_newline:]\n",
|
121 |
" # remove all \\n\n",
|
122 |
" chat_log = chat_log.replace('\\n', ' ')\n",
|
123 |
-
" return chat_log
|
124 |
-
"\n",
|
125 |
-
"cleaned = clean_chat_log(test3)\n",
|
126 |
-
"print(len(cleaned))"
|
127 |
]
|
128 |
},
|
129 |
{
|
130 |
"cell_type": "code",
|
131 |
-
"execution_count":
|
132 |
"metadata": {},
|
133 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
{
|
135 |
"data": {
|
136 |
"text/plain": [
|
137 |
-
"
|
138 |
]
|
139 |
},
|
140 |
-
"execution_count":
|
141 |
"metadata": {},
|
142 |
"output_type": "execute_result"
|
143 |
}
|
144 |
],
|
145 |
"source": [
|
146 |
-
"len(tokenizer(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
]
|
148 |
},
|
149 |
{
|
@@ -178,34 +256,21 @@
|
|
178 |
},
|
179 |
{
|
180 |
"cell_type": "code",
|
181 |
-
"execution_count":
|
182 |
"metadata": {},
|
183 |
"outputs": [
|
184 |
{
|
185 |
-
"
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
"metadata": {},
|
192 |
-
"output_type": "execute_result"
|
193 |
-
}
|
194 |
-
],
|
195 |
-
"source": [
|
196 |
-
"log(3)"
|
197 |
-
]
|
198 |
-
},
|
199 |
-
{
|
200 |
-
"cell_type": "code",
|
201 |
-
"execution_count": 96,
|
202 |
-
"metadata": {},
|
203 |
-
"outputs": [
|
204 |
{
|
205 |
"name": "stdout",
|
206 |
"output_type": "stream",
|
207 |
"text": [
|
208 |
-
"[\"
|
209 |
]
|
210 |
}
|
211 |
],
|
@@ -239,7 +304,7 @@
|
|
239 |
"# Example usage\n",
|
240 |
"input_string = \"This is a sample input string. It can be quite long. This function splits the input string into parts, each of which is no longer than the maximum length defined by the tokenizer and each of which ends on a full stop.\"\n",
|
241 |
"max_length = 512\n",
|
242 |
-
"split_strings = split_input_string(
|
243 |
"print(split_strings)\n"
|
244 |
]
|
245 |
},
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 19,
|
6 |
"metadata": {},
|
7 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
"source": [
|
9 |
"test = ''' Cancer of the womb (uterus) is a common cancer that affects the female reproductive system. It's also called uterine cancer and endometrial cancer.\n",
|
10 |
"\n",
|
|
|
49 |
"\n",
|
50 |
"\n",
|
51 |
" '''\n",
|
52 |
+
"test3 = ['[Instruction] Act as a friendly, compasionate, insightful, and empathetic AI therapist named Joy. Joy listens and offers advices. End the conversation when the patient wishes to.\\nJoy:I am Joy, your AI therapist. How are you feeling today?', \"\\n\\nPatient:im doing okay\\nJoy:That's good to hear. Is there anything in particular that you would like to talk about today?\", '\\n\\nPatient:no not really\\nJoy:No problem. Is there anything on your mind that you would like to share? I am here to listen and offer support.', \"\\n\\nPatient:maybe actually. I am afraid my spouse cheats on me\\nJoy:I'm sorry to hear that. What has been making you feel this way?\", '\\n\\nPatient:she is writing text messages constantly with people i dont know\\nJoy:That can certainly be concerning. Have you tried talking to your spouse about this?', '\\n\\nPatient:yea then she gets defensive and angry\\nJoy:I understand that this must be difficult for you. Are there any specific strategies that have helped when conversations with your spouse become heated?', \"\\n\\nPatient:i dont know\\nJoy:It's okay if you don't know right away. What do you feel comfortable doing in these situations? Are there any strategies that have helped in the past when things become tense between you and your spouse?\", '\\n\\nPatient:i just stopped talking to her or change the subject\\nJoy:It sounds like you are doing your best to find a way to manage this. Is there anything that has helped make the situation more comfortable for you?', '\\n\\nPatient:trying not thinking about it\\nJoy:It sounds like you are doing your best to handle this difficult situation. Do you think it would help to talk to a professional or find additional support?', \"\\n\\nPatient:no i havent\\nJoy:That's understandable. Is there someone who you feel comfortable talking to about this? How does having a conversation with them make you feel?\", \"\\n\\nPatient:i havent talked with anyone about this\\nJoy:That's understandable. Having someone to talk to can be beneficial in difficult times like this. Is there anyone who you trust that you feel comfortable speaking with about your concerns?\", '\\n\\nPatient:there is no one, except maybe my mom\\nJoy:Talking to your mom can be a great start. Is there anything in particular that you want to share with her about what is going on? How does the idea of having this conversation make you feel?', '\\n\\nPatient:yea like I said, about this topic that im not very comfortable with, do you still remember which?\\nJoy:Yes, you mentioned that your spouse may be cheating on you. How would you like to approach this conversation with your mom?', \"\\n\\nPatient:tell her about my suspicision i guess\\nJoy:It can be difficult to bring up a topic like this, but it's important that you have an open conversation with her. Would you like any advice on how to start the conversation?\", \"\\n\\nPatient:yes please\\nJoy:It can help to start by letting your mom know why you decided to talk to her about this. Sharing how you are feeling and asking for her advice might be a good way to open the conversation. I'm here if you need anything else before or after speaking with your mom.\"]"
|
53 |
+
]
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"cell_type": "code",
|
57 |
+
"execution_count": 31,
|
58 |
+
"metadata": {},
|
59 |
+
"outputs": [
|
60 |
+
{
|
61 |
+
"data": {
|
62 |
+
"text/plain": [
|
63 |
+
"[\" Patient:im doing okay Joy:That's good to hear. Is there anything in particular that you would like to talk about today?\",\n",
|
64 |
+
" ' Patient:no not really Joy:No problem. Is there anything on your mind that you would like to share? I am here to listen and offer support.',\n",
|
65 |
+
" \" Patient:maybe actually. I am afraid my spouse cheats on me Joy:I'm sorry to hear that. What has been making you feel this way?\",\n",
|
66 |
+
" ' Patient:she is writing text messages constantly with people i dont know Joy:That can certainly be concerning. Have you tried talking to your spouse about this?',\n",
|
67 |
+
" ' Patient:yea then she gets defensive and angry Joy:I understand that this must be difficult for you. Are there any specific strategies that have helped when conversations with your spouse become heated?',\n",
|
68 |
+
" \" Patient:i dont know Joy:It's okay if you don't know right away. What do you feel comfortable doing in these situations? Are there any strategies that have helped in the past when things become tense between you and your spouse?\",\n",
|
69 |
+
" ' Patient:i just stopped talking to her or change the subject Joy:It sounds like you are doing your best to find a way to manage this. Is there anything that has helped make the situation more comfortable for you?',\n",
|
70 |
+
" ' Patient:trying not thinking about it Joy:It sounds like you are doing your best to handle this difficult situation. Do you think it would help to talk to a professional or find additional support?',\n",
|
71 |
+
" \" Patient:no i havent Joy:That's understandable. Is there someone who you feel comfortable talking to about this? How does having a conversation with them make you feel?\",\n",
|
72 |
+
" \" Patient:i havent talked with anyone about this Joy:That's understandable. Having someone to talk to can be beneficial in difficult times like this. Is there anyone who you trust that you feel comfortable speaking with about your concerns?\",\n",
|
73 |
+
" ' Patient:there is no one, except maybe my mom Joy:Talking to your mom can be a great start. Is there anything in particular that you want to share with her about what is going on? How does the idea of having this conversation make you feel?',\n",
|
74 |
+
" ' Patient:yea like I said, about this topic that im not very comfortable with, do you still remember which? Joy:Yes, you mentioned that your spouse may be cheating on you. How would you like to approach this conversation with your mom?',\n",
|
75 |
+
" \" Patient:tell her about my suspicision i guess Joy:It can be difficult to bring up a topic like this, but it's important that you have an open conversation with her. Would you like any advice on how to start the conversation?\",\n",
|
76 |
+
" \" Patient:yes please Joy:It can help to start by letting your mom know why you decided to talk to her about this. Sharing how you are feeling and asking for her advice might be a good way to open the conversation. I'm here if you need anything else before or after speaking with your mom.\"]"
|
77 |
+
]
|
78 |
+
},
|
79 |
+
"execution_count": 31,
|
80 |
+
"metadata": {},
|
81 |
+
"output_type": "execute_result"
|
82 |
+
}
|
83 |
+
],
|
84 |
+
"source": [
|
85 |
+
"def remove_backslashN(chat_log):\n",
|
86 |
+
" chat_log = [i.replace('\\n', ' ') for i in chat_log]\n",
|
87 |
+
" return chat_log\n",
|
88 |
"\n",
|
89 |
+
"clean_chatlog(test3)"
|
|
|
|
|
|
|
|
|
90 |
]
|
91 |
},
|
92 |
{
|
93 |
"cell_type": "code",
|
94 |
+
"execution_count": 30,
|
95 |
+
"metadata": {},
|
96 |
+
"outputs": [
|
97 |
+
{
|
98 |
+
"data": {
|
99 |
+
"text/plain": [
|
100 |
+
"\"\\n\\nPatient:im doing okay\\nJoy:That's good to hear. Is there anything in particular that you would like to talk about today?\""
|
101 |
+
]
|
102 |
+
},
|
103 |
+
"execution_count": 30,
|
104 |
+
"metadata": {},
|
105 |
+
"output_type": "execute_result"
|
106 |
+
}
|
107 |
+
],
|
108 |
+
"source": [
|
109 |
+
"test3[1]"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"cell_type": "code",
|
114 |
+
"execution_count": 18,
|
115 |
"metadata": {},
|
116 |
"outputs": [
|
117 |
{
|
118 |
"name": "stderr",
|
119 |
"output_type": "stream",
|
120 |
"text": [
|
121 |
+
"Some weights of the model checkpoint at cardiffnlp/twitter-roberta-base-sentiment-latest were not used when initializing RobertaForSequenceClassification: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']\n",
|
122 |
+
"- This IS expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
|
123 |
+
"- This IS NOT expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
|
124 |
"Some weights of the model checkpoint at cardiffnlp/twitter-roberta-base-sentiment-latest were not used when initializing RobertaForSequenceClassification: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']\n",
|
125 |
"- This IS expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
|
126 |
"- This IS NOT expected if you are initializing RobertaForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n"
|
|
|
131 |
"from transformers import AutoModelForSequenceClassification\n",
|
132 |
"from transformers import TFAutoModelForSequenceClassification\n",
|
133 |
"from transformers import AutoTokenizer, AutoConfig\n",
|
134 |
+
"from transformers import pipeline\n",
|
135 |
"MODEL = \"cardiffnlp/twitter-roberta-base-sentiment-latest\"\n",
|
136 |
"\n",
|
137 |
"tokenizer = AutoTokenizer.from_pretrained(MODEL)\n",
|
138 |
"config = AutoConfig.from_pretrained(MODEL)\n",
|
139 |
"model = AutoModelForSequenceClassification.from_pretrained(MODEL)\n",
|
140 |
"\n",
|
141 |
+
"sentiment_task = pipeline(\"sentiment-analysis\", model='cardiffnlp/twitter-roberta-base-sentiment-latest', tokenizer='cardiffnlp/twitter-roberta-base-sentiment-latest')\n"
|
|
|
142 |
]
|
143 |
},
|
144 |
{
|
145 |
"cell_type": "code",
|
146 |
+
"execution_count": 20,
|
147 |
"metadata": {},
|
148 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
"source": [
|
150 |
+
"\n",
|
|
|
151 |
"def clean_chat_log(chat_log):\n",
|
152 |
" chat_log = ' '.join(chat_log)\n",
|
153 |
" # find the first /n\n",
|
|
|
155 |
" chat_log = chat_log[first_newline:]\n",
|
156 |
" # remove all \\n\n",
|
157 |
" chat_log = chat_log.replace('\\n', ' ')\n",
|
158 |
+
" return chat_log"
|
|
|
|
|
|
|
159 |
]
|
160 |
},
|
161 |
{
|
162 |
"cell_type": "code",
|
163 |
+
"execution_count": 21,
|
164 |
"metadata": {},
|
165 |
"outputs": [
|
166 |
+
{
|
167 |
+
"name": "stderr",
|
168 |
+
"output_type": "stream",
|
169 |
+
"text": [
|
170 |
+
"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"
|
171 |
+
]
|
172 |
+
},
|
173 |
{
|
174 |
"data": {
|
175 |
"text/plain": [
|
176 |
+
"682"
|
177 |
]
|
178 |
},
|
179 |
+
"execution_count": 21,
|
180 |
"metadata": {},
|
181 |
"output_type": "execute_result"
|
182 |
}
|
183 |
],
|
184 |
"source": [
|
185 |
+
"len(tokenizer(test, padding=True, truncation=True, return_tensors=\"pt\")[0])"
|
186 |
+
]
|
187 |
+
},
|
188 |
+
{
|
189 |
+
"cell_type": "code",
|
190 |
+
"execution_count": 25,
|
191 |
+
"metadata": {},
|
192 |
+
"outputs": [],
|
193 |
+
"source": [
|
194 |
+
"test3_string = clean_chat_log(test3)"
|
195 |
+
]
|
196 |
+
},
|
197 |
+
{
|
198 |
+
"cell_type": "code",
|
199 |
+
"execution_count": 26,
|
200 |
+
"metadata": {},
|
201 |
+
"outputs": [
|
202 |
+
{
|
203 |
+
"ename": "RuntimeError",
|
204 |
+
"evalue": "The expanded size of the tensor (634) must match the existing size (514) at non-singleton dimension 1. Target sizes: [1, 634]. Tensor sizes: [1, 514]",
|
205 |
+
"output_type": "error",
|
206 |
+
"traceback": [
|
207 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
208 |
+
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
|
209 |
+
"Cell \u001b[0;32mIn[26], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m sentiment_task(test3_string)\n",
|
210 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/pipelines/text_classification.py:155\u001b[0m, in \u001b[0;36mTextClassificationPipeline.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 122\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 123\u001b[0m \u001b[39m Classify the text(s) given as inputs.\u001b[39;00m\n\u001b[1;32m 124\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 153\u001b[0m \u001b[39m If `top_k` is used, one such dictionary is returned per label.\u001b[39;00m\n\u001b[1;32m 154\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 155\u001b[0m result \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49m\u001b[39m__call__\u001b[39;49m(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 156\u001b[0m \u001b[39m# TODO try and retrieve it in a nicer way from _sanitize_parameters.\u001b[39;00m\n\u001b[1;32m 157\u001b[0m _legacy \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mtop_k\u001b[39m\u001b[39m\"\u001b[39m \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m kwargs\n",
|
211 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/pipelines/base.py:1074\u001b[0m, in \u001b[0;36mPipeline.__call__\u001b[0;34m(self, inputs, num_workers, batch_size, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1072\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39miterate(inputs, preprocess_params, forward_params, postprocess_params)\n\u001b[1;32m 1073\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m-> 1074\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrun_single(inputs, preprocess_params, forward_params, postprocess_params)\n",
|
212 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/pipelines/base.py:1081\u001b[0m, in \u001b[0;36mPipeline.run_single\u001b[0;34m(self, inputs, preprocess_params, forward_params, postprocess_params)\u001b[0m\n\u001b[1;32m 1079\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mrun_single\u001b[39m(\u001b[39mself\u001b[39m, inputs, preprocess_params, forward_params, postprocess_params):\n\u001b[1;32m 1080\u001b[0m model_inputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpreprocess(inputs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpreprocess_params)\n\u001b[0;32m-> 1081\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mforward(model_inputs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mforward_params)\n\u001b[1;32m 1082\u001b[0m outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpostprocess(model_outputs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpostprocess_params)\n\u001b[1;32m 1083\u001b[0m \u001b[39mreturn\u001b[39;00m outputs\n",
|
213 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/pipelines/base.py:990\u001b[0m, in \u001b[0;36mPipeline.forward\u001b[0;34m(self, model_inputs, **forward_params)\u001b[0m\n\u001b[1;32m 988\u001b[0m \u001b[39mwith\u001b[39;00m inference_context():\n\u001b[1;32m 989\u001b[0m model_inputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ensure_tensor_on_device(model_inputs, device\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdevice)\n\u001b[0;32m--> 990\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_forward(model_inputs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mforward_params)\n\u001b[1;32m 991\u001b[0m model_outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ensure_tensor_on_device(model_outputs, device\u001b[39m=\u001b[39mtorch\u001b[39m.\u001b[39mdevice(\u001b[39m\"\u001b[39m\u001b[39mcpu\u001b[39m\u001b[39m\"\u001b[39m))\n\u001b[1;32m 992\u001b[0m \u001b[39melse\u001b[39;00m:\n",
|
214 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/pipelines/text_classification.py:182\u001b[0m, in \u001b[0;36mTextClassificationPipeline._forward\u001b[0;34m(self, model_inputs)\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_forward\u001b[39m(\u001b[39mself\u001b[39m, model_inputs):\n\u001b[0;32m--> 182\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmodel(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mmodel_inputs)\n",
|
215 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/torch/nn/modules/module.py:1194\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1190\u001b[0m \u001b[39m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1191\u001b[0m \u001b[39m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1192\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_pre_hooks \u001b[39mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1193\u001b[0m \u001b[39mor\u001b[39;00m _global_forward_hooks \u001b[39mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1194\u001b[0m \u001b[39mreturn\u001b[39;00m forward_call(\u001b[39m*\u001b[39;49m\u001b[39minput\u001b[39;49m, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1195\u001b[0m \u001b[39m# Do not call functions when jit is used\u001b[39;00m\n\u001b[1;32m 1196\u001b[0m full_backward_hooks, non_full_backward_hooks \u001b[39m=\u001b[39m [], []\n",
|
216 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/models/roberta/modeling_roberta.py:1215\u001b[0m, in \u001b[0;36mRobertaForSequenceClassification.forward\u001b[0;34m(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, output_attentions, output_hidden_states, return_dict)\u001b[0m\n\u001b[1;32m 1207\u001b[0m \u001b[39m\u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 1208\u001b[0m \u001b[39mlabels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):\u001b[39;00m\n\u001b[1;32m 1209\u001b[0m \u001b[39m Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,\u001b[39;00m\n\u001b[1;32m 1210\u001b[0m \u001b[39m config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If\u001b[39;00m\n\u001b[1;32m 1211\u001b[0m \u001b[39m `config.num_labels > 1` a classification loss is computed (Cross-Entropy).\u001b[39;00m\n\u001b[1;32m 1212\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 1213\u001b[0m return_dict \u001b[39m=\u001b[39m return_dict \u001b[39mif\u001b[39;00m return_dict \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mconfig\u001b[39m.\u001b[39muse_return_dict\n\u001b[0;32m-> 1215\u001b[0m outputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mroberta(\n\u001b[1;32m 1216\u001b[0m input_ids,\n\u001b[1;32m 1217\u001b[0m attention_mask\u001b[39m=\u001b[39;49mattention_mask,\n\u001b[1;32m 1218\u001b[0m token_type_ids\u001b[39m=\u001b[39;49mtoken_type_ids,\n\u001b[1;32m 1219\u001b[0m position_ids\u001b[39m=\u001b[39;49mposition_ids,\n\u001b[1;32m 1220\u001b[0m head_mask\u001b[39m=\u001b[39;49mhead_mask,\n\u001b[1;32m 1221\u001b[0m inputs_embeds\u001b[39m=\u001b[39;49minputs_embeds,\n\u001b[1;32m 1222\u001b[0m output_attentions\u001b[39m=\u001b[39;49moutput_attentions,\n\u001b[1;32m 1223\u001b[0m output_hidden_states\u001b[39m=\u001b[39;49moutput_hidden_states,\n\u001b[1;32m 1224\u001b[0m return_dict\u001b[39m=\u001b[39;49mreturn_dict,\n\u001b[1;32m 1225\u001b[0m )\n\u001b[1;32m 1226\u001b[0m sequence_output \u001b[39m=\u001b[39m outputs[\u001b[39m0\u001b[39m]\n\u001b[1;32m 1227\u001b[0m logits \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mclassifier(sequence_output)\n",
|
217 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/torch/nn/modules/module.py:1194\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1190\u001b[0m \u001b[39m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1191\u001b[0m \u001b[39m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1192\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_backward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_hooks \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_forward_pre_hooks \u001b[39mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1193\u001b[0m \u001b[39mor\u001b[39;00m _global_forward_hooks \u001b[39mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1194\u001b[0m \u001b[39mreturn\u001b[39;00m forward_call(\u001b[39m*\u001b[39;49m\u001b[39minput\u001b[39;49m, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 1195\u001b[0m \u001b[39m# Do not call functions when jit is used\u001b[39;00m\n\u001b[1;32m 1196\u001b[0m full_backward_hooks, non_full_backward_hooks \u001b[39m=\u001b[39m [], []\n",
|
218 |
+
"File \u001b[0;32m~/opt/miniconda3/envs/chatbot/lib/python3.8/site-packages/transformers/models/roberta/modeling_roberta.py:819\u001b[0m, in \u001b[0;36mRobertaModel.forward\u001b[0;34m(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, encoder_hidden_states, encoder_attention_mask, past_key_values, use_cache, output_attentions, output_hidden_states, return_dict)\u001b[0m\n\u001b[1;32m 817\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39membeddings, \u001b[39m\"\u001b[39m\u001b[39mtoken_type_ids\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[1;32m 818\u001b[0m buffered_token_type_ids \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39membeddings\u001b[39m.\u001b[39mtoken_type_ids[:, :seq_length]\n\u001b[0;32m--> 819\u001b[0m buffered_token_type_ids_expanded \u001b[39m=\u001b[39m buffered_token_type_ids\u001b[39m.\u001b[39;49mexpand(batch_size, seq_length)\n\u001b[1;32m 820\u001b[0m token_type_ids \u001b[39m=\u001b[39m buffered_token_type_ids_expanded\n\u001b[1;32m 821\u001b[0m \u001b[39melse\u001b[39;00m:\n",
|
219 |
+
"\u001b[0;31mRuntimeError\u001b[0m: The expanded size of the tensor (634) must match the existing size (514) at non-singleton dimension 1. Target sizes: [1, 634]. Tensor sizes: [1, 514]"
|
220 |
+
]
|
221 |
+
}
|
222 |
+
],
|
223 |
+
"source": [
|
224 |
+
"sentiment_task(test3_string)"
|
225 |
]
|
226 |
},
|
227 |
{
|
|
|
256 |
},
|
257 |
{
|
258 |
"cell_type": "code",
|
259 |
+
"execution_count": 27,
|
260 |
"metadata": {},
|
261 |
"outputs": [
|
262 |
{
|
263 |
+
"name": "stderr",
|
264 |
+
"output_type": "stream",
|
265 |
+
"text": [
|
266 |
+
"Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation=True` to explicitly truncate examples to max length. Defaulting to 'longest_first' truncation strategy. If you encode pairs of sequences (GLUE-style) with the tokenizer you can select this strategy more precisely by providing a specific strategy to `truncation`.\n"
|
267 |
+
]
|
268 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
{
|
270 |
"name": "stdout",
|
271 |
"output_type": "stream",
|
272 |
"text": [
|
273 |
+
"[\" .J.o.y.:.I. .a.m. .J.o.y.,. .y.o.u.r. .A.I. .t.h.e.r.a.p.i.s.t... .H.o.w. .a.r.e. .y.o.u. .f.e.e.l.i.n.g. .t.o.d.a.y.?. . . .P.a.t.i.e.n.t.:.i.m. .d.o.i.n.g. .o.k.a.y. .J.o.y.:.T.h.a.t.'.s. .g.o.o.d. .t.o. .h.e.a.r... .I.s. .t.h.e.r.e. .a.n.y.t.h.i.n.g. .i.n. .p.a.r.t.i.c.u.l.a.r. .t.h.a.t. .y.o.u. .w.o.u.l.d. .l.i.k.e. .t.o. .t.a.l.k. .a.b.o.u.t. .t.o.d.a.y.?. . . .P.a.t.i.e.n.t.:.n.o. .n.o.t. .r.e.a.l.l.y. .J.o.y.:.N.o. .p.r.o.b.l.e.m... .I.s. .t.h.e.r.e. .a.n.y.t.h.i.n.g. .o.n. .y.o.u.r. .m.i.n.d. .t.h.a.t. .y.o.u. .w.o.u.l.d. .l.i.k.e. .t.o. .s.h.a.r.e.?. .I. .a.m. .h.e.r.e. .t.o. .l.i.s.t.e.n. .a.n.d. .o.f.f.e.r. .s.u.p.p.o.r.t... . . .P.a.t.i.e.n.t.:.m.a.y.b.e. .a.c.t.u.a.l.l.y... .I. .a.m. .a.f.r.a.i.d. .m.y. .s.p.o.u.s.e. .c.h.e.a.t.s. .o.n. .m.e. .J.o.y.:.I.'.m. .s.o.r.r.y. .t.o. .h.e.a.r. .t.h.a.t... .W.h.a.t. .h.a.s. .b.e.e.n. .m.a.k.i.n.g. .y.o.u. .f.e.e.l. .t.h.i.s. .w.a.y.?. . . .P.a.t.i.e.n.t.:.s.h.e. .i.s. .w.r.i.t.i.n.g. .t.e.x.t. .m.e.s.s.a.g.e.s. .c.o.n.s.t.a.n.t.l.y. .w.i.t.h. .p.e.o.p.l.e. .i. .d.o.n.t. .k.n.o.w. .J.o.y.:.T.h.a.t. .c.a.n. .c.e.r.t.a.i.n.l.y. .b.e. .c.o.n.c.e.r.n.i.n.g... .H.a.v.e. .y.o.u. .t.r.i.e.d. .t.a.l.k.i.n.g. .t.o. .y.o.u.r. .s.p.o.u.s.e. .a.b.o.u.t. .t.h.i.s.?. . . .P.a.t.i.e.n.t.:.y.e.a. .t.h.e.n. .s.h.e. .g.e.t.s. .d.e.f.e.n.s.i.v.e. .a.n.d. .a.n.g.r.y. .J.o.y.:.I. .u.n.d.e.r.s.t.a.n.d. .t.h.a.t. .t.h.i.s. .m.u.s.t. .b.e. .d.i.f.f.i.c.u.l.t. .f.o.r. .y.o.u... .A.r.e. .t.h.e.r.e. .a.n.y. .s.p.e.c.i.f.i.c. .s.t.r.a.t.e.g.i.e.s. .t.h.a.t. .h.a.v.e. .h.e.l.p.e.d. .w.h.e.n. .c.o.n.v.e.r.s.a.t.i.o.n.s. .w.i.t.h. .y.o.u.r. .s.p.o.u.s.e. .b.e.c.o.m.e. .h.e.a.t.e.d.?. . . .P.a.t.i.e.n.t.:.i. .d.o.n.t. .k.n.o.w. .J.o.y.:.I.t.'.s. .o.k.a.y. .i.f. .y.o.u. .d.o.n.'.t. .k.n.o.w. .r.i.g.h.t. .a.w.a.y... .W.h.a.t. .d.o. .y.o.u. .f.e.e.l. .c.o.m.f.o.r.t.a.b.l.e. .d.o.i.n.g. .i.n. .t.h.e.s.e. .s.i.t.u.a.t.i.o.n.s.?. .A.r.e. .t.h.e.r.e. .a.n.y. .s.t.r.a.t.e.g.i.e.s. .t.h.a.t. .h.a.v.e. .h.e.l.p.e.d. .i.n. .t.h.e. .p.a.s.t. .w.h.e.n. .t.h.i.n.g.s. .b.e.c.o.m.e. .t.e.n.s.e. .b.e.t.w.e.e.n. .y.o.u. .a.n.d. .y.o.u.r. .s.p.o.u.s.e.?. . . .P.a.t.i.e.n.t.:.i. .j.u.s.t. .s.t.o.p.p.e.d. .t.a.l.k.i.n.g. .t.o. .h.e.r. .o.r. .c.h.a.n.g.e. .t.h.e. .s.u.b.j.e.c.t. .J.o.y.:.I.t. .s.o.u.n.d.s. .l.i.k.e. .y.o.u. .a.r.e. .d.o.i.n.g. .y.o.u.r. .b.e.s.t. .t.o. .f.i.n.d. .a. .w.a.y. .t.o. .m.a.n.a.g.e. .t.h.i.s... .I.s. .t.h.e.r.e. .a.n.y.t.h.i.n.g. .t.h.a.t. .h.a.s. .h.e.l.p.e.d. .m.a.k.e. .t.h.e. .s.i.t.u.a.t.i.o.n. .m.o.r.e. .c.o.m.f.o.r.t.a.b.l.e. .f.o.r. .y.o.u.?. . . .P.a.t.i.e.n.t.:.t.r.y.i.n.g. .n.o.t. .t.h.i.n.k.i.n.g. .a.b.o.u.t. .i.t. .J.o.y.:.I.t. .s.o.u.n.d.s. .l.i.k.e. .y.o.u. .a.r.e. .d.o.i.n.g. .y.o.u.r. .b.e.s.t. .t.o. .h.a.n.d.l.e. .t.h.i.s. .d.i.f.f.i.c.u.l.t. .s.i.t.u.a.t.i.o.n... .D.o. .y.o.u. .t.h.i.n.k. .i.t. .w.o.u.l.d. .h.e.l.p. .t.o. .t.a.l.k. .t.o. .a. .p.r.o.f.e.s.s.i.o.n.a.l. .o.r. .f.i.n.d. .a.d.d.i.t.i.o.n.a.l. .s.u.p.p.o.r.t.?. . . .P.a.t.i.e.n.t.:.n.o. .i. .h.a.v.e.n.t. .J.o.y.:.T.h.a.t.'.s. .u.n.d.e.r.s.t.a.n.d.a.b.l.e... .I.s. .t.h.e.r.e. .s.o.m.e.o.n.e. .w.h.o. .y.o.u. .f.e.e.l. .c.o.m.f.o.r.t.a.b.l.e. .t.a.l.k.i.n.g. .t.o. .a.b.o.u.t. .t.h.i.s.?. .H.o.w. .d.o.e.s. .h.a.v.i.n.g. .a. .c.o.n.v.e.r.s.a.t.i.o.n. .w.i.t.h. .t.h.e.m. .m.a.k.e. .y.o.u. .f.e.e.l.?. . . .P.a.t.i.e.n.t.:.i. .h.a.v.e.n.t. .t.a.l.k.e.d. .w.i.t.h. .a.n.y.o.n.e. .a.b.o.u.t. .t.h.i.s. .J.o.y.:.T.h.a.t.'.s. .u.n.d.e.r.s.t.a.n.d.a.b.l.e... .H.a.v.i.n.g. .s.o.m.e.o.n.e. .t.o. .t.a.l.k. .t.o. .c.a.n. .b.e. .b.e.n.e.f.i.c.i.a.l. .i.n. .d.i.f.f.i.c.u.l.t. .t.i.m.e.s. .l.i.k.e. .t.h.i.s... .I.s. .t.h.e.r.e. .a.n.y.o.n.e. .w.h.o. .y.o.u. .t.r.u.s.t. .t.h.a.t. .y.o.u. .f.e.e.l. .c.o.m.f.o.r.t.a.b.l.e. .s.p.e.a.k.i.n.g. .w.i.t.h. .a.b.o.u.t. .y.o.u.r. .c.o.n.c.e.r.n.s.?. . . .P.a.t.i.e.n.t.:.t.h.e.r.e. .i.s. .n.o. .o.n.e.,. .e.x.c.e.p.t. .m.a.y.b.e. .m.y. .m.o.m. .J.o.y.:.T.a.l.k.i.n.g. .t.o. .y.o.u.r. .m.o.m. .c.a.n. .b.e. .a. .g.r.e.a.t. .s.t.a.r.t... .I.s. .t.h.e.r.e. .a.n.y.t.h.i.n.g. .i.n. .p.a.r.t.i.c.u.l.a.r. .t.h.a.t. .y.o.u. .w.a.n.t. .t.o. .s.h.a.r.e. .w.i.t.h. .h.e.r. .a.b.o.u.t. .w.h.a.t. .i.s. .g.o.i.n.g. .o.n.?. .H.o.w. .d.o.e.s. .t.h.e. .i.d.e.a. .o.f. .h.a.v.i.n.g. .t.h.i.s. .c.o.n.v.e.r.s.a.t.i.o.n. .m.a.k.e. .y.o.u. .f.e.e.l.?. . . .P.a.t.i.e.n.t.:.y.e.a. .l.i.k.e. .I. .s.a.i.d.,. .a.b.o.u.t. .t.h.i.s. .t.o.p.i.c. .t.h.a.t. .i.m. .n.o.t. .v.e.r.y. .c.o.m.f.o.r.t.a.b.l.e. .w.i.t.h.,. .d.o. .y.o.u. .s.t.i.l.l. .r.e.m.e.m.b.e.r. .w.h.i.c.h.?. .J.o.y.:.Y.e.s.,. .y.o.u. .m.e.n.t.i.o.n.e.d. .t.h.a.t. .y.o.u.r. .s.p.o.u.s.e. .m.a.y. .b.e. .c.h.e.a.t.i.n.g. .o.n. .y.o.u... .H.o.w. .w.o.u.l.d. .y.o.u. .l.i.k.e. .t.o. .a.p.p.r.o.a.c.h. .t.h.i.s. .c.o.n.v.e.r.s.a.t.i.o.n. .w.i.t.h. .y.o.u.r. .m.o.m.?. . . .P.a.t.i.e.n.t.:.t.e.l.l. .h.e.r. .a.b.o.u.t. .m.y. .s.u.s.p.i.c.i.s.i.o.n. .i. .g.u.e.s.s. .J.o.y.:.I.t. .c.a.n. .b.e. .d.i.f.f.i.c.u.l.t. .t.o. .b.r.i.n.g. .u.p. .a. .t.o.p.i.c. .l.i.k.e. .t.h.i.s.,. .b.u.t. .i.t.'.s. .i.m.p.o.r.t.a.n.t. .t.h.a.t. .y.o.u. .h.a.v.e. .a.n. .o.p.e.n. .c.o.n.v.e.r.s.a.t.i.o.n. .w.i.t.h. .h.e.r... .W.o.u.l.d. .y.o.u. .l.i.k.e. .a.n.y. .a.d.v.i.c.e. .o.n. .h.o.w. .t.o. .s.t.a.r.t. .t.h.e. .c.o.n.v.e.r.s.a.t.i.o.n.?. . . .P.a.t.i.e.n.t.:.y.e.s. .p.l.e.a.s.e. .J.o.y.:.I.t. .c.a.n. .h.e.l.p. .t.o. .s.t.a.r.t. .b.y. .l.e.t.t.i.n.g. .y.o.u.r. .m.o.m. .k.n.o.w. .w.h.y. .y.o.u. .d.e.c.i.d.e.d. .t.o. .t.a.l.k. .t.o. .h.e.r. .a.b.o.u.t. .t.h.i.s... .S.h.a.r.i.n.g. .h.o.w. .y.o.u. .a.r.e. .f.e.e.l.i.n.g. .a.n.d. .a.s.k.i.n.g. .f.o.r. .h.e.r. .a.d.v.i.c.e. .m.i.g.h.t. .b.e. .a. .g.o.o.d. .w.a.y. .t.o. .o.p.e.n. .t.h.e. .c.o.n.v.e.r.s.a.t.i.o.n... .I.'.m. .h.e.r.e. .i.f. .y.o.u. .n.e.e.d. .a.n.y.t.h.i.n.g. .e.l.s.e. .b.e.f.o.r.e. .o.r. .a.f.t.e.r. .s.p.e.a.k.i.n.g. .w.i.t.h. .y.o.u.r. .m.o.m..\"]\n"
|
274 |
]
|
275 |
}
|
276 |
],
|
|
|
304 |
"# Example usage\n",
|
305 |
"input_string = \"This is a sample input string. It can be quite long. This function splits the input string into parts, each of which is no longer than the maximum length defined by the tokenizer and each of which ends on a full stop.\"\n",
|
306 |
"max_length = 512\n",
|
307 |
+
"split_strings = split_input_string(test3_string, tokenizer, max_length)\n",
|
308 |
"print(split_strings)\n"
|
309 |
]
|
310 |
},
|
twilio.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
from flask import Flask, request, session
|
2 |
-
from flask import render_template, redirect, url_for
|
3 |
-
from twilio.twiml.messaging_response import MessagingResponse
|
4 |
-
from joy import ask
|
5 |
-
|
6 |
-
app = Flask(__name__)
|
7 |
-
|
8 |
-
#app.config[‘SECRET_KEY’] = ‘any-random-string’ what is this for?
|
9 |
-
|
10 |
-
@app.route('/joy', methods=['POST'])
|
11 |
-
def joy():
|
12 |
-
incoming_msg = request.values['Body']
|
13 |
-
chat_log = session.get('chat_log')
|
14 |
-
answer, session['chat_log'] = ask(incoming_msg, chat_log)
|
15 |
-
msg = MessagingResponse()
|
16 |
-
msg.message(answer)
|
17 |
-
return str(msg)
|
18 |
-
|
19 |
-
if __name__ == '__main__':
|
20 |
-
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|