class_docstr: ## Sampler
  
  This class greedily samples from a model.
class_docstr_tok: ["#","#","Sampler","This","class","greedily","samples","from","a","model","."]
docstr: * `device` is the device of the model
  * `model` is the [Retro mode](retro.html)
  * `tds` is the text dataset (used to get neighbor chunks)
  * `chunk_len` is the length of a chunk
docstr_tok: ["*","`","device","`","is","the","device","of","the","model","*","`","model","`","is","the","[","Retro","mode","]","(","retro.html",")","*","`","tds","`","is","the","text","dataset","(","used","to","get","neighbor","chunks",")","*","`","chunk_len","`","is","the","length","of","a","chunk"]
code: def __init__(
      self,
      device: torch.device,
      model: retro.RetroModel,
      tds: TextFileDataset,
      chunk_len: int,
  ):
      """
      * `device` is the device of the model
      * `model` is the [Retro mode](retro.html)
      * `tds` is the text dataset (used to get neighbor chunks)
      * `chunk_len` is the length of a chunk
      """
      self.chunk_len = chunk_len
      self.tds = tds
      self.model = model
      self.device = device
  
      # [Retro index](database.html)
      self.index = RetroIndex()
  
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 1 to create a new Sampler object  with example: obj = Sampler(device, model, tds, chunk_len)