Spaces:
Sleeping
Sleeping
edit code
Browse files- .ipynb_checkpoints/Untitled-checkpoint.ipynb +6 -0
- .ipynb_checkpoints/utils-checkpoint.py +8 -8
- Untitled.ipynb +126 -0
- utils.py +8 -8
.ipynb_checkpoints/Untitled-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [],
|
| 3 |
+
"metadata": {},
|
| 4 |
+
"nbformat": 4,
|
| 5 |
+
"nbformat_minor": 5
|
| 6 |
+
}
|
.ipynb_checkpoints/utils-checkpoint.py
CHANGED
|
@@ -24,17 +24,17 @@ def get_single_prediction(text):
|
|
| 24 |
# manipulate data into a format that we pass to our model
|
| 25 |
text = text.lower().strip() #lower case
|
| 26 |
|
| 27 |
-
# Vectorise text
|
| 28 |
-
text_vectors = tfidf.transform(
|
| 29 |
-
|
| 30 |
# Make topic predictions
|
| 31 |
-
results = svc.predict_proba(text_vectors).squeeze().round(2)
|
| 32 |
-
|
| 33 |
pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)
|
| 34 |
-
|
| 35 |
# Make sentiment predictions
|
| 36 |
-
text_vectors_sentiment = tfidf_sentiment.transform(
|
| 37 |
-
|
| 38 |
results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)
|
| 39 |
pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)
|
| 40 |
|
|
|
|
| 24 |
# manipulate data into a format that we pass to our model
|
| 25 |
text = text.lower().strip() #lower case
|
| 26 |
|
| 27 |
+
# Vectorise text
|
| 28 |
+
text_vectors = tfidf.transform([text])
|
| 29 |
+
|
| 30 |
# Make topic predictions
|
| 31 |
+
results = svc.predict_proba(text_vectors.reshape()).squeeze().round(2)
|
| 32 |
+
|
| 33 |
pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)
|
| 34 |
+
|
| 35 |
# Make sentiment predictions
|
| 36 |
+
text_vectors_sentiment = tfidf_sentiment.transform([text])
|
| 37 |
+
|
| 38 |
results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)
|
| 39 |
pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)
|
| 40 |
|
Untitled.ipynb
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 10,
|
| 6 |
+
"id": "8e91c310-bc69-4a28-9197-e180aaaa491f",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"utils imported!\n"
|
| 14 |
+
]
|
| 15 |
+
}
|
| 16 |
+
],
|
| 17 |
+
"source": [
|
| 18 |
+
"import re\n",
|
| 19 |
+
"import pickle\n",
|
| 20 |
+
"import numpy as np\n",
|
| 21 |
+
"import pandas as pd\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"tfidf = pickle.load(open('models/tfidf.sav', 'rb'))\n",
|
| 25 |
+
"svc_sentiment = pickle.load(open('models/sentiment_model.sav', 'rb'))\n",
|
| 26 |
+
"tfidf_sentiment = pickle.load(open('models/tfidf_sentiment.sav', 'rb'))\n",
|
| 27 |
+
"svc = pickle.load(open('models/svc_model.sav', 'rb'))\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"labels = [\n",
|
| 30 |
+
" 'Product quality', 'Knowledge',\n",
|
| 31 |
+
" 'Appointment', 'Service etiquette', 'Waiting time',\n",
|
| 32 |
+
" 'Repair speed', 'Repair cost', 'Repair quality', 'Warranty',\n",
|
| 33 |
+
" 'Product replacement', 'Loan sets']\n",
|
| 34 |
+
"\n",
|
| 35 |
+
"sample_file = pd.read_csv('sample.csv').to_csv(index=False).encode('utf-8')\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"print('utils imported!')\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"def get_single_prediction(text):\n",
|
| 40 |
+
" \n",
|
| 41 |
+
" # manipulate data into a format that we pass to our model\n",
|
| 42 |
+
" text = text.lower().strip() #lower case\n",
|
| 43 |
+
"\n",
|
| 44 |
+
" # Vectorise text and store in new dataframe. Sentence vector = average of word vectors\n",
|
| 45 |
+
" text_vectors = tfidf.transform(list(text))\n",
|
| 46 |
+
" print(text_vectors.shape)\n",
|
| 47 |
+
" # Make topic predictions\n",
|
| 48 |
+
" results = svc.predict_proba(text_vectors).squeeze().round(2)\n",
|
| 49 |
+
" print(results.shape)\n",
|
| 50 |
+
"\n",
|
| 51 |
+
" pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)\n",
|
| 52 |
+
"\n",
|
| 53 |
+
" # Make sentiment predictions\n",
|
| 54 |
+
" text_vectors_sentiment = tfidf_sentiment.transform(list(text))\n",
|
| 55 |
+
"\n",
|
| 56 |
+
" results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)\n",
|
| 57 |
+
" pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"cell_type": "code",
|
| 62 |
+
"execution_count": 11,
|
| 63 |
+
"id": "b940cb16-c287-4fef-accc-fa54f20c3864",
|
| 64 |
+
"metadata": {},
|
| 65 |
+
"outputs": [
|
| 66 |
+
{
|
| 67 |
+
"name": "stdout",
|
| 68 |
+
"output_type": "stream",
|
| 69 |
+
"text": [
|
| 70 |
+
"(5, 500)\n",
|
| 71 |
+
"(5, 11)\n"
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"ename": "ValueError",
|
| 76 |
+
"evalue": "Data must be 1-dimensional",
|
| 77 |
+
"output_type": "error",
|
| 78 |
+
"traceback": [
|
| 79 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 80 |
+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
|
| 81 |
+
"\u001b[1;32m<ipython-input-11-5105897e9757>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mget_single_prediction\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'hello'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
| 82 |
+
"\u001b[1;32m<ipython-input-10-f4ad9599dac2>\u001b[0m in \u001b[0;36mget_single_prediction\u001b[1;34m(text)\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 33\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 34\u001b[1;33m \u001b[0mpred_prob\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'topic'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mlabels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'probability'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'probability'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mascending\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 35\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 36\u001b[0m \u001b[1;31m# Make sentiment predictions\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 83 |
+
"\u001b[1;32mC:\\HA\\Python\\Anaconda\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[0;32m 527\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 528\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 529\u001b[1;33m \u001b[0mmgr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minit_dict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 530\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mMaskedArray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 531\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmrecords\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mmrecords\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 84 |
+
"\u001b[1;32mC:\\HA\\Python\\Anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36minit_dict\u001b[1;34m(data, index, columns, dtype)\u001b[0m\n\u001b[0;32m 285\u001b[0m \u001b[0marr\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mis_datetime64tz_dtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marr\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32melse\u001b[0m \u001b[0marr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0marr\u001b[0m \u001b[1;32min\u001b[0m \u001b[0marrays\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 286\u001b[0m ]\n\u001b[1;32m--> 287\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0marrays_to_mgr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata_names\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 288\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 289\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 85 |
+
"\u001b[1;32mC:\\HA\\Python\\Anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36marrays_to_mgr\u001b[1;34m(arrays, arr_names, index, columns, dtype, verify_integrity)\u001b[0m\n\u001b[0;32m 83\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 84\u001b[0m \u001b[1;31m# don't force copy because getting jammed in an ndarray anyway\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 85\u001b[1;33m \u001b[0marrays\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_homogenize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marrays\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 86\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 87\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mensure_index\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 86 |
+
"\u001b[1;32mC:\\HA\\Python\\Anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36m_homogenize\u001b[1;34m(data, index, dtype)\u001b[0m\n\u001b[0;32m 353\u001b[0m \u001b[0mval\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 354\u001b[0m \u001b[0mval\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfast_multiget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moindex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 355\u001b[1;33m val = sanitize_array(\n\u001b[0m\u001b[0;32m 356\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mraise_cast_failure\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 357\u001b[0m )\n",
|
| 87 |
+
"\u001b[1;32mC:\\HA\\Python\\Anaconda\\lib\\site-packages\\pandas\\core\\construction.py\u001b[0m in \u001b[0;36msanitize_array\u001b[1;34m(data, index, dtype, copy, raise_cast_failure)\u001b[0m\n\u001b[0;32m 527\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0msubarr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 528\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 529\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Data must be 1-dimensional\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 530\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 531\u001b[0m \u001b[0msubarr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0masarray_tuplesafe\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 88 |
+
"\u001b[1;31mValueError\u001b[0m: Data must be 1-dimensional"
|
| 89 |
+
]
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"source": [
|
| 93 |
+
"get_single_prediction('hello')"
|
| 94 |
+
]
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"cell_type": "code",
|
| 98 |
+
"execution_count": null,
|
| 99 |
+
"id": "1f68efcf-479d-41de-be1e-e94d00b58fab",
|
| 100 |
+
"metadata": {},
|
| 101 |
+
"outputs": [],
|
| 102 |
+
"source": []
|
| 103 |
+
}
|
| 104 |
+
],
|
| 105 |
+
"metadata": {
|
| 106 |
+
"kernelspec": {
|
| 107 |
+
"display_name": "Python 3",
|
| 108 |
+
"language": "python",
|
| 109 |
+
"name": "python3"
|
| 110 |
+
},
|
| 111 |
+
"language_info": {
|
| 112 |
+
"codemirror_mode": {
|
| 113 |
+
"name": "ipython",
|
| 114 |
+
"version": 3
|
| 115 |
+
},
|
| 116 |
+
"file_extension": ".py",
|
| 117 |
+
"mimetype": "text/x-python",
|
| 118 |
+
"name": "python",
|
| 119 |
+
"nbconvert_exporter": "python",
|
| 120 |
+
"pygments_lexer": "ipython3",
|
| 121 |
+
"version": "3.8.8"
|
| 122 |
+
}
|
| 123 |
+
},
|
| 124 |
+
"nbformat": 4,
|
| 125 |
+
"nbformat_minor": 5
|
| 126 |
+
}
|
utils.py
CHANGED
|
@@ -24,17 +24,17 @@ def get_single_prediction(text):
|
|
| 24 |
# manipulate data into a format that we pass to our model
|
| 25 |
text = text.lower().strip() #lower case
|
| 26 |
|
| 27 |
-
# Vectorise text
|
| 28 |
-
text_vectors = tfidf.transform(
|
| 29 |
-
|
| 30 |
# Make topic predictions
|
| 31 |
-
results = svc.predict_proba(text_vectors).squeeze().round(2)
|
| 32 |
-
|
| 33 |
pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)
|
| 34 |
-
|
| 35 |
# Make sentiment predictions
|
| 36 |
-
text_vectors_sentiment = tfidf_sentiment.transform(
|
| 37 |
-
|
| 38 |
results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)
|
| 39 |
pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)
|
| 40 |
|
|
|
|
| 24 |
# manipulate data into a format that we pass to our model
|
| 25 |
text = text.lower().strip() #lower case
|
| 26 |
|
| 27 |
+
# Vectorise text
|
| 28 |
+
text_vectors = tfidf.transform([text])
|
| 29 |
+
|
| 30 |
# Make topic predictions
|
| 31 |
+
results = svc.predict_proba(text_vectors.reshape()).squeeze().round(2)
|
| 32 |
+
|
| 33 |
pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)
|
| 34 |
+
|
| 35 |
# Make sentiment predictions
|
| 36 |
+
text_vectors_sentiment = tfidf_sentiment.transform([text])
|
| 37 |
+
|
| 38 |
results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)
|
| 39 |
pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)
|
| 40 |
|