docstr: Save dictionary to file. Format is 'token<TAB>count' for every token in the
  dictionary, sorted by count with the most frequent words first.
  
  If ``append`` (default ``False``) is set to ``True``, appends instead
  of overwriting.
  
  If ``sort`` (default ``True``), then first sort the dictionary before
  saving.
code: def save(self, filename=None, append=False, sort=True):
      """
      Save dictionary to file. Format is 'token<TAB>count' for every token in the
      dictionary, sorted by count with the most frequent words first.
  
      If ``append`` (default ``False``) is set to ``True``, appends instead
      of overwriting.
  
      If ``sort`` (default ``True``), then first sort the dictionary before
      saving.
      """
      cw = sorted(
          [(count, w) for w, count in self.ansfreq.items()],
          reverse=True,
      )
      final_exs = cw[: self.opt.get("nans", 2000)]
      final_list = dict([(w, c) for c, w in final_exs])
      self.ansfreq = defaultdict(int)
      for ans, ques in self.ans2ques.items():
          if ans in final_list:
              for que in ques:
                  self.add_to_ques_dict(que)
              self.add_to_ans_dict(ans)
  
      filename = self.opt["dict_file"] if filename is None else filename
      print("Dictionary: saving dictionary to {}".format(filename))
      # if sort:
      #     self.sort()
  
      with PathManager.open(filename, "a" if append else "w") as write:
          for i in range(len(self.ind2tok)):
              tok = self.ind2tok[i]
              cnt = self.freq[tok]
              write.write(
                  "{tok}\t{cnt}\n".format(tok=escape(tok), cnt=cnt)
              )
  
      with PathManager.open(
          filename[:-5] + "_ans.dict", "a" if append else "w"
      ) as write:
          for i in range(len(self.ind2ans)):
              tok = self.ind2ans[i]
              cnt = self.ansfreq[tok]
              write.write(
                  "{tok}\t{cnt}\n".format(tok=escape(tok), cnt=cnt)
              )
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  import json
  import os
  import re
  import numpy
  from collections import Counter
  from parlai.core.agents import Agent
  from parlai.utils.io import PathManager
  from collections import defaultdict
  from parlai.core.teachers import FixedDialogTeacher
  from parlai.core.image_featurizers import ImageLoader
  from .build import build
  from parlai.tasks.coco_caption.build_2014 import buildImage
  from parlai.tasks.coco_caption.build_2015 import buildImage
label_desc: Use image node_id 13 for calling the VqaDictionaryAgent obj's underlying member method code with example usage: obj.save(filename, append, sort) without return types