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