avatarFabio Chiusano

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1948

Abstract

ined on Wiki80 dataset with a BERT encoder.</li></ul><p id="32f8">Both models are trained on the Wiki80 dataset, which consists of 80 relations, each having 700 instances.</p><p id="cfc3">In order to use the OpenNRE library, you must at first install it from its repo:</p> <figure id="f70e"> <div> <div>

            <iframe class="gist-iframe" src="/gist/fabiochiusano/390362b8a4b343a2cb76f501d72435e9.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="a7ad">The next steps are:</p><ul><li>Import the library in your Python code.</li><li>Load a pre-trained model.</li><li>Call the <i>infer </i>function of the model passing (1) a paragraph, (2) the first entity position, and (3) the second entity position. The function returns the predicted relation for the pair of entities, using the paragraph as context.</li></ul>
    <figure id="81b1">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/fabiochiusano/9c9f9c5f5d2c4a49be44f23a440b4a03.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="33e5">Despite the name <i>Relation Extraction</i>, the example we have seen here is actually a multi-label classification problem, where the possible types of relations that can be extracted are the ones present in the training set.</p><p id="4878">Thank you for reading! If you are interested in learning more about NLP, remember to follow NLPlanet on <a href="https://medium.com/nlplanet">Medium</a>, <a href="https://www.linkedin.com/company/nlplanet">LinkedIn</a>, and <a href="https://twitter.com/nlplanet_">Twitter</a>!</p><p id="9707"><b>Two minutes NLP related posts</b></p><div id="773b" c

Options

lass="link-block"> <a href="https://readmedium.com/two-minutes-nlp-easy-document-annotation-with-wikipedia-concepts-ad4e6cbbb204"> <div> <div> <h2>Two minutes NLP — Easy document annotation with Wikipedia concepts</h2> <div><h3>Semantic annotations, Wikification, Ontologies, and PageRank</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*F3ZriRJeavN64pN40o7zOg.png)"></div> </div> </div> </a> </div><div id="e9da" class="link-block"> <a href="https://readmedium.com/two-minutes-nlp-doc2vec-in-a-nutshell-25be546a8342"> <div> <div> <h2>Two minutes NLP — Doc2Vec in a nutshell</h2> <div><h3>CBOW and Skip-gram Word2Vec, DM and DBOW Doc2Vec</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*K_NWmAdrfeAcLUlS)"></div> </div> </div> </a> </div><div id="0c82" class="link-block"> <a href="https://readmedium.com/two-minutes-nlp-tips-for-recommender-systems-with-nlp-a3f03555d65a"> <div> <div> <h2>Two minutes NLP — Tips for Recommender Systems with NLP</h2> <div><h3>Content-based and User-based Filtering, Collaborative Filtering, and Hybrid Approaches</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*xUOLCqGWldPFFrAs8hFXQQ.png)"></div> </div> </div> </a> </div></article></body>

Two minutes NLP — Relation Extraction with OpenNRE

Relation Extraction, Knowledge Graphs, Entities, and OpenNRE

Photo by matthew Feeney on Unsplash

Relation Extraction is a Natural Language Processing task aiming at extracting relations between entities. For example, from the sentence Romeo and Juliet was written by William Shakespeare, we can extract the relation triple (William Shakespeare, is the writer of, Romeo and Juliet).

Relation Extraction is a crucial technique in automatic knowledge graph construction. By using Relation Extraction, we can accumulatively extract new relation facts and expand the knowledge graph, which, as a way for machines to understand the human world, has many downstream applications like question answering, recommender systems, and search engines.

OpenNRE is one of the most used libraries to do relation extraction on text.

Relation extraction with OpenNRE

OpenNRE is an open-source and extensible toolkit that provides a unified framework to implement relation extraction models.

The library comes with two pre-trained models which can be put into production without any training:

  • wiki80_cnn_softmax: trained on Wiki80 dataset with a CNN encoder.
  • wiki80_bert_softmax: trained on Wiki80 dataset with a BERT encoder.

Both models are trained on the Wiki80 dataset, which consists of 80 relations, each having 700 instances.

In order to use the OpenNRE library, you must at first install it from its repo:

The next steps are:

  • Import the library in your Python code.
  • Load a pre-trained model.
  • Call the infer function of the model passing (1) a paragraph, (2) the first entity position, and (3) the second entity position. The function returns the predicted relation for the pair of entities, using the paragraph as context.

Despite the name Relation Extraction, the example we have seen here is actually a multi-label classification problem, where the possible types of relations that can be extracted are the ones present in the training set.

Thank you for reading! If you are interested in learning more about NLP, remember to follow NLPlanet on Medium, LinkedIn, and Twitter!

Two minutes NLP related posts

NLP
Naturallanguageprocessing
AI
Artificial Intelligence
Data Science
Recommended from ReadMedium