Returns an order in [minNgramOrder, maxNgramOrder] if valid; otherwise errors out.
Returns an order in [minNgramOrder, maxNgramOrder] if valid; otherwise errors out.
The packed layout (most significant to least): [4 control bits] [farthest word] .
The packed layout (most significant to least): [4 control bits] [farthest word] ... [curr word]. If can't fill all bits, we prefer to left-align.
Unpacks the pos
word out of the packed ngram of type NGramType.
Unpacks the pos
word out of the packed ngram of type NGramType. Position 0
indicates the farthest context (if unigram, the current word), and position
MAX_ORDER-1 represents the current word.
Useful for getting words at special positions (e.g. first two in context).
Packs up to 3 words (trigrams) into a single Long by bit packing.
Assumptions: (1) |Vocab| <= one million (20 bits per word). (2) Words get mapped into [0, |Vocab|). In particular, each word ID < 2**20.