Elamur Research

Metadata Shaping: A Simple Approach for Knowledge-Enhanced Language Models

Paper · 2022 · Simran Arora, Sen Wu, Enci Liu et al.

Summary

A system can learn a great deal about people and places that turn up often in its training material and still struggle with an unfamiliar name. This matters for search and question answering, where users can ask about obscure entities as readily as famous ones. Arora and colleagues study a simple way to help a language model with that problem. If an unfamiliar name refers to a politician, for instance, the system can be given the word politician alongside the name. The name may be new to the task, while the category can connect it to many examples the system has already learned from.

The authors call their method metadata shaping. An entity linker identifies what a mention refers to, and the method retrieves information such as a type or a description from Wikidata and Wikipedia. Since many details can describe the same entity, the method uses training examples to estimate which tags give the clearest clues about the task labels. It inserts selected metadata into the text during both training and prediction. The authors use off-the-shelf BERT with an ordinary classification layer and train it for each task. The knowledge enters through the text it reads, with no additional pretraining for the main results.

The experiments cover identifying relations between marked mentions in FewRel and TACRED Revisited, and identifying the applicable types for a marked mention in OpenEntity. Across these benchmarks, the authors report an average improvement of 4.3 F1 points over BERT-base trained with unshaped inputs. The shaped system records test F1 of 90.4 on FewRel, 76.7 on TACRED Revisited, and 76.2 on OpenEntity. It leads the reported comparison on FewRel and OpenEntity, while KnowBERT-Wiki scores higher on TACRED Revisited. The average improvement from shaping is 4.4x as large on the slice with rare entities as on the slice with popular ones.

The analyses give some indication of why. A useful type can group an unfamiliar entity with familiar entities that occur in similar contexts. Training-based ranking gives better results than the alternatives tested at the same metadata budget, although even randomly selected tags help. Categories can also pull a prediction in the wrong direction when a familiar name gives a more specific clue. The experiments therefore establish that carefully chosen external text can improve prediction, especially for rare mentions, while leaving open how much of the improvement comes from category-based transfer in any individual example.

Deep dive: Metadata Shaping: A Simple Approach for Knowledge-Enhanced Language Models

Metadata shaping adds entity types and descriptions to text so BERT can classify examples about rare entities using patterns learned from familiar ones. · about 40 minutes to read

The problem and its context

A new name can refer to a familiar kind of entity

For an entity classification task, recognizing the words in a passage and knowing what a name refers to are separate problems. A passage can use ordinary language while mentioning someone who rarely appears in training. The vocabulary around the name may help, but the system has had little opportunity to learn which roles, properties, or relations are associated with that person. In the paper’s account, the problem is particularly visible in the long tail of entity mentions. Familiar names provide repeated opportunities to learn. Rare names may supply few or none, yet a useful search or assistant system still needs to handle requests about them.

What counts as rare is also a matter of where one looks. The authors cite earlier work on disambiguating entities in Wikipedia text that found a BERT-based system needed on the order of 100 samples containing an entity to reach 60 F1 points on the disambiguation task. That observation concerns an earlier task, and the paper uses it to motivate the difficulty of learning from sparse mentions. The authors also report that 89% of Wikidata entities have no appearances in Wikipedia. An entity may therefore have a record in a structured resource while offering few chances for a language system to encounter it in a source of running text. These observations explain the appeal of retrieving the record when it is needed.

Wikidata can supply entity identifiers, categories, descriptions, and relations. Its role here is that of a knowledge graph whose records can supplement the information in a passage. An entity’s identifier singles it out, while a category can tell the system something the entity shares with other entries. That distinction matters when the objective is to transfer what was learned about a group to a member that has not previously appeared. A description may supply additional clues specific to that member. The authors treat all these kinds of information as potential inputs, with usefulness depending on the task.

Daniel Dugléry illustrates the difference between coverage of entities and coverage of categories. The authors report that Dugléry occurs 0 times in the FewRel training data, while entities in the politician category occur > 700 times there. The tag gives the classifier an expression it could have learned to use from other examples. It cannot supply the relation expressed by the sentence by itself. A politician can appear in sentences expressing many different relations. Its value lies in narrowing what is plausible in combination with the words around the marked mentions.

The example also clarifies why the authors care about groups at different levels of detail. A person tag can be shared across a broad range of mentions. A politician tag is more specific and may accompany a narrower range of contexts. A description that identifies a party affiliation gives a clue closer to the individual. A system that can read these signals in the same input has a way to use the broader and narrower evidence together. The practical question is which signals are worth putting there.

How earlier systems supplied entity knowledge

The paper describes a common workflow in prior knowledge-enhancement research. First, an annotation process connects spans in ordinary text to entity records. The enhancement then changes how the underlying system processes those annotations or what it is trained to predict. Some approaches introduce continuous representations for entities. Others alter attention, add objectives for learning from entity information, or use extra components specialized for particular kinds of reasoning. The metadata is available in this workflow before the architectural or training changes are made.

The approaches differ in where the new information is handled. K-BERT and KnowBERT are examples the paper discusses in connection with changes to attention. LUKE appears in the discussion both for its treatment of attention and for the training objectives used to introduce knowledge. K-Adapter exemplifies a design with additional transformer components. These choices give the system dedicated ways to handle entity knowledge. They can also call for specialized design, optimization, and training. The authors point to the cost of those steps and the work that can arise when new entities need to be accommodated.

The paper questions whether learning a separate representation for each entity makes the best use of shared properties. It is possible for an entity-aware system to learn that similar entities behave in similar ways. The authors’ concern is that this is a difficult relationship to infer implicitly when many entity names are scarcely observed. Giving the system a common, readable type places the shared property directly in the input. The same marker can appear when a familiar entity is seen during training and when a different entity is seen at prediction time. The proposed approach uses a standard transformer to learn what to do with that marker in context.

The related work also includes precedents for putting knowledge into the text. The authors describe earlier work that used descriptions or types for a particular task, including answering questions and resolving which entity a mention denotes. They also cite work showing benefits from category information for disambiguating rare entities. Their own question is broader within classification. They want to compare a single procedure for supplying different kinds of metadata across the same entity-rich benchmarks used to assess systems with knowledge-specific components.

Feature selection, prompting, and augmentation

