src/baselines/results.py
def pivoted_to_longtex(df, bold=None, dest=None):
  """ Takes in a pivoted DF  and produces a LaTeX Table
        Each row should be a model and each column a Task.
    """
  dfl = df.copy(deep=True)

  header = r'\begin{tabular}{rl' + 'c' * (len(dfl.columns) + 2) + '}\n'
  header += r'\toprule' + '\n'
  # column headers
  dfl = dfl.reindex(sort_columns(dfl.index))

  # make and order tasks
  colmap = {c: c.capitalize() for c in dfl.columns}
  colmap['circumference'] = 'Circum.'
  dfl = dfl.rename(columns=colmap)
  #cols =

  dfl = dfl[[c for c in task_order if c in dfl.columns]]

  dfl['Average'] = dfl.mean(1)
  # print(dfl.head)
  # dfl = dfl[sort_columns(dfl.index)]
  # dfl = dfl.reindex(sort_columns(dfl.index))
  nice_rows = make_nice_rows(dfl.index)
  # print(nice_rows)
  # nice_cols = [i.capitalize()  for i in dfl.columns]

  ## Exlcluding unifiedqa
  dfl_no_uqa = dfl[~dfl.index.str.startswith('allenai-unifiedqa')]

  header += r'\multicolumn{2}{c}{Model} & ' + ' & '.join(
    dfl.columns) + r' \\' + '\n' + r'\midrule' + '\n'
  if bold == 'max':
    best_models_idxs = dfl_no_uqa.idxmax(0)
  elif bold == 'min':
    best_models_idxs = dfl_no_uqa.idxmin(0)
  else:
    best_models_idxs = defaultdict(lambda: None)

  # print(best_models_idxs)
  last_model = nice_rows[0].split('&')[0]
  # dfl = dfl.replace()

  ic(dfl)

  for ri, (i, row) in enumerate(dfl.iterrows()):
    #print(row)
    strrow = [('---' if np.isnan(r) else f'{r*100:.1f}') for r in row]
    for j, task in enumerate(row.index):
      if best_models_idxs[task] == i:
        strrow[j] = r'\textbf{' + strrow[j] + '}'

    if nice_rows[ri].split('&')[0] != last_model:
      header += r'\midrule' + '\n'
      last_model = nice_rows[ri].split('&')[0]
    elif ri == 0:
      pass
    else:
      nice_rows[ri] = '&' + nice_rows[ri].split('&')[1]
      #print(last_model, nice_rows[ri])

    # best per row is bold
    #print(row.argmin())
    #strrow[row.argmax()] = r'{\bf ' + strrow[row.argmax()] + '}'
    header += nice_rows[ri] + ' & ' + ' & '.join(strrow) + r' \\' + '\n'

    #print(i, row)
  header += r'\midrule' + '\n' + r'Task Avg. & & '
  # average over tasks
  # uf_task_avg = dfl.mean(0)
  task_avg = dfl[~dfl.index.str.startswith('allenai-unifiedqa')].mean(0)
  # ic(task_avg, uf_task_avg, dfl[~dfl.index.str.startswith('allenai-unifiedqa')])

  strrow = [('-' if np.isnan(r) else f'{r*100:.1f}') for r in task_avg]

  header += ' & '.join(strrow) + r' \\' + '\n'

  header += r'\bottomrule' + '\n' + r'\end{tabular}'
  if dest is not None:
    with open(dest, 'w') as f:
      f.write(header)

  return header
 Takes in a pivoted DF  and produces a LaTeX Table
        Each row should be a model and each column a Task.
    
Takes in a pivoted DF  and produces a LaTeX Table
Each row should be a model and each column a Task.
Takes in a pivoted DF and produces a LaTeX Table Each row should be a model and each column a Task .
def pivoted_to_longtex(df, bold=None, dest=None):
  dfl = df.copy(deep=True)
  header = r'\begin{tabular}{rl' + 'c' * (len(dfl.columns) + 2) + '}\n'
  header += r'\toprule' + '\n'
  dfl = dfl.reindex(sort_columns(dfl.index))
  colmap = {c: c.capitalize() for c in dfl.columns}
  colmap['circumference'] = 'Circum.'
  dfl = dfl.rename(columns=colmap)
  dfl = dfl[[c for c in task_order if c in dfl.columns]]
  dfl['Average'] = dfl.mean(1)
  nice_rows = make_nice_rows(dfl.index)
  dfl_no_uqa = dfl[~dfl.index.str.startswith('allenai-unifiedqa')]
  header += r'\multicolumn{2}{c}{Model} & ' + ' & '.join(
    dfl.columns) + r' \\' + '\n' + r'\midrule' + '\n'
  if bold == 'max':
    best_models_idxs = dfl_no_uqa.idxmax(0)
  elif bold == 'min':
    best_models_idxs = dfl_no_uqa.idxmin(0)
  else:
    best_models_idxs = defaultdict(lambda: None)
  last_model = nice_rows[0].split('&')[0]
  ic(dfl)
  for ri, (i, row) in enumerate(dfl.iterrows()):
    strrow = [('---' if np.isnan(r) else f'{r*100:.1f}') for r in row]
    for j, task in enumerate(row.index):
      if best_models_idxs[task] == i:
        strrow[j] = r'\textbf{' + strrow[j] + '}'
    if nice_rows[ri].split('&')[0] != last_model:
      header += r'\midrule' + '\n'
      last_model = nice_rows[ri].split('&')[0]
    elif ri == 0:
      pass
    else:
      nice_rows[ri] = '&' + nice_rows[ri].split('&')[1]
    header += nice_rows[ri] + ' & ' + ' & '.join(strrow) + r' \\' + '\n'
  header += r'\midrule' + '\n' + r'Task Avg. & & '
  task_avg = dfl[~dfl.index.str.startswith('allenai-unifiedqa')].mean(0)
  strrow = [('-' if np.isnan(r) else f'{r*100:.1f}') for r in task_avg]
  header += ' & '.join(strrow) + r' \\' + '\n'
  header += r'\bottomrule' + '\n' + r'\end{tabular}'
  if dest is not None:
    with open(dest, 'w') as f:
      f.write(header)
  return header
