Show me an implementation of nucleus sampling written in python
Here is a basic implementation of nucleus sampling in Python:

```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.