class_docstr: ## Sampler
  
  This class greedily samples from a model.
class_docstr_tok: ["#","#","Sampler","This","class","greedily","samples","from","a","model","."]
docstr: ### Retrieve nearest neighbors of a given chunk
docstr_tok: ["#","#","#","Retrieve","nearest","neighbors","of","a","given","chunk"]
code: def retrieve_nearest_neighbours(self, chunk: str):
      """
      ### Retrieve nearest neighbors of a given chunk
      """
  
      # Retrieve the offsets of the nearest neighbors
      neighbor_offsets = self.index([chunk], None)
  
      # Get the neighbors (with neighbor length equal to `chunk_len * 2`)
      text = self.tds.train
      neighbors = [
          text[j : j + self.chunk_len * 2] for j in neighbor_offsets[0]
      ]
  
      #
      return neighbors
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/train.py
imports: import torch
  from torch import nn
  from torch.utils.data import DataLoader, RandomSampler
  from labml import monit, lab, tracker, experiment, logger
  from labml.logger import Text
  from labml_helpers.datasets.text import TextFileDataset
  from labml_nn.optimizers.noam import Noam
  from labml_nn.transformers.retro import model
  from labml_nn.transformers.retro.dataset import Dataset, RetroIndex
  from labml_nn.transformers.retro.model import RetroModel, NearestNeighborEncoder
label_desc: Use image node_id 2 for calling the Sampler obj's underlying member method code with example usage: obj.retrieve_nearest_neighbours(chunk) and returns: neighbors