<?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 Ananya Gupta on Medium]]></title>
        <description><![CDATA[Stories by Ananya Gupta on Medium]]></description>
        <link>https://medium.com/@ananyagupta2508?source=rss-6046f02d735f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K1-T7OocWqBdzywk-GvgYQ.jpeg</url>
            <title>Stories by Ananya Gupta on Medium</title>
            <link>https://medium.com/@ananyagupta2508?source=rss-6046f02d735f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:32:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ananyagupta2508/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[Obtaining AllenNLP Coreference Resolution Readable Clusters in Python]]></title>
            <link>https://code.likeagirl.io/obtaining-allennlp-coreference-resolution-readable-clusters-in-python-37cd964d6ca0?source=rss-6046f02d735f------2</link>
            <guid isPermaLink="false">https://medium.com/p/37cd964d6ca0</guid>
            <category><![CDATA[codelikeagirl]]></category>
            <category><![CDATA[coneference]]></category>
            <category><![CDATA[readable]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[allennlp]]></category>
            <dc:creator><![CDATA[Ananya Gupta]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 20:05:18 GMT</pubDate>
            <atom:updated>2023-08-24T04:14:53.733Z</atom:updated>
            <content:encoded><![CDATA[<p>AllenNLP in Python for human-readable clusters.</p><p>AllenNLP’s Coreference Resolution is an amazing tool to find the complex relationship between the ‘signifier’ and the ‘signified’,i.e., which expression or phrase refers to a particular entity in a text. Important for tasks like “document summarization, question answering, and information extraction,” (<a href="https://demo.allennlp.org/coreference-resolution/MjQzMjgxNw==">https://demo.allennlp.org/coreference-resolution/MjQzMjgxNw==</a>) the potential of this technology is exciting.</p><p>I recently used coreference resolution while building gritparity.com (an AI-driven tool quantifying gender representation in textbooks). Demoing this technology, I saw relatively complex (and pretty funny) sentences being analyzed and broken down accurately:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*OFoitapIJ7GJxta8sb8xjQ.png" /><figcaption><strong>Blue</strong> signals any reference to the bartender, and <strong>Green</strong> any reference to the talking-horse.</figcaption></figure><p>The results are really well sorted and displayed. However, while using them in Python, I ran into a snag. While the code to use it as a library in python is available on the site (<a href="https://demo.allennlp.org/coreference-resolution">https://demo.allennlp.org/coreference-resolution</a>), once you get the results it&#39;s quite confusing initially to know what to make of them. I hope that this article is useful to you in using this powerful, pre-trained Natural Language Processing model.</p><pre>!pip install allennlp!pip install -U spacy  from allennlp.predictors.predictor </pre><pre>import Predictorpredictor = Predictor.from_path(&quot;https://s3-us-west-2.amazonaws.com/allennlp/models/coref-model-2018.02.05.tar.gz&quot;)</pre><p>Installing and importing the dependencies, as shown on the website, you then proceed to obtain the clusters.</p><p>The idea is that the clusters are formated as [[[a,b],[c,c]], [[d,d],[f,g]]. So, there&#39;s a list inside a list, and within that another 2 lists (okay this may seem a little confusing, but bear with me). So, let me explain this using indexes.</p><p>Let us begin with the innermost lists. Lets take [a,b] as an example. So, the document is first converted to a list of words. Now, ‘a’ is a number that corresponds to the word at the ‘a’ index in the document and ‘b’ to the ‘b’th word in the document. These two words and all the words between them together form a cluster with [c,c]. The [c,c] is only one word since all the words between the ‘c’th and the ‘c’th word are only the ‘c’th word. Together, these two form a cluster and are hence part of their own, personal list. The same entity is referenced between the words from ‘a’ to ‘b’, as well as at ‘c’.</p><p>We can take example of [[0,1],[5,5]]. The document for this example is “my(0) mother(1) was(2) happy(3).(4) She(5) gave(6) me(7) a(8) pat(9) on(10) the(11) back(12)”. Hence, “my[0] mother[1]” is referenced again as “she[5]”. As you can see, each word (and even the punctuation) is given an index, which is used within the coreference cluster. We can look at this in the following code:</p><pre>sent = &quot;my mother was happy. She gave me a pat on the back&quot; #or any other sentence.</pre><pre>pred = predictor.predict(    <br>         document= sent<br>)</pre><pre>clusters = pred[&#39;clusters&#39;]<br>document = pred[&#39;document&#39;] <br><br>n = 0<br>doc = {}<br>for obj in document:    <br>    doc.update({n :  obj}) #what I&#39;m doing here is creating a dictionary of each word with its respective index, making it easier later.    <br>    n = n+1</pre><p>Finally, after this I obtain the clusters:</p><pre>clus_all = []<br>cluster = []<br>clus_one = {}<br>for i in range(0, len(clusters)):    <br>    one_cl = clusters[i]    <br>    for count in range(0, len(one_cl)):           <br>        obj = one_cl[count]        <br>        for num in range((obj[0]), (obj[1]+1)):            <br>            for n in doc:                <br>                if num == n:                 <br>                    cluster.append(doc[n]) <br>    clus_all.append(cluster)       <br>    cluster = []     </pre><pre>print (clus_all) #And finally, this shows all coreferences</pre><p>In python, we are now able to attain readable clusters from Allen NLP’s coreference resolution. It took some time to decode the pattern, and I hope this helps anyone who faces this difficulty in the future!</p><p>Happy reading!</p><p>Find the GitHub page for this here:</p><p><a href="https://github.com/ananyagup/AllenNLP-Coreference-Resolution-in-Python---Readable-clusters">ananyagup/AllenNLP-Coreference-Resolution-in-Python---Readable-clusters</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37cd964d6ca0" width="1" height="1" alt=""><hr><p><a href="https://code.likeagirl.io/obtaining-allennlp-coreference-resolution-readable-clusters-in-python-37cd964d6ca0">Obtaining AllenNLP Coreference Resolution Readable Clusters in Python</a> was originally published in <a href="https://code.likeagirl.io/">Code Like A Girl</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>