├── CBSE-README.md ├── CONTRIBUTING.md ├── DEBUGGING.md ├── DEVELOPING.md ├── LICENSE ├── MAINTAINERS.md ├── README.md ├── data └── Mission_Impossible_6_Review.txt ├── doc └── source │ └── images │ ├── add_file.png │ ├── architecture.png │ ├── create_notebook.png │ ├── define_project.png │ ├── insert_cred.png │ ├── new_project.png │ ├── results_1.png │ └── results_2.png ├── notebook └── Text_Summarize_and_Visualize.ipynb └── part-of-speech-tags └── POS-Tags /CBSE-README.md: -------------------------------------------------------------------------------- 1 | # What is Natural Language Processing and how does it work 2 | 3 | **Usecase** :- Text summarization and visualization using watson studio 4 | 5 | We will demonstrate a methodology to summarize & visualize text using Watson Studio. Text summarization is the process of creating a short and coherent version of a longer document. There are two methods to summarize the text, extractive & abstractive summarization. We will focus on extractive summarization which involves the selection of phrases and sentences from the source document to make up the new summary. Techniques involve ranking the relevance of phrases in order to choose only those most relevant to the meaning of the source. Some of the advantages of text summarization are below. We will also demonstrate different methods to visualize the data which can aid in providing quick peek of the data. 6 | 7 | When the students have completed this code pattern, they will understand how to: 8 | 9 | * Understand what is NLP and the common terms associated with it 10 | * How to preprocess unstructured data for further analysis 11 | * Quickly summarize the text from documents & news feeds. 12 | * Create topic modeling on the text to extract important topics. 13 | * Create visualizations for better understanding of the data. 14 | * Interpret the summary and visualization of the data. 15 | * Analyze the text for further processing to generate recommendations or taking informed decisions. 16 | 17 | # Architecture Diagram 18 | 19 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/architecture.png) 20 | 21 | 1. User logs into Watson Studio, creates an instance which includes object storage. 22 | 2. User uploads the data file to the object storage. 23 | 3. User imports a Jupyter Notebook from the URL. 24 | 4. User runs the processing techniques & creates a statistical model for topics in the notebook. 25 | 5. User explores the visualization in the notebook and can export the output to object storage. 26 | 27 | ## Included components 28 | 29 | * [IBM Watson Studio](https://www.ibm.com/cloud/watson-studio): Analyze data using RStudio, Jupyter, and Python in a configured, collaborative environment that includes IBM value-adds, such as managed Spark. 30 | 31 | * [IBM Cloud Object Storage](https://console.bluemix.net/catalog/services/cloud-object-storage): An IBM Cloud service that provides an unstructured cloud data store to build and deliver cost effective apps and services with high reliability and fast speed to market. This code pattern uses Cloud Object Storage. 32 | 33 | * [Jupyter Notebooks](http://jupyter.org/): An open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. 34 | 35 | ## Featured technologies 36 | 37 | * [Data Science](https://developer.ibm.com/code/technologies/data-science/): Systems and scientific methods to analyze structured and unstructured data in order to extract knowledge and insights. 38 | * [Analytics](https://developer.ibm.com/code/technologies/analytics/): Analytics delivers the value of data for the enterprise. 39 | * [Python](https://www.python.org/): Python is a programming language that lets you work more quickly and integrate your systems more effectively. 40 | * [Text Ranking](https://pypi.org/project/gensim/): Gensim is a free Python library designed to automatically extract semantic topics from documents. The gensim implementation is based on the popular TextRank algorithm. 41 | * [Word Cloud](https://pypi.org/project/wordcloud/): It is used for identifying and visualizing the key words in the document. 42 | * [pyLDAvis](https://pypi.org/project/pyLDAvis/) : It is a Python library for interactive topic model visualization. 43 | 44 | # Watch the Video 45 | 46 | [![](http://img.youtube.com/vi/m98Jjpqi45I/0.jpg)](https://youtu.be/m98Jjpqi45I) 47 | 48 | 49 | # Steps 50 | 51 | Follow these steps to setup and run this code pattern. The steps are 52 | described in detail below. 53 | 54 | 1. [Create an account with IBM Cloud](#1-create-an-account-with-ibm-cloud) 55 | 1. [Create a new Watson Studio project](#2-create-a-new-watson-studio-project) 56 | 1. [Create the notebook](#3-create-the-notebook) 57 | 1. [Add the data](#4-add-the-data) 58 | 1. [Insert the credentials](#5-insert-the-credentials) 59 | 1. [Run the notebook](#6-run-the-notebook) 60 | 1. [Analyze the results](#7-analyze-the-results) 61 | 62 | ## 1. Create an account with IBM Cloud 63 | 64 | Sign up for IBM [**Cloud**](https://console.bluemix.net/). By clicking on create a free account you will get 30 days trial account. 65 | 66 | ## 2. Create a new Watson Studio project 67 | 68 | Sign up for IBM's [Watson Studio](http://dataplatform.ibm.com/). 69 | 70 | Click on New project and select Data Science as per below. 71 | 72 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/new_project.png) 73 | 74 | Define the project by giving a Name and hit 'Create'. 75 | 76 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/define_project.png) 77 | 78 | By creating a project in Watson Studio a free tier ``Object Storage`` service will be created in your IBM Cloud account. 79 | 80 | ## 3. Create the notebook 81 | 82 | * Open [IBM Watson Studio](https://dataplatform.ibm.com). 83 | * Click on `Create notebook` to create a notebook. 84 | * Select the `From URL` tab. 85 | * Enter a name for the notebook. 86 | * Optionally, enter a description for the notebook. 87 | * Enter this Notebook URL: https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/notebook/Text_Summarize_and_Visualize.ipynb 88 | * Select the runtime (1vCPU and 4GBRAM) 89 | * Click the `Create` button. 90 | 91 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/create_notebook.PNG) 92 | 93 | ## 4. Add the data 94 | 95 | [Clone this repo](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio) 96 | Navigate to [data](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/tree/master/data) and save the file on the disk. The data has been extracted from one of the movie review websites online. 97 | 98 | Use `Find and Add Data` (look for the `10/01` icon) 99 | and its `Files` tab. From there you can click 100 | `browse` and add data file from your computer. 101 | 102 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/add_file.png) 103 | 104 | Note: The data file is in the `data` directory 105 | 106 | ## 5. Insert the credentials 107 | 108 | Select the cell below `Read the Data` section in the notebook. 109 | 110 | Use `Find and Add Data` (look for the `10/01` icon) and its `Files` tab. You should see the file names uploaded earlier. Make sure your active cell is the empty one created earlier. Select `Insert to code` (below your file name). Click `Insert credentials` from drop down menu. 111 | 112 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/insert_cred.png) 113 | 114 | ## 6. Run the notebook 115 | 116 | When a notebook is executed, what is actually happening is that each code cell in 117 | the notebook is executed, in order, from top to bottom. 118 | 119 | Each code cell is selectable and is preceded by a tag in the left margin. The tag 120 | format is `In [x]:`. Depending on the state of the notebook, the `x` can be: 121 | 122 | * A blank, this indicates that the cell has never been executed. 123 | * A number, this number represents the relative order this code step was executed. 124 | * A `*`, this indicates that the cell is currently executing. 125 | 126 | There are several ways to execute the code cells in your notebook: 127 | 128 | * One cell at a time. 129 | * Select the cell, and then press the `Play` button in the toolbar. 130 | * Batch mode, in sequential order. 131 | * From the `Cell` menu bar, there are several options available. For example, you 132 | can `Run All` cells in your notebook, or you can `Run All Below`, that will 133 | start executing from the first cell under the currently selected cell, and then 134 | continue executing all cells that follow. 135 | 136 | ## 7. Analyze the results 137 | 138 | Lets look at the summarization of the document. We can observe that all the key pointers are included in the summary. The text ranking algorithm has produced good results. 139 | 140 | `Before its release, Mission: Impossible Fallout has been known for two things: the fact that it\'s the first direct sequel in the series and THAT injury to Tom Cruise.Let\'s get the injury out of the way first.', "The shot is in the movie and it will make you wince because you know the context, but otherwise you don't really notice any difference as the stunt in question is just the latest in a long line of deathdefying activities featuring Cruise.What makes more of an impact on the sixth movie in the series is its connection to the previous movie, Rogue Nation, with the return of the villainous Solomon Lane (played creepily again by Sean Harris) and his nefarious Syndicate, who are again threatening the world.With the addition of Ethan Hunt's former wife Julia (Michelle Monaghan) from the third movie, Fallout is immediately given more depth than previous outings and the stakes feel higher, with Ethan Hunt (Cruise) haunted by his past mistakes.", "At times, even IMAX doesn't feel big enough to contain it.Putting aside the direct connection to the previous movie and the series' first returning director in Christopher McQuarrie, it's pretty much business as usual for Ethan and the IMF.", "There's no possible way this can go wrong, right?What follows is the usual, winning Mission: Impossible mix of spy games, double \\x96 and triple \\x96 crosses, chases of all kinds and extended set pieces in various locations around the world.", "Of the newcomers, Henry Cavill has the biggest role and Fallout makes full use of his considerable frame with some muscular fights, while The Crown's Vanessa Kirby relishes her enigmatic White Widow role, even if she is underused.But you don't really come to a Mission: Impossible movie for the cast, you come for the action \\x96 and you will not be disappointed.` 141 | 142 | As we can see in the below image, the important words in the corpus have been highlighted which will help in inference of the data. Wordclouds are beautifully insightful with pros and cons. Word clouds can allow you to share back results from research in a way that does not require an understanding of the technicalities. Some of the pros are below. 143 | * It reveals the essential. 144 | * They delight and provide emotional connection. 145 | * They are fast & engaging. 146 | As observed, skilled interpretation is what provides the beautiful insights. 147 | 148 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/results_1.png) 149 | 150 | Latent Dirichlet Allocation (LDA) is a probabilistic model with interpretable topics. Topic modeling is one of the most popular NLP techniques with several real-world applications such as dimensionality reduction, text summarization, recommendation engine, etc. To visualize our topics in a 2-dimensional space we will use the pyLDAvis library. This visualization is interactive in nature and displays topics along with the most relevant words. 151 | 152 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/results_2.png) 153 | 154 | As we can see from the topics, the data is referring to Mission Impossible Fallout movie. Skilled interpretation is needed to an extent for consuming the insights from the results. 155 | 156 | # Troubleshooting 157 | 158 | [See DEBUGGING.md.](DEBUGGING.md) 159 | 160 | # License 161 | 162 | This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer [Certificate of Origin, Version 1.1 (DCO)](https://developercertificate.org/) and the [Apache Software License, Version 2](http://www.apache.org/licenses/LICENSE-2.0.txt). 163 | 164 | Check the [ASL FAQ link](http://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN) for more details. 165 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing In General 2 | 3 | Our project welcomes external contributions! If you have an itch, please 4 | feel free to scratch it. 5 | 6 | To contribute code or documentation, please submit a pull request to the [GitHub 7 | repository](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio). 8 | 9 | A good way to familiarize yourself with the codebase and contribution process is 10 | to look for and tackle low-hanging fruit in the [issue 11 | tracker](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/issues). Before embarking on 12 | a more ambitious contribution, please quickly [get in touch](#communication) 13 | with us. 14 | 15 | **We appreciate your effort, and want to avoid a situation where a contribution 16 | requires extensive rework (by you or by us), sits in the queue for a long time, 17 | or cannot be accepted at all!** 18 | 19 | ### Proposing new features 20 | 21 | If you would like to implement a new feature, please [raise an 22 | issue](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/issues) before sending a pull 23 | request so the feature can be discussed. This is to avoid you spending your 24 | valuable time working on a feature that the project developers are not willing 25 | to accept into the code base. 26 | 27 | ### Fixing bugs 28 | 29 | If you would like to fix a bug, please [raise an 30 | issue](https://github.com/IBM//issues) before sending a pull 31 | request so it can be discussed. If the fix is trivial or non controversial then 32 | this is not usually necessary. 33 | 34 | ### Merge approval 35 | 36 | The project maintainers use LGTM (Looks Good To Me) in comments on the code 37 | review to indicate acceptance. A change requires LGTMs from two of the 38 | maintainers of each component affected. 39 | 40 | For more details, see the [MAINTAINERS](MAINTAINERS.md) page. 41 | 42 | ## Communication 43 | 44 | Please feel free to connect with us on our [here] 45 | (https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/issues). 46 | 47 | ## Setup 48 | 49 | Please add any special setup instructions for your project to help the 50 | developer become productive quickly. 51 | 52 | ## Testing 53 | 54 | Please provide information that helps the developer test any changes they 55 | make before submitting. 56 | 57 | ## Coding style guidelines 58 | 59 | Beautiful code rocks! Please share any specific style guidelines you might 60 | have for your project. 61 | -------------------------------------------------------------------------------- /DEBUGGING.md: -------------------------------------------------------------------------------- 1 | Troubleshooting 2 | =============== 3 | 4 | Jupyter Notebooks 5 | ----------------- 6 | 7 | * Make sure the pip install ran correctly. You might need to restart the kernel and run the cells from the top after the pip install runs the first time. 8 | * Many of the cells rely on variables that are set in earlier cells. Some of these are cleared in later cells. Start over at the top when troubleshooting. 9 | * Many of the cells rely on service credentials from Bluemix that are set in earlier cells. Make sure to add your service credentials correctly. Run the cells from top down and evaluate the outcome. -------------------------------------------------------------------------------- /DEVELOPING.md: -------------------------------------------------------------------------------- 1 | Tips for Developers 2 | =================== 3 | 4 | The notebook is designed to be run top-down. Settings in early cells are used 5 | in later cells. Some variables are also cleared to free up memory. So, although 6 | you can often run single cell repeatedly while testing changes, you may want 7 | to start over from the top if anything seems to be missing. 8 | 9 | Setting credentials 10 | ------------------- 11 | Credentials need to be added to the notebook to access some Bluemix services. 12 | The credentials are set near the top of the notebook to make it 13 | more obvious that they need to be set and also to make it more obvious that 14 | you will be saving a notebook with credentials. You should not share your 15 | notebook with anyone that you would not share your credentials with 16 | unless you use the ``share`` feature with the ``Only text and output`` or 17 | ``All content excluding sensitive code cells`` option.Installing Python packages 18 | -------------------------- 19 | A notebook can use ```!pip install``` to install the Python packages 20 | from PyPI. You can follow this example if you decide to use additional Python 21 | packages in your notebook. Check the output to see that the install was 22 | successful. See the "Controlling output" section below for more information on 23 | how to suppress/show the output. You might want to use ``DEBUG = True`` until 24 | you've verified that the pip install was successful. 25 | 26 | > **Note**: After running a cell with pip install, you may need to restart 27 | the kernel and then run the cells again from the top. 28 | 29 | Importing libraries 30 | ------------------- 31 | Import and some setup of libraries is done near the top. This is another 32 | example of why cells need to run top-down. Keeping the imports near the top 33 | is a Python PEP9 style convention. Python does not require this convention, 34 | but Python developers are used to looking for imports at the top. 35 | 36 | Defining global variables and helper functions 37 | ---------------------------------------------- 38 | After the imports, a few global variables and helper functions are defined. 39 | These allow for code re-use. These cells need to run before other cells can 40 | use the functions and globals. These values do not change. You can change 41 | and run the later cells over and over without always restarting from the top. 42 | 43 | Controlling output 44 | ------------------ 45 | One of the great things about notebooks is that you can use them to document 46 | what you are doing, show your work, show the results, and document your 47 | conclusion -- all in one place. Sharing "your work" (the code) is a great 48 | feature, but to make the "only text and output" web page look nice and clean 49 | you can use the following tips. 50 | 51 | #### @hidden_cell magic 52 | 53 | The @hidden_cell magic is used to mark the credentials cells as "sensitive". 54 | If you do any rearranging of sensitive code, remember to identify sensitive 55 | cells with @hidden_cell. 56 | 57 | #### Ending with a semi-colon 58 | 59 | Statements in a notebook can end with a semi-colon. It looks like 60 | bad Python, but it is actually a trick to prevent these statements from 61 | showing their result in the output. 62 | 63 | #### if DEBUG 64 | 65 | A DEBUG boolean and 'if' statements can be used throughout the notebook 66 | wherever some print statements are handy during development and might be 67 | handy in the future, but are not something you want to share in the final 68 | output. 69 | 70 | #### %%capture captured_io 71 | 72 | "%%capture captured_io" magic can be used to capture the output when nothing 73 | else works. You can use that to hide the "!pip install" output and add a cell 74 | right after it that will print the captured output if DEBUG is True. 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | ## Maintainers Guide 2 | 3 | This guide is intended for maintainers — anybody with commit access to one or 4 | more Developer Journey repositories. 5 | 6 | ## Methodology: 7 | 8 | A master branch. This branch MUST be releasable at all times. Commits and 9 | merges against this branch MUST contain only bugfixes and/or security fixes. 10 | Maintenance releases are tagged against master. 11 | 12 | A develop branch. This branch contains your proposed changes. 13 | 14 | The remainder of this document details how to merge pull requests to the 15 | repositories. 16 | 17 | ## Merge approval 18 | 19 | The project maintainers use LGTM (Looks Good To Me) in comments on the code 20 | review to indicate acceptance. A change requires LGTMs from two of the members 21 | of the [journey_name-dev-admins](https://github.com/orgs/IBM/teams) 22 | team. If the code is written by a member, the change only requires one more 23 | LGTM. 24 | 25 | ## Reviewing Pull Requests 26 | 27 | We recommend reviewing pull requests directly within GitHub. This allows a 28 | public commentary on changes, providing transparency for all users. When 29 | providing feedback be civil, courteous, and kind. Disagreement is fine, so 30 | long as the discourse is carried out politely. If we see a record of uncivil 31 | or abusive comments, we will revoke your commit privileges and invite you to 32 | leave the project. 33 | 34 | During your review, consider the following points: 35 | 36 | ### Does the change have impact? 37 | 38 | While fixing typos is nice as it adds to the overall quality of the project, 39 | merging a typo fix at a time can be a waste of effort. 40 | (Merging many typo fixes because somebody reviewed the entire component, 41 | however, is useful!) Other examples to be wary of: 42 | 43 | Changes in variable names. Ask whether or not the change will make 44 | understanding the code easier, or if it could simply a personal preference 45 | on the part of the author. 46 | 47 | Essentially: feel free to close issues that do not have impact. 48 | 49 | ### Do the changes make sense? 50 | 51 | If you do not understand what the changes are or what they accomplish, 52 | ask the author for clarification. Ask the author to add comments and/or 53 | clarify test case names to make the intentions clear. 54 | 55 | At times, such clarification will reveal that the author may not be using 56 | the code correctly, or is unaware of features that accommodate their needs. 57 | If you feel this is the case, work up a code sample that would address the 58 | issue for them, and feel free to close the issue once they confirm. 59 | 60 | ### Is this a new feature? If so: 61 | 62 | Does the issue contain narrative indicating the need for the feature? If not, 63 | ask them to provide that information. Since the issue will be linked in the 64 | changelog, this will often be a user's first introduction to it. 65 | 66 | Are new unit tests in place that test all new behaviors introduced? If not, do 67 | not merge the feature until they are! 68 | Is documentation in place for the new feature? (See the documentation 69 | guidelines). If not do not merge the feature until it is! 70 | Is the feature necessary for general use cases? Try and keep the scope of any 71 | given component narrow. If a proposed feature does not fit that scope, 72 | recommend to the user that they maintain the feature on their own, and close 73 | the request. You may also recommend that they see if the feature gains traction 74 | amongst other users, and suggest they re-submit when they can show such support. 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Text summarization and visualization using watson studio 2 | 3 | We will demonstrate a methodology to summarize & visualize text using Watson Studio. Text summarization is the process of creating a short and coherent version of a longer document. There are two methods to summarize the text, extractive & abstractive summarization. We will focus on extractive summarization which involves the selection of phrases and sentences from the source document to make up the new summary. Techniques involve ranking the relevance of phrases in order to choose only those most relevant to the meaning of the source. Some of the advantages of text summarization are below. We will also demonstrate different methods to visualize the data which can aid in providing quick peek of the data. 4 | 5 | `Summaries reduce reading time. When researching documents, summaries make the selection process easier.Text summarization improves the effectiveness of indexing.Text summarization algorithms are less biased than human summarizers. 6 | Personalized summaries are useful in question-answering systems as they provide personalized information.Using automatic or semi-automatic summarization systems enables commercial abstract services to increase the number of texts they are able to process.` 7 | 8 | [A Brief about Text Summarization](https://machinelearningmastery.com/gentle-introduction-text-summarization) 9 | 10 | When the reader has completed this code pattern, they will understand how to: 11 | 12 | * Quickly summarize the text from documents & news feeds. 13 | * Create topic modeling on the text to extract important topics. 14 | * Create visualizations for better understanding of the data. 15 | * Interpret the summary and visualization of the data. 16 | * Analyze the text for further processing to generate recommendations or taking informed decisions. 17 | 18 | # Architecture Diagram 19 | 20 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/architecture.png) 21 | 22 | 1. User logs into Watson Studio, creates an instance which includes object storage. 23 | 2. User uploads the data file to the object storage. 24 | 3. User imports a Jupyter Notebook from the URL. 25 | 4. User runs the processing techniques & creates a statistical model for topics in the notebook. 26 | 5. User explores the visualization in the notebook and can export the output to object storage. 27 | 28 | ## Included components 29 | 30 | * [IBM Watson Studio](https://www.ibm.com/cloud/watson-studio): Analyze data using RStudio, Jupyter, and Python in a configured, collaborative environment that includes IBM value-adds, such as managed Spark. 31 | 32 | * [IBM Cloud Object Storage](https://console.bluemix.net/catalog/services/cloud-object-storage): An IBM Cloud service that provides an unstructured cloud data store to build and deliver cost effective apps and services with high reliability and fast speed to market. This code pattern uses Cloud Object Storage. 33 | 34 | * [Jupyter Notebooks](http://jupyter.org/): An open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. 35 | 36 | ## Featured technologies 37 | 38 | * [Data Science](https://developer.ibm.com/code/technologies/data-science/): Systems and scientific methods to analyze structured and unstructured data in order to extract knowledge and insights. 39 | * [Analytics](https://developer.ibm.com/code/technologies/analytics/): Analytics delivers the value of data for the enterprise. 40 | * [Python](https://www.python.org/): Python is a programming language that lets you work more quickly and integrate your systems more effectively. 41 | * [Text Ranking](https://pypi.org/project/gensim/): Gensim is a free Python library designed to automatically extract semantic topics from documents. The gensim implementation is based on the popular TextRank algorithm. 42 | * [Word Cloud](https://pypi.org/project/wordcloud/): It is used for identifying and visualizing the key words in the document. 43 | * [pyLDAvis](https://pypi.org/project/pyLDAvis/) : It is a Python library for interactive topic model visualization. 44 | 45 | # Watch the Video 46 | 47 | [![](http://img.youtube.com/vi/m98Jjpqi45I/0.jpg)](https://youtu.be/m98Jjpqi45I) 48 | 49 | 50 | # Steps 51 | 52 | Follow these steps to setup and run this code pattern. The steps are 53 | described in detail below. 54 | 55 | 1. [Create an account with IBM Cloud](#1-create-an-account-with-ibm-cloud) 56 | 1. [Create a new Watson Studio project](#2-create-a-new-watson-studio-project) 57 | 1. [Create the notebook](#3-create-the-notebook) 58 | 1. [Add the data](#4-add-the-data) 59 | 1. [Insert the credentials](#5-insert-the-credentials) 60 | 1. [Run the notebook](#6-run-the-notebook) 61 | 1. [Analyze the results](#7-analyze-the-results) 62 | 63 | ## 1. Create an account with IBM Cloud 64 | 65 | Sign up for IBM [**Cloud**](https://console.bluemix.net/). By clicking on create a free account you will get 30 days trial account. 66 | 67 | ## 2. Create a new Watson Studio project 68 | 69 | Sign up for IBM's [Watson Studio](http://dataplatform.ibm.com/). 70 | 71 | Click on New project and select Data Science as per below. 72 | 73 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/new_project.png) 74 | 75 | Define the project by giving a Name and hit 'Create'. 76 | 77 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/define_project.png) 78 | 79 | By creating a project in Watson Studio a free tier ``Object Storage`` service will be created in your IBM Cloud account. 80 | 81 | ## 3. Create the notebook 82 | 83 | * Open [IBM Watson Studio](https://dataplatform.ibm.com). 84 | * Click on `Create notebook` to create a notebook. 85 | * Select the `From URL` tab. 86 | * Enter a name for the notebook. 87 | * Optionally, enter a description for the notebook. 88 | * Enter this Notebook URL: https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/notebook/Text_Summarize_and_Visualize.ipynb 89 | * Select the runtime (1vCPU and 4GBRAM) 90 | * Click the `Create` button. 91 | 92 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/create_notebook.PNG) 93 | 94 | ## 4. Add the data 95 | 96 | [Clone this repo](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio) 97 | Navigate to [data](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/tree/master/data) and save the file on the disk. The data has been extracted from one of the movie review websites online. 98 | 99 | Use `Find and Add Data` (look for the `10/01` icon) 100 | and its `Files` tab. From there you can click 101 | `browse` and add data file from your computer. 102 | 103 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/add_file.png) 104 | 105 | Note: The data file is in the `data` directory 106 | 107 | ## 5. Insert the credentials 108 | 109 | Select the cell below `Read the Data` section in the notebook. 110 | 111 | Use `Find and Add Data` (look for the `10/01` icon) and its `Files` tab. You should see the file names uploaded earlier. Make sure your active cell is the empty one created earlier. Select `Insert to code` (below your file name). Click `Insert credentials` from drop down menu. 112 | 113 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/insert_cred.png) 114 | 115 | ## 6. Run the notebook 116 | 117 | When a notebook is executed, what is actually happening is that each code cell in 118 | the notebook is executed, in order, from top to bottom. 119 | 120 | Each code cell is selectable and is preceded by a tag in the left margin. The tag 121 | format is `In [x]:`. Depending on the state of the notebook, the `x` can be: 122 | 123 | * A blank, this indicates that the cell has never been executed. 124 | * A number, this number represents the relative order this code step was executed. 125 | * A `*`, this indicates that the cell is currently executing. 126 | 127 | There are several ways to execute the code cells in your notebook: 128 | 129 | * One cell at a time. 130 | * Select the cell, and then press the `Play` button in the toolbar. 131 | * Batch mode, in sequential order. 132 | * From the `Cell` menu bar, there are several options available. For example, you 133 | can `Run All` cells in your notebook, or you can `Run All Below`, that will 134 | start executing from the first cell under the currently selected cell, and then 135 | continue executing all cells that follow. 136 | 137 | ## 7. Analyze the results 138 | 139 | Lets look at the summarization of the document. We can observe that all the key pointers are included in the summary. The text ranking algorithm has produced good results. 140 | 141 | `Before its release, Mission: Impossible Fallout has been known for two things: the fact that it\'s the first direct sequel in the series and THAT injury to Tom Cruise.Let\'s get the injury out of the way first.', "The shot is in the movie and it will make you wince because you know the context, but otherwise you don't really notice any difference as the stunt in question is just the latest in a long line of deathdefying activities featuring Cruise.What makes more of an impact on the sixth movie in the series is its connection to the previous movie, Rogue Nation, with the return of the villainous Solomon Lane (played creepily again by Sean Harris) and his nefarious Syndicate, who are again threatening the world.With the addition of Ethan Hunt's former wife Julia (Michelle Monaghan) from the third movie, Fallout is immediately given more depth than previous outings and the stakes feel higher, with Ethan Hunt (Cruise) haunted by his past mistakes.", "At times, even IMAX doesn't feel big enough to contain it.Putting aside the direct connection to the previous movie and the series' first returning director in Christopher McQuarrie, it's pretty much business as usual for Ethan and the IMF.", "There's no possible way this can go wrong, right?What follows is the usual, winning Mission: Impossible mix of spy games, double \\x96 and triple \\x96 crosses, chases of all kinds and extended set pieces in various locations around the world.", "Of the newcomers, Henry Cavill has the biggest role and Fallout makes full use of his considerable frame with some muscular fights, while The Crown's Vanessa Kirby relishes her enigmatic White Widow role, even if she is underused.But you don't really come to a Mission: Impossible movie for the cast, you come for the action \\x96 and you will not be disappointed.` 142 | 143 | As we can see in the below image, the important words in the corpus have been highlighted which will help in inference of the data. Wordclouds are beautifully insightful with pros and cons. Word clouds can allow you to share back results from research in a way that does not require an understanding of the technicalities. Some of the pros are below. 144 | * It reveals the essential. 145 | * They delight and provide emotional connection. 146 | * They are fast & engaging. 147 | As observed, skilled interpretation is what provides the beautiful insights. 148 | 149 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/results_1.png) 150 | 151 | Latent Dirichlet Allocation (LDA) is a probabilistic model with interpretable topics. Topic modeling is one of the most popular NLP techniques with several real-world applications such as dimensionality reduction, text summarization, recommendation engine, etc. To visualize our topics in a 2-dimensional space we will use the pyLDAvis library. This visualization is interactive in nature and displays topics along with the most relevant words. 152 | 153 | ![](https://github.com/IBM/text-summarization-and-visualization-using-watson-studio/blob/master/doc/source/images/results_2.png) 154 | 155 | As we can see from the topics, the data is referring to Mission Impossible Fallout movie. Skilled interpretation is needed to an extent for consuming the insights from the results. 156 | 157 | # Troubleshooting 158 | 159 | [See DEBUGGING.md.](DEBUGGING.md) 160 | 161 | # License 162 | 163 | This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer [Certificate of Origin, Version 1.1 (DCO)](https://developercertificate.org/) and the [Apache Software License, Version 2](http://www.apache.org/licenses/LICENSE-2.0.txt). 164 | 165 | Check the [ASL FAQ link](http://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN) for more details. 166 | -------------------------------------------------------------------------------- /data/Mission_Impossible_6_Review.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/data/Mission_Impossible_6_Review.txt -------------------------------------------------------------------------------- /doc/source/images/add_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/add_file.png -------------------------------------------------------------------------------- /doc/source/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/architecture.png -------------------------------------------------------------------------------- /doc/source/images/create_notebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/create_notebook.png -------------------------------------------------------------------------------- /doc/source/images/define_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/define_project.png -------------------------------------------------------------------------------- /doc/source/images/insert_cred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/insert_cred.png -------------------------------------------------------------------------------- /doc/source/images/new_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/new_project.png -------------------------------------------------------------------------------- /doc/source/images/results_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/results_1.png -------------------------------------------------------------------------------- /doc/source/images/results_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/text-summarization-and-visualization-using-watson-studio/937b67f93bc4501254f45c0558ebc1ebb37e761d/doc/source/images/results_2.png -------------------------------------------------------------------------------- /part-of-speech-tags/POS-Tags: -------------------------------------------------------------------------------- 1 | 2 | Number Tag Description 3 | 1. CC Coordinating conjunction 4 | 2. CD Cardinal number 5 | 3. DT Determiner 6 | 4. EX Existential there 7 | 5. FW Foreign word 8 | 6. IN Preposition or subordinating conjunction 9 | 7. JJ Adjective 10 | 8. JJR Adjective, comparative 11 | 9. JJS Adjective, superlative 12 | 10. LS List item marker 13 | 11. MD Modal 14 | 12. NN Noun, singular or mass 15 | 13. NNS Noun, plural 16 | 14. NNP Proper noun, singular 17 | 15. NNPS Proper noun, plural 18 | 16. PDT Predeterminer 19 | 17. POS Possessive ending 20 | 18. PRP Personal pronoun 21 | 19. PRP$ Possessive pronoun 22 | 20. RB Adverb 23 | 21. RBR Adverb, comparative 24 | 22. RBS Adverb, superlative 25 | 23. RP Particle 26 | 24. SYM Symbol 27 | 25. TO to 28 | 26. UH Interjection 29 | 27. VB Verb, base form 30 | 28. VBD Verb, past tense 31 | 29. VBG Verb, gerund or present participle 32 | 30. VBN Verb, past participle 33 | 31. VBP Verb, non-3rd person singular present 34 | 32. VBZ Verb, 3rd person singular present 35 | 33. WDT Wh-determiner 36 | 34. WP Wh-pronoun 37 | 35. WP$ Possessive wh-pronoun 38 | 36. WRB Wh-adverb --------------------------------------------------------------------------------