Spaces:
Runtime error
Runtime error
Commit ·
8f762f0
1
Parent(s): a600a71
reduce log event pump
Browse files
app.py
CHANGED
|
@@ -25,7 +25,6 @@ from sklearn.naive_bayes import MultinomialNB
|
|
| 25 |
df_product_title = pd.read_csv('product_title_100.csv')
|
| 26 |
df = df_product_title[df_product_title.subcategory!='อื่นๆ'].copy()
|
| 27 |
|
| 28 |
-
|
| 29 |
target = df.iloc[:, 2]
|
| 30 |
title = df.iloc[:, 4]
|
| 31 |
rand = random.randint(0,len(df))
|
|
@@ -34,9 +33,6 @@ print('Title example:',title[rand:rand+1].values[0])
|
|
| 34 |
print('Token example:',word_tokenize(title[rand:rand+1].values[0],engine='longest'))
|
| 35 |
|
| 36 |
# In[234]:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
sh = gc.open('Subcategory Prediction')
|
| 41 |
wk = sh.worksheet_by_title('huggingface-test')
|
| 42 |
wk2 = sh.worksheet_by_title('correction')
|
|
@@ -80,7 +76,6 @@ def count_str(string):
|
|
| 80 |
except: pass
|
| 81 |
return result
|
| 82 |
|
| 83 |
-
|
| 84 |
# In[239]:
|
| 85 |
# run on data set
|
| 86 |
temp = np.vectorize(count_str, otypes=[object])(title_split)
|
|
@@ -93,8 +88,6 @@ for sl in temp:
|
|
| 93 |
for e in sl:
|
| 94 |
test.append(e)
|
| 95 |
test_2.append(test)
|
| 96 |
-
|
| 97 |
-
# In[241]:
|
| 98 |
x_f1 = np.array(test_2)
|
| 99 |
|
| 100 |
# In[242]:
|
|
@@ -104,20 +97,6 @@ model.fit(x_f1, target)
|
|
| 104 |
y_pred = model.predict(x_f1)
|
| 105 |
print("Model Acc. on train data %f%%"
|
| 106 |
% ((target == y_pred).sum() / x_f1.shape[0] * 100))
|
| 107 |
-
# In[258]:
|
| 108 |
-
## test prediictiion
|
| 109 |
-
word = 'เขียนบทความ'
|
| 110 |
-
token = word_tokenize(word,engine='longest')
|
| 111 |
-
clean_token = []
|
| 112 |
-
for i in token:
|
| 113 |
-
res = token_processing(i)
|
| 114 |
-
if res != None : clean_token.append(res)
|
| 115 |
-
## try: clean_token.remove('')
|
| 116 |
-
## except : pass
|
| 117 |
-
print('Tokenizied:',token)
|
| 118 |
-
print('Clean Tokenizied:',clean_token)
|
| 119 |
-
model.predict(count_str(clean_token).reshape(1,-1))[0]
|
| 120 |
-
|
| 121 |
# In[259]:
|
| 122 |
def predict_prob_df(word):
|
| 123 |
token = word_tokenize(word,engine='longest')
|
|
@@ -143,16 +122,23 @@ def subcat_predict(word):
|
|
| 143 |
return dict(zip(pr.loc[:2,'predict'],pr.loc[:2,'prob']))
|
| 144 |
log = []
|
| 145 |
log_correct= []
|
|
|
|
|
|
|
| 146 |
|
| 147 |
def correct_number1(number):
|
|
|
|
|
|
|
| 148 |
log.append([text_,'1-right',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 149 |
-
|
|
|
|
| 150 |
return 'thank for teaching the model'
|
| 151 |
|
| 152 |
def correct_number2(number):
|
|
|
|
| 153 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 154 |
log.append([text_,'2-right',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 155 |
-
|
|
|
|
| 156 |
return 'thank for teaching the model'
|
| 157 |
|
| 158 |
def correct_number3(number):
|
|
@@ -160,17 +146,19 @@ def correct_number3(number):
|
|
| 160 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 161 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 162 |
log.append([text_,'3-right',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 163 |
-
|
| 164 |
-
|
| 165 |
return 'thank for teaching the model'
|
| 166 |
|
| 167 |
def feedback(correction_input,text_input):
|
|
|
|
|
|
|
| 168 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 169 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 170 |
log.append([text_,'3-wrong',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 171 |
log_correct.append([text_,'feedback',pr.loc[0,'predict'],pr.loc[0,'prob'],correction_input])
|
| 172 |
-
|
| 173 |
-
|
| 174 |
return 'thank for teaching the model'
|
| 175 |
with demo:
|
| 176 |
with gr.Row():
|
|
|
|
| 25 |
df_product_title = pd.read_csv('product_title_100.csv')
|
| 26 |
df = df_product_title[df_product_title.subcategory!='อื่นๆ'].copy()
|
| 27 |
|
|
|
|
| 28 |
target = df.iloc[:, 2]
|
| 29 |
title = df.iloc[:, 4]
|
| 30 |
rand = random.randint(0,len(df))
|
|
|
|
| 33 |
print('Token example:',word_tokenize(title[rand:rand+1].values[0],engine='longest'))
|
| 34 |
|
| 35 |
# In[234]:
|
|
|
|
|
|
|
|
|
|
| 36 |
sh = gc.open('Subcategory Prediction')
|
| 37 |
wk = sh.worksheet_by_title('huggingface-test')
|
| 38 |
wk2 = sh.worksheet_by_title('correction')
|
|
|
|
| 76 |
except: pass
|
| 77 |
return result
|
| 78 |
|
|
|
|
| 79 |
# In[239]:
|
| 80 |
# run on data set
|
| 81 |
temp = np.vectorize(count_str, otypes=[object])(title_split)
|
|
|
|
| 88 |
for e in sl:
|
| 89 |
test.append(e)
|
| 90 |
test_2.append(test)
|
|
|
|
|
|
|
| 91 |
x_f1 = np.array(test_2)
|
| 92 |
|
| 93 |
# In[242]:
|
|
|
|
| 97 |
y_pred = model.predict(x_f1)
|
| 98 |
print("Model Acc. on train data %f%%"
|
| 99 |
% ((target == y_pred).sum() / x_f1.shape[0] * 100))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# In[259]:
|
| 101 |
def predict_prob_df(word):
|
| 102 |
token = word_tokenize(word,engine='longest')
|
|
|
|
| 122 |
return dict(zip(pr.loc[:2,'predict'],pr.loc[:2,'prob']))
|
| 123 |
log = []
|
| 124 |
log_correct= []
|
| 125 |
+
num = 0
|
| 126 |
+
num_2 = 0
|
| 127 |
|
| 128 |
def correct_number1(number):
|
| 129 |
+
global num
|
| 130 |
+
num+=1
|
| 131 |
log.append([text_,'1-right',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 132 |
+
if (num % 10 == 0) :
|
| 133 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 134 |
return 'thank for teaching the model'
|
| 135 |
|
| 136 |
def correct_number2(number):
|
| 137 |
+
global num
|
| 138 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 139 |
log.append([text_,'2-right',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 140 |
+
if (num % 10 == 0) :
|
| 141 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 142 |
return 'thank for teaching the model'
|
| 143 |
|
| 144 |
def correct_number3(number):
|
|
|
|
| 146 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 147 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 148 |
log.append([text_,'3-right',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 149 |
+
if (num % 10 == 0) :
|
| 150 |
+
wk.set_dataframe(pd.DataFrame(log,columns=['title','label','sc_pred','prob']),'A1')
|
| 151 |
return 'thank for teaching the model'
|
| 152 |
|
| 153 |
def feedback(correction_input,text_input):
|
| 154 |
+
global num , num_2
|
| 155 |
+
|
| 156 |
log.append([text_,'1-wrong',pr.loc[0,'predict'],pr.loc[0,'prob']])
|
| 157 |
log.append([text_,'2-wrong',pr.loc[1,'predict'],pr.loc[1,'prob']])
|
| 158 |
log.append([text_,'3-wrong',pr.loc[2,'predict'],pr.loc[2,'prob']])
|
| 159 |
log_correct.append([text_,'feedback',pr.loc[0,'predict'],pr.loc[0,'prob'],correction_input])
|
| 160 |
+
if (num_2 % 5 == 0 ):
|
| 161 |
+
wk2.set_dataframe(pd.DataFrame(log_correct,columns=['title','label','sc_pred','prob','real_sc']),'A1')
|
| 162 |
return 'thank for teaching the model'
|
| 163 |
with demo:
|
| 164 |
with gr.Row():
|