Metadata shaping draws on feature selection, where an input attribute is useful if it helps distinguish the outputs a classifier needs to predict. An entity can have many correct attributes, and a correct attribute can be irrelevant to the label. The authors use class statistics to select among the available attributes. This carries over an idea from classical classification while giving the selected features a different form. A tag becomes readable text inside the example, and the classifier can interpret it together with the original sentence.

The authors distinguish their proposal from traditional linguistic annotation schemes with a defined inventory of features. They can use familiar annotations such as named entity recognition and part-of-speech tagging, but the method also has room for phrases from entity records. A fixed category can recur consistently across examples, while a description can express a property in ordinary words. Both can enter through the same text interface. The paper cites the Penn Treebank and prior work on relation extraction when situating this distinction. Penn Treebank · Distant supervision for relation extraction

Prompting provides another point of comparison because both approaches change what a system reads. The paper describes prompting as often using human-chosen words or templates to elicit information held by the underlying system. Metadata shaping retrieves a detail about the particular entity in the current example and makes that detail explicit. Which text is inserted can vary from mention to mention. The goal is to let the classifier learn to use supplied facts alongside ordinary task context. Pre-train, Prompt, and Predict

The authors also relate the approach to data augmentation. Generating more training sentences about a rare entity gives the system additional contexts in which to encounter it. The common property that links the entity to others may still be implicit in those sentences. Shaping inserts that property directly, and it can do so for a new entity when the test input is prepared. The paper treats this as a form of implicit augmentation and places it alongside proposals that alter training data to improve generalization. EDA · Unsupervised Data Augmentation for Consistency Training

The method, step by step

From an entity mention to a shaped example

Start with a passage that has a marked mention. The task may ask what types apply to the mention, or it may mark a subject and object and ask what relation the passage expresses between them. The original wording remains available throughout. Shaping adds information to that wording, so the classifier receives both the context in which the entity appears and metadata retrieved about it.

The first operation is to identify the entity in an external resource. The authors use the pretrained entity linker from Orr and colleagues to connect task text to entries in an October 2020 Wikidata dump. FewRel also comes with entity annotations. Linking matters because the same string in a passage can, in principle, refer to different entries. The linked entry gives the metadata lookup a definite target. Some spans have no link, including examples where the relevant string is a pronoun or a date. The procedure works with whatever candidate metadata is available.

The next operation is to collect attributes. Categorical metadata range from labels that apply to many entities to more specific types that characterize a smaller group. The paper’s example moves from person to politician. For the experiments, the authors retain only category types with at least 100 occurrences in Wikidata among entities in the Wikipedia data that trained the linker. For descriptions, they draw on Wikidata and introductory text from Wikipedia. The experiment section identifies the first sentence as the Wikipedia source, and the appendix describes using the first 50 words of the page. Both specify that the material comes from the beginning of the entry.

Categories and descriptions can help for different reasons. The same category phrase can appear exactly as written for many entities, giving the classifier repeated exposure to it. Descriptions can provide details unique to an individual or use alternate wording for something the classifier has encountered elsewhere. A category can itself contain multiple words. When the appendix reports a limit on the number of categories inserted, that limit counts metadata items and does not on its own determine the number of text tokens added to the input.

The selection step asks how the labels are distributed in training data that contain a given tag. A candidate that occurs with many labels in similar proportions provides little guidance about which class to predict. A candidate associated with a more concentrated class distribution receives a stronger rank. The statistics used for this decision are computed from the task training split. They can then be applied to the metadata retrieved for a test example without revealing that example’s true label.

The chosen text is placed inside the example. The authors use boundary markers to identify the inserted span and task markers to identify the mention or mentions that matter for prediction. In the main FewRel and OpenEntity configurations, metadata follows its corresponding entity mention. In the main TACRED configuration, the inserted material goes at the end of the example. The resulting text goes through the same BERT-base input interface as other task examples.

Preparing inputs for metadata shaping

The steps in order.

Preparing inputs for metadata shapingStep 1: Mark the task’s target mentions1. Mark the task’s target mentionsStep 2: Link mentions to knowledge base entries2. Link mentions to knowledge base entriesStep 3: Retrieve candidate categories and descriptions3. Retrieve candidate categories and descriptionsStep 4: Estimate tag and label associations from training4. Estimate tag and label associations from trainingStep 5: Rank available tags for each mention5. Rank available tags for each mentionStep 6: Insert selected text with boundary markers6. Insert selected text with boundary markersStep 7: Fine-tune and predict on shaped examples7. Fine-tune and predict on shaped examples

The classification setup

The authors describe shaping as a transformation of an input example. In the basic classification setup, an input belongs to a space of possible examples and its label belongs to a space of output categories. The labeled dataset can be written in indexed form.

D = {(xᵢ, yᵢ)}ᵢ₌₁ⁿ

Here D is the dataset, n is its size, and i indexes its examples. The symbol xᵢ is the original input at index i, and yᵢ is the corresponding label. The braces enclose the collection of pairs. The paper calls the input space X and the label space Y. For OpenEntity, the practical prediction problem allows multiple applicable types, so its training objective treats type decisions separately.

For each example, the authors use M for the inventory of metadata tags and M(xᵢ) for the tags collected for that particular input. An individual tag is written m. The shaping function turns the input into a member of the shaped input space, written Xₛ.

sᵢ = fₛ(xᵢ)

Here sᵢ is the shaped example corresponding to original input xᵢ. The function fₛ selects a subset of the available metadata and inserts its text into the example. The subscript s denotes shaping, and i identifies the same example on both sides of the expression. The transformation concerns the input, so the task label stays attached to the example after the insertion.

The symbol p̂φ denotes the downstream predictor. The hat marks an estimated distribution, and φ denotes the learned parameters of the task system. The classifier reads shaped examples during fine-tuning and again at test time. During training it sees where metadata occurs, how those words relate to the original context, and how useful they are for predicting the label. The resulting predictor can encounter the same metadata phrase with a different entity when it is evaluated. The ranking procedure determines what information to expose, while the task training determines how to use it.

Why a shared tag can help

The paper begins its conceptual argument with the expected classification loss.

L_cls = E₍ₓ,ᵧ₎[−log p̂φ(y | x)]

