<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Farhad Sadeghlo on Medium]]></title>
        <description><![CDATA[Stories by Farhad Sadeghlo on Medium]]></description>
        <link>https://medium.com/@farhad-ml?source=rss-529d60650076------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*jXoACQMCEBOT6W10_bsoZw.jpeg</url>
            <title>Stories by Farhad Sadeghlo on Medium</title>
            <link>https://medium.com/@farhad-ml?source=rss-529d60650076------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:57:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@farhad-ml/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What Is Topic Modeling and How Can It Improve Natural Language Processing?]]></title>
            <link>https://medium.com/omdena/what-is-topic-modeling-and-how-can-it-improve-natural-language-processing-8b98e5ef58de?source=rss-529d60650076------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b98e5ef58de</guid>
            <category><![CDATA[mallet-library]]></category>
            <category><![CDATA[natural-based-solutions]]></category>
            <category><![CDATA[pyldavis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Farhad Sadeghlo]]></dc:creator>
            <pubDate>Sun, 14 Feb 2021 19:18:38 GMT</pubDate>
            <atom:updated>2021-02-14T19:18:38.405Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fsOu1BA0LW-sizEYbpM9XA.png" /></figure><h4>Topic Modeling and Visualizations with Gensim LDA equipped with Mallet library.</h4><h3>The problem</h3><p>The whole idea about topic modeling comes from the inspection of websites followed by an analysis to see if the website is performing as it is expected.</p><p>In this matter, deriving the following is useful — the dominant topic in each sentence, the most representative document in each topic, the topic distribution across documents, the frequency distribution of the word counts, the word cloud of top N keywords in each topic, the word counts of topic keywords, the sentence chart colored by topic, and a t-SNE clustering chart.</p><h3>How Topic Modeling can help: An example</h3><p>World Resources Institute (WRI) has been seeking to understand how regional and global Nature-Based Solutions (NbS) (e.g. forest and landscape restoration) can be leveraged to address and minimize climate change impacts. More than 50 Omdena AI changemakers developed an interactive dashboard, which visualizes the impact of climate change in various areas as well as showcases mitigating Nature-Based-Solutions.</p><h3>Where it is needed</h3><p>The used cases for such a project are everywhere and the results can be endless expectations; As explained the real reason is to qualify the clarity of the website; Some examples of websites that would need to be analyzed by topic modeling are those in the business of stock market, political views, publications, news, articles, blogs, in general, any website on the internet which has paragraphs in a large capacity which would not be possible for an individual to provide thorough analysis just by reading the raw text; Some examples of sectors which would ask for such analysis are everywhere, the owner(s) of the website, governments, jurisdictions, institutions for example, those who would like to invest their money in an industry, and etc.</p><h3>How we used topic modeling — The datasets</h3><p>The three datasets that this project was based on were: 1. <a href="https://afr100.org/">afr100</a>, 2. <a href="https://initiative20x20.org/">initiative20x20</a>, 3. <a href="https://cities4forests.com/">cities4forsets</a>.</p><p>Specifically, for this article, there were dozens of pdf files provided by the <a href="https://initiative20x20.org/">initiative20x20</a> website. We analyzed the extracted datasets, the following is the report of our analysis.</p><h3>The approach</h3><p>Let’s go through all the steps that are preferable to do for topic modeling analysis.</p><h4>Major libraries used in this project</h4><p>pyLDAvis is one of the major libraries that would help us in providing great analysis equipped with nice visualizations.</p><p>Another useful package to be installed is the mallet library. According to their <a href="http://mallet.cs.umass.edu/">website</a>, it is a Java-based package for topic modeling, document classification, clustering, information extraction, and other statistical natural language processing and machine learning applications.</p><p>Mallet library provides a better implementation of LDA, it runs faster and gives better topic separation.</p><h4>Pros of Gensim LDA</h4><p>It provides a general view of the context, unigrams, bigrams, and trigrams can be combined altogether.</p><p>Gensim LDA works perfectly on unigrams.</p><p>Two parameters of min_count and threshold would help in modifying the results from just unigrams to a general format. Min_count means the least number of cases in each topic, and threshold means</p><p>Gensim works properly with pyLDAvis.</p><h4>Cons of Gensim LDA</h4><p>The performance of Gensim LDA on bigrams and trigrams is weak, if one is interested just to generate bigrams and trigrams it doesn’t provide such important unique results, as mentioned above it provides a combination of all the N-grams.</p><p>For example, these are some results that Gensim LDA has provided.</p><p>min_count=1 and threshold=100</p><pre>[[&#39;city&#39;, &#39;take&#39;, &#39;many&#39;, &#39;shape&#39;, &#39;size&#39;, &#39;abandon&#39;, &#39;overgrow&#39;, &#39;lot&#39;, &#39;avenue&#39;, &#39;tower&#39;, &#39;vast&#39;, &#39;inner&#39;, &#39;city&#39;, &#39;park&#39;, &#39;repurpose&#39;, &#39;parking&#39;, &#39;space&#39;, &#39;serve&#39;, &#39;green&#39;, &#39;pocket&#39;, &#39;park&#39;, <strong>&#39;inner_forest&#39;</strong>, &#39;wild&#39;, &#39;natural&#39;, &#39;manicure&#39;, &#39;somewhere&#39;, &#39;find&#39;, &#39;public&#39;, &#39;private&#39;, &#39;land&#39;, &#39;provide&#39;, &#39;leisure&#39;, &#39;recreation&#39;, &#39;opportunity&#39;, &#39;riverbank&#39;, &#39;reduce&#39;, &#39;damaging&#39;, &#39;effect&#39;, &#39;stormwater&#39;, &#39;form&#39;, &#39;add&#39;, &#39;mosaic&#39;]]</pre><p>min_count =1 and threshold=50</p><pre>[[&#39;city&#39;, &#39;take&#39;, &#39;many&#39;, &#39;shape&#39;, &#39;size&#39;, &#39;abandon&#39;, &#39;overgrow&#39;, &#39;lot&#39;, &#39;avenue&#39;, &#39;tower&#39;, &#39;vast&#39;, &#39;inner&#39;, &#39;city&#39;, &#39;park&#39;, &#39;repurpose&#39;, &#39;parking&#39;, &#39;space&#39;, &#39;serve&#39;, &#39;green&#39;, &#39;<strong>inner_forest</strong>&#39;, &#39;wild&#39;, &#39;natural&#39;, &#39;manicure&#39;, &#39;somewhere&#39;, &#39;find&#39;, &#39;public&#39;, &#39;private&#39;, &#39;land&#39;, &#39;provide&#39;, &#39;leisure&#39;, &#39;riverbank&#39;, &#39;reduce&#39;, &#39;damaging&#39;, &#39;effect&#39;, &#39;stormwater&#39;, &#39;form&#39;, &#39;add&#39;, &#39;mosaic&#39;]]</pre><p>min_count=1 and threshold=10.</p><pre>[[&#39;city&#39;, &#39;take&#39;, &#39;many&#39;, &#39;shape&#39;, &#39;size&#39;, &#39;abandon&#39;, &#39;overgrow&#39;, &#39;lot&#39;, &#39;avenue&#39;, &#39;tower&#39;, &#39;vast&#39;, <strong>&#39;inner_city&#39;</strong>, &#39;park&#39;, &#39;repurpose&#39;, &#39;parking&#39;, &#39;space&#39;, &#39;serve&#39;, &#39;green&#39;, <strong>&#39;inner_forest&#39;</strong>, &#39;wild&#39;, &#39;natural&#39;, &#39;manicure&#39;, &#39;somewhere&#39;, &#39;find&#39;, &#39;land&#39;, &#39;provide&#39;, &#39;leisure&#39;, &#39;riverbank&#39;, &#39;reduce&#39;, &#39;damaging&#39;, &#39;effect&#39;, &#39;stormwater&#39;, &#39;form&#39;, &#39;add&#39;, &#39;mosaic&#39;, &#39;city&#39;]]</pre><p>While for min_count=1 and threshold=1 number of bigrams may not increase significantly as expected. The most unsatisfactory result is that although a specific function to remove stop_words was in place, it was failed on not considering “inner_for” as a bigram, as it is meaningless.</p><pre>[[<strong>&#39;inner_for&#39;</strong>, &#39;city&#39;, &#39;shape&#39;, &#39;size&#39;, &#39;abandon&#39;, &#39;overgrow&#39;, &#39;lot&#39;, &#39;avenue&#39;, &#39;tower&#39;, &#39;vast&#39;, <strong>&#39;inner_city&#39;</strong>, &#39;park&#39;, &#39;repurpose&#39;, &#39;parking&#39;, &#39;space&#39;, &#39;serve&#39;, &#39;green&#39;, <strong>&#39;inner_forest&#39;</strong>, &#39;wild&#39;, &#39;natural&#39;, &#39;manicure&#39;, &#39;somewhere&#39;, &#39;find&#39;, &#39;land&#39;, &#39;provide&#39;, &#39;leisure&#39;, &#39;riverbank&#39;, &#39;reduce&#39;, &#39;damaging&#39;, &#39;effect&#39;, &#39;stormwater&#39;, &#39;form&#39;, &#39;add&#39;, &#39;mosaic&#39;, &#39;forest&#39;]]</pre><p>Therefore, as it may contain stop_words, it can not be trusted, so we would stick to the most conservative parameters of min_count=5 and threshold=100.</p><pre>[[&#39;city&#39;, &#39;take&#39;, &#39;many&#39;, &#39;shape&#39;, &#39;size&#39;, &#39;abandon&#39;, &#39;overgrow&#39;, &#39;lot&#39;, &#39;avenue&#39;, &#39;tower&#39;, &#39;vast&#39;, &#39;inner&#39;, &#39;city&#39;, &#39;park&#39;, &#39;repurpose&#39;, &#39;parking&#39;, &#39;space&#39;, &#39;serve&#39;, &#39;green&#39;, &#39;pocket&#39;, &#39;park&#39;, <strong>&#39;inner_forest&#39;</strong>, &#39;wild&#39;, &#39;natural&#39;, &#39;manicure&#39;, &#39;somewhere&#39;, &#39;find&#39;, &#39;public&#39;, &#39;private&#39;, &#39;land&#39;, &#39;provide&#39;, &#39;leisure&#39;, &#39;recreation&#39;, &#39;opportunity&#39;, &#39;stabilize&#39;, &#39;slope&#39;, &#39;riverbank&#39;, &#39;intercept&#39;, &#39;rainfall&#39;, &#39;reduce&#39;, &#39;damaging&#39;, &#39;effect&#39;, &#39;stormwater&#39;, &#39;form&#39;, &#39;add&#39;, &#39;mosaic&#39;]]</pre><h4>What would pyLDAvis provide?</h4><p>pyLDAvis is very well suited with visualizations of topic models that add additional quality to one&#39;s interaction with the result of topic classification. It is equipped with a slide to adjust the relevance metric. As it can be seen in the following figure all of the segregated topic models are shown and one can choose the topic of interest, the result is according to the relevance metric equipped with the top-30 most relevant terms for each topic, the words are provided with the number of times each word mentioned in that topic. One must know that non-overlapped topics are better choices as they would contain unique words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fsOu1BA0LW-sizEYbpM9XA.png" /><figcaption>Visualizing topic-keywords with pyLDAvis</figcaption></figure><h4>How mallet library can help?</h4><p>To emphasize how the usage of the mallet library is essential let’s provide word clouds of the topics modeled before and after using the mallet library.</p><p>As mentioned in the title, this project&#39;s main topic is Natural Based Solutions (NBS) in climate change. The following pictures of 8 topics the first without and the second with the mallet library clearly show this big change. Below, the most used cases in each topic have become bolder than the rest.</p><p>The case with the mallet library provides more meaningful topics related to this project than the case without the mallet library. For example “NBS” which is one of the keywords in this project can only be seen in the case with the mallet library.</p><ul><li>Without the mallet library.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*_wgC7j2rAGfaW1r6YwoS6w.png" /><figcaption>LDA model word cloud without considering the mallet library</figcaption></figure><ul><li>With the mallet library.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*4mAg2eDN3CWrOuxUiaaGvA.png" /><figcaption>Optimized LDA model word cloud by using the mallet library</figcaption></figure><h4>What is perplexity?</h4><p>Perplexity measures the amount of surprise that this model shows from itself while seeing a new dataset. The lower the perplexity, the better the model, or The higher the log-likelihood in the numerator the better.</p><p>The perplexity in this format is a decreasing function of the log-likelihood L(w), i.e. the numerator is the log-likelihood of a set of unseen documents Wd given the topics Phi and the hyperparameter alpha for topic-distribution theta d of documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*30wK_RdeG0O3YABAPUqLGw.png" /></figure><p>In case of the need to compare models, we can use the likelihood of unseen documents for it.</p><p>We should bear in mind that the likelihood P(Wd|Phi, alpha) of one document is intractable, and therefore is perplexity.</p><h4>What is the coherence score?</h4><p>Coherence score is a real number quantifying the degree of semantic similarity among the highest scoring words in the set. Such measurements help us to identify semantically interpretable topics and those which are the artifacts of statistical interference. There are steps to do so.</p><ol><li>What are the top n most used words in each topic?</li><li>What is the summation of all pairwise scores (UCI or UMass) for each of the words in the previous question? The answer is the coherence score for each topic.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*toyV4uiblMzqbMtmdvH1Mw.png" /></figure><p>3. What is the mean of the coherence score per topic for all topics in the model? That would be the coherence score for the topic model.</p><p>Also, by using the coherencemodel() method and providing the type of coherence of interest, one can compute the current coherence score and perplexity, and after supplying the pipeline with the LDA mallet deriving the coherence score and perplexity for different models and finally by plotting a graph of several topics with the coherence score, optimizing the number of topics to improve the quality of the final results. For example, according to the following graph, the best number of topics should be 8. But also, one should bear in mind that if the number of repetitions of topic models in the final results is high, it would be a wise decision to increase the number of topics although the coherence score may decrease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*zo4bVrUIT0m-sAsHjYzRFQ.png" /><figcaption>Coherence score and number of topics</figcaption></figure><h4>Frequency Distribution of Document Word Counts by Dominant Topic</h4><p>This important part would help us to understand in each set of our dominant topics how many related words existed in what number of documents. Therefore, we can estimate how such words were scattered in our topics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-814r-psWXZFafcxHBIDSA.png" /></figure><h4>The word clouds of top N keywords in each topic</h4><p>Following with the word clouds of top N keywords in each topic and with the previous paragraph to provide an example we can discuss the distribution of document word counts in “topic 1”, “topic 0”, and “topic 7”.</p><p>“Topic 1, 0 and 7” had shown more involvement in the number of counts and they were addressing words like “key woman local community and group work project, landscape forest restoration, and water resource area and natural ecosystem” as we can see on average.</p><p>While the others like “topic 2” and “topic 5” which had less involvement were more focused on “practice farmer policy support” and “measure estimate model report time” respectively.</p><p>Therefore, we can summarize that most of our pdf files address the issues and cases that we need to talk about in NBS solutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*4mAg2eDN3CWrOuxUiaaGvA.png" /></figure><h4>The word counts of topic keywords</h4><p>We discussed earlier that according to our analysis “topic 1, 0, and 7” <em>on average</em> play a dominant role in our model, below we can have a look at 10 of the most used words in each of the topic keywords, their word counts and weights. We can see that <em>on average</em> “topic 1, 0, and 7” number of word counts are higher than the rest i.e. closer to ~ 900 or 1000. We can see topic 6 has some considerable amounts for words “climate” and “change” but it decreases quickly for the rest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DELxidl4z78vnXxQ2ocdRw.png" /></figure><h4>A t-SNE clustering chart</h4><p>As discussed topics “1, 0, and 7&quot; had more dominancy of word usage on the rest, so we need more clarification. One type of solution that can help us in finding the most dominant topic is plotting the clustering chart.</p><p>Here in the following figure, all 8 topics usages are plotted. Clearly, we can see topic 1 has a considerable amount of dominancy over the rest, then topic 0, but topic 7 is not that much dominant as we expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*E-M0_0l57BiNaCVITqHp7Q.png" /></figure><h3>Conclusion and Summary</h3><p>In this article, we provided the benefits of topic modeling, cons and pros of topic modeling with Gensim LDA, some use case examples, introduced pyLDAvis and mallet library, described perplexity and coherence score, the frequency distribution of document word counts by dominant topic, the word clouds of top n keywords in each topic, the word counts of topic keywords and finally t-SNE chart for clarification.</p><h3>References:</h3><p><a href="https://github.com/bmabey/pyLDAvis">https://github.com/bmabey/pyLDAvis</a></p><p><a href="http://qpleple.com/perplexity-to-evaluate-topic-models/">http://qpleple.com/perplexity-to-evaluate-topic-models/</a></p><h3>About Omdena</h3><p><a href="http://www.omdena.com/"><strong>Omdena</strong></a> is an innovation platform for building AI solutions to real-world problems through the power of bottom-up collaboration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b98e5ef58de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omdena/what-is-topic-modeling-and-how-can-it-improve-natural-language-processing-8b98e5ef58de">What Is Topic Modeling and How Can It Improve Natural Language Processing?</a> was originally published in <a href="https://medium.com/omdena">Omdena</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Scrape Website Information Most Efficiently]]></title>
            <link>https://medium.com/omdena/why-should-we-web-scrape-website-information-6a580ff7a1b1?source=rss-529d60650076------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a580ff7a1b1</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[web-scraping-tools]]></category>
            <dc:creator><![CDATA[Farhad Sadeghlo]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 15:20:35 GMT</pubDate>
            <atom:updated>2021-01-29T02:11:47.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h8HPMt6luYAEVdmGpm9VNA.png" /></figure><h4>Building pipelines to scrape website information and web addresses with BeatifulSoup and Urllib.</h4><blockquote><em>The work described in the article is part of </em><a href="https://omdena.com/projects/climate-change/"><em>Omdena’s AI collaboration</em></a><em> with the WRI climate change.</em></blockquote><h3>The problem</h3><p>Almost in all data science/analysis projects, not having proper datasets is usual. In all companies who have substantial projects, there is a specific section or a defined subtask just to web-scrape (record) websites information to create a dataset for their data scientists/analysts. In some projects like this, with a time period of two months, as the projects grow step by step, the very same data scientists needed to make their datasets, too.</p><h3>Making the pipeline</h3><p>First things first, one must know what kind of dataset to what quality is needed. There are two types of web scraping: 1. Light Scraping and 2. Heavy Scraping</p><h3>Light Scraping</h3><p>Light scraping is the case in which the pipeline would grab a section like all paragraphs as a whole or all of the sections (everything in the website) and save them as a whole. In this approach, extra information from the website would be collected which may ruin the final dataset.</p><h3>Heavy Scraping</h3><p>In heavy scraping, the pipeline reads the required sections of the website segregating different sections by their title and paragraph e.g. considering the title of each paragraph the column name and its context in the column data. In this process, one needs to read information from different sections by going through every single one of webpages recording the key identification characters which would address that specific section or subsection. This process could take a very long time especially if some pages of the website are different than others, even if the difference is just one small section or context, not doing so could ruin everything in this process, saving information in the wrong parts of a dataset. In the code provided in this article, the parameter inside the find_all() method of the BeautifulSoup addresses this issue. For example, parameter ‘‘a’’ refers to the web-address, parameter ‘‘p’’ refers to the paragraph, parameter “title” refers to the title of the paragraph. A full list of such parameters can be investigated by inspecting the website of interest as explained below.</p><h3>The websites</h3><p>In this project, our client was only interested in the analysis of three websites: 1. <a href="https://afr100.org/">afr100</a>, 2. <a href="https://initiative20x20.org/">initiative20x20</a>, 3. <a href="https://cities4forests.com/">cities4forsets</a>.</p><p>For the sake of similarity, only two subpages of the first website are discussed in this article.</p><p>For example, if we are interested in <a href="https://afr100.org/">The afr100</a> website section news and events <a href="https://afr100.org/news-events/all-news">all the news</a>. We would need to reach the page by a web browser that supports website inspection like google chrome and highlighting the needed section or right-clicking the desired word of a section and inspect it, like the following picture.</p><p>In this special case, h1 represents the page title font size and the information we need are “class” and “id”. So, by providing these to the BeautifulSoup parameters, the page title i.e. “NEWS” would be provided as the result of one of the code’s subfunctions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5H-3GgbzFgdOydfiV20dw.png" /><figcaption>Grabbed from <a href="https://afr100.org/news-events/all-news">afr100 website</a></figcaption></figure><p>In a similar fashion, we would grab the needed parameters for the sections of interest, like below as we were interested in the titles and texts of each article on the all-news and event-calendar pages of afr100.</p><h3>The code</h3><h4>BeautifulSoup</h4><p>Importing the needed libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*Lq3RtOMUMwdaSVbK0-NE1w.png" /><figcaption>Importing the needed datasets</figcaption></figure><p>Saving the web addresses as a string in variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Oal_BMdh03xu-Kd0-YzpNQ.png" /></figure><p>Defining a function to extract the links that refer to each article in the news and events pages of afr100.org. The key parts are getting the texts of the webpage in the variable “soup” with the help of the “html5lib” library, finding everything assigned with parameter ‘a’ as such parameter refers to webpages in HTML language, and finally considering only the unique web addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*REWh9nzzttbylQtQ_8ErtQ.png" /><figcaption>“get_pages” function to get the web addresses</figcaption></figure><p>Applying the function on the web address and saving the results in variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*nkovJ6G_ZMYFx9LpmElQnw.png" /><figcaption>Applying the functions</figcaption></figure><p>Not all of the gathered information is useful. There are some web addresses that are referring to SuperPages and not the respective articles. (This kind of cleaning is only useful for the small size of information)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*ziDyZwfqWGd3OTCZXcTzvw.png" /><figcaption>Web addresses</figcaption></figure><p>To delete the irrelevant information the basics come in handy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*XpEqc8HnlUMF5mrU52bvew.png" /><figcaption>Cleaning useless information from the variables</figcaption></figure><p>Next, we should define a function to add the main web domain address, “<a href="https://afr100.org/">https://afr100.org</a>” to the start of each one of the web addresses, as previously we only read the path of each link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*tx1hiU3Ob4DsdR0ZEkHQJA.png" /><figcaption>“link_prep” function to prepare web addresses</figcaption></figure><p>Also, we should apply the link_prep function on the variables and updating them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*eBJZ6wYjPA94eCfJuqZUag.png" /><figcaption>Applying the functions</figcaption></figure><p>Then, we need to define the column names of our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*0FVDbcUSEF00sJ2ukl1cyA.png" /><figcaption>Making the datasets and defining the columns</figcaption></figure><p>Saving the variables information, the complete web addresses in their respective columns of our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*7pY2S9mqW1ixyvs7K8ZG2A.png" /><figcaption>Moving the web addresses to their respective columns</figcaption></figure><p>Defining two key functions, “get_title_pages” and “get_paragraph_pages” that would help us gather the titles and their respective paragraphs from each webpage also considering just their texts and removing their useless characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*3llugythIpQnIKlduiK--g.png" /><figcaption>Defining the “get_title_pages” and “get_paragraph_pages” functions</figcaption></figure><p>Defining a “collector” function that would apply the previous two functions on each of the web addresses that we planned to be saved in the first columns of our future datasets as ‘news_link’ and ‘events_link’.</p><p>This is the best and most friendly approach to scrape information from a website. The reason is that the code loads the webpages, in this project ‘‘articles’’ from the website one by one and not all at once, therefore not causing the website to collapse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*pY0RYVD73WUiWv6Wdi0Yig.png" /><figcaption>Defining “collect” function</figcaption></figure><p>Applying the “collector” function on the variables which are having the complete web addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*OedVltAsSIwXGkGsgHGzKg.png" /><figcaption>Applying the functions</figcaption></figure><p>Finally, saving the complete variables containing our datasets into .csv files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*RgQfQWFWdSYWwqDjqZXm-g.png" /><figcaption>Saving the variables data to .csv datasets</figcaption></figure><h4>Urllib</h4><p>Urllib is one of the best solutions to parse website address subpages. It is equipped with BeautifulSoup which provides a collection of information in each subpage of a website in a hierarchical approach. This results in parsed data collection based on the subpages name in the web address. Therefore, the full information of a webpage can be saved based on the subpages name. In short, urllib parse() method provides information of the website protocol type (scheme), main address (netloc), sub-address (path), params (parameters), query (information about the one viewing the webpage), and the rest of useful information which are provided below. For a list of web addresses, each of the attributes can be a column of a dataset for future analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*kP_VvnUfyqv5F7RohFhOVA.png" /><figcaption>Urllib parsing attributes</figcaption></figure><p>One of the used cases in this approach is to analyze information of massive websites like <a href="https://www.amazon.com/">Amazon</a>, <a href="https://www.ebay.com/">eBay</a>, or <a href="https://shopping.google.com/">Google shopping</a> qualifying if a product is posted on a correct subpage.</p><h3>Final datasets</h3><p>Finally, the results of our web scraping pipeline are provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GeCOgnFanYJeXC7ERTbH9A.png" /><figcaption>final_news final dataset</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yd8qJ9msKSYbc8pTJ8AIPA.png" /><figcaption>final_events final dataset</figcaption></figure><h3>Conclusion and summary</h3><p>In this article, light, and heavy scraping, two of the solutions to scrape website information in the most efficient and friendly way with a website were provided, the BeautifulSoup for scraping website information, the Urllib for parsing web addresses, and the final datasets used in our project were provided.</p><h3>About Omdena</h3><p><a href="http://www.omdena.com/"><strong>Omdena</strong></a> is an innovation platform for building AI solutions to real-world problems through the power of bottom-up collaboration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a580ff7a1b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omdena/why-should-we-web-scrape-website-information-6a580ff7a1b1">How to Scrape Website Information Most Efficiently</a> was originally published in <a href="https://medium.com/omdena">Omdena</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing India’s COVID-19 Employment Loss with Tableau]]></title>
            <link>https://medium.com/omdena/visualizing-indias-covid-19-employment-loss-with-tableau-3c2ee72a1d01?source=rss-529d60650076------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c2ee72a1d01</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[unemployment-rate]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[tableau]]></category>
            <dc:creator><![CDATA[Farhad Sadeghlo]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 12:24:36 GMT</pubDate>
            <atom:updated>2020-06-18T12:40:55.821Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmmdeoJoFV-q4TZIFU8oWw.png" /><figcaption>Total of the unemployment rates (explanation below)</figcaption></figure><h4>Estimating the total employed population and total unemployed rate in India on a monthly statewide map.</h4><p>I dived into Tableau via 7 hours of training to visualize some findings from the <a href="https://omdena.com/projects/ai-pandemics/">Omdena COVID 19 AI project</a>. The aim of this project was to help governments design data-driven policies and enabling them to deal with pandemics like the Coronavirus more effectively and efficiently.</p><p>As we all know Covid-19 has spread everywhere and caused dramatic negative effects on many company sectors around the world. According to <a href="https://www.ctvnews.ca/health/coronavirus/business-is-booming-for-these-companies-during-the-covid-19-pandemic-1.4933907">CTV News</a> and <a href="https://www.mercurynews.com/2020/05/07/business-is-booming-for-these-14-companies-during-the-coronavirus-pandemic/">Mercury News</a>, only a few companies in this COVID-19 pandemic condition could provide reliable business.</p><h3>Sectors affected</h3><p>Overall in this project, we researched four sectors affected by the spread of COVID-19, including domestic violence, wage loss, and access to health facilities. This article focuses on employment loss. You can see all findings <a href="https://omdena.com/blog/pandemic-policy/">here</a>.</p><h3>The datasets</h3><p>The datasets used in this study are:</p><ol><li>Rural areas unemployment, and labor participation rates.</li><li>Urban areas unemployment, and labor participation rates, which are derived by India’s government dataset as above.</li><li>Policies enactment date regarding people’s mobility in different measures which is provided by Oxford University called <a href="https://www.bsg.ox.ac.uk/research/research-projects/coronavirus-government-response-tracker">OxCGRT</a>. It provides information about containment and closure policies for this study. Those measures are:</li></ol><ul><li>C1_School closing</li><li>C2_Workplace closing</li><li>C3_Cancel public events</li><li>C4_Restrictions on gatherings</li><li>C5_Close public transport</li><li>C6_Stay at home requirements</li><li>C7_Restrictions on internal movement</li><li>C8_International travel controls</li><li>H1_Public information campaigns</li></ul><p>Those policies are rated by government officials based on the severity of the conditions in the country. By other means, they forecast future problems and make decisions to lower the impact that those problems may have on different sectors of the country.</p><p>The table on page 14 of the report from <a href="https://www.bsg.ox.ac.uk/sites/default/files/2020-05/BSG-WP-2020-032-v6.0.pdf">Oxford University</a> provides a description of each policy and its severity ratio by the term “coding instructions”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*9JTij8Mtc0EXNTiRNFet4Q.png" /><figcaption>Fig 3–1. Policy instructions</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*iQUyHthSn-fg4ceupX83tg.png" /><figcaption>Fig 3–2. Health policy measures</figcaption></figure><p>For the sake of the simplicity of the graphs, I removed zero cases from the annotations.</p><h3>The value of Tableau for visualization</h3><p>I chose Tableau because of its easiness, and the many features that it provides. Before we dive into the graphics, I share with you the terms used in the visualizations.</p><h4>Terms</h4><ul><li>Unemployment rate (%): The number of unemployed persons divided by the number of persons in the labor force (not the overall adult population). <a href="https://opentextbc.ca/principlesofeconomics/chapter/21-1-how-the-unemployment-rate-is-defined-and-computed/#:~:text=The%20unemployment%20rate%20is%20defined%20as%20the%20number%20of%20unemployed,labor%20force%20that%20is%20unemployed.">Link</a>.</li><li>Labor participation rate (%): The number of people in the economy who are the active workforce either employed or unemployed.</li><li>Policies enactment dates: Two types of policy records are shown below.</li></ul><p>1. On the daily basis diagrams, policies that are issued on each day are shown, and 2. For the weekly basis diagrams, policies that are issued on the first day of each week.</p><ul><li>Stringency Index: A composite measure based on nine response indicators. It provides more in-depth information about the country’s enforced its strongest measures. More information available <a href="https://www.civilsdaily.com/news/what-is-stringency-index/">here</a>.</li></ul><p>It is calculated by averaging the policy indicators index values of C1-C8 and H1 (health system policy to provide campaigns for public information). These nine indicators would be used in the stringency index equation. Its current format is what can be seen in Eq 5–1, and it gets updated from time to time. So, the future format may not be like this. Future versions are available in their <a href="https://github.com/OxCGRT/covid-policy-tracker/blob/master/documentation/index_methodology.md">GitHub</a>.</p><p>The stringency index is one of the simple averages of the individual component indicators. Among others in <a href="https://www.bsg.ox.ac.uk/sites/default/files/2020-05/BSG-WP-2020-032-v6.0.pdf">a report by</a> the University of Oxford, it’s derived by the equation Eq 5–1, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*SX9VxL1wbE6w7iMQkVn9Ug.png" /><figcaption>Eq 5–1. Stringency Index Equation</figcaption></figure><p>Those index values are calculated by the equation Eq 5–2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*3bhTJHzjoRY-ji4aZi_vgg.png" /><figcaption>Eq 5–2. Stringency Index, Index values calculations</figcaption></figure><p>Eq 5–2 has four parameters which are defined as below. Nj and Fj are constant values available in Table 5–1, and vj,t, and fj,t are variables available in our dataset.</p><ul><li>the maximum possible value of the indicators C1-C8, and H1 (as Nj)</li><li>whether that indicator has a flag (Fj=1 if the indicator has a flag variable, or 0 if the indicator does not have a flag variable)</li><li>the recorded policy value on the ordinal scale for that specific day (vj,t)</li><li>the recorded binary flag for that indicator, if that indicator has a flag (fj,t)</li></ul><p>The following is the table of those constant values</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*4irUsyYa6kaii5Im6SSYxg.png" /><figcaption>Table 5–1. Constant values for stringency index</figcaption></figure><p>Below is an example of the calculated data with constant and variable values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*hqyoOwq1wk0lUKQcBO6hLw.png" /><figcaption>Table 5–2. Example of calculated data</figcaption></figure><p>Which provides the calculated stringency index of 43.98 for a specific day.</p><h3>Discussion</h3><p>The daily basis for unemployment and labor participation rates wouldn’t make much sense as the information takes time to be in effect and being reported especially for in developing countries. So, the provided figures are on a weekly basis.</p><p>The first annotation is started at the date in which the policies are started. As the weeks go on if no annotation is represented it means no changes had been issued. The small changes in estimated rates (%) can be read from the y-axis of the figures.</p><h4>Unemployment Rates</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h6kT6pjW7Q0osBWjSQKeQg.png" /><figcaption>Fig 6–1. Rural areas unemployment rates (weekly timeline)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3oKnhpoKxWwAUQvm4izdhA.png" /><figcaption>Fig 6–2. Urban areas unemployment rates (weekly timeline)</figcaption></figure><p>The first impression is:</p><ul><li>Only five changes to the number of policies for the period of four months had been issued which is really low. As the number of infected people can be tracked per day and the growth can be acknowledged just after a couple of days the expectation is to have changes of policies daily, or at least after two weeks that the number of deaths would make the need for policy changes inevitable.</li><li>Policy order happened really late on the second week of March, while the whispers of this disease were around on mid of Dec 2019, and this huge unpleasant unfaithful corruption and disloyalty of the World Health Organization (WHO) against the world which had been addressed by the country of the People’s Republic of China, that exploded all over the news as WHO and China or CHO (China Health Organization) scandal came out on Jan 30th. So, there was a lot of room to act on before Mar 8th. <a href="https://globalnews.ca/news/6826415/world-health-organization-accused-of-mishandling-coronavirus-pandemic-covid-19/">Link</a>.</li><li>On the week of March 8th that only closing of some schools and recommendations on canceling public events, stay at home requirements, and quarantining international travelers to the level of screening had been addressed, unemployment rates decreased instead of increase. On the next week March 15th, that quarantining international travelers were forced, unemployment rates increased to some extent. Only after ordering tough policies to the highest degree on March 22th, the unemployment rates jumped off hugely on March 29th. But, people from urban areas found opportunities in rural areas. Or, people living in rural areas didn’t take the condition seriously and found opportunities that resulted in a decrease in unemployment rates in rural areas and their increase in urban areas.</li><li>Also, the urban areas&#39; unemployment rates affected by the policies a lot more than the rural areas as expected due to the larger population.</li><li>Suddenly on the week after Apr 12th, there was a huge jump in unemployment rates of rural areas and a huge dive in unemployment rates of urban areas i.e. people living in the countryside had found opportunities in the cities and this traveling back and forth between the locations had continued till Apr 26 that a change of policies had been issued and both unemployment rates had jumped off again.</li></ul><h4>Labor Participation Rates</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sj0PA58Uabmrjd4JpCxxTg.png" /><figcaption>Fig 6–3. Rural areas labor participation rate (weekly timeline)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gkIhWCZ1-xTg1dHVQXzr1w.png" /><figcaption>Fig 6–4. Urban areas labor participation rate (weekly timeline)</figcaption></figure><ul><li>Rural and urban areas labor participation rates increased about 2% in the first two weeks of March for rural and the last two weeks of March for urban also similar increases did happen in the months before. Rural areas had a gradual drop and urban areas had a significant drop of 10% as the strict policy measures of March 22th had been issued, which definitely shows that the workforce did take in charge the policies to some extent. But, as the timeline reaches the month of spring both had increased due to more possible activities that the spring season provides.</li></ul><h4>Policies</h4><p>The following figure provides stepwise policy enactment dates on a daily basis. Stay home and international travel ban recommendations issued first on Jan 26th, school closing, and cancel public events issued on March 8th, following with the rest of policy orders on March 15th and March 22nd. Also, H1 public information campaigns started on March 3rd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNQ7_6l23T8eTKhHxB4Zxw.png" /><figcaption>Fig 6–5. Policies C1-C8, and H1 (daily timeline)</figcaption></figure><h4>Stringency Index</h4><p>Stringency index or countries&#39; policy strictness measure. The tougher the policies are getting the higher the stringency index becomes. The main value that this information provides is that all these policy measures can be called out with only one number i.e. stringency index.</p><p>The policies strictness jumped off fast, starting March 5th and reached 100 on March 22nd quickly but this lateness of six weeks to two months shows itself clearly. This had to happen two months before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*ADxlx_T-HP94LOFyGObg6w.png" /><figcaption>Fig 6–6. Stringency Index (daily timeline)</figcaption></figure><p>The following figure plots the estimated total employed population and total unemployed rate in India on a monthly statewide map. The bar graph below each map shows the severity of the condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmmdeoJoFV-q4TZIFU8oWw.png" /><figcaption>Fig 6–7. Total of the unemployment rates and count of employment, map of states</figcaption></figure><p>More user-friendly figures with the capability of investigating based on dates are provided in my <a href="https://public.tableau.com/profile/farhad.sadeghlo/#!/vizhome/India_15903647244940/Story1">Tableau profile</a>.</p><p>The video format of changing the slider is provided below. For more information please play the video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQ8U7eCDe8Qk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ8U7eCDe8Qk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQ8U7eCDe8Qk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3da81f3998fe695790faf5eee9c6337/href">https://medium.com/media/c3da81f3998fe695790faf5eee9c6337/href</a></iframe><h3>Suggested improvements for future pandemics</h3><p>To combat future pandemics some advice can be addressed.</p><ul><li>The first set of policies issued on Jan 26th while as we all know, the whispers about COVID-19 started from mid of Dec 2019. Maybe, if such policies were issued sooner. People could have accepted them easier and as the days were closing to mid of Jan, the policies were already in full effect.</li><li>The number of only five policies for the period of four months was really low. Effectively, it shows how slow is the response of the communities to the policy enactment dates by the government. Although the information to people did provide by starting March 3rd, for future conditions It needs to be addressed by providing more informative pamphlets that show people do really die for example because of this disease and make it more sensible for the citizens that really the result of ignoring policies is death, or even by applying significantly more pressure on the citizens to understand the condition.</li><li>In my opinion, this massive corruption that took over everyone’s attention had obvious reasons to believe and act on. But, no comparable response to the greatness of the incident ever issued. It seems there was a lot of trust in organizations and countries which all have been destroyed in 24 hours. Therefore, countries had to act hastily in closing everything in their country. Every time any corruption happens a lot of consequences would come after, therefore when the corruption of this huge size happens, the prediction on the consequences must be larger and faster.</li></ul><h3>Conclusion</h3><p>I would be pleased if the readers have a look at my <a href="https://public.tableau.com/profile/farhad.sadeghlo#!/vizhome/India_15903647244940/Story1">Tableau profile</a> too. It provides you with access to the figures in this report in a wider space with the capability of moving forward according to the time series that you can choose the date that you’re looking for and compare the information easier.</p><h3>About Omdena</h3><p><a href="http://www.omdena.com/"><strong>Omdena</strong></a> is an innovation platform for building AI solutions to real-world problems through the power of bottom-up collaboration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c2ee72a1d01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omdena/visualizing-indias-covid-19-employment-loss-with-tableau-3c2ee72a1d01">Visualizing India’s COVID-19 Employment Loss with Tableau</a> was originally published in <a href="https://medium.com/omdena">Omdena</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simplified NLP Model to Prevent Child and Sexual Abuse in Organizations]]></title>
            <link>https://medium.com/omdena/a-simplified-nlp-model-to-prevent-child-and-sexual-abuse-in-organizations-ccc81f4668c?source=rss-529d60650076------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccc81f4668c</guid>
            <category><![CDATA[corrupt-organizations]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[stop-sexual-abuse]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[stop-child-abuse]]></category>
            <dc:creator><![CDATA[Farhad Sadeghlo]]></dc:creator>
            <pubDate>Thu, 23 Apr 2020 17:04:05 GMT</pubDate>
            <atom:updated>2022-11-30T17:32:31.144Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdcZu069XKKvPE1MFYW6yg.png" /></figure><h4>How to build a classification model to identify molesters in chat conversations.</h4><blockquote>The work described in the article is part of <a href="https://omdena.com/challenges/ai-sexual-harassment">Omdena’s AI project</a> with the Zero Abuse Project.</blockquote><h4>The problem</h4><p>There is a long history of predators abusing children and women. Some say predatory comes back to <a href="https://areomagazine.com/2017/11/29/evolution-rape-and-power-why-understanding-human-nature-matters/">human history</a>. According to <a href="https://family.findlaw.com/child-abuse/child-abuse-background-and-history.html">English common law</a> children were considered the property of their fathers as women were considered the property of their husbands. It was in the late <a href="https://family.findlaw.com/child-abuse/child-abuse-background-and-history.html">1800s</a> when the law changed which is pretty recent. The first case of predatory against children on file dates back only to <a href="https://family.findlaw.com/child-abuse/child-abuse-background-and-history.html">the 1870s</a>. Despite advancements in human civilization, the numbers are on the rise which comes with detrimental <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4311357/">consequences</a> for the victims.</p><h4>Where it happens</h4><p>Especially in organizations like <a href="https://www.washingtonpost.com/local/education/academias-metoo-moment-women-accuse-professors-of-sexual-misconduct/2018/05/10/474102de-2631-11e8-874b-d517e912f125_story.html">academics</a>, <a href="https://www.buzzfeednews.com/article/lamvo/eeoc-sexual-harassment-data">companies</a>, and also <a href="https://en.wikipedia.org/wiki/Catholic_Church_sexual_abuse_cases">churches</a> incidents have been frequent. Another problem is that many institutions engage in <a href="https://qz.com/598609/university-cover-ups-of-sexual-harassment-are-just-like-the-catholic-church/">cover-ups</a> to avoid negative press. <a href="https://www.unicef.ca/en/discover/child-protection">UNICEF</a> and societies like “The International Society for Prevention of Child Abuse and Neglect” (<a href="https://www.who.int/violenceprevention/about/participants/ispcan/en/">ISPCAN</a>) are some of the organizations that try to help children who are particularly at risk of molesters.</p><h4>The project</h4><p>To help combat the severity of the problem, I joined an Omdena project together with the <a href="https://www.zeroabuseproject.org/">Zero Abuse Project</a>. Among 45 Omdena collaborators from across 6 continents, the goal was <a href="https://omdena.com/projects/ai-sexual-harassment">to build AI models</a> to identify patterns in the behavior of institutions when they cover-up incidents of sexual abuse.</p><p>In the following, I explain how we build a simplified NLP model that will be of great help to classify predator individuals.</p><h4>The dataset</h4><p>The dataset that is used in this report is <a href="https://www.aclweb.org/anthology/W13-1607.pdf">Pan12</a>. Pan12 contains chat texts between the molesters and children.</p><p>We can import its XML version by using one of the libraries of <a href="https://www.guru99.com/manipulating-xml-with-python.html">xml.dom.minidom</a> or <a href="https://docs.python.org/2/library/xml.etree.elementtree.html#module-xml.etree.ElementTree">xml.etree.ElementTree</a> or <a href="https://linuxhint.com/parse_xml_python_beautifulsoup/">BeautifulSoap</a>.</p><p>We decided to use the latter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*oTaCADX4dPQORgUVi8t7tg.png" /><figcaption>Applying BeautifulSoap on .XML dataset</figcaption></figure><h4>Discussion</h4><p>The texts are imported in one big array of HTML format i.e. “&lt;text&gt;ABCD&lt;/text&gt;,” while the part which we are interested in for example, in this case, is just “ABCD”. So, we should extract the raw text in a combined format of one array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*h0GbxRVgS0aSdxqAJ05rhQ.png" /><figcaption>Combining all the raw text</figcaption></figure><p>Then we can change it to a more popular DataFrame format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*-pppkeIV5V3eaOOzbykeQg.png" /><figcaption>Switching to DataFrame</figcaption></figure><p>Check for any null values. In case the result of the following is true,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*13bXzoBLUONHrZ8V29Fudw.png" /><figcaption>Checking for null values</figcaption></figure><p>We would need to drop the null values, and reset the index which happens every time after the drop of null values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*E9twqKGMXCUmUpOCcr6GoQ.png" /><figcaption>Dropping the null values and resetting the index</figcaption></figure><p>Now that we have cleaned our dataset, we need to import the NLP packages to do the preprocessing.</p><h4>Importing the NLP packages: Preprocessing</h4><p>The first major library that needs to be imported is “<a href="https://docs.python.org/3/library/re.html">re</a>” or Regular Expression. It provides functions that let us check if a given string matches a particular expression. If A and B are regular expressions then AB is a regular expression, too. If string A and M are a match and string B and N are a match too then string AB is a match with string MN. And so on.</p><blockquote>Also, they can include both special and ordinary characters. Simply the previous important theorem states that if two objects are of the same format any combination of them is of the same format too.</blockquote><p>The second major library is the Natural Language Tool Kit (<a href="https://www.nltk.org/">NLTK</a>), which is another Python library that will help us to program with natural language. It comes with more than <a href="http://www.nltk.org/nltk_data/">50 other</a> repositories such as WordNet, providing libraries that can perform tokenizing, stemming, classification, parsing, tagging, and semantic analysis. The latest version is NLTK 3.5 and it can be installed on all three major operating systems (Mac/Windows/Linux). One of the libraries in NLTK is the stopwords contained in stopwords.corpus library which includes those of words and characters that are not of significant importance in our notes like a, an, is, as, the, be, and etc. Note: Each programming language comes with its own list of stopwords.</p><p>The last one is PorterStemmer from the NLTK library, which provides us with stemming. Stemming is the process of linguistic normalization. It reduces words to their word roots for example organization, organizes, organized, organizer, and organize, all would become organize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*klAtRLQCEYRUA1STuv97Rg.png" /><figcaption>Importing NLP packages</figcaption></figure><p>Now, we can apply all those changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*E2VoQbCuYpEUc3tZ9g49Pw.png" /><figcaption>NLP preprocessing</figcaption></figure><p>Also, a better approach, especially for large datasets, is to define a function like this and then calling a lambda function on it. Just be careful in our previous approach the output was an array. But by applying lambda function on the following, the output would be a column in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*FPSo7qlwYwzOjtJMhGAcNQ.png" /><figcaption>The function of NLP preprocessing</figcaption></figure><p>In the foregoing, the readout from the stemming line “ps.stem” in a more fluent way is: apply stem function from ps module on word, for all “word (here the word is our choice of variable, it could be i, or n, or nn)” in pre (pre is the split words from the previous line) if that word is not in the set of English words in the stopwords class.</p><p>As mentioned here is the lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*szekoJeAUyaxNj_VXf5AiQ.png" /><figcaption>Lambda function</figcaption></figure><p>If we had used lambda function following with a column of the dataset then we would need to change the format of that column to a list. By calling list function on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*LBrr5sD8I_IqtfuvumMQLA.png" /><figcaption>list function</figcaption></figure><p>In case of having a slow system then we can separate our list into smaller sets accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*lnDyZpX0Ky8JVw8z_uKK3w.png" /><figcaption>Making subsets of data</figcaption></figure><p>Afterward, we can do the following to have a look at the unique strings of the dataset to label the important ones by choosing their classification to be “0” or “1”.</p><p>This method works for datasets with a limited number of unique features. In the case of having a large number of features in a dataset, this method isn’t efficient. Future versions of this article will address this issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*XP2CBcAyi5z6PVGtTiVN2A.png" /><figcaption>Finding most-used strings in the subsets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*e_gVs6d9qH9F4h4n1OlMHg.png" /><figcaption>Labeling the important strings</figcaption></figure><p>Then we would need to extract the features of our dataset. Features are specific words that are being used between the child and the potential molester. The model predicts whether communicated words are sexual or not.</p><p>The bag of words model is one of the good choices for us. In this model, a text (a sentence) is considered as a bag (multiset) of its words. It only considers multiplicity without considering the grammar or the order of the words.</p><p>To do so <a href="https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html">CountVectorizer</a> from Sickit-Learn is our module choice, it provides us with a conversion of text documents to a matrix of token counts. So, we would have a dictionary of words in an array, and if in each set of strings or bag of words any of these predefined texts or words are included, the corresponding number to that specific word in the matrix format of the dictionary would be 1, and 0 if not included.</p><p>Then we would fit and transform the function on our features part of our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*-GAI3RllmUi0EyKvrw9uhA.png" /><figcaption>Creating NLP model</figcaption></figure><p>Then we would separate the dataset into train_features, test_features, train_labels, and test_labels by randomly considering 80% of values to train sets and 20% of values to test sets. X parameter represents those columns of the dataset having the features and y parameter represents their corresponding labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*3AIvszTK78MqK-12gBnKKw.png" /><figcaption>Making training and test sets</figcaption></figure><p>Introducing the Gaussian module and fitting it to our training features and labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*pN4FRscVptCsQ-56t5IeaA.png" /><figcaption>Classifying training set by Gaussian method</figcaption></figure><p>Following with the prediction of our labels based on our test_features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*8fO1I-60WATdgdNvh7BKDA.png" /><figcaption>Making predictions on the test set</figcaption></figure><p>In the end, we would provide a confusion_matrix to check our predicted labels with our test_labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*LEmTtBcDdQ3I_CBXLn2vLg.png" /><figcaption>Making the confusion matrix to qualify our model</figcaption></figure><h4>Conclusion and Summary:</h4><p>In this report, we provided a simplified NLP model to classify child molesters. We used BeautifulSoap to import the dataset in .XML format, derived the raw text and cleaned the dataset.</p><p>Next, we introduced various NLP libraries and packages and applied them to our dataset. Due to the complexity and size of the data set, additional improvements are on the way.</p><h3>About Omdena</h3><p><strong><em>Solving Challenges Through Collaboration</em></strong></p><p><a href="http://www.omdena.com/"><strong>Omdena</strong></a> is an innovation platform for building AI solutions to real-world problems through the power of bottom-up collaboration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccc81f4668c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omdena/a-simplified-nlp-model-to-prevent-child-and-sexual-abuse-in-organizations-ccc81f4668c">A Simplified NLP Model to Prevent Child and Sexual Abuse in Organizations</a> was originally published in <a href="https://medium.com/omdena">Omdena</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>