Token embedding based on target-context pairs includes obtaining a structural representation of data, the structural representation including nodes and indicating relationships between the nodes, obtaining a context template that identifies relationship(s) to use in identifying a respective context for different nodes of the structural representation, applying the context template to the structural representation to obtain a set of target-context pairs, each of which includes a respective target node of the structural representation and a respective set of context node(s), of the structural representation, for that target node, as identified based on the context template, and using the target-context pairs in a model and obtaining, as output of the model, representations of target nodes of the target-context pairs as vectors in a vector space.