Here L_cls is classification cross-entropy and E₍ₓ,ᵧ₎ means an expectation over input and label pairs. The symbol x is the input used for prediction and y is its true class. The expression p̂φ(y | x) is the probability the classifier with parameters φ assigns to y given x. The vertical bar means “given,” log is the logarithm, and the minus sign makes assignments of small probability to the true class incur larger losses. The paper uses x in this general expression. When the classifier is trained or evaluated with shaping, the input it actually reads is the shaped sequence.

To discuss the evidence available within an input, the authors refer to patterns. A pattern is a subset of tokens in an example. It may be an entity mention, a tag, or a combination of tokens. Thinking in patterns separates the ability to recognize an exact mention from the ability to recognize a broader category. An unfamiliar name can be a pattern that the task training has never supplied. An inserted category can be a pattern that occurs repeatedly across labeled examples.

The paper uses a maximum entropy formulation to express the assumed connection between these local signals and the full class distribution.

Pr(y | xᵢ) = exp(∑ₖ∈Kᵢ λₖ Pr(y | k)) / Z(xᵢ)

Here Pr denotes a probability in the conceptual distribution, y is a class, and xᵢ is the original example at index i. The set Kᵢ contains the patterns in xᵢ. The sum ranges over patterns k belonging to that set. The weight λₖ describes the contribution of pattern k, and Pr(y | k) is the conditional probability of class y given the pattern. The exponential function exp converts the weighted score into a positive quantity. The partition function Z(xᵢ) normalizes the scores across classes so the result is a probability distribution. This equation describes the conceptual argument about patterns. The actual experiment estimates tag usefulness from training statistics and fine-tunes BERT to make predictions.

The argument focuses on a case where the exact pattern has never occurred in task training. The authors simplify by treating the unseen pattern as independent of the class under the predictor. They also set aside signals acquired during pretraining and use a uniform prediction over the label set as their reference case.

p̂φ(y | k) = p̂φ(y) = 1 / |Y|

Here p̂φ(y | k) is the estimated probability of class y given the unseen pattern k. The unconditional estimate is p̂φ(y), and |Y| is the number of possible classes. The numeral in the numerator gives the equal share of probability assigned to each class in the uniform case. These equalities express the paper’s simplifying assumptions. In an actual task, pretraining, similarities between strings, and uneven class frequencies can all make the prediction for a new name depart from this case.

For a fixed pattern, the uncertainty of the normalized conditional distribution is its entropy. The uniform case gives the maximum entropy over the available classes.

Ĥ(Y | k) = −∑ᵧ∈Y p̂φ(y | k) log p̂φ(y | k) = log(|Y|)

Here Ĥ(Y | k) is the entropy associated with the estimated class distribution for fixed pattern k. The sum ranges over labels y in the set Y. Each term uses p̂φ(y | k), the conditional weight of that class, and the logarithm of the same weight. The equality to log(|Y|) applies in the uniform case. The normalization by conditioning on k is important for this interpretation. A weight for the joint occurrence of the pattern and a class would also include the frequency of the pattern and would describe its contribution to a wider average.

The paper also discusses the contribution to expected cross-entropy from the examples associated with the unseen pattern.

Pr(k) log |Y|

Here Pr(k) is the probability of encountering the pattern k, and log |Y| is the loss per example under the uniform prediction across Y. The product weights that loss by how often the pattern occurs. It expresses how an uninformative prediction can contribute to expected error even when the corresponding examples are rare.

In a shaped example, the set of available patterns is enlarged. The authors write Kᵢˢ for the patterns in sᵢ and kₘ for a pattern that contains the inserted metadata tag m. A useful kₘ can have a more concentrated label distribution than the unseen name. If the actual relationship between that metadata and the task is learned, the classifier can use the new evidence to shift its prediction. Concentration alone establishes how uneven the class distribution is. The prediction benefits when the pattern points toward classes that are appropriate for the example.

The distinction between entropy and correctness is central to reading the argument. Entropy measures the predictor’s uncertainty, and cross-entropy evaluates the probability it assigns to the observed label. A sharply concentrated prediction can still give very low probability to the right class. Likewise, exactly matching a true distribution gives its entropy as expected cross-entropy, which can be positive when the true distribution itself is uncertain. The reasoning about shared tags motivates selection and gives a testable expectation. The experiments determine whether the additional evidence improves the actual predictions.

How the selection score is calculated

The selection procedure uses pointwise mutual information, abbreviated PMI. It compares how often a class and a pattern occur together with how frequently that joint event would be expected if the class and pattern occurred independently. This is distinct from the frequency of the tag alone. A very common tag can have weak association with a particular class, while a more specific tag can occur disproportionately with that class.

pmi(y, kₘ) = log₂(Pr(y, kₘ) / (Pr(y) Pr(kₘ)))

Here pmi is the pointwise mutual information between class y and metadata-bearing pattern kₘ. The joint probability Pr(y, kₘ) is the chance of observing both. The product of the marginal probabilities Pr(y) and Pr(kₘ) gives the joint probability under independence. The base of the logarithm is consistent with the paper’s use of powers of 2 when recovering the conditional probability. A positive PMI indicates that the class and pattern co-occur more often than independence would predict.

The paper then expresses a class probability given the metadata-bearing pattern in terms of that association and the class’s overall probability.

Pr(y | kₘ) = 2^pmi(y, kₘ) × Pr(y)

Here Pr(y | kₘ) is the probability of class y conditional on the pattern kₘ. The exponent pmi(y, kₘ) expresses the association between the two events, and Pr(y) is the overall probability of y. The factor based on 2 adjusts the class probability according to that association. This matters because the ranking aims to estimate the label distribution for a tag, and a tag’s association with a class is only part of that distribution.

Computing distributions for every possible pattern formed after insertion would require considering many token combinations across the dataset. The implementation uses a narrower proxy. It estimates the class association of each individual metadata tag m. Before preparing individual examples, it computes PMI for tag and label pairs and records the training frequency of each class. When it encounters a tag eligible for insertion, it uses those stored quantities to compute a score for every label.

rᵧ = 2^pmi(m, y) × fᵧ

