{"id":156978,"date":"2022-09-14T11:20:00","date_gmt":"2022-09-14T15:20:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=156978"},"modified":"2022-11-21T09:58:12","modified_gmt":"2022-11-21T14:58:12","slug":"natural-language-processing-in-python-using-spacy-part-ii","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/","title":{"rendered":"Natural Language Processing in Python using spaCy \u2013 Part II"},"content":{"rendered":"\n<p><em><a href=\"\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-i\/\">Part I<\/a> in this series provides and overview of spaCy and demonstrates how to install the library.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-split-text-into-sentences-using-spacy\">Split text into sentences using spaCy<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Initialize the text that you want to analyze\ntext = \"Ripple was founded in 2012 by Jed McCaleb and Chris Larsen (co-founder of E-Loan). But the gears were in motion back in 2004, four years before Bitcoin, when a Canadian programmer, Ryan Fugger, developed RipplePay.RipplePay, though not based on blockchain, was a secure payment system for a financial network. In 2012, Jed McCaleb and Chris Larsen started the company OpenCoin, renamed Ripple Labs in 2013.\"\ntext\n# Source: https:\/\/blog.quantinsti.com\/ripple-xrp\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/433e4d516318f7f7a14c2b74c580e24f#file-show_text-py\" target=\"_blank\" rel=\"noreferrer noopener\">show_text.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Source:&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/ripple-xrp\/\">Exploring Ripple and XRP: What it is, Features, and More<\/a><\/code><\/pre>\n\n\n\n<p>Let us now pass this text to our model and split it into individual sentences.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>doc = nlp(text)\n\n# Split the text into sentences\nsentences = &#91;sentence.text for sentence in doc.sents]\n# Print the original text\nprint(f\"Original text: \\n\\n{text}\\n{'-'*50}\\n\")\n# Print the different sentences from the text\nprint(\n    f\"We have split the above into {len(sentences)} sentences:\\n\\n 1. {sentences&#91;0]}\\n2. {sentences&#91;1]}\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/d72b92c9fd47de2bc284e42c42ed9a94#file-split_the_text-py\" target=\"_blank\" rel=\"noreferrer noopener\">split_the_text.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"removing-punctuation-using-spacy\">Removing punctuation using spaCy<\/h2>\n\n\n\n<p>Before we proceed further with our analysis, let us remove the punctuations from our text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>token_without_punc = &#91;token for token in doc if not token.is_punct]\ntoken_without_punc<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/b31150772347cb8ce07c8e26169e72ea#file-remove_punctuation-py\" target=\"_blank\" rel=\"noreferrer noopener\">remove_punctuation.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"removing-stop-words-using-spacy\">Removing stop words using spaCy<\/h2>\n\n\n\n<p>We can remove the stop words like&nbsp;<em>and<\/em>,&nbsp;<em>the<\/em>, etc. from the text because these words don\u2019t add much value to it for analysis purposes.<\/p>\n\n\n\n<p>For this, we first get the list of all the stop words for that language. There are two ways in which we can do it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get the stop words: 1st method\nall_stopwords = nlp.Defaults.stop_words\n\nlen(all_stopwords) # Output: 326<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/a8ab4a164143ebbbdedcf5ce1d8e89da#file-remove_stop_words-py\" target=\"_blank\" rel=\"noreferrer noopener\">remove_stop_words.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>This is the second method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get the stop words: 2nd method\nfrom spacy.lang.en.stop_words import STOP_WORDS\n\nlen(STOP_WORDS) # Output: 326<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/466a1cc689acd7d190342c753fc81901#file-remov_stop_words_2nd_method-py\" target=\"_blank\" rel=\"noreferrer noopener\">remov_stop_words_2nd_method.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>As we can see from the code below, the results of both the above methods are the same.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Both are the same\nall_stopwords is STOP_WORDS<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/eb4f513166381bbf98147f61039de231#file-check_methods_equality-py\" target=\"_blank\" rel=\"noreferrer noopener\">check_methods_equality.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>Now that we have got the list of stop words, let\u2019s remove them from our text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Remove the stop words\ntoken_without_stop = &#91;\n    token for token in token_without_punc if not token.is_stop]\ntoken_without_stop<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/ec2d284bcde15a560a1e37d886791fc3#file-remove_stop_words_from_text-py\" target=\"_blank\" rel=\"noreferrer noopener\">remove_stop_words_from_text.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pos-tagging-using-spacy\">POS tagging using spaCy<\/h2>\n\n\n\n<p>Let us now see how spaCy tags each token with its respective part-of-speech.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\ntoken_pos = &#91;]\nfor token in token_without_punc:\n    token_pos.append(&#91;token.text, token.lemma_, token.pos_, token.tag_, token.dep_,\n                      token.shape_, token.is_alpha, token.is_stop])\ndf = pd.DataFrame(token_pos, columns=&#91;'Text', 'Lemma', 'POS', 'Tag',\n                  'Syntactic dependency relation', 'Shape', 'Is Alphabet', 'Is stop word'])\ndf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/8b3201e64dd2684c9db7c24edd06e8e1#file-pos_tagging-py\" target=\"_blank\" rel=\"noreferrer noopener\">pos_tagging.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>If you would like to know more about the different token attributes, please click&nbsp;<a href=\"https:\/\/spacy.io\/api\/token#attributes\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"named-entity-recognition-using-spacy\">Named entity recognition using spaCy<\/h2>\n\n\n\n<p>What is a named entity? It is any \u2018real-world object\u2019 with an assigned name. It may be a country, city, person, building, company, etc. spaCy models can predict the different named entities in a text with remarkable accuracy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ner = &#91;]\nfor ent in doc.ents:\n    ner.append(&#91;ent.text, ent.start_char, ent.end_char, ent.label_])\n\ndf_ner = pd.DataFrame(\n    ner, columns=&#91;'Text', 'Start character', 'End character', 'Label'])\ndf_ner<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/7a565f2438df919769549b131c1ccadf#file-named_entity-py\" target=\"_blank\" rel=\"noreferrer noopener\">named_entity.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dependency-visualization-using-displacy\">Dependency Visualization using displaCy<\/h2>\n\n\n\n<p>Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled&nbsp;<a href=\"https:\/\/spacy.io\/usage\/visualizers\" target=\"_blank\" rel=\"noreferrer noopener\">displaCy<\/a>&nbsp;that lets you check your model&#8217;s predictions in your browser.<\/p>\n\n\n\n<p>To use it from the browser, we use the \u2018serve\u2019 method. DisplaCy can auto-detect if you are working on a Jupyter notebook. We can use the \u2018render\u2019 method to return markup that can be rendered in a cell.<\/p>\n\n\n\n<p>Let us try the spaCy\u2019s entity visualizer to render the NER results we got above.<\/p>\n\n\n\n<p>For this, let us import displaCy which is \u2018<strong>a modern and service-independent visualisation library<\/strong>\u2019<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from spacy import displacy\n\ndisplacy.render(doc, style=\"ent\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/c8276ff6bc957cd14c4be75d8d422ca4#file-dependency_visualisation-py\" target=\"_blank\" rel=\"noreferrer noopener\">dependency_visualisation.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"720\" height=\"109\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/NER-results-quantinsti.png\" alt=\"\" class=\"wp-image-157033 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/NER-results-quantinsti.png 720w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/NER-results-quantinsti-700x106.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/NER-results-quantinsti-300x45.png 300w\" data-sizes=\"(max-width: 720px) 100vw, 720px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 720px; aspect-ratio: 720\/109;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"getting-linguistic-annotations-using-spacy\">Getting linguistic annotations using spaCy<\/h2>\n\n\n\n<p>You can get insights into the grammatical structure of a text using spaCy\u2019s linguistic annotations functionality. It basically tells you the part of speech each word belongs to and how the different words are related to each other.<\/p>\n\n\n\n<p>We need to have installed spaCy and the trained model that we want to use. In this blog, we\u2019ll work with the English language model, the en_core_web_sm.<\/p>\n\n\n\n<p>Let\u2019s look at an example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Pass the text you want to analyze to your model\ndoc = nlp(\"Jennifer is learning quantitative analysis.\")\n\n# Print the part-of-speech and the syntactic dependency relation for the tokens\nfor token in doc:\n    print(token.text, token.pos_, token.dep_)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/2a179da3f307639f7e5b1e92b83dec25#file-linguistic_annotations-py\" target=\"_blank\" rel=\"noreferrer noopener\">linguistic_annotations.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>Let\u2019s visualize the syntactic relationship between the different tokens.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from spacy import displacy\ndisplacy.render(doc, style=\"dep\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/4beeb0c082340902d0c51369d4376eb7#file-visualise_syntactic_relationship-py\" target=\"_blank\" rel=\"noreferrer noopener\">visualise_syntactic_relationship.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"720\" height=\"250\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/syntactic-relationship-quantinsti.png\" alt=\"\" class=\"wp-image-157048 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/syntactic-relationship-quantinsti.png 720w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/syntactic-relationship-quantinsti-700x243.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/syntactic-relationship-quantinsti-300x104.png 300w\" data-sizes=\"(max-width: 720px) 100vw, 720px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 720px; aspect-ratio: 720\/250;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"spacy-examples-on-github\">spaCy examples on Github<\/h2>\n\n\n\n<p>We\u2019ve covered some of the basic NLP techniques using the spaCy library. To delve into further details, you can head to the&nbsp;<a href=\"https:\/\/github.com\/explosion\/spaCy\" target=\"_blank\" rel=\"noreferrer noopener\">spaCy GitHub page<\/a>&nbsp;where you can find tons of examples to help you in your journey into the spaCy universe.<\/p>\n\n\n\n<p>In addition to the development techniques, you can also try out the&nbsp;<a href=\"https:\/\/github.com\/explosion\/spaCy\/tree\/master\/spacy\/tests\" target=\"_blank\" rel=\"noreferrer noopener\">extensive test suite<\/a>&nbsp;offered by spaCy which uses the&nbsp;<a href=\"https:\/\/docs.pytest.org\/en\/latest\/contents.html\" target=\"_blank\" rel=\"noreferrer noopener\">pytest<\/a>&nbsp;framework.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h3>\n\n\n\n<p>We\u2019ve explored some of the main features of spaCy, but there is a lot more to be explored in this powerful Python natural language processing library. I hope that this blog has gotten you started with the initial few steps of this journey. So go ahead and explore the enormous world of human language and thoughts!<\/p>\n\n\n\n<p>Want to harness alternate sources of data, to quantify human sentiments expressed in news and tweets using machine learning techniques? Check out this course on&nbsp;<a href=\"https:\/\/quantra.quantinsti.com\/course\/trading-twitter-sentiment-analysis\" target=\"_blank\" rel=\"noreferrer noopener\">Trading Strategies with News and Tweets<\/a>. You can use sentiment indicators and sentiment scores to create a trading strategy and implement the same in live trading.<\/p>\n\n\n\n<p>Till then, happy tweeting and Pythoning!<\/p>\n\n\n\n<p><em>Visit QuantInsti website for additional insight on this topic:&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/spacy-python\/\">https:\/\/blog.quantinsti.com\/spacy-python\/<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check your model&#8217;s predictions in your browser.<\/p>\n","protected":false},"author":731,"featured_media":44932,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,349,338,350,341,351,352,344,2197],"tags":[806,865,12705,12706,595,12704],"contributors-categories":[13654],"class_list":{"0":"post-156978","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"category-quant-asia-pacific","12":"category-quant-development","13":"category-quant-europe","14":"category-quant-north-america","15":"category-quant-regions","16":"category-quant-south-america","17":"tag-data-science","18":"tag-github","19":"tag-natural-language-processing-nlp","20":"tag-natural-language-toolkit-nltk","21":"tag-python","22":"tag-spacy","23":"contributors-categories-quantinsti"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Natural Language Processing in Python using spaCy \u2013 Part II<\/title>\n<meta name=\"description\" content=\"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/156978\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Natural Language Processing in Python using spaCy \u2013 Part II | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check your model&#039;s predictions in your browser.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-14T15:20:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:58:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Udisha Alok\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Udisha Alok\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Udisha Alok\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/7faa788f12ff54d5d598292f5a252fab\"\n\t            },\n\t            \"headline\": \"Natural Language Processing in Python using spaCy \u2013 Part II\",\n\t            \"datePublished\": \"2022-09-14T15:20:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:12+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/\"\n\t            },\n\t            \"wordCount\": 643,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/python-mag-glass.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"GitHub\",\n\t                \"Natural Language Processing (NLP)\",\n\t                \"Natural Language Toolkit (NLTK)\",\n\t                \"Python\",\n\t                \"spaCy\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Asia Pacific\",\n\t                \"Quant Development\",\n\t                \"Quant Europe\",\n\t                \"Quant North America\",\n\t                \"Quant Regions\",\n\t                \"Quant South America\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/\",\n\t            \"name\": \"Natural Language Processing in Python using spaCy \u2013 Part II | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/python-mag-glass.jpg\",\n\t            \"datePublished\": \"2022-09-14T15:20:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:12+00:00\",\n\t            \"description\": \"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check your model's predictions in your browser.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/natural-language-processing-in-python-using-spacy-part-ii\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/python-mag-glass.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/python-mag-glass.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/7faa788f12ff54d5d598292f5a252fab\",\n\t            \"name\": \"Udisha Alok\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/udisha-alok\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Natural Language Processing in Python using spaCy \u2013 Part II","description":"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/156978\/","og_locale":"en_US","og_type":"article","og_title":"Natural Language Processing in Python using spaCy \u2013 Part II | IBKR Quant Blog","og_description":"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check your model's predictions in your browser.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/","og_site_name":"IBKR Campus US","article_published_time":"2022-09-14T15:20:00+00:00","article_modified_time":"2022-11-21T14:58:12+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","type":"image\/jpeg"}],"author":"Udisha Alok","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Udisha Alok","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/"},"author":{"name":"Udisha Alok","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/7faa788f12ff54d5d598292f5a252fab"},"headline":"Natural Language Processing in Python using spaCy \u2013 Part II","datePublished":"2022-09-14T15:20:00+00:00","dateModified":"2022-11-21T14:58:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/"},"wordCount":643,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","keywords":["Data Science","GitHub","Natural Language Processing (NLP)","Natural Language Toolkit (NLTK)","Python","spaCy"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Asia Pacific","Quant Development","Quant Europe","Quant North America","Quant Regions","Quant South America"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/","name":"Natural Language Processing in Python using spaCy \u2013 Part II | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","datePublished":"2022-09-14T15:20:00+00:00","dateModified":"2022-11-21T14:58:12+00:00","description":"Adding another powerful functionality to it\u2019s arsenal, spaCy also comes with a built-in dependency visualizer valled\u00a0displaCy\u00a0that lets you check your model's predictions in your browser.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/natural-language-processing-in-python-using-spacy-part-ii\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","width":900,"height":550,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/7faa788f12ff54d5d598292f5a252fab","name":"Udisha Alok","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/udisha-alok\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/python-mag-glass.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/156978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/731"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=156978"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/156978\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/44932"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=156978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=156978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=156978"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=156978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}