{"id":23080628,"url":"https://github.com/chen0040/keras-text-summarization","last_synced_at":"2025-07-28T18:07:05.524Z","repository":{"id":29013591,"uuid":"115468635","full_name":"chen0040/keras-text-summarization","owner":"chen0040","description":"Text summarization using seq2seq in Keras","archived":false,"fork":false,"pushed_at":"2022-02-23T09:20:51.000Z","size":319756,"stargazers_count":292,"open_issues_count":17,"forks_count":126,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-19T18:08:24.071Z","etag":null,"topics":["keras","seq2seq","text-summarization"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chen0040.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-27T01:34:55.000Z","updated_at":"2025-04-16T12:53:55.000Z","dependencies_parsed_at":"2022-07-26T04:02:09.727Z","dependency_job_id":null,"html_url":"https://github.com/chen0040/keras-text-summarization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chen0040/keras-text-summarization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fkeras-text-summarization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fkeras-text-summarization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fkeras-text-summarization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fkeras-text-summarization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chen0040","download_url":"https://codeload.github.com/chen0040/keras-text-summarization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fkeras-text-summarization/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267560512,"owners_count":24107500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keras","seq2seq","text-summarization"],"created_at":"2024-12-16T13:15:53.754Z","updated_at":"2025-07-28T18:07:05.469Z","avatar_url":"https://github.com/chen0040.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# keras-text-summarization\n\nText summarization using seq2seq and encoder-decoder recurrent networks in Keras\n\n# Machine Learning Models\n\nThe follow neural network models are implemented and studied for text summarization:\n\n### Seq2Seq\n\nThe seq2seq models encodes the content of an article (encoder input) and one character (decoder input) from the summarized text to predict the next character in the summarized text\n\nThe implementation can be found in [keras_text_summarization/library/seq2seq.py](keras_text_summarization/library/seq2seq.py)\n\nThere are three variants of seq2seq model implemented for the text summarization   \n* Seq2SeqSummarizer (one hot encoding)\n    * training: run [demo/seq2seq_train.py](demo/seq2seq_train.py ) \n    * prediction: demo code is available in [demo/seq2seq_predict.py](demo/seq2seq_predict.py) \n* Seq2SeqGloVeSummarizer (GloVe encoding for encoder input)\n    * training: run [demo/seq2seq_glove_train.py](demo/seq2seq_glove_train.py) \n    * prediction: demo code is available in [demo/seq2seq_glove_predict.py](demo/seq2seq_glove_predict.py) \n* Seq2SeqGloVeSummarizerV2 (GloVe encoding for both encoder input and decoder input)\n    * training: run [demo/seq2seq_glove_v2_train.py](demo/seq2seq_glove_v2_train.py)\n    * prediction: demo code is available in [demo/seq2seq_glove_v2_predict.py](demo/seq2seq_glove_v2_predict.py) \n    \n### Other RNN models\n\nThere are currently 3 other encoder-decoder recurrent models based on some recommendation [here](https://machinelearningmastery.com/encoder-decoder-models-text-summarization-keras/)\n\nThe implementation can be found in [keras_text_summarization/library/rnn.py](keras_text_summarization/library/rnn.py)\n\n* One-Shot RNN (OneShotRNN in [rnn.py](keras_text_summarization/library/rnn.py)):\nThe one-shot RNN is a very simple encoder-decoder recurrent network model which encodes the content of an article and decodes the entire content of the summarized text\n    * training: run [demo/one_hot_rnn_train.py](demo/one_hot_rnn_train.py)\n    * prediction: run [demo/one_hot_rnn_predict.py](demo/one_hot_rnn_predict.py)\n* Recursive RNN 1 (RecursiveRNN1 in [rnn.py](keras_text_summarization/library/rnn.py)):\nThe recursive RNN 1 takes the artcile content and the current built-up summarized text to predict the next character of the summarized text.\n    * training: run [demo/recursive_rnn_v1_train.py](demo/recursive_rnn_v1_train.py)\n    * prediction: run [demo/recursive_rnn_v1_predict.py](demo/recursive_rnn_v1_predict.py)\n* Recursive RNN 2 (RecursiveRNN2 in [rnn.py](keras_text_summarization/library/rnn.py)):\nThe recursive RNN 2 takes the article content and the current built-up summarized text to predict the next character of the summarized text + one layer of LSTM decoder.\n    * training: run [demo/recursive_rnn_v2_train.py](demo/recursive_rnn_v2_train.py)\n    * prediction: run [demo/recursive_rnn_v2_predict.py](demo/recursive_rnn_v2_predict.py)\n\nThe trained models are available in the demo/models folder \n\n# Usage\n\nThe demo below shows how to use seq2seq to do training and prediction, but other models described above also follow\nthe same process of training and prediction.\n\n### Train Deep Learning model\n\nTo train a deep learning model, say Seq2SeqSummarizer, run the following commands:\n\n```bash\npip install requirements.txt\n\ncd demo\npython seq2seq_train.py \n```\n\nThe training code in seq2seq_train.py is quite straightforward and illustrated below:\n\n```python\nfrom __future__ import print_function\n\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom keras_text_summarization.library.utility.plot_utils import plot_and_save_history\nfrom keras_text_summarization.library.seq2seq import Seq2SeqSummarizer\nfrom keras_text_summarization.library.applications.fake_news_loader import fit_text\nimport numpy as np\n\nLOAD_EXISTING_WEIGHTS = True\n\nnp.random.seed(42)\ndata_dir_path = './data'\nreport_dir_path = './reports'\nmodel_dir_path = './models'\n\nprint('loading csv file ...')\ndf = pd.read_csv(data_dir_path + \"/fake_or_real_news.csv\")\n\nprint('extract configuration from input texts ...')\nY = df.title\nX = df['text']\n\nconfig = fit_text(X, Y)\n\nsummarizer = Seq2SeqSummarizer(config)\n\nif LOAD_EXISTING_WEIGHTS:\n    summarizer.load_weights(weight_file_path=Seq2SeqSummarizer.get_weight_file_path(model_dir_path=model_dir_path))\n\nXtrain, Xtest, Ytrain, Ytest = train_test_split(X, Y, test_size=0.2, random_state=42)\n\nhistory = summarizer.fit(Xtrain, Ytrain, Xtest, Ytest, epochs=100)\n\nhistory_plot_file_path = report_dir_path + '/' + Seq2SeqSummarizer.model_name + '-history.png'\nif LOAD_EXISTING_WEIGHTS:\n    history_plot_file_path = report_dir_path + '/' + Seq2SeqSummarizer.model_name + '-history-v' + str(summarizer.version) + '.png'\nplot_and_save_history(history, summarizer.model_name, history_plot_file_path, metrics={'loss', 'acc'})\n```\n\nAfter the training is completed, the trained models will be saved as cf-v1-*.* in the video_classifier/demo/models.\n\n### Summarization\n\nTo use the trained deep learning model to summarize an article, the following code demo how to do this:\n\n```python\n\nfrom __future__ import print_function\n\nimport pandas as pd\nfrom keras_text_summarization.library.seq2seq import Seq2SeqSummarizer\nimport numpy as np\n\nnp.random.seed(42)\ndata_dir_path = './data' # refers to the demo/data folder\nmodel_dir_path = './models' # refers to the demo/models folder\n\nprint('loading csv file ...')\ndf = pd.read_csv(data_dir_path + \"/fake_or_real_news.csv\")\nX = df['text']\nY = df.title\n\nconfig = np.load(Seq2SeqSummarizer.get_config_file_path(model_dir_path=model_dir_path)).item()\n\nsummarizer = Seq2SeqSummarizer(config)\nsummarizer.load_weights(weight_file_path=Seq2SeqSummarizer.get_weight_file_path(model_dir_path=model_dir_path))\n\nprint('start predicting ...')\nfor i in range(20):\n    x = X[i]\n    actual_headline = Y[i]\n    headline = summarizer.summarize(x)\n    print('Article: ', x)\n    print('Generated Headline: ', headline)\n    print('Original Headline: ', actual_headline)\n```\n\n# Configure to run on GPU on Windows\n\n* Step 1: Change tensorflow to tensorflow-gpu in requirements.txt and install tensorflow-gpu\n* Step 2: Download and install the [CUDA® Toolkit 9.0](https://developer.nvidia.com/cuda-90-download-archive) (Please note that\ncurrently CUDA® Toolkit 9.1 is not yet supported by tensorflow, therefore you should download CUDA® Toolkit 9.0)\n* Step 3: Download and unzip the [cuDNN 7.0.4 for CUDA@ Toolkit 9.0](https://developer.nvidia.com/cudnn) and add the\nbin folder of the unzipped directory to the $PATH of your Windows environment \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fkeras-text-summarization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchen0040%2Fkeras-text-summarization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fkeras-text-summarization/lists"}