Here rᵧ is the unnormalized weight for class y for the candidate tag m. The quantity fᵧ is the frequency of the class in training, and pmi(m, y) is the tag’s association with that class. The power of 2 converts the association back into a multiplicative adjustment. The algorithm normalizes the weights so they sum to 1.

Hₘ = −∑ᵧ∈Y rᵧ log rᵧ

Here Hₘ is the entropy assigned to tag m, and rᵧ now denotes the normalized weight for class y. The sum considers every class y in the label set Y. The minus sign, probabilities, and logarithms give greater entropy to a more dispersed distribution. A lower Hₘ places the tag higher in the ranking.

min(n, |M(xᵢ)|)

Here min chooses the smaller of its arguments. In the selection algorithm n is the insertion budget, a use of the symbol distinct from its earlier role as dataset size. The expression |M(xᵢ)| counts the candidate tags collected for example xᵢ. The algorithm takes that many of the lowest-entropy tags, so the budget is a ceiling and an example can contribute fewer tags when less metadata is available. The experimental configurations apply budgets to the individual task mentions.

The procedure makes a deliberately simple decision about each tag. It can prefer a tag that is useful by itself, even when another selected tag gives similar evidence. The authors describe possible extensions that would score longer patterns containing metadata or account for correlations among already selected and remaining candidates. Those alternatives would involve more computation. The tested procedure uses the individual tags to find a manageable selection before the classifier sees the entire sequence.

From selected tags to a trained classifier

The main settings use up to 20 metadata categories for each subject and object in FewRel, up to 5 for each subject and object in TACRED, and up to 25 for the marked entity in OpenEntity. The authors choose the limits by grid search and investigate placement and masking as implementation choices. They use boundary markers in the reported experiments. In the main OpenEntity setting, they randomly mask 10% of inserted metadata tokens during training. The main relation extraction settings use the selected text without that masking.

The implementation begins with pretrained BERT-base-uncased. A linear classifier reads the pooled representation associated with the special [CLS] token, so the prediction can draw on the full input sequence. The authors use cross-entropy for FewRel and TACRED because each example calls for a relation label. They use binary cross-entropy for OpenEntity, where the same mention can have several applicable labels. The task classifier and the input encoder are fine-tuned for each benchmark.

The authors select a learning rate of 2e-5 for the reported task settings. FewRel uses a maximum sequence length of 512 and a batch size of 16. OpenEntity also uses batches of 16 and has a maximum sequence length of 256. TACRED uses a maximum length of 256 with batch size 48. The appendix gives these details because shaping changes the amount of text the system reads, and validation determines which training checkpoint is evaluated. The search for the best validation checkpoint extends over 15 epochs for FewRel, 20 for OpenEntity, and 8 for TACRED.

A separate experiment asks whether shaped text is also easier to predict under a masked-token objective. This experiment starts from BERT with a masked language modeling head, using the implementation from the Transformers toolkit. The task system used for the benchmark comparison does not go through this extra stage. In the analytical experiment, the additional training fits a separate predictor on shaped task data, with the objective of identifying tokens withheld from the sequence.

L_mlm = Eₛ∼D,ₘ∼M,ᵢ∼I[−log p̂θ(sᵐᵢ | sᵐ₍₋ᵢ₎)]

Here L_mlm is the masked-token loss and E denotes an average over the indicated draws. The symbol s is a sequence drawn from the task data D, m is metadata drawn from the collection M used to shape it, and i is a token position drawn under the masking distribution I. The sign ∼ denotes sampling. The superscript m indicates a sequence shaped with metadata. The expression sᵐᵢ denotes the original token at masked position i, while sᵐ₍₋ᵢ₎ denotes the shaped sequence with that token hidden. The predictor p̂θ, with parameters θ, estimates the token’s probability given the remaining visible sequence. The negative logarithm penalizes low probability for the correct token. The authors evaluate the resulting predictor by perplexity on task test data, where lower perplexity indicates better prediction of the withheld text.

The paper releases the metadata shaping implementation and identifies the ERNIE benchmark distribution as the source of the raw task datasets. It also identifies the entity-linking implementation used to generate annotations. These pieces serve different roles in the procedure. The benchmark supplies text and supervision, the linker supplies access to entity records, and the shaping code prepares inputs from the information available for each example.

Experiments and results

What each benchmark measures

The two relation extraction tasks ask a system to identify the relationship expressed between marked strings. FewRel has 80 output relations. TACRED Revisited has 42. The input sentence provides context, and the task supplies the subject and object spans the classifier should consider. Shaping can add information about either participant. The classifier still has to decide what the sentence says about them, since the participants can plausibly take part in several kinds of relations. This is a supervised information extraction setting with predictions evaluated against benchmark labels.

OpenEntity asks a different question about an individual target span. Given a passage and the marked mention, the classifier predicts which entity types apply. The benchmark used here has 9 output types. A retrieved category can provide evidence for a type, but the source vocabulary and the benchmark label inventory are distinct elements of the setup. The procedure learns the relationship between the inserted text and the eligible task labels from examples. A detailed description can also supply a clue when its wording differs from the category used in the benchmark.

The paper reports precision, recall, and F1 on the test splits. Precision measures how often predicted positives are correct. Recall measures how much of the annotated positive set is recovered. F1 combines precision and recall so a system needs both to score well. The authors use the scoring implementations released by the ERNIE researchers, and they select each test checkpoint by its validation result. The test comparisons therefore concern task predictions made after separate fine-tuning and validation, with the shaping configuration applied to the relevant train and test inputs.

How much metadata the tasks provide

Metadata coverage differs sharply across the tasks. The reported FewRel split sizes are 8k training examples, 16k validation examples, and 16k test examples. In the test split, the counts with category metadata are 16k/15k for the subject and object spans, respectively. The counts with descriptions are 15k/16k in that same order. Those figures use the paper’s reported precision for the counts. They show that candidate metadata is available for nearly the entire benchmark, although the tag budget and ranking still determine what gets inserted.

For TACRED Revisited, the paper reports 68,124 training examples, 22,631 validation examples, and 15,509 test examples. Its test category counts are 9k/10k for subjects and objects, and its test description counts are 8k/9k. Counts for the two spans overlap when the same example has metadata for both. The coverage figures therefore describe the availability of each kind of annotation at each span, and do not by themselves give the number of examples that receive at least one insert.

