Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)
OpenAssistant Conversations (oasst2)
Show me an implementation of nucleus sampling written in python
In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
- User
Show me an implementation of nucleus sampling written in python
- Assistant
Here is a basic implementation of nucleus sampling in Python:
import random def nucleus_sampling(input_text, p=0.9): input_words = input_text.split() prob = [p if random.random() < p else (1-p)/(len(input_words)-1) for word in input_words] filtered_words = [word for word, p in zip(input_words, prob) if random.random() < p] output_text = ' '.join(filtered_words) return output_text input_text = "This is an example of nucleus sampling." output_text = nucleus_sampling(input_text) print(output_text)In this implementation, the nucleus_sampling function takes an input text as input and applies nucleus sampling to it by assigning each word a probability of being kept. The probability of keeping a word is given by p, which is set to 0.9 by default. If a word is kept, its probability of being kept remains p, otherwise it becomes (1-p)/(len(input_words)-1). The words are then filtered based on their probabilities, and the filtered words are concatenated to form the output text.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.