SlowGuess/ACL_2020_OCR huggingface dataset:
Tongfei Chen Yunmo Chen Benjamin Van Durme
{tongfei, ychen, vandurme}@cs.jhu.edu
We propose a novel method for hierarchical entity classification that embraces ontological structure at both training and during prediction. At training, our novel multi-level learning-to-rank loss compares positive types against negative siblings according to the type tree. During prediction, we define a coarse-to-fine decoder that restricts viable candidates at each level of the ontology based on already predicted parent type(s). We achieve state-of-the-art across multiple datasets, particularly with respect to strict accuracy.
Entity typing is the assignment of a semantic label to a span of text, where that span is usually a mention of some entity in the real world. Named entity recognition (NER) is a canonical information extraction task, commonly considered a form of entity typing that assigns spans to one of a handful of types, such as PER, ORG, GPE, and so on. Fine-grained entity typing (FET) seeks to classify spans into types according to more diverse, semantically richer ontologies (Ling and Weld, 2012; Yosef et al., 2012; Gillick et al., 2014; Del Corro et al., 2015; Choi et al., 2018), and has begun to be used in downstream models for entity linking (Gupta et al., 2017; Raiman and Raiman, 2018).
Consider the example in Figure 1 from the FET dataset, FIGER (Ling and Weld, 2012). The mention of interest, Hollywood Hills, will be typed with the single label LOC in traditional NER, but may be typed with a set of types  $\{ / location, / geography, / geography/mountain\}$  under a fine-grained typing scheme. In these finer-grained typing schemes, types usually form a hierarchy: there are a set of coarse types that lies on
He is interred at Forest Lawn Memorial Park in Hollywood Hills, Los Angeles, CA.
Figure 1: An example mention classified using the FIGER ontology. Positive types are highlighted.
the top level—these are similar to traditional NER types, e.g. /person; additionally, there are finer types that are subtypes of these top-level types, e.g. /person/artist or /person/doctor.
Most prior work concerning fine-grained entity typing has approached the problem as a multi-label classification problem: given an entity mention together with its context, the classifier seeks to output a set of types, where each type is a node in the hierarchy. Approaches to FET include handcrafted sparse features to various neural architectures (Ren et al., 2016a; Shimaoka et al., 2017; Lin and Ji, 2019, inter alia, see section 2).
Perhaps owing to the historical transition from "flat" NER types, there has been relatively little work in FET that exploits ontological tree structure, where type labels satisfy the hierarchical property: a subtype is valid only if its parent supertype is also valid. We propose a novel method that takes the explicit ontology structure into account, by a multi-level learning to rank approach that ranks the candidate types conditioned on the given entity mention. Intuitively, coarser types are easier whereas finer types are harder to classify: we capture this intuition by allowing distinct margins at each level of the ranking model.
1 Code can be found at https://github.com/ctongfei/hierarchical-typing.
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 8465-8475 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
Figure 2: Various type ontologies. Different levels of the types are shown in different shades, from L0 to L3. The ENTITY and OTHER special nodes are discussed in section 3.
Coupled with a novel coarse-to-fine decoder that searches on the type hierarchy, our approach guarantees that predictions do not violate the hierarchical property, and achieves state-of-the-art results according to multiple measures across various commonly used datasets.
FET is usually studied as allowing for sentence-level context in making predictions, notably starting with Ling and Weld (2012) and Gillick et al. (2014), where they created the commonly used FIGER and OntoNotes datasets for FET. While researchers have considered the benefits of document-level (Zhang et al., 2018), and corpus-level (Yaghoobzadeh and Schütze, 2015) context, here we focus on the sentence-level variant for best contrast to prior work.
Progress in FET has focused primarily on:
- Better mention representations: Starting from sparse hand-crafted binary features (Ling and Weld, 2012; Gillick et al., 2014), the community has moved to distributed representations (Yogatama et al., 2015), to pre-trained word embeddings with LSTMs (Ren et al., 2016a,b; Shimaoka et al., 2016; Abhishek et al., 2017; Shimaoka et al., 2017) or CNNs (Murty et al., 2018), with mention-to-context attention (Zhang et al., 2018), then to employing pre-trained language models like ELMo (Peters et al., 2018) to generate ever better representations (Lin and Ji, 2019). Our approach builds upon these developments and uses state-of-the-art mention encoders.
- Incorporating the hierarchy: Most prior works approach the hierarchical typing problem
as multi-label classification, without using information in the hierarchical structure, but there are a few exceptions. Ren et al. (2016a) proposed an adaptive margin for learning-to-rank so that similar types have a smaller margin; Xu and Barbosa (2018) proposed hierarchical loss normalization that penalizes output that violates the hierarchical property; and Murty et al. (2018) proposed to learn a subtyping relation to constrain the type embeddings in the type space. In contrast to these approaches, our coarse-to-fine decoding approach strictly guarantees that the output does not violate the hierarchical property, leading to better performance. HYENA (Yosef et al., 2012) applied ranking to sibling types in a type hierarchy, but the number of predicted positive types are trained separately with a meta-model, hence does not support neural end-to-end training.
Researchers have proposed alternative FET formulations whose types are not formed in a type hierarchy, in particular Ultra-fine entity typing (Choi et al., 2018; Xiong et al., 2019; Onoe and Durrett, 2019), with a very large set of types derived from phrases mined from a corpus. FET in KB (Jin et al., 2019) labels mentions to types in a knowledge base with multiple relations, forming a type graph. Dai et al. (2019) augments the task with entity linking to KBs.
We denote a mention as a tuple  $x = (w, l, r)$ , where  $w = (w_1, \dots, w_n)$  is the sentential context and the span  $[l : r]$  marks a mention of interest in sentence  $w$ . That is, the mention of interest is  $(w_l, \dots, w_r)$ . Given  $x$ , a hierarchical entity typing model outputs
8466
a set of types  $Y$  in the type ontology  $\mathcal{V}$ , i.e.  $Y \subseteq \mathcal{V}$ .
Type hierarchies take the form of a forest, where each tree is rooted by a top-level supertype (e.g. /person, /location, etc.). We add a dummy parent node ENTITY = "/", the supertype of all entity types, to all the top-level types, effectively transforming a type forest to a type tree. In Figure 2, we show 3 type ontologies associated with 3 different datasets (see subsection 5.1), with the dummy ENTITY node augmented.
We now introduce some notation for referring to aspects of a type tree. The binary relation "type  $z$  is a subtype of  $y$ " is denoted as  $z <: y$ . The unique parent of a type  $y$  in the type tree is denoted  $\bar{y} \in \mathcal{V}$ , where  $\bar{y}$  is undefined for  $y = \text{ENTITY}$ . The immediate subtypes of  $y$  (children nodes) are denoted  $\operatorname{Ch}(y) \subseteq \mathcal{V}$ . Siblings of  $y$ , those sharing the same immediate parent, are denoted  $\operatorname{Sb}(y) \subseteq \mathcal{V}$ , where  $y \notin \operatorname{Sb}(y)$ .
In the AIDA FET ontology (see Figure 2), the maximum depth of the tree is  $L = 3$ , and each mention can only be typed with at most 1 type from each level. We term this scenario single-path typing, since there can be only 1 path starting from the root (ENTITY) of the type tree. This is in contrast multi-path typing, such as in the BBN dataset, where mentions may be labeled with multiple types on the same level of the tree.
Additionally, in AIDA, there are mentions labeled such as as /per/police/<unspecified>. In FIGER, we find instances with labeled type /person but not any further subtype. What does it mean when a mention  $x$  is labeled with a partial type path, i.e., a type  $y$  but none of the subtypes  $z <: y$ ? We consider two interpretations:
- Exclusive:  $x$  is of type  $y$ , but  $x$  is not of any type  $z < : y$ .
- Undefined:  $x$  is of type  $y$ , but whether it is an instance of some  $z < : y$  is unknown.
We devise different strategies to deal with these two conditions. Under the exclusive case, we add a dummy OTHER node to every intermediate branch node in the type tree. For any mention  $x$  labeled with type  $y$  but none of the subtypes  $z <: y$ , we add this additional label "y/OTHER" to the labels of  $x$  (see Figure 2: AIDA). For example, if we interpret a partial type path /person
in FIGER as exclusive, we add another type /person/OTHER to that instance. Under the undefined case, we do not modify the labels in the dataset. We will see this can make a significant difference depending on the way a specific dataset is annotated.
4.1 Mention Representation
Hidden representations for entity mentions in sentence  $w$  are generated by leveraging recent advances in language model pre-training, e.g. ELMo (Peters et al., 2018). The ELMo representation for each token  $w_{i}$  is denoted as  $\mathbf{w}_i \in \mathbb{R}^{d_w}$ . Dropout is applied with probability  $p_{\mathrm{D}}$  to the ELMo vectors.
Our mention encoder largely follows Lin and Ji (2019). First a mention representation is derived using the representations of the words in the mention. We apply a max pooling layer atop the mention after a linear transformation:4
$$
\mathbf {m} = \operatorname {M a x P o o l} \left(\mathbf {T w} _ {l}, \dots , \mathbf {T w} _ {r}\right) \in \mathbb {R} ^ {d _ {w}}. \tag {1}
$$
Then we employ mention-to-context attention first described in Zhang et al. (2018) and later employed by Lin and Ji (2019): a context vector  $\mathbf{c}$  is generated by attending the sentence with a query vector derived from the mention vector  $\mathbf{m}$ . We use the multiplicative attention of Luong et al. (2015):
$$
a _ {i} \propto \exp (\mathbf {m} ^ {\mathrm {T}} \mathbf {Q} \mathbf {w} _ {i}) \tag {2}
$$
$$
\mathbf {c} = \sum_ {i = 1} ^ {N} a _ {i} \mathbf {w} _ {i} \in \mathbb {R} ^ {d _ {w}} \tag {3}
$$
The final representation for an entity mention is generated via concatenation of the mention and context vector:  $[\mathbf{m};\mathbf{c}]\in \mathbb{R}^{2d_w}$
4.2 Type Scorer
We learn a type embedding  $\mathbf{y} \in \mathbb{R}^{d_t}$  for each type  $y \in \mathcal{V}$ . To score an instance with representation  $[\mathbf{m};\mathbf{c}]$ , we pass it through a 2-layer feed-forward network that maps into the same space as the type space  $\mathbb{R}^{d_t}$ , with tanh as the nonlinearity. The final
3 Lin and Ji (2019) found that ELMo performs better than BERT (Devlin et al., 2019) for FET. Our internal experiments also confirm this finding. We hypothesize that this is due to the richer character-level information contained in lower-level ELMo representations that are useful for FET.
4 Lin and Ji (2019) proposed an attentive pooler with a learned global query vector. We found out that a simple max pooling layer achieves similar performance.
2 Per programming language literature, e.g. the type system  $F_{<}$ : that supports subtyping.
8467
score is an inner product between the transformed feature vector and the type embedding:
$$
F (x, y) = \operatorname {F F N N} ([ \mathbf {m}; \mathbf {c} ]) \cdot \mathbf {y}. \tag {4}
$$
4.3 Hierarchical Learning-to-Rank
We introduce our novel hierarchical learning-to-rank loss that (1) allows for natural multi-label classification and (2) takes the hierarchical ontology into account.
We start with a multi-class hinge loss that ranks positive types above negative types (Weston and Watkins, 1999):
$$
J _ {\text {f l a t}} (x, Y) = \sum_ {y \in Y} \sum_ {y ^ {\prime} \notin Y} [ \xi - F (x, y) + F (x, y ^ {\prime}) ] _ {+} \tag {5}
$$
where  $[x]_{+} = \max \{0, x\}$ . This is actually learning-to-rank with a ranking SVM (Joachims, 2002): the model learns to rank the positive types  $y \in Y$  higher than those negative types  $y' \notin Y$ , by imposing a margin  $\xi$  between  $y$  and  $y'$ : type  $y$  should rank higher than  $y'$  by  $\xi$ . Note that in Equation 5, since it is a linear SVM, the margin hyperparameter  $\xi$  could be just set as 1 (the type embeddings are linearly scalable), and we rely on  $L_{2}$  regularization to constrain the type embeddings.
Multi-level Margins However, this method considers all candidate types to be flat instead of hierarchical — all types are given the same treatment without any prior on their relative position in the type hierarchy. Intuitively, coarser types (higher in the hierarchy) should be easier to determine (e.g. /person vs /location should be fairly easy for the model), but fine-grained types (e.g. /person/artist/singer) are harder.
We encode this intuition by (i) learning to rank types only on the same level in the type tree; (ii) setting different margin parameters for the ranking model with respect to different levels:
$$
\sum_ {y \in Y} \sum_ {y ^ {\prime} \in \operatorname {S b} (y) \backslash Y} [ \xi_ {\operatorname {l e v} (y)} - F (x, y) + F (x, y ^ {\prime}) ] _ {+} \tag {6}
$$
Here  $\mathrm{lev}(y)$  is the level of the type  $y$ : for example,  $\mathrm{lev}(/location) = 1$ , and  $\mathrm{lev}(/person/artist/singer) = 3$ . In Equation 6, each positive type  $y$  is only compared against its negative siblings  $\mathrm{Sb}(y) \backslash Y$ , and the margin hyperparameter is set to be  $\xi_{\mathrm{lev}(y)}$ , i.e., a margin dependent on which level  $y$  is in the tree. Intuitively, we should set  $\xi_1 > \xi_2 > \xi_3$  since our
Figure 3: Hierarchical learning-to-rank. Positive type paths are colored black, negative type paths are colored gray. Each blue line corresponds to a threshold derived from a parent node. Positive types (on the left) are ranked above negative types (on the right).
model should be able to learn a larger margin between easier pairs: we show that this is superior than using a single margin in our experiments.
Analogous to the reasoning that in Equation 5 the margin  $\xi$  can just be 1, only the relative ratios between  $\xi$ 's are important. For simplicity, if the ontology has  $L$  levels, we assign
$$
\xi_ {l} = L - l + 1. \tag {7}
$$
For example, given an ontology with 3 levels, the margins per level are  $(\xi_1,\xi_2,\xi_3) = (3,2,1)$ .
Flexible Threshold Equation 6 only ranks positive types higher than negative types so that all children types given a parent type are ranked based on their relevance to the entity mention. What should be the threshold between positive and negative types? We could set the threshold to be 0 (approaching the multi-label classification problem as a set of binary classification problem, see Lin and Ji (2019)), or tune an adaptive, type-specific threshold for each parent type (Zhang et al., 2018). Here, we propose a simpler method.
We propose to directly use the parent node as the threshold. If a positive type is  $y$ , we learn the following ranking relation:
$$
y > \bar {y} > y ^ {\prime}, \quad \forall y ^ {\prime} \in \mathrm {S b} (t) \tag {8}
$$
where  $\succ$  means "ranks higher than". For example, a mention has gold type /person/artist/singer. Since the
5 We did hyperparameter search on these margin hyperparameters and found that Equation 7 generalized well.
8468
parent type /person/artist can be considered as a kind of prior for all types of artists, the model should learn that the positive type "singer" should have a higher confidence than "artist", and in turn, higher than other types of artists like "author" or "actor". Hence the ranker should learn that "a positive subtype should rank higher than its parent, and its parent should rank higher than its negative children." Under this formulation, at decoding time, given parent type  $y$ , a child subtype  $z <: y$  that scores higher than  $y$  should be output as a positive label.
We translate the ranking relation in Equation 8 into a ranking loss that extends Equation 6. In Equation 6, there is an expected margin  $\xi$  between positive types and negative types. Since we inserted the parent in the middle, we divide the margin  $\xi$  into  $\alpha \xi$  and  $(1 - \alpha)\xi$ :  $\alpha \xi$  being the margin between positive types and the parent; and  $(1 - \alpha)\xi$  is the margin between the parent and the negative types. For a visualization see Figure 3.
The hyperparameter  $\alpha \in [0,1]$  can be used to tune the precision-recall tradeoff when outputting types: the smaller  $\alpha$ , the smaller the expected margin there is between positive types and the parent. This intuitively increases precision but decreases recall (only very confident types can be output). Vice versa, increasing  $\alpha$  decreases precision but increase recall.
Therefore we learn 3 sets of ranking relations from Equation 8: (i) positive types should be scored above parent by  $\alpha \xi$ ; (ii) parent should be scored above any negative sibling types by  $(1 - \alpha)\xi$ ; (iii) positive types should be scored above negative sibling types by  $\xi$ . Our final hierarchical ranking loss is formulated as follows.
$$
\begin{array}{l} J _ {y > \bar {y}} = [ \alpha \xi_ {\mathrm {l e v} (y)} - F (x, y) + F (x, \bar {y}) ] _ {+} \\ J _ {\bar {y} > y ^ {\prime}} = \sum_ {y ^ {\prime} \in \mathrm {S b} (y) \backslash Y} [ (1 - \alpha) \xi_ {\mathrm {l e v} (y)} - F (x, \bar {y}) + F (x, y ^ {\prime}) ] _ {+} \end{array}
$$
$$
J _ {y \succ y ^ {\prime}} = \sum_ {y ^ {\prime} \in \operatorname {S b} (y) \backslash Y} [ \quad \xi_ {\operatorname {l e v} (y)} - F (x, y) + F (x, y ^ {\prime}) ] _ {+}
$$
$$
J _ {\text {h i e r}} (x, Y) = \sum_ {y \in Y} \left(J _ {y ^ {\prime} > \bar {y}} + J _ {\bar {y} > y ^ {\prime}} + J _ {y ^ {\prime} > y ^ {\prime}}\right) \tag {9}
$$
4.4 Decoding
Predicting the types for each entity mention can be performed via iterative searching on the type tree, from the root ENTITY node to coarser types, then to finer-grained types. This ensures that our output does not violate the hierarchical property, i.e., if a subtype is output, its parent must be output.
Given instance  $x$  we compute the score  $F(x,y)$  for each type  $y\in \mathcal{V}$ , the searching process starts with the root node  $\text{ENTITY}$  of the type tree in the queue. For each type  $y$  in the node, a child node  $z <: y$  (subtypes) is added to the predicted type set if  $F(x,z) > F(x,y)$ , corresponding to the ranking relation in Equation 8 that the model has learned.
Here we only take the top-  $k$  element to add to the queue to prevent from over-generating types. This can also be used to enforce the single-path property (setting  $k = 1$ ) if the dataset is single-path. For each level  $i$  in the type hierarchy, we limit the branching factor (allowed children) to be  $k_{i}$ . The algorithm is listed in Algorithm 1, where the function  $\mathrm{TOPK}(S,k,f)$  selects the top-  $k$  elements from  $S$  with respect to the function  $f$ .
4.5 Subtyping Relation Constraint
Each type  $y \in \mathcal{V}$  in the ontology is assigned a type embedding  $\mathbf{y} \in \mathbb{R}^{d_t}$ . We notice the binary subtyping relation “ $\leq$ ”  $\subseteq$ $\mathcal{V} \times \mathcal{V}$  on the types. Trouillon et al. (2016) proposed the relation embedding method ComplEx that works well with anti-symmetric and transitive relations such as subtyping. It has been employed in FET before
For the OntoNotes dataset, we introduce another set of per-level hyperparameters  $\delta_{\mathrm{lev}(y)}$ , and the threshold value  $F(x,y)$  is modified to  $F(x,y) + \delta_{\mathrm{lev}(y)}$ , akin to the adaptive threshold in Zhang et al. (2018). This is due to a large type distribution mismatch between the training and dev/test sets in OntoNotes (in dev/test there are a lot of instances with the single type /other but not in the training set). For other datasets they are unused, i.e. just 0.
8469
— in Murty et al. (2018), ComplEx is added to the loss to regulate the type embeddings. ComplEx operates in the complex space — we use the natural isomorphism between real and complex spaces to map the type embedding into complex space (first half of the embedding vector as the real part, and the second half as the imaginary part):
$$
\phi : \mathbb {R} ^ {d _ {t}} \rightarrow \mathbb {C} ^ {d _ {t} / 2} \tag {10}
$$
$$
\mathbf {t} = \left[ \operatorname {R e} \phi (\mathbf {t}); \operatorname {I m} \phi (\mathbf {t}) \right] \tag {11}
$$
We learn a single relation embedding  $\mathbf{r} \in \mathbb{C}^{d_t / 2}$  for the subtyping relation. Given type  $y$  and  $z$ , the subtyping statement  $y \ll z$  is modeled using the following scoring function:
$$
r (y, z) = \operatorname {R e} \left(\mathbf {r} \cdot \left(\phi (\mathbf {y}) \odot \overline {{\phi (\mathbf {z})}}\right)\right) \tag {12}
$$
where  $\odot$  is element-wise product and  $\overline{x}$  is the complex conjugate of  $x$ . If  $y <: z$  then  $r(y, z) > 0$ ; and vice versa,  $r(y, z) < 0$  if  $y \not\leq: z$ .
Loss Given instance  $(x,Y)$ , for each positive type  $y\in Y$ , we learn the following relations:
$$
y <   : \bar {y}
$$
$$
y \not \vdash : y ^ {\prime}, \quad \forall y ^ {\prime} \in \operatorname {S b} (y)
$$
$$
y \neq : y ^ {\prime}, \quad \forall y ^ {\prime} \in \mathrm {S b} (\bar {y}) \tag {13}
$$
Translating these relation constraints as a binary classification problem ("is or is not a subtype") under a primal SVM, we get a hinge loss:
$$
\begin{array}{l} J _ {\text {r e l}} (x, Y) = \sum_ {y \in Y} \left([ 1 - r (y, \bar {y}) ] _ {+} \right. \\ \left. + \sum_ {y ^ {\prime} \in \mathrm {S b} (y) \cup \mathrm {S b} (\bar {y})} [ 1 + r (y, y ^ {\prime}) ] _ {+}\right). \tag {14} \\ \end{array}
$$
This is different from Murty et al. (2018), where a binary cross-entropy loss on randomly sampled  $(y, y')$  pairs is used. Our experiments showed that the loss in Equation 14 performs better than the cross-entropy version, due to the structure of the training pairs: we use siblings and siblings of parents as negative samples (these are types closer to the positive parent type), hence are training with more competitive negative samples.
4.6 Training and Validation
Our final loss is a combination of the hierarchical ranking loss and the subtyping relation constraint loss, with  $L_{2}$  regularization:
$$
J _ {\text {h i e r}} (x, Y) + \beta J _ {\text {r e l}} (x, Y) + \frac {\lambda}{2} \| \boldsymbol {\Theta} \| _ {2} ^ {2}. \tag {15}
$$
The AdamW optimizer (Loshchilov and Hutter, 2019) is used to train the model, as it is shown to be superior than the original Adam under  $L_{2}$  regularization. Hyperparameters  $\alpha$  (ratio of margin above/below threshold),  $\beta$  (weight of subtyping relation constraint), and  $\lambda$  ( $L_{2}$  regularization coefficient) are tuned.
At validation time, we tune the maximum branching factors for each level  $k_{1},\dots ,k_{L}$ . These parameters tune the trade-off between the precision and recall for each layer and prevents over-generation (as we observed in some cases). All hyperparameters are tuned so that models achieve maximum micro  $F_{1}$  scores (see subsection 5.4).
AIDA The AIDA Phase 1 practice dataset for hierarchical entity typing comprises of 297 documents from LDC2019E04 / LDC2019E07, and the evaluation dataset is from LDC2019E42 / LDC2019E77. We take only the English part of the data, and use the practice dataset as train/dev, and the evaluation dataset as test. The practice dataset comprises of 3 domains, labeled as R103, R105, and R107. Since the evaluation dataset is out-of-domain, we use the smallest domain R105 as dev, and the remaining R103 and R107 as train.