OpenEntity has 1998 examples in each split. For the single target span in its test split, 647 examples have category metadata and 649 have description metadata. The authors characterize coverage on OpenEntity as sparse and describe metadata as available for only 30% of examples when discussing the end-to-end results. That makes the task a useful contrast with FewRel. The benchmark score reflects a mixture of inputs with and without retrieved text, and the shaped classifier has to handle both.

Coverage is the scope of opportunity for a method like this. An eligible mention still needs a usable linked record, and a record can yield several candidates of different quality. An annotation count says that metadata can be retrieved. It does not establish whether the retrieved tag is correct, whether it is useful for the benchmark label, or whether the particular tag survives selection. Those stages give different reasons why having metadata and benefiting from it can come apart.

What the comparison holds in common

The unshaped BERT-base system is the main comparison for measuring the value of preparing inputs in this way. The authors also compare with knowledge-enhanced systems chosen to share BERT-base as the foundation and Wikipedia as the external information resource. This makes the comparison more focused than one between arbitrary architectures trained on unrelated knowledge sources. It still permits the competing systems to process and learn from that information in different ways. Those differences are part of the practical question the paper asks.

Some competitors add objectives and require further pretraining. ERNIE and CokeBERT are examples in the results table. E-BERT instead aligns entity representations with word representations and is described as requiring no extra pretraining. KnowBERT-Wiki represents the line of work that changes how attention to entity information is handled. Metadata shaping gives standard BERT input text that already contains the selected knowledge. Knowledge Enhanced Contextual Word Representations

The table combines scores available from earlier reports with scores the authors obtain using released implementations. The paper credits the CokeBERT researchers with reporting the K-BERT numbers and some KnowBERT-Wiki results. The appendix describes running the available implementations of KnowBERT-Wiki and ERNIE where results were needed for TACRED Revisited. A missing score indicates that a result was unavailable for the comparison. As a result, the set of systems in the comparison varies from task to task.

FewRel

The shaped classifier scores 90.4 test F1 on FewRel. CokeBERT reports 89.4, KnowBERT-Wiki 89.2, and unshaped BERT-base 84.9 in the main results table. The shaped system’s test precision and recall are both reported as 90.4. The result shows that the ordinary classification setup with retrieved text can outperform the reported knowledge-enhanced systems on this benchmark.

Relation extraction systems on FewRel test F1

Metadata shaping leads the reported FewRel comparison.

Relation extraction systems on FewRel test F1BERT-base: 84.9BERT-base84.9E-BERT concat: 88.5E-BERT concat88.5KnowBERT-Wiki: 89.2KnowBERT-Wiki89.2CokeBERT: 89.4CokeBERT89.4Metadata shaping with BERT-base (this paper): 90.4Metadata shaping with BERT-base (thispaper)90.4
The numbers
System or settingF1
BERT-base84.9
E-BERT concat88.5
KnowBERT-Wiki89.2
CokeBERT89.4
Metadata shaping with BERT-base (this paper)90.4

The authors describe the improvement over unshaped BERT-base as 5.3 F1 points in their discussion of the end-to-end results. That stated FewRel gain and the baseline F1 displayed alongside the shaped score in the main results table do not align. The test scores above follow the table, and 5.3 is the gain reported in the prose. Keeping their provenance explicit preserves both reported quantities without treating them as interchangeable.

FewRel gives the method substantial opportunity to insert evidence because metadata covers nearly all examples. Its separate tail analyses are also particularly informative because coverage is available for many mentions whose names are novel to task training. The overall F1 result concerns the complete test split. The evidence about where those gains occur comes from grouping examples by mention frequency and examining the groups separately.

TACRED Revisited

The shaped system records 76.7 test F1 on TACRED Revisited, compared with 72.0 for unshaped BERT-base. The authors report a gain of 4.7 F1 points over that baseline. KnowBERT-Wiki records 77.9 F1 and ERNIE 75.9. The strongest knowledge-based system in this comparison is therefore ahead of the shaped approach, although shaping recovers substantial performance over using the original text alone.

Relation extraction systems on TACRED Revisited test F1

Metadata shaping improves on BERT-base, and KnowBERT-Wiki scores highest.

Relation extraction systems on TACRED Revisited test F1BERT-base: 72.0BERT-base72.0ERNIE: 75.9ERNIE75.9Metadata shaping with BERT-base (this paper): 76.7Metadata shaping with BERT-base (thispaper)76.7KnowBERT-Wiki: 77.9KnowBERT-Wiki77.9
The numbers
System or settingF1
BERT-base72.0
ERNIE75.9
Metadata shaping with BERT-base (this paper)76.7
KnowBERT-Wiki77.9

The shaped system’s precision and recall are 77.0 and 76.3, respectively. Unshaped BERT-base records 66.3 precision and 78.7 recall. This makes the practical change clearer than F1 alone. The shaped classifier has substantially higher precision in the reported comparison, while recall is lower. In the balance represented by F1, the improvement in precision is enough to yield the higher score. The paper’s separate analyses of metadata placement indicate a small advantage for placing inserted text at the end on this task, which is the arrangement used for its main score.

OpenEntity

On OpenEntity, metadata shaping gives 76.2 test F1 and unshaped BERT-base gives 73.2. The authors report a gain of 3.0 F1 points. ERNIE and CokeBERT both record 75.6, and KnowBERT-Wiki records 75.0. The shaped classifier reports precision of 79.3 and recall of 73.3. CokeBERT has the same reported recall of 73.3 and precision of 78.8.

Entity typing systems on OpenEntity test F1

Metadata shaping has the highest reported OpenEntity test F1.

Entity typing systems on OpenEntity test F1BERT-base: 73.2BERT-base73.2K-BERT: 74.0K-BERT74.0KnowBERT-Wiki: 75.0KnowBERT-Wiki75.0ERNIE: 75.6ERNIE75.6CokeBERT: 75.6CokeBERT75.6Metadata shaping with BERT-base (this paper): 76.2Metadata shaping with BERT-base (thispaper)76.2
The numbers
System or settingF1
BERT-base73.2
K-BERT74.0
KnowBERT-Wiki75.0
ERNIE75.6
CokeBERT75.6
Metadata shaping with BERT-base (this paper)76.2

