Skip to content

Commit

Permalink
Fix the logic for seq2seq
Browse files Browse the repository at this point in the history
  • Loading branch information
healess committed Nov 27, 2017
1 parent 79631e2 commit abeae13
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 61 deletions.
110 changes: 58 additions & 52 deletions chap20_hoayi_api_guide/04.nlp/seq2seq.ipynb
Expand Up @@ -71,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 37,
"metadata": {
"collapsed": false
},
Expand All @@ -80,18 +80,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : nn100999\n",
"evaluation result : nn100999\n"
"evaluation result : {'graph': [], 'nn_id': 'seq2seq_one_hot_2'}\n",
"evaluation result : 1\n"
]
}
],
"source": [
"import requests\n",
"import json, os\n",
"\n",
"nn_id = 'nn100999' # put some key value you want to test\n",
"nn_id = 'seq2seq_one_hot_2' # put some key value you want to test\n",
"\n",
"url = \"{0}:{1}\".format(os.environ['HOSTNAME'] , \"8000\")\n",
"url = \"{0}:{1}\".format(os.environ['HOSTNAME'] , \"8989\")\n",
"\n",
"####(1) 네트워크 생성 ####\n",
"resp = requests.post('http://' + url + '/api/v1/type/common/target/nninfo/nnid/' + nn_id + '/',\n",
Expand Down Expand Up @@ -143,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 38,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -182,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 39,
"metadata": {
"collapsed": false
},
Expand All @@ -199,7 +199,7 @@
"import os\n",
"\n",
"return_dict = {}\n",
"return_dict['test'] = open('../../data/seq2seq_mansearch_2.csv', 'rb')\n",
"return_dict['test'] = open('../../data/seq2seq.csv', 'rb')\n",
"\n",
"resp = requests.post('http://' + url + '/api/v1/type/wf/state/framedata/src/local/form/raw/prg/source/nnid/'+nn_id+'/ver/1/node/data_csv_node/',\n",
" files = return_dict)\n",
Expand All @@ -222,7 +222,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 40,
"metadata": {
"collapsed": false
},
Expand All @@ -231,7 +231,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : /hoya_str_root/nn100999/1/data_csv_node\n"
"evaluation result : /hoya_str_root/seq2seq_one_hot_2/common/data_csv_node\n"
]
}
],
Expand Down Expand Up @@ -272,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 41,
"metadata": {
"collapsed": false
},
Expand All @@ -281,7 +281,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : {'decode_column': 'decode', 'decode_len': 10, 'encode_column': 'encode', 'encode_len': 10, 'preprocess': 'mecab'}\n"
"evaluation result : {'encode_column': 'encode', 'encode_len': 10, 'decode_column': 'decode', 'preprocess': 'mecab', 'decode_len': 10}\n"
]
}
],
Expand Down Expand Up @@ -322,7 +322,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 42,
"metadata": {
"collapsed": false
},
Expand All @@ -331,7 +331,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : {'drop_out': 0.8, 'cell_size': 500, 'word_embed_type': 'w2v', 'decoder_depth': 2, 'early_stop': 0.9, 'encoder_depth': 2, 'batch_size': 100, 'word_embed_id': 'nn05', 'decoder_len': 10, 'model_path': '/hoya_model_root/nn100999/1/netconf_node', 'learning_rate': 0.001, 'encoder_len': 10, 'cell_type': 'lstm', 'iter': 100}\n"
"evaluation result : {'encoder_len': 10, 'early_stop': 0.9, 'iter': 100, 'cell_size': 500, 'vocab_size': 200, 'model_path': '/hoya_model_root/seq2seq_one_hot_2/1/netconf_node', 'decoder_depth': 2, 'learning_rate': 0.001, 'word_embed_id': '', 'drop_out': 0.8, 'cell_type': 'lstm', 'word_embed_type': 'onehot', 'batch_size': 5, 'encoder_depth': 2, 'decoder_len': 10}\n"
]
}
],
Expand All @@ -346,8 +346,9 @@
" \"cell_type\" : \"lstm\", #vanila, lstm, gru\n",
" \"cell_size\" : 500,\n",
" \"drop_out\" : 0.8,\n",
" \"word_embed_type\" : \"w2v\", #w2v, onehot\n",
" \"word_embed_id\" : \"nn05\",\n",
" \"word_embed_type\" : \"onehot\", #w2v, onehot\n",
" \"word_embed_id\" : \"\", #onehot 시 null\n",
" \"vocab_size\" : 200,\n",
" \"batch_size\" : 5,\n",
" \"iter\" : 100,\n",
" \"early_stop\" : 0.9,\n",
Expand All @@ -367,7 +368,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 43,
"metadata": {
"collapsed": false
},
Expand All @@ -377,16 +378,16 @@
"output_type": "stream",
"text": [
"evaluation result : ['1 file upload success']\n",
"evaluation result : {'type': 'csv', 'source_type': 'local', 'multi_node_flag': None, 'source_server': 'local', 'source_sql': 'all', 'max_sentence_len': 0, 'source_path': '/hoya_src_root/nn100999/1/evaldata', 'preprocess': 'none', 'store_path': '/hoya_str_root/nn100999/1/evaldata', 'source_parse_type': 'raw'}\n",
"evaluation result : {'source_server': 'local', 'predict_path': '/hoya_src_root/seq2seq_one_hot_2/1/predict', 'source_path': '/hoya_src_root/seq2seq_one_hot_2/common/evaldata', 'source_parse_type': 'raw', 'type': 'csv', 'multi_node_flag': None, 'drop_duplicate': False, 'max_sentence_len': 0, 'source_type': 'local', 'source_sql': 'all'}\n",
"evaluation result : none\n",
"evaluation result : /hoya_str_root/nn100999/1/evaldata\n",
"evaluation result : /hoya_str_root/seq2seq_one_hot_2/common/evaldata\n",
"evaluation result : {'type': 'seq2seq'}\n"
]
}
],
"source": [
"return_dict = {}\n",
"return_dict['test'] = open('../../data/seq2seq_mansearch_2.csv', 'rb')\n",
"return_dict['test'] = open('../../data/seq2seq.csv', 'rb')\n",
"\n",
"# 테스트 데이터 업로드\n",
"resp = requests.post('http://' + url + '/api/v1/type/wf/state/framedata/src/local/form/raw/prg/source/nnid/'+nn_id+'/ver/1/node/evaldata/',\n",
Expand Down Expand Up @@ -450,11 +451,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : {'seq2seq_one_hot_2_1': {'nn_batch_ver_id': '', 'result_info': {'predict': ['@ 차원/NNG 창조/NNG 레아/NNG ./SF SF # # # #', '@ 국왕/NNG 창조신/NNG ./SF SF # # # # #', '@ 들려오/VV 는/ETM 말/NNG 의/JKG 울음/NNG 소리/NNG ./SF SF #', '@ 또/MAG 다른/MM 이름/NNG 은/JX 한스/NNP 게/NNB+JKS 이시스/NNP ./SF SF', '@ 넌/NP+JX 반드시/MAG 죽/VV 는다고/EF ./SF SF # # #', '@ 넌/NP+JX 반드시/MAG 죽/VV 는다고/EF ./SF ./SF SF # #'], 'question': ['# # # # 드래곤/NNP 은/JX 무엇/NP 인가/VCP+EF ./SF SF', '# # # 칼베/NNP 리온/NNP 은/JX 누구/NP 인가/VCP+EF ./SF SF', '# 잭/NNG 의/JKG 말/NNG 이/JKS 끝남/VV+ETN 과/JC 동시/NNG ./SF SF', '# 모든/MM 죽/VV 은/ETM 자/NNB 들/XSN 의/JKG 주인/NNG ./SF SF', '# # # # 넌/NP+JX 반드시/MAG 죽/VV 는다/EF ./SF SF', '# # # # 세/MM 사람/NNG 의/JKG 메시지/NNG ./SF SF'], 'accuracy': [None, None, None, None, None, None], 'answer': ['@ 차원/NNG 창조/NNG 레아/NNG ./SF SF # # # #', '@ 국왕/NNG 창조신/NNG ./SF SF # # # # #', '@ 들려오/VV 는/ETM 말/NNG 의/JKG 울음/NNG 소리/NNG ./SF SF #', '@ 또/MAG 다른/MM 이름/NNG 은/JX 한스/NNP 게/NNB+JKS 이시스/NNP ./SF SF', '@ 넌/NP+JX 반드시/MAG 죽/VV 는다고/EF ./SF SF # # #', '@ 아빠/NNG 는/JX 바보/NNG ./SF SF # # # #']}, 'nn_wf_ver_id': '1', 'nn_id': 'seq2seq_one_hot_2', 'accuracy': 0.0}}\n"
]
}
],
"source": [
"# Run All Workflow\n",
"resp = requests.post('http://' + url + '/api/v1/type/runmanager/state/train/nnid/'+nn_id+'/ver/1/')\n",
Expand Down Expand Up @@ -485,7 +494,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 51,
"metadata": {
"collapsed": false
},
Expand All @@ -494,44 +503,41 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : START 넌/NP+JX 는/JX 레아/NNG ./SF ./SF SF SF SF SF\n",
"evaluation result : START 국왕/NNG 창조신/NNG ./SF SF SF SF SF SF SF\n",
"evaluation result : START 들려오/VV 는/ETM 이름/NNG 의/JKG 울음/NNG 소리/NNG ./SF ./SF SF\n",
"evaluation result : START 들려오/VV 는/ETM 이름/NNG 의/JKG 울음/NNG 소리/NNG ./SF ./SF SF\n",
"evaluation result : START 넌/NP+JX 는/JX 레아/NNG ./SF ./SF SF SF SF SF\n"
"evaluation result : [' 들려오 는 말 의 울음 소리 .']\n"
]
}
],
"source": [
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/nn00007/ver/active/',\n",
" json={\"input_data\" : \"드래곤은 무엇인가?\" }\n",
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/' + nn_id + '/ver/active/',\n",
" json={\"input_data\" : \"잭의 말이 끝남과 동시.\" }\n",
" )\n",
"data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(data))\n",
"#data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(resp.json()))\n",
"\n",
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/nn00007/ver/active/',\n",
" json={\"input_data\" : \"칼베리온은 누구인가?\" }\n",
" )\n",
"data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(data))\n",
"\n",
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/nn00007/ver/active/',\n",
" json={\"input_data\" : \"잭의 말이 끝남과 동시.\" }\n",
" )\n",
"data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(data))\n",
"# resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/' + nn_id + '/ver/active/',\n",
"# json={\"input_data\" : \"칼베리온은 누구인가?\" }\n",
"# )\n",
"# data = json.loads(resp.json())\n",
"# print(\"evaluation result : {0}\".format(data))\n",
"\n",
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/nn00007/ver/active/',\n",
" json={\"input_data\" : \"모든 죽은 자들의 주인.\" }\n",
" )\n",
"data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(data))\n",
"# resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/' + nn_id + '/ver/active/',\n",
"# json={\"input_data\" : \"잭의 말이 끝남과 동시.\" }\n",
"# )\n",
"# data = json.loads(resp.json())\n",
"# print(\"evaluation result : {0}\".format(data))\n",
"\n",
"resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/nn00007/ver/active/',\n",
" json={\"input_data\" : \"세 사람의 메시지.\" }\n",
" )\n",
"data = json.loads(resp.json())\n",
"print(\"evaluation result : {0}\".format(data))"
"# resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/' + nn_id + '/ver/active/',\n",
"# json={\"input_data\" : \"모든 죽은 자들의 주인.\" }\n",
"# )\n",
"# data = json.loads(resp.json())\n",
"# print(\"evaluation result : {0}\".format(data))\n",
"\n",
"# resp = requests.post('http://' + url + '/api/v1/type/service/state/predict/type/seq2seq/nnid/' + nn_id + '/ver/active/',\n",
"# json={\"input_data\" : \"세 사람의 메시지.\" }\n",
"# )\n",
"# data = json.loads(resp.json())\n",
"# print(\"evaluation result : {0}\".format(data))"
]
},
{
Expand Down
18 changes: 9 additions & 9 deletions chap20_hoayi_api_guide/04.nlp/seq2seq_onehot.ipynb
Expand Up @@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 1,
"metadata": {
"collapsed": false
},
Expand All @@ -88,13 +88,13 @@
"\n",
"nn_id = 'seq2seq002' # put some key value you want to test\n",
"\n",
"url = \"{0}:{1}\".format(os.environ['HOSTNAME'] , \"8000\")\n",
"url = \"{0}:{1}\".format(os.environ['HOSTNAME'] , \"8989\")\n",
"print(\"done\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -103,8 +103,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : seq2seq002\n",
"evaluation result : seq2seq002\n"
"evaluation result : {'graph': [], 'nn_id': 'seq2seq002'}\n",
"evaluation result : 1\n"
]
}
],
Expand Down Expand Up @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -238,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand All @@ -247,7 +247,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"evaluation result : /hoya_str_root/seq2seq002/1/data_csv_node\n"
"evaluation result : /hoya_str_root/seq2seq002/common/data_csv_node\n"
]
}
],
Expand Down

0 comments on commit abeae13

Please sign in to comment.