def pivoted_to_longtex ( df , bold = None , dest = None ) : dfl = df . copy ( deep = True ) header = r'\begin{tabular}{rl' + 'c' * ( len ( dfl . columns ) + 2 ) + '}\n' header += r'\toprule' + '\n' dfl = dfl . reindex ( sort_columns ( dfl . index ) ) colmap = { c : c . capitalize ( ) for c in dfl . columns } colmap [ 'circumference' ] = 'Circum.' dfl = dfl . rename ( columns = colmap ) dfl = dfl [ [ c for c in task_order if c in dfl . columns ] ] dfl [ 'Average' ] = dfl . mean ( 1 ) nice_rows = make_nice_rows ( dfl . index ) dfl_no_uqa = dfl [ ~ dfl . index . str . startswith ( 'allenai-unifiedqa' ) ] header += r'\multicolumn{2}{c}{Model} & ' + ' & ' . join ( dfl . columns ) + r' \\' + '\n' + r'\midrule' + '\n' if bold == 'max' : best_models_idxs = dfl_no_uqa . idxmax ( 0 ) elif bold == 'min' : best_models_idxs = dfl_no_uqa . idxmin ( 0 ) else : best_models_idxs = defaultdict ( lambda : None ) last_model = nice_rows [ 0 ] . split ( '&' ) [ 0 ] ic ( dfl ) for ri , ( i , row ) in enumerate ( dfl . iterrows ( ) ) : strrow = [ ( '---' if np . isnan ( r ) else f'{r*100:.1f}' ) for r in row ] for j , task in enumerate ( row . index ) : if best_models_idxs [ task ] == i : strrow [ j ] = r'\textbf{' + strrow [ j ] + '}' if nice_rows [ ri ] . split ( '&' ) [ 0 ] != last_model : header += r'\midrule' + '\n' last_model = nice_rows [ ri ] . split ( '&' ) [ 0 ] elif ri == 0 : pass else : nice_rows [ ri ] = '&' + nice_rows [ ri ] . split ( '&' ) [ 1 ] header += nice_rows [ ri ] + ' & ' + ' & ' . join ( strrow ) + r' \\' + '\n' header += r'\midrule' + '\n' + r'Task Avg. & & ' task_avg = dfl [ ~ dfl . index . str . startswith ( 'allenai-unifiedqa' ) ] . mean ( 0 ) strrow = [ ( '-' if np . isnan ( r ) else f'{r*100:.1f}' ) for r in task_avg ] header += ' & ' . join ( strrow ) + r' \\' + '\n' header += r'\bottomrule' + '\n' + r'\end{tabular}' if dest is not None : with open ( dest , 'w' ) as f : f . write ( header ) return header
Takes in a pivoted DF  and produces a LaTeX Table
Each row should be a model and each column a Task.
Takes in a pivoted DF and produces a LaTeX Table Each row should be a model and each column a Task .
""" Takes in a pivoted DF  and produces a LaTeX Table
        Each row should be a model and each column a Task.
    """ # column headers # make and order tasks #cols = # print(dfl.head) # dfl = dfl[sort_columns(dfl.index)] # dfl = dfl.reindex(sort_columns(dfl.index)) # print(nice_rows) # nice_cols = [i.capitalize()  for i in dfl.columns] ## Exlcluding unifiedqa # print(best_models_idxs) # dfl = dfl.replace() #print(row) #print(last_model, nice_rows[ri]) # best per row is bold #print(row.argmin()) #strrow[row.argmax()] = r'{\bf ' + strrow[row.argmax()] + '}' #print(i, row) # average over tasks # uf_task_avg = dfl.mean(0) # ic(task_avg, uf_task_avg, dfl[~dfl.index.str.startswith('allenai-unifiedqa')])
df
bold
dest