Sparse metadata makes the whole-test improvement notable. The gain is measurable even though many individual examples have no metadata available. That result applies to a classifier trained on a mixture of shaped and unshaped inputs and evaluated on the full task. It allows for improvement on examples with metadata and for changes in learned behavior on other examples. The aggregate result alone cannot distinguish these possibilities.

Across the tasks, the documented average improvement over unshaped BERT-base is 4.3 F1 points. The paper frames this as a comparison between ways of introducing external knowledge. The headline results show that a standard encoder reading edited task examples can compete with systems that have dedicated machinery for knowledge. The differing results across tasks are also important. A lead on one benchmark, or a gain over the common baseline, does not imply the same ordering on another benchmark with different examples, labels, and metadata coverage.

What the ablations show

Selecting informative tags helps at a fixed budget

The main result uses a tuned shaping configuration. To test whether the selection heuristic contributes in its own right, the authors compare strategies under the same limits on how many tags can be inserted. On FewRel and TACRED the limit is 3 per subject and 3 per object. On OpenEntity it is 2 for the target span. The choice is motivated partly by availability. In OpenEntity training data, 33% of examples have ≥ 2 categories, while 80.7% of FewRel training examples have ≥ 3. The selection comparison is averaged over 3 random seeds.

High Rank chooses the candidates with the lowest estimated class entropy. Low Rank uses the opposite end of that ranking. Random samples metadata from the candidates available for the example, and Popular favors tags that occur often across training. Each strategy starts from real candidate metadata for the current input. In particular, Random in this experiment is distinct from the experiment that inserts arbitrary vocabulary words. A randomly chosen available category can still describe the linked entity correctly.

The high-ranked setting gives the best mean test F1 on all the tasks in this comparison. For FewRel, High Rank gives 88.9 ±0.6, compared with 87.9 ±0.1 for Popular, 87.8 ±0.4 for Low Rank, and 87.2 ±0.8 for Random. For TACRED, it gives 74.7 ±0.5, alongside 73.8 ±1.6 for Random, 73.6 ±0.9 for Popular, and 73.3 ±1.0 for Low Rank. For OpenEntity, it gives 74.8 ±0.1, alongside 74.5 ±0.4 for Popular, 74.3 ±0.7 for Random, and 74.1 ±0.4 for Low Rank. The quantities after the means are the reported standard deviations across the seeds.

The unshaped reference scores in that comparison are 84.9 for FewRel, 72.0 for TACRED, and 73.2 for OpenEntity. Every random selection mean exceeds its corresponding unshaped reference. This indicates that real entity metadata can help even without choosing tags specifically for a task. The consistent ordering of High Rank above the alternatives shows that the training-based scores can improve the selection further under these budgets. On some tasks the spread between strategies is modest in relation to seed variation, so the pattern across benchmarks is more informative than a broad claim about the size of each advantage.

The authors also compare the distributions of selected categories using KL divergence, a measure of how one probability distribution differs from another. On FewRel, the reported divergence is 0.2 for Low Rank versus Popular and 2.8 for High Rank versus Popular. On OpenEntity, the respective divergences are 4.6 and 2.4. High Rank consequently yields a category distribution quite different from the popularity policy on FewRel, while its distribution is closer to Popular than Low Rank is on OpenEntity. Those figures concern which tags the policies choose, and help explain how similar performance comparisons can arise from different selections.

The examples make the distinction concrete. In FewRel, occupation is the most frequent category selected by Low Rank and occurs in 2.4k training examples. Among the top-10 categories selected by High Rank are director and politician, each of which occurs in > 300 training examples. The broader tag is available often, but the more specific tags can offer clearer clues about which relations are plausible. In OpenEntity, business is among the top-10 types selected by High Rank, while non-profit, which appears in 2 training examples, is among the top-10 selected by Low Rank. The authors suggest that with sparser metadata, broad types can overlap more with the useful selections because the training evidence for fine distinctions is limited.

The authors assess whether shaping makes class-associated words more available to the classifier. They rank individual words using PMI with each label in the training data. They then look at FewRel test examples and use the true label to ask whether an example contains a top-20 PMI word for that label. Accuracy is reported to be 27.6% higher for the slice containing such a word than for the slice without one. The true label is needed to define this analysis group. Selection when preparing a test input uses the whole estimated label distribution for a candidate, without knowing which label is correct.

When PMI is computed from shaped training data, 74. The number of examples containing one of their class’s 20 highest-PMI words is 1% higher than when PMI is calculated using unshaped training data. This statistic concerns how many cases present a word that the training data associate with the correct class. It supports the argument that shaping brings useful words into view. It does not show how predictions would change if a particular word were removed from the same example. The slices are defined by what naturally appears under the respective conditions and may differ in other indicators of difficulty.

The paper also examines the entropy of the classifier’s output. Lower average entropy on test examples correlates with higher test F1 across shaping schemes. The authors hold the number of inserted tokens constant and vary how many of the true metadata tokens are replaced with random words from the vocabulary. The condition with all true metadata represents the informative end of the comparison. Replacing true metadata degrades the relationship between the inserted words and the entity while preserving the size of the insert. The setup helps distinguish the effect of informative content from the effect of merely adding tokens.

An additional comparison uses the independent masked-token predictor described in the method. For each shaping condition, that predictor and the task classifier learn from the same shaped training data, but optimize different objectives. The paper compares test perplexity for the masked-token predictor with test F1 for the downstream classifier. Lower perplexity accompanies better downstream results across the shaping conditions. The reported R² is 0.985 for FewRel and 0.956 for OpenEntity, with each plotted condition represented by its median over 3 random seeds.

For TACRED the authors report R² of 0.782 after excluding the condition that inserts all random words. With that condition included, they give R² of 0.02. The sensitivity of the TACRED statistic matters. The relationship is strong for the remaining conditions and weak in the full comparison. The masked-token result is best interpreted as a diagnostic of properties that the two objectives can share under a shaping scheme. It cannot establish that changing the masked-token predictor would cause a change in classification performance.

Rare and frequent mentions respond differently

The paper defines tail entities as those seen < 10 times during task training, and head entities as those seen ≥ 10 times. In the plotted comparison, the improvement from shaping is on average 4.4x larger for the tail slice than for the head slice. This statistic compares improvements over unshaped inputs on the respective slices. It gives no direct ordering of their absolute F1 scores. The result addresses the authors’ original question about whether the added context is especially helpful when the name itself is poorly represented.

