emnlp 2023 commited on
Commit
69c7970
1 Parent(s): cbb670a

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +138 -0
README.md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
3
+ # Doc / guide: https://huggingface.co/docs/hub/model-cards
4
+ datasets:
5
+ - emnlp2023/Calc-gsm8k
6
+ - emnlp2023/Calc-aqua_rat
7
+ - emnlp2023/Calc-math_qa
8
+ - emnlp2023/Calc-ape210k
9
+ metrics:
10
+ - exact_match
11
+ - rouge
12
+ model-index:
13
+ - name: Calc-FLAN-t5-xl
14
+ results:
15
+ - task:
16
+ type: question-answering
17
+ name: Question Answering
18
+ dataset:
19
+ type: gsm8k
20
+ name: GSM8K
21
+ split: validation
22
+ metrics:
23
+ - type: exact_match
24
+ value: 0.495
25
+ - type: rouge
26
+ value: 0.655
27
+ license: apache-2.0
28
+ language:
29
+ - en
30
+ ---
31
+
32
+ # Model Card for Calc-FLAN-t5-xl
33
+
34
+ <!-- Provide a quick summary of what the model is/does. -->
35
+
36
+ This model generates reasoning chains over mathematical questions while **using an external tool: Sympy calculator**.
37
+
38
+ ## Model Details
39
+
40
+ ### Model Description
41
+
42
+ <!-- Provide a longer summary of what this model is. -->
43
+
44
+ With the idea to offload a symbolic reasoning from the stochastic language model,
45
+ we train this model to utilize a calculator **for all applicable numeric operations**.
46
+ This is achieved by training the model to construct calls to the tool's API in this format:
47
+
48
+ ```html
49
+ <gadget id="calculator">100/2</gadget> <output>50</output>
50
+ ```
51
+
52
+ where `<gadget>` segment triggers a call of the tool,
53
+ which is subsequently served by extending model's decoder input context by adding the output of the tool within the `<output>` segment.
54
+
55
+ - **Developed by:** Anonymous
56
+ - **Model type:** Autoregressive Encoder-Decoder
57
+ - **Language(s):** en
58
+ - **Finetuned from:** google/flan-t5-xl
59
+
60
+ ### Model Sources
61
+
62
+ <!-- Provide the basic links for the model. -->
63
+
64
+ - **Repository:** https://github.com/emnlp2023/gadgets
65
+ - **Paper:** Stay tuned!
66
+
67
+ ## Usage
68
+
69
+ Additionally to conventional generation, using Tool-augmented generation requires
70
+ (1) implementation of the tool(s) and
71
+ (2) a customization of generate() method augmenting input context on-demand with the outputs of the tools.
72
+
73
+ You can find these two components implemented in the attached **gadget_assisted_model.py** and **gadget.py** in this model's repo
74
+ and the project's [home repo](https://github.com/emnlp2023/gadgets).
75
+
76
+ After adding these two scripts to your directory, you can use the model as follows:
77
+
78
+ ```python
79
+ from gadget_assisted_model import GadgetAssistedModel
80
+ from gadget import Calculator
81
+
82
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
83
+
84
+
85
+ class GadgetAssistedT5(GadgetAssistedModel, T5ForConditionalGeneration):
86
+ # GadgetAssistedModel overrides the standard generate() from transformers
87
+ pass
88
+
89
+
90
+ model = GadgetAssistedT5.from_pretrained("emnlp2023/Calc-FLAN-t5-xl")
91
+ tokenizer = T5Tokenizer.from_pretrained("emnlp2023/Calc-FLAN-t5-xl")
92
+
93
+ model.prepare_for_generate(tokenizer,
94
+ enabled_gadgets=[Calculator()],
95
+ default_max_tokens=512)
96
+ query = """
97
+ The profit from a business transaction is shared among 2 business partners,
98
+ Mike and Johnson in the ratio 2:5 respectively.
99
+ If Johnson got $2500, how much will Mike have
100
+ after spending some of his share on a shirt that costs $200?
101
+ """
102
+
103
+ inputs = tokenizer(query, return_tensors="pt")
104
+ output_ids = model.generate(**inputs)
105
+ tokenizer.decode(output_ids[0], spaces_between_special_tokens=False)
106
+ ```
107
+ This returns:
108
+ ```html
109
+ According to the ratio, Mike got 2/5*$2500 = $<gadget id="calculator">2/5*2500</gadget><output>1_000</output> 1000
110
+ Mike will have $1000-$200 = $<gadget id="calculator">1000-200</gadget><output>800</output> 800 after buying a shirt.
111
+ Final result is<result>800</result></s>
112
+ ```
113
+
114
+ ### Out-of-Scope Usage
115
+
116
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
117
+
118
+ Note that given the limited scope of the exercises' complexity in the training, this model will not work well for tasks requiring
119
+ more complex algebraic operations, including equations, variables and operations outside the scope of (+-*/).
120
+
121
+ ## Training Details
122
+
123
+ ### Training Data
124
+
125
+ <!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
126
+
127
+ This model was trained on our [Calculator-augmented set of GSM8K, aqua_rat, math_qa, ape210k](https://huggingface.co/datasets/gsm8k,https://huggingface.co/datasets/aqua_rat,https://huggingface.co/datasets/math_qa,https://huggingface.co/datasets/ape210k),
128
+ in a standard auto-regressive setup i.e. for a conditional next-token prediction with teacher-forced prefix.
129
+
130
+ ### Training Procedure
131
+
132
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
133
+
134
+ The model was fine-tuned from [google/flan-t5-xl](https://huggingface.co/google/flan-t5-xl) for TODO steps
135
+ aiming to maximise exact-match ration on a validation split of the questions from [gsm8k dataset](https://huggingface.co/datasets/gsm8k).
136
+ We fine-tune only TODO of the parameters finding that this circumvents overfitting to relatively small training dataset.
137
+
138
+ The full training configuration can be identified from the [training script](https://github.com/emnlp2023/gadgets/blob/9185d1fc4b4812321179f8e5cad3e2f2a764f1df/examples/train_gsm8k_flan-t5-slice.py).