Rule-based RE
Many instances of relations can be found by looking for triples (X, Y), where X is entities and Y are words in between, using hand-crafted patterns. α =" is in" in the case of "Paris is in France." A regular expression could be used to obtain this information.
Many false positives will be returned if you only seek keyword matches. We can avoid this by filtering on named entities and retrieving only those (CITY, is in, COUNTRY). We can also use part-of-speech (POS) tags to eliminate extra false positives.
Because the rule specifies a pattern that follows the order of the text, these are examples of word sequence patterns. Unfortunately, these criteria break down for longer-range patterns and sequences with more variation. A word sequence pattern, for example, cannot handle the phrase "Fred and Mary married."
Instead, we can use dependency routes in sentences to figure out which words are grammatically dependent on which other words. This can dramatically expand the rule's reach without requiring additional effort.
Before implementing the rule, we can additionally alter the sentences. For example, "Harry baked the cake" or "Harry baked the cake" can be changed to "Harry baked the cake."Then, to operate with our "linear rule," we reverse the sequence and remove the unnecessary modifying word in the middle.
Pros
- Humans can generate patterns with a great degree of precision.
- It's possible to customize it for specific domains.
Cons
- Human patterns are still notoriously difficult to recall (too much variety in languages)
- To design all feasible rules, a lot of manual work was required.
- Every form of relationship must have its own set of rules.
Weakly Supervised RE
The goal is to start with a set of hand-crafted rules and, through an iterative process, automatically find new ones from the unlabeled text input (bootstrapping). Alternatively, a collection of seed tuples describing entities with a specified relation can be used as a starting point. Seed=(ORG: IBM, LOC: Armonk), (ORG: Microsoft, LOC: Redmond), for example, declares entities with the relation "based in."
Snowball is an old example of an algorithm that accomplishes this:
- Begin with a collection of seed tuples (or extract a seed set from the unlabeled text with a few hand-crafted rules).
- Extract occurrences that match the tuples from the unlabeled text and tag them with a NER (named entity recognizer).
- Make patterns out of these occurrences, such as "ORG is located in LOC."
- Add new tuples generated from the text to the seed set, such as (ORG: Intel, LOC: Santa Clara).
- Continue to step 2 or stop and use the patterns you've developed for future extraction.
Pros
- More relationships can be uncovered than with Rule-based RE (higher recall)
- Human effort is reduced (it does only require a high-quality seed)
Cons
- With each iteration, the set of patterns becomes more prone to errors.
- When generating new patterns from occurrences of tuples, be cautious; for example, "IBM shut down an office in Hursley" could easily be overlooked when producing designs for the "based in" connection.
- Fresh sorts of relationships necessitate new seeds (which have to be manually provided)
Supervised RE
Training a stacked binary classifier (or a standard binary classifier) to identify if there is a specific relationship between two things is a common approach to accomplish Supervised Relation Extraction. These classifiers use text features as input, which means other NLP modules must first tag the text. Context words, part-of-speech tags, dependency paths between entities, NER tags, tokens, proximity distance between words, and other attributes are shared.
We could hone our skills and extract information by:
-
Manually label the text data to indicate whether or not a sentence is related to a particular relation type. For example, consider the "CEO" relationship:
"Steve Jobs, the CEO of Apple, stated to Bill Gates." is relevant. "Bob, the Pie Enthusiast, told Bill Gates." is irrelevant.
- If the relevant sentences convey the relationship, manually classify them as positive or negative. "Apple CEO Steve Jobs started to Bill Gates," for example:(Apple CEO Steve Jobs) is optimistic.(Apple CEO Bill Gates) is a pessimist.
- Learn a binary classifier to decide if the statement is appropriate for the relation type.
- Learn a binary classifier to assess if the relevant sentences represent the relationship or not.
- To find relationships in new text data, use the classifiers.
Some people prefer not to train a "relevance classifier," preferring to use a single binary classifier to determine both items simultaneously.
Pros
- Supervision of exceptional quality (ensuring that the relations that are extracted are relevant)
- There are specific negative examples available.
Cons
- Labeling examples is costly.
- Adding new relationships is costly and complicated (need to train a new classifier)
- It isn't very adaptable to new domains.
- It is only possible for less number of relationship kinds
Distantly Supervised RE
We can combine seed data, as in Weakly Supervised RE, with classifier training, as in Supervised RE. Instead of creating a set of seed tuples from scratch, we can use one from a Freebase Knowledge Base (KB), such as Wikipedia, DBpedia, Wikidata, or Yago.
- The KB has a section for each form of relationship we're interested in.
- In the KB, for every relation in this tuple.
- Select sentences from the unlabeled text data that match these tuples (both tuple terms cooccur in the phrase) and presume they are positive examples for this connection type.
- Take notes on the characteristics of these sentences (e.g., POS, context words, etc.)
- On this, train a supervised classifier.
Pros
- Manual work is reduced.
- Can handle a vast amount of labeled data and numerous relationships on a wide scale.
- There are no iterations required (compared to Weakly Supervised RE)
Cons
- Annotation of the training corpus with a lot of noise (sentences that have both words in the tuple may not describe the relation)
- There are no clear examples of negative behavior (this can be tackled by matching unrelated entities)
- It is only available in the Knowledge Base
- The task may necessitate some fine-tuning.
Unsupervised RE
We can extract relations from text without labeling any training data, providing a set of seed tuples, or writing rules to capture various links in the text. Instead, we rely on a set of heuristics and limitations that are pretty broad. It's debatable whether this is unsupervised because we're employing "rules" that are more generic. In certain circumstances, modest collections of labeled text data are used to create and tune the systems. Nonetheless, these systems generally necessitate less oversight. This approach is known as Open Information Extraction (Open IE).
TextRunner is a RE solution that uses this type of method. Its algorithm can be summarised as follows:
1. On a tiny corpus, train a self-supervised classifier.
Find all noun phrase pairs (X, Y) that are connected by the term r. for each parsed sentence. If they fit all conditions, mark them as positive examples; otherwise, label them as negative examples.
Convert each triple (X, r, Y) into a feature vector (e.g., incorporating POS tags, NER tag, number of stop words in r, etc.)
To identify trustworthy candidates, train a binary classifier.
2. Examine the full corpus for probable relationships.
Get a list of potential relationships from the canon.
Candidates are kept or discarded based on whether or not the classifier deems them to be trustworthy.
3. Relationships are ranked depending on their text redundancy.
Normalize (remove non-essential modifiers) and consolidate similar relations
Count how many different sentences the relations appear in and give probability to each one.
Two open-source systems that achieve this are OpenIE 5.0 and Stanford OpenIE.
They're much more up-to-date than TextRunner (which was just used here to demonstrate the paradigm). As a result of systems like these, we can expect a wide range of relationship kinds (since we don't say what kind of relationships we're looking for).
Pros
- Training data that hasn't been labeled (or almost hasn't been tagged) isn't required.
- Instead of requiring us to describe each relationship of interest individually, it considers all conceivable relation types.
Cons
- The system's performance is highly dependent on how well the constraints and heuristics are designed.
- Relationships are not as standardized as pre-defined relation types.
Frequently Asked Questions
What is information extraction in NLP?
The automatic retrieval of specific information relating to a given topic from a body or body of the text is known as information extraction (IE). Information extraction software allows you to extract data from text documents, databases, webpages, and other sources.
Why is relation extraction essential?
Relation extraction (RE) is an important activity in Natural Language Processing (NLP) that seeks to uncover semantic links between pairs of entity mentions. Many downstream tasks require RE, such as knowledge base completion and query answering.
What is open relation extraction?
OpenRE is a technique for extracting relational information from an open-domain corpus. It accomplishes this by identifying relationship patterns between named items and then grouping those semantically comparable patterns into a single relation cluster.
What is entity relation extraction?
Relationship extraction is identifying relationships between entities, concentrating on binary relationships. Relationship extraction is beneficial in various applications, including gene-disease correlations, protein-protein interactions, etc.
What is data extraction in Python?
In simple words, BeautifulSoup is a Python library for pulling data out of HTML and XML files. It can be used with requests because it needs an input (document or URL) to create a soup object as it cannot fetch a web page by itself. You can use the following Python script to gather the web page title and hyperlinks.
Conclusion
So that's the end of the article Relation Extraction.
After reading about the Relation Extraction, are you not feeling excited to read/explore more articles on the topic of NLP? Don't worry; Coding Ninjas has you covered.
Upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and more with our Coding Ninjas Studio Guided Path! If you want to put your coding skills to the test, check out the mock test series and enter the contests on Coding Ninjas Studio! If you're just getting started and want to know what questions big giants like Amazon, Microsoft, and Uber ask, check the difficulties, interview experiences, and interview bundle for placement preparations.
However, you may want to pursue our premium courses to give your job an advantage over the competition!
Please vote for our blogs if you find them valuable and exciting.
Happy studying!