sourcelibs/Sample/demos/next.xtl

1⍝!/usr/bin/env xetal 2⍝│ Choosing the next word from a model's scores over six words: the 3⍝│ greedy choice, the probabilities at three temperatures, top-2, and 4⍝│ twenty draws (r_oll!, seeded). Run with "just demo-lib Sample next". 5 6"sm:" u̲se< "Sample" 7 8⍝│ Scores for: cat dog fox bird the runs 9s ← 2.0 1.6 0.4 0.2 -1.0 -2.0 10ˢᵐg̲reedy 1 6 r̲eshape s 11ᵘr̲ound ← { a → (f̲loat f̲loor 0.5 + 100.0 × a) ÷ 100.0 } 12⍝│ Cooler is surer; hotter, more even. 13ᵘr̲ound 0.5 ˢᵐp̲robs s 14ᵘr̲ound 1.0 ˢᵐp̲robs s 15ᵘr̲ound 2.0 ˢᵐp̲robs s 16⍝│ Only the two likeliest, renormalized. 17ᵘr̲ound 2 ˢᵐt̲op 1.0 ˢᵐp̲robs s 18⍝│ Twenty draws at temperature 1 (the uniform numbers from r_oll!). 19u ← (f̲loat r̲oll! 20 r̲eshape 1000) ÷ 1000.0 20u ˢᵐd̲raw 20 6 r̲eshape 1.0 ˢᵐp̲robs s