The examples behind the slice definitions require care. The paper reports that 90.7% of FewRel test examples have a subject span that never appeared as a subject during training, and 59.7% have an object span that never appeared as an object during training. In discussing the popularity analysis for the relation tasks, the authors use object spans because > 90% of subject spans are unseen. This makes an object-based split more informative for comparing frequency groups. The paper also notes that 42% of the head spans in TACRED are stopwords or numbers, compared with 7% in FewRel. A frequently repeated pronoun is a different kind of span from a often repeated person’s name, even though both can count as frequent under a string-based grouping.

To examine the proposed transfer within groups, the authors turn to TF-IDF. They collect words associated with a category in training and use the score to identify words that are distinctive for that category. In FewRel, government is among the top-20 TF-IDF words associated with politician. At test time, the authors look for examples that contain one of the characteristic words associated with the categories inserted for a mention. This asks whether the surrounding passage also contains language that resembles the contexts in which the category was seen during training.

Among FewRel examples with unseen subject entities, test performance is 9.0 F1 points higher when a top-20 word for a relevant subject category is present than when it is absent. For examples with unseen object entities, the corresponding difference is 3.5 F1 points for a word associated with the object category. The comparison is consistent with the authors’ account of category transfer. A tag can connect the new entity to a group, and the surrounding sentence can contain words that the classifier has learned to use with that group. Since the examples are split by whether the cue is already present, their difficulty can vary for reasons besides the cue.

The paper also uses an attention example from FewRel to illustrate this possibility at the level of a single prediction. The target spans shown there are unseen during task training. The tuned unshaped system gives the displayed name words low attention, while the shaped system gives attention to a useful tag such as politician. The visualization excludes stopwords, punctuation, and special tokens. It illustrates that metadata can become part of the attended context. The experimental support for better prediction comes from the F1 comparisons and the slice analyses, since attention weights alone do not establish why an answer changed.

When a shared category points away from the answer

The authors examine a situation where a known name and its category point to different relations. A name can acquire a strong association with a particular relation from occurrences in training. Its broader category may occur with a different set of relations. The authors illustrate the tension with Thames River. The full mention is associated with a label for being located in or beside a body of water, while river is associated with a label for a watercourse’s mouth. Both signals are meaningful. Their relative value depends on the example.

The analysis begins with subject and object spans that appear ≥ 1 time in training. This is the eligibility condition for this particular analysis, which differs from the main head threshold. For a test input, the authors form a set of labels that have positive PMI with an eligible mention in the example. They call the set Yₚ, where p denotes a previously seen mention. They form another set, Yₘ, of labels with positive PMI for an inserted tag m. The sets indicate which labels the mention evidence and the metadata evidence separately favor according to the training statistics.

The authors compare test examples where both sets are nonempty with a narrower group where only the mention set contains the correct class. On that narrower FewRel slice, the gain from shaping is 2.3 F1 points less than on the broader slice with both sources of evidence. This is a smaller benefit, and the reported comparison does not require that shaping produce a net loss on that group. It locates a condition under which useful evidence from a familiar name and a general category can compete.

That result also gives a practical interpretation to the difference between the head and tail gains. Popular names can already carry strong task associations. Supplying a broad category can add less that is new, or bring in patterns that reflect other members of the group. For an unseen name, the category is more likely to be a salient pattern the system has encountered before. The different slice results therefore fit the paper’s proposal that metadata changes which training regularities are available for use in a particular example.

Masking, descriptions, and formatting

The paper tests whether making metadata less predictable can help the classifier avoid leaning too heavily on it. In OpenEntity experiments, randomly masking 10% of the inserted metadata tokens at training time yields an F1 gain of 0 over the corresponding results for unmasked selection.1 for High Rank, 0.5 for Popular, and 0.5 for Low Rank over the same 3 seeds. FewRel shows no consistent benefit from masking. The authors suggest that the sparse availability of metadata in OpenEntity makes this kind of training variation helpful. The comparison establishes a small improvement in the tested settings, and the regularization account remains an explanation proposed by the authors.

Descriptions introduce variation of a different kind. The paper reports that, over FewRel training data, a word in the description collection appears an average of 8 times, while a word in the category collection appears an average of 18 times. The descriptions contain 3.3x as many unique words as the categories. Categories therefore offer more repeated wording, while descriptions give the classifier a richer set of expressions. This allows a comparison of whether a mixture of the two is less sensitive to the loss of some inserted text.

In that comparison, one FewRel setting inserts 10 category tokens. The mixed setting uses 5 category and 5 description tokens, with the category items sampled randomly. The category-only setting gives 89.8 F1 on ordinary inputs, and the mixed setting gives 89.5 F1. When the authors randomly remove 10% of the metadata tokens per test example, scores drop by 1.4 F1 for category-only inputs and 1.0 F1 for mixed inputs. Thus the two settings give close scores in the original evaluation, and the mixed setting loses less under the particular removal test. The result concerns simulated missing tokens and leaves performance under wrong entity links open.

The way the insert is presented matters as well. Boundary markers separate the original sentence from the retrieved phrase. Comparing shaped inputs with and without these markers, the authors report gains of 0.7 F1 on FewRel and 1.4 F1 on OpenEntity for the marked version in their main configurations. The task structure markers serve a different purpose. They designate the relevant spans, such as the subject of a relation or the target of typing. In an experiment with no other shaping, adding those markers improves F1 by 26.3 on FewRel and 24.7 on OpenEntity over training without them. Those large gains belong to the span-marking comparison. The metadata gains are measured on top of an already structured task input.

Placement and budget have smaller effects in the authors’ tests. Inserting tags immediately after the relevant span works better for FewRel and OpenEntity, while inserting them at the end works better for TACRED. The differences are described as small. For the analyses in the main analysis section, the authors use placement immediately after the relevant span on all tasks. This makes the controlled analyses easier to compare and explains why their exact setup differs from the main benchmark configuration for TACRED.

