code: def test_top_p_search(self):
      initial_predictions = torch.tensor([0] * 5)
      beam_size = 3
      take_step = take_step_with_timestep
      p_sampler = TopPSampler(p=0.8)
  
      top_p, log_probs = BeamSearch(
          self.end_index,
          beam_size=beam_size,
          max_steps=10,
          sampler=p_sampler,
      ).search(initial_predictions, {}, take_step)
  
      beam_size = beam_size or 1
      batch_size = 5
  
      # top_p should be shape `(batch_size, beam_size, max_predicted_length)`.
      assert list(top_p.size())[:-1] == [batch_size, beam_size]
  
      assert ((0 <= top_p) & (top_p <= 5)).all()
  
      # log_probs should be shape `(batch_size, beam_size, max_predicted_length)`.
      assert list(log_probs.size()) == [batch_size, beam_size]
  
imports: from typing import Dict, Tuple, Union
  import numpy
  import pytest
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn.beam_search import MultinomialSampler, BeamSearch, TopKSampler, TopPSampler, GumbelSampler, LengthNormalizedSequenceLogProbabilityScorer, RepeatedNGramBlockingConstraint, StepFunctionTypeWithTimestep, StepFunctionTypeNoTimestep
  from allennlp.common.params import Params
  from allennlp.nn.util import min_value_of_dtype
label_desc: Use image node_id 17 for calling the BeamSearchTest obj's underlying member method code with example usage: obj.test_top_p_search() without return types