class_docstr: This is an implementation of `NearestNeighbors` that uses the Annoy module. At a
  high level, Annoy finds nearest neighbors by constructing binary trees in which
  vectors reside at leaf nodes. Vectors near each other will tend to be in the same
  leaf node. See https://tinyurl.com/2p89sb2h and https://github.com/spotify/annoy
  for more details. Annoy has 1 key parameter: the number of trees to construct.
  Increasing the number of trees leads to more accurate results, but longer time to
  create the trees and memory usage. As mentioned in the `NearestNeighbors`
  documentation, for the use case of computing proponents / opponents, the nearest
  neighbors returned should be those with the largest dot product with the query
  vector. The term "vector" is used here because Annoy stores 1D vectors. However
  in our wrapper around Annoy, we will allow the stored tensors to be of a common
  but arbitrary shape *, and flatten them before storing in the Annoy data structure.
class_docstr_tok: ["This","is","an","implementation","of","`","NearestNeighbors","`","that","uses","the","Annoy","module",".","At","a","high","level",",","Annoy","finds","nearest","neighbors","by","constructing","binary","trees","in","which","vectors","reside","at","leaf","nodes",".","Vectors","near","each","other","will","tend","to","be","in","the","same","leaf","node",".","See","https",":","\/\/tinyurl.com\/2p89sb2h","and","https",":","\/\/github.com\/spotify\/annoy","for","more","details",".","Annoy","has","1","key","parameter",":","the","number","of","trees","to","construct",".","Increasing","the","number","of","trees","leads","to","more","accurate","results",",","but","longer","time","to","create","the","trees","and","memory","usage",".","As","mentioned","in","the","`","NearestNeighbors","`","documentation",",","for","the","use","case","of","computing","proponents","\/","opponents",",","the","nearest","neighbors","returned","should","be","those","with","the","largest","dot","product","with","the","query","vector",".","The","term","``","vector","''","is","used","here","because","Annoy","stores","1D","vectors",".","However","in","our","wrapper","around","Annoy",",","we","will","allow","the","stored","tensors","to","be","of","a","common","but","arbitrary","shape","*",",","and","flatten","them","before","storing","in","the","Annoy","data","structure","."]
docstr: Args:
      num_trees (int): The number of trees to use. Increasing this number gives
              more accurate computation of nearest neighbors, but requires longer
              setup time to create the trees, as well as memory.
docstr_tok: ["Args",":","num_trees","(","int",")",":","The","number","of","trees","to","use",".","Increasing","this","number","gives","more","accurate","computation","of","nearest","neighbors",",","but","requires","longer","setup","time","to","create","the","trees",",","as","well","as","memory","."]
code: def __init__(self, num_trees: int = 10) -> None:
      """
      Args:
          num_trees (int): The number of trees to use. Increasing this number gives
                  more accurate computation of nearest neighbors, but requires longer
                  setup time to create the trees, as well as memory.
      """
      try:
          import annoy  # noqa
      except ImportError:
          raise ValueError(
              (
                  "Using `AnnoyNearestNeighbors` requires installing the annoy "
                  "module. If pip is installed, this can be done with "
                  "`pip install --user annoy`."
              )
          )
  
      self.num_trees = num_trees
  
file_path: captum/captum/influence/_utils/nearest_neighbors.py
imports: from abc import ABC, abstractmethod
  from typing import Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 1 to create a new AnnoyNearestNeighbors object from inherited base classes: NearestNeighbors with example: obj = AnnoyNearestNeighbors(num_trees)