diff --git a/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/.ipynb_checkpoints/Untitled-checkpoint.ipynb index 2fd6442..069ab86 100644 --- a/.ipynb_checkpoints/Untitled-checkpoint.ipynb +++ b/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -1,6 +1,244 @@ { - "cells": [], - "metadata": {}, + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n", + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n", + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n", + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n", + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n", + "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n", + " np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11:40:51 INFO:best_model: ./results/output_poem/best_model/model-61170\n", + "\n", + "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n", + "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n", + "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Colocations handled automatically by placer.\n", + "11:40:51 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Colocations handled automatically by placer.\n", + "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n", + "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use standard file APIs to check for files with this prefix.\n", + "11:40:51 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use standard file APIs to check for files with this prefix.\n" + ] + } + ], + "source": [ + "from handler import handle" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "conf = {'体裁':'五言', 'style':'藏头诗', 'Chinese_word':'一二三四'}\n", + "res = handle(conf)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Poetry': '一谈安信惭转真,\\n二毛吹血自在斯。\\n三年波澜恐不安,\\n四海无人不可知。\\n'}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "res1 = res['Poetry'].split('。')[:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "res1 = res['Poetry'].split('。')[:2]\n", + "res2 = []\n", + "for i in res1:\n", + " res2.extend(i.split(','))\n", + "res3 = res2[0]+',\\n'+res2[1]+'。\\n'+res2[2]+',\\n'+res2[3]+'。'" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['一闻江城涯', '二月月涛中', '三湘闇北内', '四海无人同']" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res2" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "一闻江城涯,\n", + "二月月涛中。\n", + "三湘闇北内,\n", + "四海无人同。\n" + ] + } + ], + "source": [ + "res3 = res2[0]+',\\n'+res2[1]+'。\\n'+res2[2]+',\\n'+res2[3]+'。'\n", + "print(res3)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# You can use other public modules via our Client object with module's identifier\n", + "# and parameters.\n", + "# For more detailes, please see our online document - https://momodel.github.io/docs/#\n", + "\n", + "import os\n", + "import sys\n", + "\n", + "# Define root path\n", + "sys.path.append('../')\n", + "\n", + "# Import necessary packages\n", + "from modules import json_parser\n", + "from modules import Client\n", + "\n", + "# Initialise Client object\n", + "client = Client(api_key='33799e1c5d6fa05fdd7dec3aa7aad868445d1c737edcf9c37fa89cb3b39cb2d9',\n", + " project_id='5bfd118f1afd942b66b36b30', user_ID='yangsaisai',\n", + " project_type='app', source_file_path='Untitled.ipynb')\n", + "\n", + "# Make run/train/predict command alias for further use\n", + "run = client.run\n", + "train = client.train\n", + "predict = client.predict\n", + "\n", + "# Make controller alias for further use\n", + "controller = client.controller\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OVERVIEW.md poems_edge_split.txt rhyme_words.txt\n", + "poem_ids.txt \u001b[0m\u001b[01;34mresults\u001b[0m/ vectors_poem.bin\n" + ] + } + ], + "source": [ + "ls /home/jovyan/work/datasets/yangsaisai-poetrydatasets" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, "nbformat": 4, "nbformat_minor": 2 } diff --git a/.ipynb_checkpoints/handler-checkpoint.py b/.ipynb_checkpoints/handler-checkpoint.py index f007870..f086178 100644 --- a/.ipynb_checkpoints/handler-checkpoint.py +++ b/.ipynb_checkpoints/handler-checkpoint.py @@ -1,7 +1,8 @@ # coding: utf-8 import os import sys - +# Define root path +sys.path.append('../') # Import necessary packages from modules import json_parser from modules import Client @@ -34,26 +35,27 @@ style = conf['style'] # value_type: str # description: some description Chinese_word = conf['Chinese_word'] # value_type: str # description: some description - ticai = conf['体裁'] + # ticai = conf['体裁'] # add your code - if ticai == '七言': - char_len = 32 - else: - char_len = 24 + # if ticai == '七言': + # char_len = 32 + # else: + # char_len = 24 # add your code if style == '藏头诗': poetry_test = writer.cangtou(Chinese_word) - while len(poetry_test) != char_len: - poetry_test = writer.cangtou(Chinese_word) + # while len(poetry_test) != char_len: + # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test elif conf['style'] == '藏字诗': poetry_test = writer.hide_words(Chinese_word) - while len(poetry_test) != char_len: - poetry_test = writer.cangtou(Chinese_word) + # while len(poetry_test) != char_len: + # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test else: poetry_test = writer.rhyme_verse() - while len(poetry_test) != char_len: - poetry_test = writer.cangtou(Chinese_word) + # while len(poetry_test) != char_len: + # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test + poetry = poetry.replace(',', ',\n').replace('。', '。\n') return {'Poetry': poetry}diff --git a/Untitled.ipynb b/Untitled.ipynb index d8c39f7..069ab86 100644 --- a/Untitled.ipynb +++ b/Untitled.ipynb @@ -27,36 +27,36 @@ "name": "stdout", "output_type": "stream", "text": [ - "04:29:29 INFO:best_model: ./results/output_poem/best_model/model-61170\n", + "11:40:51 INFO:best_model: ./results/output_poem/best_model/model-61170\n", "\n", "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n", - "04:29:29 WARNING:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n", "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n", - "04:29:29 WARNING:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n", "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Colocations handled automatically by placer.\n", - "04:29:29 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "11:40:51 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Colocations handled automatically by placer.\n", "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n", - "04:29:29 WARNING:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n", + "11:40:51 WARNING:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n", "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Use standard file APIs to check for files with this prefix.\n", - "04:29:29 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n", + "11:40:51 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", "Use standard file APIs to check for files with this prefix.\n" ] @@ -68,12 +68,32 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "conf = {'体裁':'五言', 'style':'藏头诗', 'Chinese_word':'一二三四'}\n", "res = handle(conf)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Poetry': '一谈安信惭转真,\\n二毛吹血自在斯。\\n三年波澜恐不安,\\n四海无人不可知。\\n'}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res" ] }, { diff --git a/handler.py b/handler.py index dfce570..f086178 100644 --- a/handler.py +++ b/handler.py @@ -57,9 +57,5 @@ # while len(poetry_test) != char_len: # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test - res1 = poetry.split('。')[:2] - res2 = [] - for i in res1: - res2.extend(i.split(',')) - res3 = res2[0]+',\n'+res2[1]+'。\n'+res2[2]+',\n'+res2[3]+'。' - return {'Poetry': res3} \ No newline at end of file + poetry = poetry.replace(',', ',\n').replace('。', '。\n') + return {'Poetry': poetry} \ No newline at end of file