Per my reading, the top p picks the one with cumulative probability greater or equal to the top p value. so in this case, 0.38 will be chosen because it is greater than the top p value(0.38>0.3)

I also think it should be first two tokens - apple + banana. The top_p parameter sets the threshold on cumulative probability of tokens so that we can restrict tokens from being considered for next token prediction.

Top-k sampling refers to selecting the next token randomly from a specified number, k, of tokens with the highest probabilities.

Top-p sampling refers to selecting the next token randomly from the smallest set of tokens for which the cumulative probability exceeds (or is equal) a specified value, p. and that’s why 0.1 and 0.2 where selected