Views
No views yet
| Version | Model Revision | Note |
|---|---|---|
| v1.0 (Random Negatives) | main or v1-random-negatives | The variant trained on random negatives, as detailed in the paper. |
| v1.0 (Hard Negatives) | v1-hard-negatives | The variant trained on hard negatives, as detailed in the paper. |
1from hierarchy_transformers import HierarchyTransformer
2
3# load the model
4model = HierarchyTransformer.from_pretrained('Hierarchy-Transformers/HiT-MiniLM-L12-WordNetNoun')
5
6# entity names to be encoded.
7entity_names = ["computer", "personal computer", "fruit", "berry"]
8
9# get the entity embeddings
10entity_embeddings = model.encode(entity_names)1# suppose we want to compare "personal computer" and "computer", "berry" and "fruit"
2child_entity_embeddings = model.encode(["personal computer", "berry"], convert_to_tensor=True)
3parent_entity_embeddings = model.encode(["computer", "fruit"], convert_to_tensor=True)
4
5# compute the hyperbolic distances and norms of entity embeddings
6dists = model.manifold.dist(child_entity_embeddings, parent_entity_embeddings)
7child_norms = model.manifold.dist0(child_entity_embeddings)
8parent_norms = model.manifold.dist0(parent_entity_embeddings)
9
10# use the empirical function for subsumption prediction proposed in the paper
11# `centri_score_weight` and the overall threshold are determined on the validation set
12subsumption_scores = - (dists + centri_score_weight * (parent_norms - child_norms))HierarchyTransformer(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
)@article{he2024language,
title={Language models as hierarchy encoders},
author={He, Yuan and Yuan, Moy and Chen, Jiaoyan and Horrocks, Ian},
journal={Advances in Neural Information Processing Systems},
volume={37},
pages={14690--14711},
year={2024}
}yuan.he(at)cs.ox.ac.uk).