find_bug_in_paper.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from evaluator import *
  2. DESCRIPTION = "Test if a model can find math errors in the latex source of a paper."
  3. TAGS = ['explain']
  4. question = r"""
  5. # Setup
  6. Which of the following equations are incorrect according to the specification?
  7. # Notation
  8. A neural network is a function $F(x) = y$ that accepts an input $x \in \mathbb{R}^n$
  9. and produces an output $y \in \mathbb{R}^m$.
  10. The model $F$ also implicitly depends on some model parameters $\theta$; in our work
  11. the model is fixed, so for convenience we don't show the dependence on $\theta$.
  12. In this paper we focus on neural networks used as an $m$-class classifier.
  13. The output of the network is computed using the softmax function,
  14. which ensures that the output vector $y$ satisfies
  15. $0 \le y_i \le 1$ and $y_1 + \dots + y_m = 1$.
  16. The output vector $y$ is thus treated as a probability distribution, i.e.,
  17. $y_i$ is treated as the probability that input $x$ has class $i$.
  18. The classifier assigns the label $C(x) = \arg\max_i F(x)_i$ to the input $x$.
  19. Let $C^*(x)$ be the correct label of $x$.
  20. The inputs to the softmax function are called \emph{logits}.
  21. We use the notation from Papernot et al. \cite{distillation}: define $F$ to
  22. be the full neural network including the softmax function, $Z(x) = z$ to be the output of
  23. all layers except the softmax (so $z$ are the logits), and
  24. \begin{equation*}
  25. F(x) = \softmax(Z(x)) = y.
  26. \end{equation*}
  27. A neural network typically \footnote{Most simple networks have this simple
  28. linear structure, however other more sophisticated networks have
  29. more complicated structures (e.g., ResNet \cite{he2016deep} and Inception \cite{szegedy2015rethinking}).
  30. The network architecture does not impact our attacks.}
  31. consists of layers
  32. \begin{equation*}
  33. F = \softmax \circ F_n \circ F_{n-1} \circ \cdots \circ F_1
  34. \end{equation*}
  35. where
  36. \begin{equation*}
  37. F_i(x) = \sigma(\theta_i \cdot x) + \hat\theta_i
  38. \end{equation*}
  39. for some non-linear activation function $\sigma$, some matrix $\theta_i$ of model
  40. weights, and some vector $\hat\theta_i$ of model biases. Together $\theta$ and
  41. $\hat\theta$ make up the model parameters.
  42. Common choices of $\sigma$
  43. are tanh \cite{mishkin2015all}, sigmoid, ReLU \cite{maas2013rectifier}, or ELU \cite{clevert2015fast}.
  44. In this paper we focus primarily on networks that use a ReLU activation function,
  45. as it currently is the most widely used
  46. activation function
  47. \cite{szegedy2015rethinking,springenberg2014striving,mishkin2015all,distillation}.
  48. # Specification:
  49. We define an objective function $f$ such that
  50. $C(x+\delta) = t$ if and only if $f(x+\delta) \le 0$.
  51. There are many possible choices for $f$:
  52. # The equations
  53. \begin{align*}
  54. f_{1}(x') &= -\loss_{F,t}(x') + 1\\
  55. f_{2}(x') &= (\max_{i \ne t}( F(x')_i) - F(x')_t)^+\\
  56. f_{3}(x') &= \text{softplus}(\max_{i \ne t}(F(x')_i) - F(x')_t)-\log(2)\\
  57. f_{4}(x') &= (0.5 - F(x')_t)^+\\
  58. f_{5}(x') &= -\log(2 F(x')_t - 2)\\
  59. f_{6}(x') &= (\max_{i \ne t}( Z(x')_i) - Z(x')_t)^+\\
  60. f_{7}(x') &= \text{softplus}(\max_{i \ne t}(Z(x')_i) - Z(x')_t)-\log(2)
  61. \end{align*}
  62. where $s$ is the correct classification, $(e)^+$ is short-hand for
  63. $\max(e,0)$, $\text{softplus}(x) = \log(1+\exp(x))$, and
  64. $\loss_{F,s}(x)$ is the cross entropy loss for $x$.
  65. # Your task
  66. Consider each equation one by one. End your answer with a python list of numbers [1,2,3,4,5,6,7] for those that are wrong.
  67. """
  68. question_easier = question + "\nSpecifically, make sure that $C(x+\delta) = t$ if and only if $f(x+\delta) \le 0$. Think step by step about if this is true for each equation and then give your answer as a python list"
  69. def check(x):
  70. ints = list(map(int,x.split("[")[-1].split("]")[0].split(",")))
  71. return ints == [1,3,4,5,7], ""
  72. TestFindBugPaper = question >> LLMRun() >> Echo() >> PyFunc(check)
  73. TestFindBugPaperEasy = question_easier >> LLMRun() >> Echo() >> PyFunc(check)
  74. if __name__ == "__main__":
  75. print(run_test(TestFindBugPaper))