merge prediction optimization
This commit is contained in:
parent
33b1e26a2a
commit
cd6167f80a
@ -139,7 +139,9 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#sys.path.append(\"..\")\n",
|
||||
@ -151,7 +153,9 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tmp_dict = clf_naive.prepareData()"
|
||||
@ -167,8 +171,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def merged_prediction(msg , split = 0.5 , number = 8, target_emojis = top_emojis):\n",
|
||||
@ -178,10 +184,23 @@
|
||||
" number_naive = round((1-split)*number)\n",
|
||||
" \n",
|
||||
" #predict emojis with the naive approach\n",
|
||||
" prediction_naive = clf_naive.predict(sentence = msg, lookup= tmp_dict, n = number_naive)\n",
|
||||
" prediction_naive , prediction_naive_values = clf_naive.predict(sentence = msg, lookup= tmp_dict, n = number_naive)\n",
|
||||
"\n",
|
||||
" #filter 0 values\n",
|
||||
" tmp1 = []\n",
|
||||
" tmp2 = []\n",
|
||||
" epsilon = 0.0001\n",
|
||||
"\n",
|
||||
" for i in range(len(prediction_naive)):\n",
|
||||
" if(abs(prediction_naive_values[i]) > epsilon):\n",
|
||||
" tmp1.append(prediction_naive[i])\n",
|
||||
" tmp2.append(prediction_naive[i])\n",
|
||||
"\n",
|
||||
" prediction_naive = tmp1\n",
|
||||
" prediction_naive_values = tmp2\n",
|
||||
" \n",
|
||||
" if(len(prediction_naive) < number_naive):\n",
|
||||
" print(\"only few matches\")\n",
|
||||
" #print(\"only few matches\")\n",
|
||||
" number_advanced = number - len(prediction_naive)\n",
|
||||
" \n",
|
||||
" #print(number, number_advanced, number_naive)\n",
|
||||
@ -222,8 +241,9 @@
|
||||
" #p = ed.sentiment_vector_to_emoji(sent,n_results = 8, custom_target_emojis=top_emojis)\n",
|
||||
" \n",
|
||||
" #merged prediction\n",
|
||||
" if(current_message != \"\"):\n",
|
||||
" p = merged_prediction(msg = current_message, target_emojis=top_emojis)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" predictions = p\n",
|
||||
" update_descriptions()"
|
||||
]
|
||||
@ -527,13 +547,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "9b6fd63901c84db9a5a2d10399053cb3",
|
||||
"model_id": "3b8a6a311c1e4a1bb2b711d59246577a",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@ -543,16 +563,6 @@
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"8 4 4\n",
|
||||
"8 4 4\n",
|
||||
"8 4 4\n",
|
||||
"8 4 4\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
Loading…
Reference in New Issue
Block a user