In the insertion-budget analysis, tags are inserted in random order to control for differences in their class association. On FewRel, maximum budgets per entity of 1, 5, 10, and 20 give test F1 of 85.4, 86.4, 87.6, and 88.5, respectively. On OpenEntity, budgets of 1, 5, 10, 20, and 40 give 74.9, 75.7, 74.8, 74.5, and 75.8. FewRel improves as the tested budget grows, while OpenEntity fluctuates. A larger budget gives the system an opportunity to receive more useful text, but the availability of tags and their specificity determine how much evidence it actually gains.

Limitations

Limits the authors identify

The authors explicitly simplify their account of an unseen pattern. Their conceptual argument ignores whether the entity appeared during BERT’s original pretraining and whether a new pattern resembles one already encountered during training. Either could supply predictive evidence even for a name absent from the task split. They propose using those priors to refine the unseen slice. As evaluated, the reported gains concern frequency in the supervised task data, rather than prior exposure across all stages of training.

The paper relies on entity annotations with real failure rates. The authors acknowledge both errors in annotation and cases with no linked entity. They also point out that the comparison systems use entity linking and face the same general kind of failure. That shared dependency makes the problem relevant to all the approaches in the comparison, while leaving the tested system dependent on the quality of the retrieval it receives. The paper seeks tolerance to noise and gives initial tests with masking and token removal. Direct evaluation with systematically incorrect links remains open.

The selection analysis uses individual tags as proxies for the many patterns an insertion can create. The authors identify longer patterns and correlations between tags as possible extensions. This is a substantive restriction. Two individually helpful tags can convey much the same clue, and an otherwise weak tag can matter only in combination with another phrase. The ranking algorithm has no explicit mechanism for evaluating those interactions when building the insert. The downstream classifier can learn interactions among the words it sees, but it only sees the metadata that survives selection.

The authors also give the composition of the frequent-span slices as a qualification. In TACRED, the prevalence of pronouns, other stopwords, and numbers among frequent spans weakens the interpretation of that slice as a group of well-known named entities. The paper gives separate statistics for FewRel and TACRED to show how much that composition can vary. The masking experiments receive a similarly qualified interpretation. The authors describe the observations as initial support for a regularization hypothesis, with further work needed to investigate more targeted masking strategies.

Limits of what the experiments establish

The benchmark results establish the usefulness of shaping on the tested relation extraction and typing tasks with BERT-base. The method is described in terms broad enough to apply to classification tasks generally, but its empirical coverage is narrower. The experiments use text with identifiable target mentions and access to external resources that provide entity information. Results on other classification settings, or on inputs for which useful tags are difficult to obtain, would require separate evidence. The effective method includes retrieval, selection, and training on the prepared inputs, so portability depends on more than the ability to concatenate strings.

The key baseline comparison shows the added value of the complete shaping configuration. Tag selection, amount of inserted text, placement, and on OpenEntity training-time masking can all contribute. The smaller controlled comparisons isolate some of those choices at particular budgets. They do not decompose the whole end-to-end gain into independent contributions that could be added together. Changing one choice can alter how useful another is, especially when tags are scarce or have overlapping meanings.

The tail result is a comparison of gains under a particular definition and grouping. Since the counts are based on task spans and their frequency in training, the analysis can conflate an unfamiliar surface form with an unfamiliar entity. The choice to use object spans in the relation tasks also means the analysis emphasizes one side of the relation. The example of Daniel Dugléry illustrates the transfer the method aims to achieve, while the slice statistic covers a broader set of cases with varying amounts of observable context and metadata. Its interpretation is strongest as an improvement for rare task mentions under the benchmark setup.

The analyses of class-associated words, TF-IDF cues, entropy, and perplexity all provide evidence about possible mechanisms. They differ in what they establish. Replacing valid metadata with random words is a controlled change in the inserted content. Grouping examples by existing words compares naturally different subsets. Comparing perplexity and F1 across shaping conditions associates two outcomes under a common input intervention. These results together support the conclusion that informative text matters, while leaving unresolved which part of the text was decisive for each prediction.

Finally, the paper’s comparison with knowledge-enhanced approaches is primarily a comparison of predictive quality. The appendix supplies settings and running times for its own training, and avoiding additional pretraining makes the encoder training procedure simpler. The full method still requires an entity linker, access to metadata, computation of training statistics, and preparation of longer sequences. The reported F1 scores and training details do not measure the full retrieval and serving costs against those of the competing approaches. The evidence supports a practical alternative for the tested tasks, with the end-to-end cost comparison left open.

What came after

No subsequent citing study is documented for this paper. The authors themselves identify several places where further experiments could extend the work. The first concerns what it means for an entity to be unseen. Their results group mentions by appearances in task training. Incorporating evidence about prior exposure or similarities to known mentions would distinguish cases where a category supplies genuinely new information from cases where it reinforces information already available to BERT.

A second direction concerns selection. The paper ranks individual tags by how concentrated their label distributions are. The authors propose scoring longer patterns or choosing tags in a way that accounts for the information already supplied by earlier choices. This follows directly from their example of competing signals. A description and a type can reinforce each other, offer complementary clues, or favor different labels. Joint selection would let a follow-up test whether choosing the group of tags improves on choosing each tag independently.

The authors also propose investigating more targeted masking and examining the broader use of side information in task inputs. Their masking evidence is strongest for the sparse OpenEntity setting and for the particular FewRel test with randomly removed tokens. Those observations define concrete questions for a follow-up. The unresolved issue is how much robustness comes from varied descriptions, deliberate corruption during training, or a better way of selecting the evidence to insert.

Cite

Cite as Simran Arora, Sen Wu, Enci Liu and Christopher Re. 2022. Metadata Shaping: A Simple Approach for Knowledge-Enhanced Language Models. Findings of the Association for Computational Linguistics: ACL 2022.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2022.findings-acl.137

@inproceedings{arora2022metadata,
  title = {{Metadata Shaping: A Simple Approach for Knowledge-Enhanced Language Models}},
  author = {Simran Arora, Sen Wu, Enci Liu and Christopher Re},
  booktitle = {Findings of the Association for Computational Linguistics: ACL 2022},
  year = {2022},
  doi = {10.18653/v1/2022.findings-acl.137},
  url = {https://doi.org/10.18653/v1/2022.findings-acl.137}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/arora-2022-metadata-shaping-simple-approach-knowledge/