File: hsm.proto

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (62 lines) | stat: -rw-r--r-- 2,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
syntax = "proto2";

package caffe2;

// Hierarchical Softmax protobuffer convention:
// The HSM operator requires a hierarchy of vocabulary words in the form of a
// tree from the user. This tree is expressed using the proto format.
// TreeProto points to the root NodeProto which can recursively contain children
// NodeProtos (internal nodes) or word_ids (leaf nodes).

// The aforementioned TreeProto is internally translated into a list of word_ids
// tagged with a list of NodeProtos that lie in the path from the root to that
// word_id using hsm_util.create_hierarchy(tree_proto).
// Specifically, HierarchyProto contains a list of PathProtos. Each PathProto
// belongs to a word_id and contains a list of PathNodeProtos. Each
// PathNodeProto contains information about the number of children the node has
// (length), the index of the child node that lies in the path from root to
// word_id (target) and a cumulative sum of children nodes (index; this acts as
// the weight parameter matrix offset).

// Each node in the hierarchy contains links to either leaf nodes or more
// non-terminal nodes
message NodeProto {
  // Links to non-terminal children nodes
  repeated NodeProto children = 1;
  // Links to terminal (leaf) nodes
  repeated int32 word_ids = 2;
  optional int32 offset = 3;
  optional string name = 4;
  repeated float scores = 5;
}

// Protobuf format to accept hierarchy for hierarchical softmax operator.
// TreeProto points to the root node.
message TreeProto {
  optional NodeProto root_node = 1;
}

// Internal Protobuf format which represents the path in the tree hierarchy for
// each word in the vocabulary.
message HierarchyProto {
  optional int32 size = 1;
  repeated PathProto paths = 2;
}

// Each PathProto belongs to a word and is an array of nodes in the
// path from the root to the leaf (which is the word itself) in the tree.
message PathProto {
  optional int32 word_id = 1;
  repeated PathNodeProto path_nodes = 2;
}

// Represents a node in the path from the root node all the way down to the
// word (leaf).
message PathNodeProto {
  // Parameter matrix offset for this node
  optional int32 index = 1;
  // Number of children
  optional int32 length = 2;
  // Index of the next node in the path
  optional int32 target = 3;
}