FastPrepAutoregressive Token Generation

Autoregressive Token Generation

Ambience Healthcare logoAmbience Healthcare● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

An autoregressive model starts with inputTokens. Its deterministic next-token calls are represented by predictedTokens in call order.

Append predictions until the sequence reaches maxTotalTokens, a generated token equals stopToken, or no supplied prediction remains. Include a generated stop token in the result.

Function

generateTokens(inputTokens: int[], predictedTokens: int[], maxTotalTokens: int, stopToken: int) → int[]

Examples

Example 1

inputTokens = [1,2]predictedTokens = [3,4,9,5]maxTotalTokens = 6stopToken = 9return = [1,2,3,4,9]

Generation includes the stop token and ends before token 5.

Example 2

inputTokens = [7]predictedTokens = [8,9,10]maxTotalTokens = 3stopToken = 99return = [7,8,9]

The maximum total length stops generation.

Example 3

inputTokens = [4,5]predictedTokens = []maxTotalTokens = 5stopToken = 0return = [4,5]

The supplied generator has no more predictions.

Constraints

  • 1 <= inputTokens.length <= maxTotalTokens <= 100000.
  • 0 <= predictedTokens.length <= 100000.
  • Tokens and stopToken are integers.

More Ambience Healthcare problems

See Ambience Healthcare hiring insights
public int[] generateTokens(int[] inputTokens, int[] predictedTokens, int maxTotalTokens, int stopToken) {
    // Append predictions until a stopping condition is met.
}
inputTokens[1,2]
predictedTokens[3,4,9,5]
maxTotalTokens6
stopToken9
expected[1,2,3,4,9]
Checking account…