├── LICENSE ├── README.md ├── data ├── GraphConstruction │ ├── constituency.py │ └── file_for_parsing.pkl └── TextData │ ├── all.txt │ ├── test.txt │ ├── train.txt │ ├── valid.txt │ ├── vocab.f.txt │ └── vocab.q.txt ├── pics ├── graph2tree.png └── pic1.png ├── src ├── __init__.py ├── data_utils.py ├── graph2tree.py ├── graph_encoder.py ├── graph_utils.py ├── nn_modules.py ├── pretrained_embedding.py ├── sample_test.py ├── sample_valid.py └── tree.py ├── test.sh └── train.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2020] [Shucheng Li and Lingfei Wu] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Graph2Tree 2 | 3 | Graph2Tree aims to automatically learn the mapping between structured input like graphs and output like trees. 4 | This example code is for our EMNLP'20 paper "Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem". You can access our paper via this link: https://arxiv.org/abs/2004.13781. 5 | 6 | This model can effectively solve two problems: Semantic Parsing (SP) and Math Word Problem automatically solving (MWP). Actually, they both deal with the translation problem from original word sequence inputs (which can be augmented to be a syntactic graph) to tree outputs (the logic forms in SP and mathmatical expression in MWP are both hierarchical). 7 | 8 | When we employ our general Graph2Tree model in these two problems, by encoding both word order features and auxiliary structure features in our graph encoder, and decode the hierarchical outputs in a tree decoder, our Graph2Tree model achieve higher performance than baselines. 9 | 10 | In this repo, we evaluate this model in **Math Word Problem (MWP)** auto-solving. 11 | 12 | ## An Overview to Graph2Tree 13 | 14 | 15 | 16 | 17 | ## Simple Introduction for MWP 18 | Math Word Problem (MWP) solver aims to automatically generate equations according to natural language problem descriptions. We evaluated our Graph2Tree model in MWP benchmark dataset [MAWPS](https://www.aclweb.org/anthology/N16-1136). A plain sample is shown below. 19 | 20 | | Problem Description | Output Equation | 21 | |-|-| 22 | | 0.5 of the cows are grazing grass . 0.75 of the remaining are sleeping and 9 cows are drinking water from the pond . find the total number of cows . | ( ( 0.5 * x ) + ( 0.75 * ( 0.5 * x ) ) ) + 9.0 = x | 23 | 24 | 25 | As shown in the picture below, to apply our Graph2Tree model. We firstly construct graph input from problem description by syntactic parsing (CoreNLP) and then represent the output equation with a hierarchical structure. 26 | 27 | 28 | 29 | ## GetStarted 30 | 31 | - Intall required python packages 32 | 33 | > pytorch==1.0.0 34 | > numpy==1.15.4 35 | > networkx==2.2 36 | > tqdm==4.28.1 37 | 38 | - Download [GloVe](http://nlp.stanford.edu/data/glove.6B.zip). For this task, We use the "glove.6B.300d.txt" pretrained embedding. 39 | 40 | - To save your time, we have completed parsing with Stanford CoreNLP for you, and parsing results can be read from ``data/GraphConstruction/file_for_parsing.pkl`` 41 | 42 | ## Data 43 | 44 | Our graph data are organized in a dictionary form where meaning of different key-value mappings are as follows: 45 | 46 | - *g_ids*: a mapping from the node ID to its ID in the graph 47 | - *g_id_features*: a mapping from the node ID to its text features 48 | - *g_adj*: a mapping from the node ID to its adjacent nodes (represented as thier IDs) 49 | 50 | 51 | ## Train 52 | > sh train.sh 53 | 54 | ## Test 55 | > sh test.sh 56 | 57 | ## Environment: 58 | 59 | * OS:Ubuntu 16.04.4 LTS 60 | * Gcc version: 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 61 | * GPU: TITAN Xp 62 | * CUDA: 8.0 63 | 64 | ## Reference 65 | 66 | If you found this repo useful, please consider citing our paper: 67 | 68 | Shucheng Li, Lingfei Wu, Shiwei Feng, Fangli Xu, Fengyuan Xu and Sheng Zhong, **"Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem."** In *Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing.* 69 | 70 | @article{li2020graph, 71 | title={Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem}, 72 | author={Li, Shucheng and Wu, Lingfei and Feng, Shiwei and Xu, Fangli and Xu, Fengyuan and Zhong, Sheng}, 73 | journal={EMNLP}, 74 | year={2020} 75 | } 76 | -------------------------------------------------------------------------------- /data/GraphConstruction/constituency.py: -------------------------------------------------------------------------------- 1 | 2 | from sys import path 3 | path.append(r'../../src') 4 | 5 | import time 6 | import os 7 | import torch 8 | import json 9 | import tqdm 10 | import copy 11 | import random 12 | import numpy as np 13 | import argparse 14 | import pickle as pkl 15 | import networkx as nx 16 | import networkx.algorithms as nxalg 17 | 18 | from pycorenlp import StanfordCoreNLP 19 | from data_utils import SymbolsManager 20 | from data_utils import convert_to_tree 21 | from collections import OrderedDict 22 | from pythonds.basic.stack import Stack 23 | 24 | 25 | 26 | ## Some options about constituency tree construction : 27 | # * whether cut root node 28 | # * whether cut line/pos node 29 | # * whether link word nodes 30 | # * whether split sentence 31 | 32 | 33 | _cut_root_node = True 34 | _cut_line_node = True 35 | _cut_pos_node = False 36 | _link_word_nodes = False 37 | _split_sentence = False 38 | 39 | source_data_dir = "../TextData/" 40 | output_data_dir = "../GraphConstruction/" 41 | batch_size = 30 42 | min_freq = 2 43 | max_vocab_size = 15000 44 | seed = 123 45 | 46 | random.seed(seed) 47 | np.random.seed(seed) 48 | torch.manual_seed(seed) 49 | 50 | 51 | class InputPreprocessor(object): 52 | def __init__(self, url = 'http://localhost:9000'): 53 | self.nlp = StanfordCoreNLP(url) 54 | 55 | def featureExtract(self,src_text,whiteSpace=True): 56 | if src_text.strip() in preparsed_file.keys(): 57 | return preparsed_file[src_text.strip()] 58 | print("miss!") 59 | data = {} 60 | output = self.nlp.annotate(src_text.strip(), properties={ 61 | 'annotators': "tokenize,ssplit,pos,parse", 62 | "tokenize.options":"splitHyphenated=true,normalizeParentheses=false", 63 | "tokenize.whitespace": whiteSpace, 64 | 'ssplit.isOneSentence': True, 65 | 'outputFormat': 'json' 66 | }) 67 | 68 | snt = output['sentences'][0]["tokens"] 69 | depency = output['sentences'][0]["basicDependencies"] 70 | data["tok"] = [] 71 | data["pos"] = [] 72 | data["dep"] = [] 73 | data["governor"] = [] 74 | data["dependent"] = [] 75 | data['parse'] = output['sentences'][0]['parse'] 76 | for snt_tok in snt: 77 | data["tok"].append(snt_tok['word']) 78 | data["pos"].append(snt_tok['pos']) 79 | for deps in depency: 80 | data["dep"].append(deps['dep']) 81 | data["governor"].append(deps['governor']) 82 | data["dependent"].append(deps['dependent']) 83 | return data 84 | 85 | import os 86 | 87 | def get_preparsed_file(): 88 | if not os.path.exists("./file_for_parsing.pkl"): 89 | file_for_parsing = {} 90 | processor_tmp = InputPreprocessor() 91 | 92 | with open(source_data_dir+"all.txt", "r") as f: 93 | lines = f.readlines() 94 | for l in tqdm.tqdm(lines): 95 | str_ = l.strip().split('\t')[0] 96 | file_for_parsing[str_] = processor_tmp.featureExtract(str_) 97 | 98 | pkl.dump(file_for_parsing, open("./file_for_parsing.pkl", "wb")) 99 | else: 100 | preparsed_file = pkl.load(open("./file_for_parsing.pkl", "rb")) 101 | return preparsed_file 102 | 103 | preparsed_file = get_preparsed_file() 104 | 105 | class Node(): 106 | def __init__(self, word, type_, id_): 107 | # word: this node's text 108 | self.word = word 109 | 110 | # type: 0 for word nodes, 1 for constituency nodes, 2 for dependency nodes(if they exists) 111 | self.type = type_ 112 | 113 | # id: unique identifier for every node 114 | self.id = id_ 115 | 116 | self.head = False 117 | 118 | self.tail = False 119 | 120 | def __str__(self): 121 | return self.word 122 | 123 | 124 | def split_str(string): 125 | if " . " not in string: 126 | return [string] 127 | else: 128 | s_arr = string.split(" . ") 129 | res = [] 130 | for s in s_arr: 131 | if s[-1] != "." and s != s_arr[-1]: 132 | s = s+" ." 133 | res.append(s) 134 | return res 135 | 136 | def cut_root_node(con_string): 137 | tmp = con_string 138 | if con_string[0] == '(' and con_string[-1] == ')': 139 | tmp = con_string[1:-1].replace("ROOT", "") 140 | if tmp[0] == '\n': 141 | tmp = tmp[1:] 142 | return tmp 143 | 144 | def cut_pos_node(g): 145 | node_arr = list(g.nodes()) 146 | del_arr = [] 147 | for n in node_arr: 148 | edge_arr = list(g.edges()) 149 | cnt_in = 0 150 | cnt_out = 0 151 | for e in edge_arr: 152 | if n.id == e[0].id: 153 | cnt_out += 1 154 | out_ = e[1] 155 | if n.id == e[1].id: 156 | cnt_in += 1 157 | in_ = e[0] 158 | if cnt_in == 1 and cnt_out == 1 and out_.type == 0: 159 | del_arr.append((n, in_, out_)) 160 | for d in del_arr: 161 | g.remove_node(d[0]) 162 | g.add_edge(d[1], d[2]) 163 | return g 164 | 165 | def cut_line_node(g): 166 | node_arr = list(g.nodes()) 167 | 168 | for n in node_arr: 169 | edge_arr = list(g.edges()) 170 | cnt_in = 0 171 | cnt_out = 0 172 | for e in edge_arr: 173 | if n.id == e[0].id: 174 | cnt_out += 1 175 | out_ = e[1] 176 | if n.id == e[1].id: 177 | cnt_in += 1 178 | in_ = e[0] 179 | if cnt_in == 1 and cnt_out == 1: 180 | g.remove_node(n) 181 | # print "remove", n 182 | g.add_edge(in_, out_) 183 | # print "add_edge", in_, out_ 184 | return g 185 | 186 | 187 | def get_seq_nodes(g): 188 | res = [] 189 | node_arr = list(g.nodes()) 190 | for n in node_arr: 191 | if n.type == 0: 192 | res.append(copy.deepcopy(n)) 193 | return sorted(res, key=lambda x:x.id) 194 | 195 | def get_non_seq_nodes(g): 196 | res = [] 197 | node_arr = list(g.nodes()) 198 | for n in node_arr: 199 | if n.type != 0: 200 | res.append(copy.deepcopy(n)) 201 | return sorted(res, key=lambda x:x.id) 202 | 203 | def get_all_text(g): 204 | seq_arr = get_seq_nodes(g) 205 | nonseq_arr = get_non_seq_nodes(g) 206 | seq = [x.word for x in seq_arr] 207 | nonseq = [x.word for x in nonseq_arr] 208 | return seq + nonseq 209 | 210 | def get_all_id(g): 211 | seq_arr = get_seq_nodes(g) 212 | nonseq_arr = get_non_seq_nodes(g) 213 | seq = [x.id for x in seq_arr] 214 | nonseq = [x.id for x in nonseq_arr] 215 | return seq + nonseq 216 | 217 | def get_id2word(g): 218 | res = {} 219 | seq_arr = get_seq_nodes(g) 220 | nonseq_arr = get_non_seq_nodes(g) 221 | for x in seq_arr: 222 | res[x.id] = x.word 223 | for x in nonseq_arr: 224 | res[x.id] = x.word 225 | return res 226 | 227 | def nodes_to_string(l): 228 | return " ".join([x.word for x in l]) 229 | 230 | def print_edges(g): 231 | edge_arr = list(g.edges()) 232 | for e in edge_arr: 233 | print (e[0].word, e[1].word),(e[0].id, e[1].id) 234 | 235 | def print_nodes(g, he_ta = False): 236 | nodes_arr = list(g.nodes()) 237 | if he_ta: 238 | print [(n.word, n.id, n.head, n.tail) for n in nodes_arr] 239 | else: 240 | print [(n.word, n.id) for n in nodes_arr] 241 | 242 | def graph_connect(a_, b_): 243 | a = copy.deepcopy(a_) 244 | b = copy.deepcopy(b_) 245 | max_id = 0 246 | for n in a.nodes(): 247 | if n.id > max_id: 248 | max_id = n.id 249 | tmp = copy.deepcopy(b) 250 | for n in tmp.nodes(): 251 | n.id += max_id 252 | 253 | res = nx.union(a, tmp) 254 | seq_nodes_arr = [] 255 | for n in res.nodes(): 256 | if n.type == 0: 257 | seq_nodes_arr.append(n) 258 | seq_nodes_arr.sort(key=lambda x:x.id) 259 | for idx in range(len(seq_nodes_arr)): 260 | if idx != len(seq_nodes_arr) - 1 and seq_nodes_arr[idx].tail == True: 261 | if seq_nodes_arr[idx + 1].head == True: 262 | res.add_edge(seq_nodes_arr[idx], seq_nodes_arr[idx + 1]) 263 | res.add_edge(seq_nodes_arr[idx + 1], seq_nodes_arr[idx]) 264 | return res 265 | 266 | def get_vocab(g): 267 | a = set() 268 | for n in list(g.nodes()): 269 | a.add(n.word) 270 | return a 271 | 272 | def get_adj(g): 273 | #reverse the direction 274 | adj_dict = {} 275 | for node, n_dict in g.adjacency(): 276 | adj_dict[node.id] = [] 277 | 278 | for node, n_dict in g.adjacency(): 279 | for i in n_dict.items(): 280 | adj_dict[i[0].id].append(node.id) 281 | return adj_dict 282 | 283 | def get_constituency_graph(input_tmp): 284 | tmp_result = input_tmp 285 | 286 | if _cut_root_node: 287 | parse_str = cut_root_node(str(tmp_result['parse'])) 288 | else: 289 | parse_str = str(tmp_result['parse']) 290 | for punc in ['(',')']: 291 | parse_str = parse_str.replace(punc,' ' + punc + ' ') 292 | parse_list = str(parse_str).split() 293 | 294 | res_graph = nx.DiGraph() 295 | pstack = Stack() 296 | idx = 0 297 | while idx < len(parse_list): 298 | if parse_list[idx] == '(': 299 | new_node = Node(word=parse_list[idx+1], id_=idx+1, type_=1) 300 | res_graph.add_node(new_node) 301 | pstack.push(new_node) 302 | 303 | if pstack.size() > 1: 304 | node_2 = pstack.pop() 305 | node_1 = pstack.pop() 306 | res_graph.add_edge(node_1, node_2) 307 | pstack.push(node_1) 308 | pstack.push(node_2) 309 | elif parse_list[idx] == ')': 310 | pstack.pop() 311 | elif parse_list[idx] in tmp_result['tok']: 312 | new_node = Node(word=parse_list[idx], id_=idx, type_=0) 313 | node_1 = pstack.pop() 314 | if node_1.id != new_node.id: 315 | res_graph.add_edge(node_1, new_node) 316 | pstack.push(node_1) 317 | idx += 1 318 | 319 | max_id = 0 320 | for n in res_graph.nodes(): 321 | if n.type == 0 and n.id > max_id: 322 | max_id = n.id 323 | 324 | min_id = 99999 325 | for n in res_graph.nodes(): 326 | if n.type == 0 and n.id < min_id: 327 | min_id = n.id 328 | 329 | for n in res_graph.nodes(): 330 | if n.type == 0 and n.id == max_id: 331 | n.tail = True 332 | if n.type == 0 and n.id == min_id: 333 | n.head = True 334 | return res_graph 335 | 336 | 337 | 338 | def generate_batch_graph(output_file, string_batch): 339 | 340 | # generate constituency graph 341 | graph_list = [] 342 | processor = InputPreprocessor() 343 | max_node_size = 0 344 | for s in string_batch: 345 | 346 | # generate multiple graph 347 | if _split_sentence: 348 | s_arr = split_str(s) 349 | 350 | g = cut_line_node(get_constituency_graph(processor.featureExtract(s_arr[0]))) 351 | for sub_s in s_arr: 352 | if sub_s != s_arr[0]: 353 | tmp = cut_line_node(get_constituency_graph(processor.featureExtract(sub_s))) 354 | g = graph_connect(g, tmp) 355 | 356 | # decide how to cut nodes 357 | if _cut_pos_node: 358 | g = cut_pos_node(get_constituency_graph(processor.featureExtract(s))) 359 | elif _cut_line_node: 360 | g = cut_line_node(get_constituency_graph(processor.featureExtract(s))) 361 | else: 362 | g = (get_constituency_graph(processor.featureExtract(s))) 363 | 364 | if len(list(g.nodes())) > max_node_size: 365 | max_node_size = len(list(g.nodes())) 366 | graph_list.append(g) 367 | 368 | info_list = [] 369 | batch_size = len(string_batch) 370 | for index in range(batch_size): 371 | word_list = get_all_text(graph_list[index]) 372 | word_len = len(get_seq_nodes(graph_list[index])) 373 | id_arr = get_all_id(graph_list[index]) 374 | adj_dic = get_adj(graph_list[index]) 375 | new_dic = {} 376 | 377 | # transform id to position in wordlist 378 | for k in adj_dic.keys(): 379 | new_dic[id_arr.index(k)] = [id_arr.index(x) for x in adj_dic[k]] 380 | 381 | info = {} 382 | 383 | g_ids = {} 384 | g_ids_features = {} 385 | g_adj = {} 386 | 387 | for idx in range(max_node_size): 388 | g_ids[idx] = idx 389 | if idx < len(word_list): 390 | g_ids_features[idx] = word_list[idx] 391 | 392 | if _link_word_nodes: 393 | if idx <= word_len - 1: 394 | if idx == 0: 395 | new_dic[idx].append(idx + 1) 396 | elif idx == word_len - 1: 397 | new_dic[idx].append(idx - 1) 398 | else: 399 | new_dic[idx].append(idx - 1) 400 | new_dic[idx].append(idx + 1) 401 | 402 | g_adj[idx] = new_dic[idx] 403 | else: 404 | g_ids_features[idx] = '

' 405 | g_adj[idx] = [] 406 | 407 | info['g_ids'] = g_ids 408 | info['g_ids_features'] = g_ids_features 409 | info['g_adj'] = g_adj 410 | 411 | info_list.append(info) 412 | 413 | with open(output_file, "a+") as f: 414 | for idx in range(len(info_list)): 415 | f.write(json.dumps(info_list[idx]) + '\n') 416 | 417 | batch_vocab = [] 418 | for x in graph_list: 419 | non_arr = nodes_to_string(get_non_seq_nodes(x)).split() 420 | for w in non_arr: 421 | if w not in batch_vocab: 422 | batch_vocab.append(w) 423 | return batch_vocab 424 | 425 | 426 | def train_data_preprocess(): 427 | time_start = time.time() 428 | word_manager = SymbolsManager(True) 429 | word_manager.init_from_file("{}/vocab.q.txt".format(source_data_dir), min_freq, max_vocab_size) 430 | form_manager = SymbolsManager(True) 431 | form_manager.init_from_file("{}/vocab.f.txt".format(source_data_dir), 0, max_vocab_size) 432 | print(word_manager.vocab_size) 433 | print(form_manager.vocab_size) 434 | 435 | data = [] 436 | with open("{}/{}.txt".format(source_data_dir, "train"), "r") as f: 437 | for line in f: 438 | l_list = line.split("\t") 439 | w_list = l_list[0].strip().split(' ') 440 | r_list = form_manager.get_symbol_idx_for_list(l_list[1].strip().split(' ')) 441 | cur_tree = convert_to_tree(r_list, 0, len(r_list), form_manager) 442 | 443 | data.append((w_list, r_list, cur_tree)) 444 | 445 | out_graphfile = "{}/graph.train".format(output_data_dir) 446 | if os.path.exists(out_graphfile): 447 | os.remove(out_graphfile) 448 | # generate batch graph here 449 | if len(data) % batch_size != 0: 450 | n = len(data) 451 | for i in range(batch_size - len(data)%batch_size): 452 | data.insert(n-i-1, copy.deepcopy(data[n-i-1])) 453 | 454 | index = 0 455 | while index + batch_size <= len(data): 456 | # generate graphs with order and dependency information 457 | input_batch = [" ".join(data[index + idx][0]) for idx in range(batch_size)] 458 | new_vocab = generate_batch_graph(output_file=out_graphfile, string_batch=input_batch) 459 | for w in new_vocab: 460 | if w not in word_manager.symbol2idx: 461 | word_manager.add_symbol(w) 462 | print "{} Added.".format(w) 463 | index += batch_size 464 | print index 465 | 466 | out_datafile = "{}/train.pkl".format(output_data_dir) 467 | with open(out_datafile, "wb") as out_data: 468 | pkl.dump(data, out_data) 469 | 470 | out_mapfile = "{}/map.pkl".format(output_data_dir) 471 | with open(out_mapfile, "wb") as out_map: 472 | pkl.dump([word_manager, form_manager], out_map) 473 | 474 | print(word_manager.vocab_size) 475 | print(form_manager.vocab_size) 476 | 477 | time_end = time.time() 478 | print "time used:" + str(time_end - time_start) 479 | 480 | def test_data_preprocess(): 481 | data = [] 482 | managers = pkl.load( open("{}/map.pkl".format(output_data_dir), "rb" ) ) 483 | word_manager, form_manager = managers 484 | with open("{}/{}.txt".format(source_data_dir, "test"), "r") as f: 485 | for line in f: 486 | l_list = line.split("\t") 487 | w_list = l_list[0].strip().split(' ') 488 | r_list = form_manager.get_symbol_idx_for_list(l_list[1].strip().split(' ')) 489 | cur_tree = convert_to_tree(r_list, 0, len(r_list), form_manager) 490 | data.append((w_list, r_list, cur_tree)) 491 | out_datafile = "{}/test.pkl".format(output_data_dir) 492 | with open(out_datafile, "wb") as out_data: 493 | pkl.dump(data, out_data) 494 | 495 | out_graphfile = "{}/graph.test".format(output_data_dir) 496 | if os.path.exists(out_graphfile): 497 | os.remove(out_graphfile) 498 | 499 | index = 0 500 | while index + batch_size <= len(data): 501 | # generate graphs with order and dependency information 502 | input_batch = [" ".join(data[index + idx][0]) for idx in range(batch_size)] 503 | new_vocab = generate_batch_graph(output_file=out_graphfile, string_batch=input_batch) 504 | index += batch_size 505 | 506 | if index != len(data): 507 | input_batch = [" ".join(data[idx][0]) for idx in range(index,len(data))] 508 | new_vocab = generate_batch_graph(output_file=out_graphfile, string_batch=input_batch) 509 | 510 | 511 | def valid_data_preprocess(): 512 | data = [] 513 | managers = pkl.load( open("{}/map.pkl".format(output_data_dir), "rb" ) ) 514 | word_manager, form_manager = managers 515 | with open("{}/{}.txt".format(source_data_dir, "valid"), "r") as f: 516 | for line in f: 517 | l_list = line.split("\t") 518 | w_list = l_list[0].strip().split(' ') 519 | r_list = form_manager.get_symbol_idx_for_list(l_list[1].strip().split(' ')) 520 | cur_tree = convert_to_tree(r_list, 0, len(r_list), form_manager) 521 | data.append((w_list, r_list, cur_tree)) 522 | out_datafile = "{}/valid.pkl".format(output_data_dir) 523 | with open(out_datafile, "wb") as out_data: 524 | pkl.dump(data, out_data) 525 | 526 | out_graphfile = "{}/graph.valid".format(output_data_dir) 527 | if os.path.exists(out_graphfile): 528 | os.remove(out_graphfile) 529 | 530 | index = 0 531 | while index + batch_size <= len(data): 532 | # generate graphs with order and dependency information 533 | input_batch = [" ".join(data[index + idx][0]) for idx in range(batch_size)] 534 | new_vocab = generate_batch_graph(output_file=out_graphfile, string_batch=input_batch) 535 | index += batch_size 536 | 537 | if index != len(data): 538 | input_batch = [" ".join(data[idx][0]) for idx in range(index,len(data))] 539 | new_vocab = generate_batch_graph(output_file=out_graphfile, string_batch=input_batch) 540 | 541 | train_data_preprocess() 542 | 543 | test_data_preprocess() 544 | 545 | valid_data_preprocess() 546 | 547 | 548 | 549 | -------------------------------------------------------------------------------- /data/TextData/test.txt: -------------------------------------------------------------------------------- 1 | what is 1 % of 2 ? 1 * 0.01 * 2 = x 2 | a bee has 2 legs . how many legs do 1 bees have ? x = ( 2 * 1 ) 3 | twice a number increased by 2 is 1 . find the number . ( 2.0 * x ) + 2 = 1 4 | the sum of 1 of a number and two is eight . find the number . ( 1 * x ) + 2.0 = 8.0 5 | the sum of a number and its reciprocal is 1 . find the number . x + ( 1.0 / x ) = 1 6 | a number is 1 less than the sum of 2 and 3 . what is the number ? ( 2 + 3 ) - 1 = x 7 | norma has 1 cards . she loses 2 . how many cards will norma have ? x = ( 1 - 2 ) 8 | sara has 1 marbles . she loses 2 . how many marbles will sara have ? x = ( 1 - 2 ) 9 | bert runs 1 miles every day . how many miles will bert run in 2 weeks ? 1 * ( 2 * 7 ) = x 10 | ruby has 1 apples . emily takes 2 away . how many apples will ruby have ? x = ( 1 - 2 ) 11 | there are 2 birds and 1 nests . how many more birds are there than nests ? x = ( 2 - 1 ) 12 | tim has 2 books . mike has 1 books . how many books do they have together ? 2 + 1 = x 13 | 2 dogs are barking . 1 more dogs start to bark . how many dogs are barking ? x = ( 2 + 1 ) 14 | keith has 1 books . jason has 2 books . how many books do they have together ? x = 1 + 2 15 | paco had 1 cookies . paco ate 2 of them . how many cookies did paco have left ? 1 - 2 = x 16 | dorothy has 1 cards . she gives 2 to harold . how many cards will dorothy have ? x = ( 1 - 2 ) 17 | wendy ran 2 miles and walked 1 miles . how much farther did wendy run than walk ? x = 2 - 1 18 | mary starts with 1 eggs . she finds another 2 . how many eggs does mary end with ? x = ( 1 + 2 ) 19 | there are 1 calories in a candy bar . how many calories are there in 2 candy bars ? 1 * 2 = x 20 | pamela has 1 skittles . she gives 2 to karen . how many skittles will pamela have ? x = ( 1 - 2 ) 21 | sally grew 2 carrots . fred grew 1 carrots . how many carrots did they grow in all ? x = 2 + 1 22 | christopher strolled 2 miles at 1 miles per hour . how long did christopher stroll ? x = ( 2 / 1 ) 23 | sandy grew 2 carrots . sam grew 1 carrots . how many carrots did they grow in total ? x = 2 + 1 24 | if benjamin strolled 2 miles at 1 miles per hour , how long was benjamin travelling ? x = ( 2 / 1 ) 25 | donald has 1 oranges . he finds another 2 . how many oranges does donald have in all ? x = ( 1 + 2 ) 26 | virginia starts with 1 eggs . amy takes 2 away . how many eggs does virginia end with ? x = ( 1 - 2 ) 27 | the town of milburg has 1 grown - ups and 2 children . how many people live in milburg ? 1 + 2 = x 28 | sandy grew 1 pumpkins . mike grew 2 pumpkins . how many pumpkins did they grow in total ? 1 + 2 = x 29 | william starts with 2 tickets . he buys 1 more . how many tickets does william end with ? x = ( 2 + 1 ) 30 | nancy grew 1 potatoes . sandy grew 2 potatoes . how many potatoes did they grow in total ? 1 + 2 = x 31 | tina has 1 bananas . she gets 2 more from joyce . how many bananas does tina have in all ? x = ( 1 + 2 ) 32 | if lawrence walked 2 kilometers at 1 kilometers per hour , how long was lawrence walking ? x = ( 2 - 1 ) 33 | 4 times the sum of a number and 2 is 3 less than 1 times that number . what is the number ? 4 * ( 2 + x ) = ( 1 * x ) - 3 34 | there are 2 squirrels in a tree with 1 nuts . how many more squirrels are there than nuts ? x = ( 2 - 1 ) 35 | five times the difference of twice a number and nine is negative fifteen . find the number . 5.0 * ( ( 2.0 * x ) - 9.0 ) = 0 - 15.0 36 | paula has 2 boxes of peanuts . each box holds 1 peanuts . how many peanuts does paula have ? x = ( 2 * 1 ) 37 | pamela bought 2 ounces of sugar , and she spilled 1 ounces of it on the floor . how much is ? x = 2 - 1 38 | brenda has 1 apples . she gets 2 more from willie . how many apples does brenda have in all ? x = ( 1 + 2 ) 39 | james has 1 balloons . amy has 2 balloons . how many more balloons does james have than amy ? x = ( 1 - 2 ) 40 | karen has 2 crayons . cindy has 1 crayons . how many more crayons does karen have than cindy ? 2 - 1 = x 41 | there were 1 book shelves . each book shelf had 2 books . how many books were on the shelves ? x = ( 1 * 2 ) 42 | bobby collects 1 blocks . bobby's father gives bobby 2 more . how many blocks does bobby have ? x = ( 1 + 2 ) 43 | willie has 1 bananas . charles has 3 bananas . he loses 2 . how many bananas will willie have ? x = ( 1 - 2 ) 44 | if there are 2 eggs in a box and daniel puts 1 more eggs inside , how many eggs are in the box ? x = ( 2 + 1 ) 45 | in a class of 2 students , 1 received a grade of a . what percent of the students received a 's ? x = ( 1 / 2 ) * 100.0 46 | 2 owls were sitting on the fence . 1 more owls joined them . how many owls are on the fence now ? x = ( 2 + 1 ) 47 | mr . guzman bought 1 doughnuts packed equally into 2 boxes . how many doughnuts were in each box ? 1 / 2 = x 48 | jack is inviting 1 friends to a party . he has 1 cookies . how many cookies will each friend get ? x = ( 1 / 1 ) 49 | cody is 2 years old . his grandmother is 1 times as old as he is . how old is cody's grandmother ? x = ( 2 * 1 ) 50 | sean has 1 whistles . sean has 2 more whistles than charles . how many whistles does charles have ? 1 - 2 = x 51 | sandy has 3 books , benny has 1 books , and tim has 2 books . how many books do they have together ? x = 3 + 1 + 2 52 | megan had 1 markers . robert gave her 2 more markers . how many markers does megan have altogether ? 1 + 2 = x 53 | sarah picked 2 apples . her brother picked 1 apples . how many times as many apples did sarah pick ? x = ( 2 / 1 ) 54 | if apples cost 1 dollars for 2 pounds , what is the cost , at the same rate , of 3 pounds of apples ? ( 1 / 2 ) * 3 = x 55 | carla has some marbles . she bought 2 marbles . now she has 1 marbles . how many did she start with ? x = ( 1 - 2 ) 56 | carlos starts with 2 bananas . 1 are eaten by a hippopotamus . how many bananas does carlos end with ? x = ( 2 - 1 ) 57 | lucy has an aquarium with 1 fish . she wants to buy 2 more fish . how many fish would lucy have then ? x = ( 1 + 2 ) 58 | fred had 2 dimes in his bank . his sister borrowed 1 of his dimes . how many dimes does fred have now ? 2 - 1 = x 59 | kyle jogged 1 laps in p.e . class and 2 laps during track practice . how many laps did kyle jog in all ? x = 1 + 2 60 | jose starts with 2 bottle caps . he gets 1 more from rebecca . how many bottle caps does jose end with ? x = ( 2 + 1 ) 61 | sandy sold half of her comic books and then bought 2 more . she now has 1 . how many did she begin with ? ( x / 2 ) + 2 = 1 62 | benny picked 2 apples and dan picked 1 apples from the apple tree . how many apples were picked in total ? x = 2 + 1 63 | jason had 2 quarters in his bank . his dad gave him 1 more quarters . how many quarters does he have now ? 2 + 1 = x 64 | marilyn starts with 1 bottle caps . she shares 2 with nancy . how many bottle caps does marilyn end with ? x = ( 1 - 2 ) 65 | if the quotient of three times a number and five is increased by four , the result is 1 . find the number . ( ( 3.0 * x ) / 5.0 ) + 4.0 = 1 66 | robin has 1 packages of gum . there are 2 pieces in each package . how many pieces of gum does robin have ? x = ( 1 * 2 ) 67 | three friends own a car in florida . one owns 2 of the car the second owns 1 . how much does the third own ? x = 1.0 - 2 - 1 68 | it snowed 2 inches on monday and 1 inches on tuesday . how much did it snow on monday and tuesday combined ? 2 + 1 = x 69 | sara has 1 green and 3 red marbles . tom has 2 green marbles . how many green marbles do they have in total ? x = 1 + 2 70 | 2 beavers were working on their home . 1 went for a swim . how many beavers are still working on their home ? x = ( 2 - 1 ) 71 | it rained 2 inches on saturday and 1 inches on sunday . how much did it rain on saturday and sunday combined ? x = 2 + 1 72 | mary found 2 seashells and jessica found 1 seashells on the beach . how many seashells did they find together ? x = 2 + 1 73 | mary picked 2 oranges and jason picked 1 oranges from the orange tree . how many oranges were picked in total ? 2 + 1 = x 74 | mrs . hilt bought 2 hot dogs . each hot dog cost 1 cents . how much money did she pay for all of the hot dogs ? x = ( 2 * 1 ) 75 | 1 people are watching a movie in a theater . the theater has 2 seats . how many seats are empty in the theater ? 1 + x = 2 76 | isabel bought 2 pieces of paper . she used 1 pieces of the paper . how many pieces of paper does she have left ? x = ( 2 - 1 ) 77 | mrs . hilt bought a yoyo for 1 cents and a whistle for 2 cents . how much did she spend in all for the two toys ? x = ( 1 + 2 ) 78 | emily had 3 coloring books . if she gave away 1 of them , but then bought 2 more , how many would she have total ? x = ( ( 3 + 2 ) - 1 ) 79 | virginia has 2 eggs and 1 skittles . if she shares the eggs among 3 friends , how many eggs does each friend get ? x = ( 2 / 3 ) 80 | fred has 1 baseball cards . keith bought 2 of fred 's baseball cards . how many baseball cards does fred have now ? x = 1 - 2 81 | johnny practiced for the track team and ran 2 laps per minute . how many minutes did it take johnny to run 1 laps ? x = ( 1 / 2 ) 82 | a pet store had 2 siamese cats and 1 house cats . during a sale they sold 1 cats . how many cats do they have left ? x = ( ( 2 + 1 ) - 1 ) 83 | dan has 1 violet balloons . tim has 2 times more violet balloons than dan . how many violet balloons does tim have ? 1 * 2 = x 84 | mrs . sheridan has 1 cats . mr . sheridan gave her 2 more cats . how many cats does mrs . sheridan have altogether ? x = ( 1 + 2 ) 85 | a vase can hold 2 flowers . if you had 1 carnations and 3 roses , how many vases would you need to hold the flowers ? x = ( ( 1 + 3 ) / 2 ) 86 | steven wants to split a collection of cards into groups of 1 . steven has 2 cards . how many groups will be created ? x = ( 2 / 1 ) 87 | tom had 2 pennies and 4 dimes in his bank . his dad gave him 1 dimes and 3 nickels . how many dimes does he have now ? x = 4 + 1 88 | darnel sprinted 1 of a lap and then took a break by jogging 2 of a lap . how much farther did darnel sprint than jog ? 1 - 2 = x 89 | dan has 1 green and 2 violet marbles . mike took 3 of dan 's green marbles . how many green marbles does dan now have ? x = 1 - 3 90 | sam had saved up 1 dollars . if he received another 3 dollars for his allowance , how many 2 dollar toys could he buy ? x = ( ( 1 + 3 ) / 2 ) 91 | mrs . sheridan has 2 cats . mrs . garrett has 1 cats . how many more cats does mrs . garrett have than mrs . sheridan ? x = ( 1 - 2 ) 92 | paul had saved up 2 dollars . if he received another 1 dollars for his allowance , how many 3 dollar toys could he buy ? x = ( ( 2 + 1 ) / 3 ) 93 | joan went to 2 football games this year . she went to 1 games last year . how many football games did joan go to in all ? x = 2 + 1 94 | will had 1 dollars . if he spent 3 bucks on a new game , how many 2 dollar toys could he buy with the money he had left ? x = ( ( 1 - 3 ) / 2 ) 95 | a construction company bought 1 tons of gravel and 2 tons of sand . how many tons of material did the company buy in all ? x = 1 + 2 96 | adam had 1 books . if he sold 2 of them and used the money he earned to buy 3 new books , how many books would adam have ? x = ( ( 1 + 3 ) - 2 ) 97 | it took carl 2 hours to ride to ralph's house at 1 miles per hour . how far is it between carl's house and ralph's house ? x = ( 2 * 1 ) 98 | oliver had 2 dollars . for his birthday he got 1 more dollars but spent 3 on a new game . how much money does he have now ? x = ( ( 2 + 1 ) - 3 ) 99 | 2 children are taking a bus to the zoo . they sit 1 children in every seat . how many seats will the children need in all ? x = ( 2 / 1 ) 100 | at the arcade dave won 2 tickets . if he spent 3 tickets on a beanie and later won 1 more tickets , how many would he have ? x = ( ( 2 + 1 ) - 3 ) 101 | michael has some fish in his fish tank . ben gave him 2 more fish . now he has 1 . how many fish did he have to begin with ? x = ( 1 - 2 ) 102 | alyssa loves eating fruits . alyssa paid $ 1 for grapes , and $ 2 for cherries . in total , how much money did alyssa spend ? x = 1 + 2 103 | keith grew 3 cantelopes , fred grew 1 cantelopes , and jason grew 2 cantelopes . how many cantelopes did they grow in total ? 3 + 1 + 2 = x 104 | at the arcade victor won 2 tickets . if he spent 1 tickets on a beanie and later won 3 more tickets , how many would he have ? x = ( ( 2 + 3 ) - 1 ) 105 | last week tom had 1 dollars . he washed cars over the weekend and now has 2 dollars . how much money did he make washing cars ? 1 + x = 2 106 | at tom's restaurant a group with 2 adults and 3 children came in to eat . if each meal cost 1 dollars , how much was the bill ? x = ( 1 * ( 2 + 3 ) ) 107 | recently , the value of kate 's retirement fund decreased by $ 2 . if her fund was worth $ 1 before , how much is it worth now ? x = 1 - 2 108 | for the school bake sale carol made 3 cupcakes . if she sold 1 of them and then made 2 more , how many cupcakes would she have ? x = ( ( 3 + 2 ) - 1 ) 109 | a pet store has 1 bird cages . if each cage has 2 parrots and 3 parakeets in it , how many birds does the pet store have total ? x = ( 1 * ( 2 + 3 ) ) 110 | joan had 3 pokemon cards , and 2 were torn . sara bought 1 of joan 's pokemon cards . how many pokemon cards does joan have now ? x = 3 - 1 111 | at billy's restaurant a group with 1 adults and 3 children came in to eat . if each meal cost 2 dollars , how much was the bill ? x = ( 2 * ( 1 + 3 ) ) 112 | a recipe calls for 1 cups of sugar . you find that you only have 2 cups of sugar left . what fraction of the recipe can you make ? x = 2 / 1 113 | jovana had 2 pounds of shells in her bucket . she added some shells and now has 1 pounds of shells . how many pounds did she add ? x = ( 1 - 2 ) 114 | a tennis racket that regularly sells for 2 dollars is on sale for 1 % off the regular price . what is the sale price , in dollars ? x = 2 - ( 2 * 1 * 0.01 ) 115 | emily collected eggs from the hen and put them into 2 baskets . she put 1 eggs into each basket . how many eggs did emily collect ? 2 * 1 = x 116 | the sum of twice a number and 2 less than the number is the same as the difference between - 1 and the number . what is the number ? ( 2.0 * x ) + ( x - 2 ) = ( - 1 ) - x 117 | ellen went to a garage sale to buy chairs . each chair cost 2 dollars . how much money did ellen spend for the 1 chairs she bought ? x = ( 2 * 1 ) 118 | alyssa has 2 blue balloons , sandy has 1 blue balloons , and sally has 3 blue balloons . how many blue balloons do they have in all ? 2 + 1 + 3 = x 119 | there are 1 bottle caps in beverly's bottle cap collection . if the bottle caps are organized into 2 groups , how big is each group ? x = ( 1 / 2 ) 120 | each chocolate bar in a box cost $ 1 . if a box had 3 bars total and rachel sold all but 2 bars , how much money would she have made ? x = ( 1 * ( 3 - 2 ) ) 121 | isabella's hair is 2 inches long . if she gets a haircut and now her hair is 1 inches long , how much of isabella's hair got cut off ? x = ( 2 - 1 ) 122 | each chocolate bar in a box cost $ 2 . if a box had 1 bars total and vanessa sold all but 3 bars , how much money would she have made ? x = ( 2 * ( 1 - 3 ) ) 123 | joan found 2 seashells on the beach . she gave sam some of her seashells . she has 1 seashell . how many seashells did she give to sam ? x = 2 - 1 124 | carefully following a recipe , kenny used exactly 2 of a cup of oil and 1 cups of water . how many cups of liquid did kenny use in all ? 2 + 1 = x 125 | diane has 3 crayons . she gets 2 more from frances . later , diane buys 1 cards at the store . how many crayons does diane have in all ? x = ( 3 + 2 ) 126 | a clothing store offers a 1 % discount on all purchases . how much would a shopper pay for an item originally costing 2 dollars dollars ? x = 2 - ( ( 1 * 0.01 ) * 2 ) 127 | a teacher had 1 worksheets to grade . if she graded 3 , but then another 2 were turned in , how many worksheets would she have to grade ? x = ( ( 1 + 2 ) - 3 ) 128 | sally had 2 pokemon cards . dan gave her 1 new pokemon cards . sally bought 3 pokemon cards . how many pokemon cards does sally have now ? x = 2 + 1 + 3 129 | a pet store had 3 puppies . in one day they sold 2 of them and put the rest into cages with 1 in each cage . how many cages did they use ? x = ( ( 3 - 2 ) / 1 ) 130 | there are 1 students in the class and 2 tickets . if the tickets are divided equally among the students , how many does each student get ? x = ( 2 / 1 ) 131 | the ferris wheel in paradise park has 2 seats . each seat can hold 1 people . how many people can ride the ferris wheel at the same time ? x = ( 2 * 1 ) 132 | amy had 2 music files and 3 video files on her flash drive . if she deleted 1 of the files , how many files were still on her flash drive ? x = ( ( 2 + 3 ) - 1 ) 133 | david has 1 bananas . he gets 3 more from christopher . later , david buys 2 cards at the store . how many bananas does david have in all ? x = ( 1 + 3 ) 134 | the school cafeteria had 3 apples . if they used 2 to make lunch for the students and then bought 1 more , how many apples would they have ? x = ( ( 3 + 1 ) - 2 ) 135 | mrs . hilt saw a rollercoaster . 1 students rode the rollercoaster every 2 minutes . how many students rode the rollercoaster in 3 minutes ? 1 * ( 3 / 2 ) = x 136 | haley had 1 music files and 2 video files on her flash drive . if she deleted 3 of the files , how many files were still on her flash drive ? x = ( ( 1 + 2 ) - 3 ) 137 | there were 1 friends playing a video game online when 2 players quit . if each player left had 2 lives , how many lives did they have total ? x = ( 2 * ( 1 - 2 ) ) 138 | blake filled a bucket with 2 of a gallon of water . later , he poured out 1 of a gallon of the water . how much water is left in the bucket ? 2 - 1 = x 139 | dan 's cat had kittens and 2 had spots . he gave 3 to tim and 1 to jason . he now has 2 kittens . how many kittens did he have to start with ? x - 3 - 1 = 2 140 | vanessa had 2 music files and 3 video files on her flash drive . if she deleted 1 of the files , how many files were still on her flash drive ? x = ( ( 2 + 3 ) - 1 ) 141 | james had 2 stickers . he got some more stickers for his birthday . then he had 1 stickers . how many stickers did james get for his birthday ? x = ( 1 - 2 ) 142 | on three consecutive passes , a football team gains 1 yards , loses 3 yards , and gains 2 yards . what number represents the total net yardage ? x = ( 1 - 3 ) + 2 143 | on friday , 1 people visited the zoo . 2 times as many people visited on saturday than on friday . how many people visited the zoo on saturday ? 1 * 2 = x 144 | frank had 2 dollars . at the store he spent $ 1 on a new game . if he got another 3 dollars for his allowance , how much money does he have now ? x = ( ( 2 + 3 ) - 1 ) 145 | a waiter had 3 customers in his section . if 2 of them left and the rest of his tables had 1 people at each table , how many tables did he have ? x = ( ( 3 - 2 ) / 1 ) 146 | a bowl contains 3 red chips , 2 blue chips , and 1 green chips . you choose 4 chip at random . what is the probability that your chip is not red ? x = ( 2 + 1 ) / ( ( 3 + 2 ) + 1 ) 147 | jonah added 1 of a cup of yellow raisins and 2 of a cup of black raisins to a batch of trail mix . how many cups of raisins did jonah add in all ? 1 + 2 = x 148 | keith picked 2 pears and jason picked 1 pears from the pear tree . joan picked 3 apples from the apple tree . how many pears were picked in total ? x = 2 + 1 149 | jane helped her mom prepare fresh lemonade . if each glass needs 2 lemons , how many glasses of fresh lemonade can she make if they have 1 lemons ? 2 * x = 1 150 | a pet shelter had 1 puppies when another 3 were brought in . if 2 puppies a day are adopted , how long would it take for all of them to be adopted ? x = ( ( 1 + 3 ) / 2 ) 151 | dave bought 2 boxes of chocolate candy and gave 3 to his little brother . if each box has 1 pieces inside it , how many pieces did dave still have ? x = ( 1 * ( 2 - 3 ) ) 152 | sandy went to the mall to buy clothes . she spent $ 2 on shorts , $ 1 on a shirt , and $ 3 on a jacket . how much money did sandy spend on clothes ? 2 + 1 + 3 = x 153 | while digging through her clothes for ice cream money , joan found 2 dimes in her jacket , and 1 dimes in her shorts . how much money did joan find ? ( 2 * 0.1 ) + ( 1 * 0.1 ) = x 154 | 1 painter can paint a room in 3 hours and another can paint the same room in 2 hours . how long will it take to paint the room if they work together ? ( ( 1 / 3 ) * x ) + ( ( 1 / 2 ) * x ) = 1 155 | katie had 2 songs on her mp3 player . if she deleted 3 old songs from it and then added 1 new songs , how many songs does she have on her mp3 player ? x = ( ( 2 + 1 ) - 3 ) 156 | a restaurant served 3 slices of pie during lunch and 2 during dinner today . it served 1 of them yesterday . how many slices of pie were served today ? x = 3 + 2 157 | for halloween emily received 2 pieces of candy . she ate 1 pieces then placed the rest into piles with 3 in each pile . how many piles could she make ? x = ( ( 2 - 1 ) / 3 ) 158 | a car rents for 2 dollars per day plus 3 cents per mile . you are on a daily budget of 1 dollars . what mileage can you go and stay within your budget ? 2 + ( 3 * 0.01 * x ) = 1 159 | there were 2 friends playing a video game online when 3 more players joined the game . if each player had 1 lives , how many lives did they have total ? x = ( 1 * ( 2 + 3 ) ) 160 | there are 1 apples in a pile on the desk . each apple comes in a package of 3 . 2 apples are added to the pile . how many apples are there in the pile ? x = ( 1 + 2 ) 161 | last week tim had 3 dollars and keith had 1 dollars . tim washed cars over the weekend and now has 2 dollars . how much money did tim make washing cars ? 3 + x = 2 162 | mrs . hilt spent 4 cents at the school store . she bought a notebook for 1 cents , a ruler for 2 cents , and 3 pencils . what is the cost of one pencil ? 4 = 1 + 2 + 3 * x 163 | in 1 , there were 4 students in central high school . the number of students enrolled in 2 was 3 % less than in 1 . how many students were enrolled in 2 ? x = 4 * ( 1.0 - 3 * 0.01 ) 164 | sarah had 1 pages of math homework and 2 pages of reading homework . if each page had 1 problems on it , how many problems did she have to complete total ? x = ( 1 * ( 1 + 2 ) ) 165 | betty also bought 1 shiny blue round stones . if 2 pieces of this stone is in each bracelet , how many bracelets of blue shiny round stones will there be ? 1 / 2 = x 166 | isabel had 1 pages of math homework and 2 pages of reading homework . if each page had 3 problems on it , how many problems did she have to complete total ? x = ( 3 * ( 1 + 2 ) ) 167 | at a restaurant each adult meal costs $ 2 and kids eat free . if a group of 3 people came in and 1 were kids , how much would it cost for the group to eat ? x = ( 2 * ( 3 - 1 ) ) 168 | martin strolled to lawrence's house . it is 1 miles from martin's house to lawrence's house . it took martin 2 hours to get there . how fast did martin go ? x = ( 1 / 2 ) 169 | for homework amy had 1 math problems and 3 spelling problems . if she can finish 2 problems in an hour how long will it take her to finish all the problems ? x = ( ( 1 + 3 ) / 2 ) 170 | christina just transferred $ 1 out of her bank account . as a result , the account now has $ 2 in it . how much money was in the account before the transfer ? x = 1 + 2 171 | for homework faye had 3 math problems and 1 spelling problems . if she can finish 2 problems in an hour how long will it take her to finish all the problems ? x = ( ( 3 + 1 ) / 2 ) 172 | a magician was selling magic card decks for 1 dollars each . if he started with 2 decks and by the end of the day he had 3 left , how much money did he earn ? x = ( 1 * ( 2 - 3 ) ) 173 | mary had 3 baseball cards , and 2 were torn . fred gave mary 4 new baseball cards . mary bought 1 baseball cards . how many baseball cards does mary have now ? x = 3 + 4 + 1 174 | if sally can paint a house in 1 hours , and john can paint the same house in 2 hour , how many hours will it take for both of them to paint the house together ? ( 1.0 / 1 ) + ( 1.0 / 2 ) = 1.0 / x 175 | for the school bake sale wendy made pastries . she baked 2 cupcakes and 3 cookies . after the sale she had 1 to take back home . how many pastries did she sell ? x = ( ( 2 + 3 ) - 1 ) 176 | haley baked 3 cupcakes for her school's bake sale . if her brother , todd , ate 2 of them how many packages could she make if she put 1 cupcake in each package ? x = ( ( 3 - 2 ) / 1 ) 177 | isabel baked 3 cupcakes for her school's bake sale . if her brother , todd , ate 2 of them how many packages could she make if she put 1 cupcake in each package ? x = ( ( 3 - 2 ) / 1 ) 178 | will was organizing his baseball cards in a binder with 3 on each page . if he had 1 new cards and 2 old cards to put in the binder , how many pages would he use ? x = ( ( 1 + 2 ) / 3 ) 179 | there was a stack of 1 sheets of used paper . lexie wants to place it in boxes for recycling . if every box can contain 2 sheets , how many boxes does lexie need ? 1 / 7 = x 180 | luke was putting his spare change into piles . he had 2 piles of quarters and 2 piles of dimes . if each pile had 1 coins in it , how many coins did he have total ? x = ( 1 * ( 2 + 2 ) ) 181 | last year at newberg's airport , 1 passengers landed on time . unfortunately , 2 passengers landed late . in all , how many passengers landed in newberg last year ? 1 + 2 = x 182 | billy was putting his spare change into piles . he had 1 piles of quarters and 2 piles of dimes . if each pile had 3 coins in it , how many coins did he have total ? x = ( 3 * ( 1 + 2 ) ) 183 | a painter needed to paint 3 rooms in a building . each room takes 2 hours to paint . if he already painted 1 rooms , how much longer will he take to paint the rest ? x = ( 2 * ( 3 - 1 ) ) 184 | sam had to wash 1 short sleeve shirts and 3 long sleeve shirts before school . if he had only washed 2 of them by the time school started , how many did he not wash ? x = ( ( 1 + 3 ) - 2 ) 185 | edward made 2 dollars mowing lawns over the summer . if he spent 3 dollars buying new mower blades , how many 1 dollar games could he buy with the money he had left ? x = ( ( 2 - 3 ) / 1 ) 186 | dave had to wash 1 short sleeve shirts and 2 long sleeve shirts before school . if he had only washed 3 of them by the time school started , how many did he not wash ? x = ( ( 1 + 2 ) - 3 ) 187 | for halloween emily received 3 pieces of candy from neighbors and 2 pieces from her older sister . if she only ate 1 pieces a day , how long would the candy last her ? x = ( ( 3 + 2 ) / 1 ) 188 | there are 1 books in oak grove 's public library . in addition , there are 2 books in its school libraries . how many books do the libraries in oak grove have overall ? x = 1 + 2 189 | while shopping for music online , zoe bought 1 country albums and 2 pop albums . each album came with a lyric sheet and had 1 songs . how many songs did zoe buy total ? x = ( 1 * ( 1 + 2 ) ) 190 | isabel was selling her necklaces at a garage sale . she sold 1 bead necklaces and 1 gem stone necklaces . if each necklace cost 2 dollars , how much money did she earn ? x = ( 2 * ( 1 + 1 ) ) 191 | the school cafeteria ordered 2 red apples and 3 green apples for students lunches . but , if only 1 students wanted fruit , how many extra did the cafeteria end up with ? x = ( ( 2 + 3 ) - 1 ) 192 | while shopping for music online , faye bought 1 country albums and 2 pop albums . each album came with a lyric sheet and had 3 songs . how many songs did faye buy total ? x = ( 3 * ( 1 + 2 ) ) 193 | there are 1 orchid bushes currently in the park . park workers will plant 2 orchid bushes today . how many orchid bushes will the park have when the workers are finished ? x = 1 + 2 194 | for halloween robin scored 1 pieces of candy . she ate 3 pieces the first night and then her sister gave her 2 more pieces . how many pieces of candy does robin have now ? x = ( ( 1 + 2 ) - 3 ) 195 | while on vacation , megan took 2 pictures at the zoo and 1 at the museum . if she later deleted 3 of the pictures , how many pictures from her vacation did she still have ? x = ( ( 2 + 1 ) - 3 ) 196 | emily bought 3 new chairs and 2 new tables for her house . if she spent 1 minutes on each piece furniture putting it together , how many minutes did it take her to finish ? x = ( 1 * ( 3 + 2 ) ) 197 | the cafeteria had 1 apples . for lunch they handed out 2 to students and decided to use the rest to make pies . if each pie takes 3 apples , how many pies could they make ? x = ( ( 1 - 2 ) / 3 ) 198 | the next act involved several jugglers . if each juggler is juggling 2 balls at a time , how many balls are needed if there are 1 jugglers putting a show at the same time ? 2 * 1 = x 199 | rachel bought 3 new chairs and 1 new tables for her house . if she spent 2 minutes on each piece furniture putting it together , how many minutes did it take her to finish ? x = ( 2 * ( 3 + 1 ) ) 200 | alyssa went to 1 soccer games this year , but missed 2 . she went to 3 games last year and plans to go to 4 games next year . how many soccer games will alyssa go to in all ? x = 1 + 3 + 4 201 | olivia and her mom were picking carrots from their garden . olivia picked 2 and her mother picked 3 . if only 1 of the carrots were good , how many bad carrots did they have ? x = ( ( 2 + 3 ) - 1 ) 202 | hannah's vegetarian restaurant bought 1 of a pound of green peppers and 1 of a pound of red peppers . how many pounds of peppers did hannah's vegetarian restaurant buy in all ? 1 + 1 = x 203 | sam was collecting cans for recycling . on saturday he filled 2 bags up and on sunday he filled 1 more bags . if each bag had 3 cans in it , how many cans did he pick up total ? x = ( 3 * ( 2 + 1 ) ) 204 | 2 trains leave simultaneously traveling on the same track in opposite directions at speeds of 3 and 1 miles per hour . how many hours will it take before they are 4 miles apart ? ( 3 * x ) + ( 1 * x ) = 4 205 | rachel was playing a video game where she scores 1 points for each treasure she finds . if she found 3 treasures on the first level and 2 on the second , what would her score be ? x = ( 1 * ( 3 + 2 ) ) 206 | jordan 's salary is 1 dollars a month plus a 3 % commission on all of his sales . what must the amount of his sales be , in dollars , for him to earn at least 2 dollars each month ? 1 + ( 3 * 0.01 * x ) = 2 207 | there are 3 short trees and 2 tall trees currently in the park . park workers will plant 1 short trees today . how many short trees will the park have when the workers are finished ? x = 3 + 1 208 | marilyn has 1 bananas that must be put away in boxes . daniel comes to help and brings 3 cookies to share with marilyn . if there are 2 boxes , how many bananas must go in each box ? x = ( 1 / 2 ) 209 | in fourth grade there were 2 students at the start of the year . during the year 1 students left and 1 new students came to school . how many students were in fourth grade at the end ? x = ( ( 2 + 1 ) - 1 ) 210 | a toy store had 3 giant stuffed bears in stock when they got another shipment with 2 bears in it . the put the bears onto shelves with 1 on each shelf . how many shelves did they use ? x = ( ( 3 + 2 ) / 1 ) 211 | the owner of a pizza parlor wants to make a profit of 2 % of the cost for each pizza sold . if it costs 1 dollars to make a pizza , at what price should each pizza be sold , in dollars ? x - 1 = ( 2 * x ) * 0.01 212 | there are 3 known nesting pairs of bald eagles in the lower 1 states today . this is 2 more pairs than in 4 . how many nesting pairs of bald eagles were there in the lower 1 states in 4 ? 2 + x = 3 213 | there are 3 students trying out for the school's trivia teams . if 1 of them didn't get picked for the team and the rest were put into 2 groups , how many students would be in each group ? x = ( ( 3 - 1 ) / 2 ) 214 | there were a total of 2 basketball games in the season . the season is played for 1 months . how many basketball games were played each month , if each month has the same number of games ? 2 = 1 * x 215 | a group of 2 friends went into a restaurant . the chef already had 1 chicken wings cooked but cooked 3 more for the group . if they each got the same amount how many would each person get ? x = ( ( 1 + 3 ) / 2 ) 216 | a lawyer bills her clients 1 dollars per hour of service . if a client 's case requires 2 hours to complete , use proportion to calculate how much the client will owe the lawyer in dollars . 1 * 2 = x 217 | while playing at the arcade , luke won 1 tickets playing 'whack a mole' and 3 tickets playing 'skee ball' . if he was trying to buy candy that cost 2 tickets a piece , how many could he buy ? x = ( ( 1 + 3 ) / 2 ) 218 | while playing a trivia game , frank answered 2 questions correct in the first half and 1 questions correct in the second half . if each question was worth 2 points , what was his final score ? x = ( 2 * ( 2 + 1 ) ) 219 | will was working as a sacker at a grocery store where he made 1 dollars an hour . on monday he worked 1 hours and on tuesday he worked 2 hours . how much money did will make in those two days ? x = ( 1 * ( 1 + 2 ) ) 220 | the speed of a motor boat in still water is 60kph . it goes 2 kilometers up the river and then comes the 2 kilometers back in a total of 1 hours . what is the speed of the current of the river ? ( 2 / ( 60.0 - x ) ) + ( 2 / ( 60.0 + x ) ) = 1 221 | a physician 's assistant measures a child and finds that his height is 1 inches . at his last visit to the doctor's office , the child was 2 inches tall . how much did the child grow , in inches ? x = 1 - 2 222 | for halloween katie and her sister combined the candy they received . katie had 2 pieces of candy while her sister had 3 . if they ate 1 pieces the first night , how many pieces do they have left ? x = ( ( 2 + 3 ) - 1 ) 223 | soledad worked 5 hours 2 week and earned a 3 dollars paycheck . she earns 4 times her regular hourly wage for the hours she works in excess of 1 . what is soledad 's regular hourly wage in dollars ? ( 1 * x ) + ( ( 5 - 1 ) * ( 4 * x ) ) = 3 224 | gwen was organizing her book case making sure each of the shelves had exactly 1 books on it . if she had 2 shelves of mystery books and 3 shelves of picture books , how many books did she have total ? x = ( 1 * ( 2 + 3 ) ) 225 | there are 3 short bushes and 2 tall trees currently in the park . park workers had to cut down 1 short bushes that were damaged . how many short bushes will the park have when the workers are finished ? x = 3 - 1 226 | benny received 2 dollars for his birthday . he went to a sporting goods store and bought a baseball glove , baseball , and bat . he had 1 dollars left over . how much did he spent on the baseball gear ? 2 - x = 1 227 | there are 1 walnut trees and 2 orange trees currently in the park . park workers had to cut down 3 walnut trees that were damaged . how many walnut trees will be in the park when the workers are finished ? x = 1 - 3 228 | a store had 1 coloring books in stock . they ended up putting them on sale and getting rid of 3 of them . the put the ones they still had onto shelves with 2 on each shelf . how many shelves did they use ? x = ( ( 1 - 3 ) / 2 ) 229 | jerry was helping the cafeteria workers pick up lunch trays , but he could only carry 1 trays at a time . if he had to pick up 2 trays from one table and 3 trays from another , how many trips will he make ? x = ( ( 2 + 3 ) / 1 ) 230 | victor was helping the cafeteria workers pick up lunch trays , but he could only carry 3 trays at a time . if he had to pick up 1 trays from one table and 2 trays from another , how many trips will he make ? x = ( ( 1 + 2 ) / 3 ) 231 | while taking inventory at her pastry shop , kelly realizes that she had 2 of a box of baking powder yesterday , but the supply is now down to 1 of a box . how much more baking powder did kelly have yesterday ? 2 - 1 = x 232 | there are 3 dogwood trees currently in the park . park workers will plant 2 more dogwood trees today and 1 more dogwood trees tomorrow . how many dogwood trees will the park have when the workers are finished ? 3 + 2 + 1 = x 233 | haley and her friends were recycling paper for their class . for every 1 pounds they recycled they earned one point . if haley recycled 3 pounds and her friends recycled 2 pounds , how many points did they earn ? x = ( ( 3 + 2 ) / 1 ) 234 | during a canned food drive , items were sorted into bins . the drive resulted in 1 of a bin of soup , 1 of a bin of vegetables , and 2 of a bin of pasta . altogether , how many bins would the canned food take up ? 1 + 1 + 2 = x 235 | robin uploaded 3 pictures from her phone and 2 from her camera to facebook . if she sorted the pics into 1 different albums with the same amount of pics in each album , how many pictures were in each of the albums ? x = ( ( 3 + 2 ) / 1 ) 236 | during 2 year , the wagners ' real estate bill included 1 dollars for local schools . of this amount , 3 dollars went to the high school district . what percent did the wagner family pay to the high school district ? x = ( 3 / 1 ) * 100.0 237 | cashews sell for 4 dollars per 1 - pound and brazil nuts sell for 2 dollars per 1 - pound . how many pounds of cashews should be mixed with 5 pounds of brazil nuts to get a mix that sells for 3 dollars per 1 - pound ? ( ( 4 / 1 ) * x ) + ( ( 2 / 1 ) * 5 ) = ( 3 / 1 ) * ( 5 + x ) 238 | there are 2 maple trees currently in the park . park workers will plant more maple trees today . when the workers are finished there will be 1 maple trees in the park . how many maple trees did the workers plant today ? 2 + x = 1 239 | at the beach , miki and her sister both built sandcastles and then measured their heights . miki 's sandcastle was 2 foot tall and her sister 's was 1 foot tall . how much taller was miki 's sandcastle than her sister 's ? x = 2 - 1 240 | as part of a lesson on earthquakes , a science class is researching the movement of a nearby fault line . the fault line moved 2 inches during the past year and 1 inches the year before . how far did the fault line move in all ? x = 2 + 1 241 | during a school play , jonah staffed the snack bar . he served 1 pitcher of lemonade during the first intermission , 2 pitcher during the second , and 1 pitcher during the third . how many pitchers of lemonade did jonah pour in all ? x = 1 + 2 + 1 242 | nicole found an orange caterpillar and a green caterpillar in her backyard . the green caterpillar was 2 inches long and the orange caterpillar was 1 inches long . how much longer was the green caterpillar than the orange caterpillar ? x = 2 - 1 243 | a spaceship traveled 1 of a light - year from earth to planet x and 2 of a light - year from planet x to planet y . then it traveled 2 of a light - year from planet y back to earth . how many light - years did the spaceship travel in all ? 1 + 2 + 2 = x 244 | recently , at&t offered 3 long - distance calling plans . the rate plus plan cost 2 dollars per month plus 4 cents a minute . another plan has no monthly fee , but costs 1 cents a minute . for what number of minutes will the 3 plans cost the same ? 2 + ( ( 4 * 0.01 ) * x ) = ( 1 * 0.01 ) * x 245 | a waitress put leftover tarts into the fridge on thursday night . she noticed that the restaurant had 2 tart filled with cherries , 1 tart filled with blueberries , and 2 tart filled with peaches . how many leftover tarts did the restaurant have in all ? x = 2 + 1 + 2 246 | heather went to the county fair last weekend . when she got there , she had to walk 2 mile from the car to the entrance . then she walked 2 mile to the carnival rides and 1 mile from the carnival rides back to the car . how many miles did heather walk in all ? x = 2 + 2 + 1 247 | dalton wants to buy a jump rope that costs $ 5 , a board game that costs $ 2 , and a playground ball that costs $ 1 . he has saved $ 4 from his allowance , and his uncle gave him $ 3 . how much more money does dalton need to buy the jump rope , the game , and the ball ? ( ( 5 + 2 ) + 1 ) - ( 4 + 3 ) = x 248 | tom quig travelled 4 miles east of st louis . for most of the trip he travelled 1 miles per hour , but for one period of time he was slowed to 2 miles per hour due to a major accident . if the total time of travel was 3 hours , how many miles did he drive at the reduced speed ? ( x / 2 ) + ( ( 4 - x ) / 1 ) = 3 249 | martha wants to buy a digital camera from her 3 month savings . to do this she needs to maintain an average saving of 4 in each month . she saves 2 in the first month and 1 in the second month . find the amount she should save in the third month , in dollars , to buy a digital camera at the end of three months . ( ( 2 + 1 ) + x ) / 3 = 4 250 | a producer of packaged frozen meat wants to market mixed meat at 4 dollars per kilogram . how many kilograms of pork meat worth 6 dollars per kilogram must be mixed with 5 kilograms of chicken meat worth 2 dollars per kilogram and 3 kilograms of beef meat worth 1 dollars per kilogram to produce a satisfactory mixture ? ( ( 6 * x ) + ( 2 * 5 ) ) + ( 3 * 1 ) = ( ( 3 + x ) + 5 ) * 4 251 | -------------------------------------------------------------------------------- /data/TextData/valid.txt: -------------------------------------------------------------------------------- 1 | convert 1 to a percent . 1 * 100.0 = x 2 | a bee has 2 legs . how many legs do 1 bees have ? x = ( 2 * 1 ) 3 | the sum of 2 and twice a number is 1 . find the number . 2 + ( 2.0 * x ) = 1 4 | there are 2 eggs in each box . how many eggs are in 1 boxes ? x = ( 2 * 1 ) 5 | nancy has 1 five dollars bills . how much money does she have ? 1 * 5 = x 6 | if 3 of a pound is worth 1 dollars , how much is 2 pounds worth ? x = ( 1 / 3 ) * 2 7 | sally saw 1 dozen birds in a tree . how many birds did sally see ? 1 * 12 = x 8 | there are 2 eggs in a box . harry takes 1 eggs . how many are left ? x = ( 2 - 1 ) 9 | benny worked 1 hours for 2 days . how many hours did he work in total ? 1 * 2 = x 10 | brian has 2 cards . wayne takes 1 away . how many cards will brian have ? x = ( 2 - 1 ) 11 | if norma wandered for 2 hours at 1 miles per hour . how far did norma go ? x = ( 2 * 1 ) 12 | sam has 1 books . joan has 2 books . how many books do they have together ? 1 + 2 = x 13 | there are 1 fishbowls . each fishbowl has 2 fish . how many fish are there ? 1 * 2 = x 14 | ellen had 1 legos , but she lost 2 legos . how many legos does she have now ? x = ( 1 - 2 ) 15 | a certain number is 1 less than three times the next number . find the number . ( 3.0 * ( 1.0 + x ) ) - 1 = x 16 | carol starts with 2 blocks . she loses 1 . how many blocks does carol end with ? x = ( 2 - 1 ) 17 | mike has 1 dollars in 2 dollar bills . how many five dollars bills does he have ? 1 / 2 = x 18 | each bag contains 2 pounds of oranges . how many pounds of oranges are in 1 bags ? 2 * 1 = x 19 | there are 1 calories in a candy bar . how many calories are there in 2 candy bars ? 1 * 2 = x 20 | charles has 1 skittles . diana takes 2 away . how many skittles will charles have ? x = ( 1 - 2 ) 21 | dan picked 1 limes and gave sara 2 of the limes . how many limes does dan have now ? x = 1 - 2 22 | sean has 2 blocks . 1 are eaten by a hippopotamus . how many blocks will sean have ? x = ( 2 - 1 ) 23 | jane buys an apple for $ 1 and pays with a $ 2 bill . how much change will she get ? x = ( 2 - 1 ) 24 | bruce has 2 eggs . kimberly has 1 eggs . he loses 3 . how many eggs will bruce have ? x = ( 2 - 3 ) 25 | roger has 2 blocks . 1 are eaten by a hippopotamus . how many blocks will roger have ? x = ( 2 - 1 ) 26 | mary earns $ 2 cleaning a home . how many homes did she clean , if she made 1 dollars ? 2 * x = 1 27 | my car gets 1 miles per gallon of gas . how many miles can i drive on 2 gallons of gas ? 1 * 2 = x 28 | joan has 1 blue balloons but lost 2 of them . how many blue balloons does joan have now ? x = 1 - 2 29 | joyce starts with 1 apples . she gives 2 to larry . how many apples does joyce end with ? x = ( 1 - 2 ) 30 | sara grew 1 pumpkins , but the rabbits ate 2 pumpkins . how many pumpkins does sara have ? x = 1 - 2 31 | ruth starts with 1 apples . she shares 2 with peter . how many apples does ruth end with ? x = ( 1 - 2 ) 32 | mrs . hilt ate 2 apples every hour . how many apples had she eaten at the end of 1 hours ? x = ( 2 * 1 ) 33 | if a pair of shoes that cost 2 dollars was marked down by 1 % , how much do they cost now ? x = 2 - ( ( 1 * 0.01 ) * 2 ) 34 | charlie has 2 more snowballs than lucy . she has 1 snowballs . how many does charlie have ? x = ( 2 + 1 ) 35 | the sum of three consecutive even numbers is 1 . what is the smallest of the three numbers ? ( 3 * x ) + 6 = 1 36 | william has 2 bottle caps . he buys 1 more . how many bottle caps does william have in all ? x = ( 2 + 1 ) 37 | joan has 1 orange balloons but lost 2 of them . how many orange balloons does joan have now ? x = 1 - 2 38 | angela has 1 tickets . annie gives angela 2 more . how many tickets does angela have in all ? x = ( 1 + 2 ) 39 | 2 boats are in the lake . each boat has 1 people . how many people are on boats in the lake ? x = ( 2 * 1 ) 40 | i have 1 pencils . if i put 2 pencils in each pencil box , how many pencil boxes will i fill ? 1 / 2 = x 41 | gary had 1 dollars . he spent 2 dollars on a pet snake . how many dollars did gary have left ? x = ( 1 - 2 ) 42 | wayne collects 1 blocks . wayne's father gives wayne 2 more . how many blocks does wayne have ? x = ( 1 + 2 ) 43 | ashley sold 1 boxes of samoas . how many cases of 1 boxes , plus extra boxes does ashley need ? x = ( 1 / 1 ) 44 | charles has 1 apples . jessica gives charles 2 more . how many apples does charles have in all ? x = ( 1 + 2 ) 45 | what 's the number ? if i multuply it by 1 and add 2 , i get the same answer when i add 1 to it . ( 1 * x ) + 2 = 1 + x 46 | lori has 2 marbles . if she shares them among 1 friends , how many marbles does each friend get ? x = ( 2 / 1 ) 47 | there are 1 stickers on a page . if you have 2 pages of stickers , how many stickers do you have ? 1 * 2 = x 48 | each child has 2 bottle caps . if there are 1 children , how many bottle caps are there in total ? x = ( 2 * 1 ) 49 | a box of books weighs 1 pounds . each book weighs 2 pounds . how many books are there in the box ? x = ( 1 / 2 ) 50 | betty has 1 oranges stored in boxes . if there are 2 boxes , how many oranges must go in each box ? x = ( 1 / 2 ) 51 | mrs . hilt bought 2 pizzas for $ 1 each . what was the total amount she paid for the three pizzas ? x = ( 2 * 1 ) 52 | david has 2 boxes of stuffed toy dogs . each box has 1 dogs in it . how many dogs are there in all ? 2 * 1 = x 53 | megan had 1 markers . robert gave her 2 more markers . how many markers does megan have altogether ? x = ( 1 + 2 ) 54 | joan has 1 blue balloons melanie has 2 blue balloons . how many blue balloons do they have in total ? 1 + 2 = x 55 | james ate 1 carrot sticks before dinner and 2 more after dinner . how many carrot sticks did he eat ? x = ( 1 + 2 ) 56 | craig starts with 2 skittles . 1 are eaten by a hippopotamus . how many skittles does craig end with ? x = ( 2 - 1 ) 57 | jesse's room is 2 feet long and 1 feet wide . how much carpet does she need to cover the whole floor ? x = ( 2 * 1 ) 58 | alyssa picked 2 pears and nancy picked 1 pears from the pear tree . how many pears were picked in all ? 2 + 1 = x 59 | tom has 2 violet balloons , he gave fred 1 of the balloons . how many violet balloons does he now have ? x = 2 - 1 60 | kyle jogged 1 laps in p.e . class and 2 laps during track practice . how many laps did kyle jog in all ? 1 + 2 = x 61 | when a number is increased by 2 the number is equal to 1 the original number . find the original number ? 2 + x = 1 * x 62 | sara grew 2 onions , sally grew 3 onions , and fred grew 1 onions . how many onions did they grow in all ? x = 2 + 3 + 1 63 | sara had 2 quarters in her bank . her dad gave her 1 more quarters . how many quarters does she have now ? 2 + 1 = x 64 | jenny sold 1 boxes of trefoils . how many cases of 2 boxes , plus extra boxes does jenny need to deliver ? x = ( 1 / 2 ) 65 | joan picked 1 apples from the orchard , and gave 2 apples to melanie . how many apples does joan have now ? x = 1 - 2 66 | robin has 2 packages of gum . there are 1 pieces in each package . how many pieces of gum does robin have ? x = ( 2 * 1 ) 67 | if 2 is added to a number and this sum is doubled , the result is 1 more than the number . find the number . 1 * ( 2 + x ) = 1 + x 68 | a dvd book holds 2 dvds . there are 1 dvds already in the book . how many more dvds can be put in the book ? 2 - 1 = x 69 | sara picked 1 pears and 2 apples from the orchard . she gave 3 pears to dan . how many pears does sara have ? x = 1 - 3 70 | theresa has 1 crayons . janice has 2 crayons . she shares 3 with nancy . how many crayons will theresa have ? x = ( 1 - 3 ) 71 | joan grew 1 watermelons and 3 turnips . tom grew 2 watermelons . how many watermelons did they grow in total ? x = 1 + 2 72 | joan found 1 seashells on the beach , she gave mike 2 of the seashells . how many seashells does she now have ? x = 1 - 2 73 | sally earns $ 2 for each house she cleans . if she cleans 1 houses , how many dozens of dollars will she make ? ( 2 * 1 ) = x * 12 74 | fred found 2 seashells on the beach , he gave jessica 1 of the seashells . how many seashells does he now have ? x = 2 - 1 75 | marcia spent 1 minutes working on her science project . how many hours did marcia spend on her science project ? 1 / 60 = x 76 | andrew spent 2 day working on his science report . he worked for 1 hours each day . how many hours did he work ? x = ( 2 * 1 ) 77 | mrs . hilt bought a notebook for $ 1 . she paid with nickels . how many nickels did she use to buy the notebook ? 1 / 5 = x 78 | jason grew 2 watermelons and 3 pumpkins . sandy grew 1 watermelons . how many watermelons did they grow in total ? x = 2 + 1 79 | shawn has 3 blocks . mildred has with 1 blocks . mildred finds another 2 . how many blocks does mildred end with ? x = ( 1 + 2 ) 80 | mike picked 3 oranges and melanie picked 1 oranges . fred picked 2 apples . how many oranges were picked in total ? x = 3 + 1 81 | marlee has 2 guests coming to her halloween party . each table will hold 1 guests . how many tables will she need ? x = ( 2 / 1 ) 82 | a pet store had 3 siamese cats and 1 house cats . during a sale they sold 2 cats . how many cats do they have left ? x = ( ( 3 + 1 ) - 2 ) 83 | melanie , benny , sandy , and jessica each have 1 dozen pokemon cards . how many pokemon cards do they have in all ? 4 * ( 1 * 12 ) = x 84 | iesha has 1 books . 2 are about school and the rest are about sports . how many books about sports does iesha have ? x = ( 1 - 2 ) 85 | john had 1 socks . if he threw away 2 old ones that didn't fit and bought 3 new ones , how many socks would he have ? x = ( ( 1 + 3 ) - 2 ) 86 | eric wants to split a collection of peanuts into groups of 1 . eric has 2 peanuts . how many groups will be created ? x = ( 2 / 1 ) 87 | sam went to 2 football games this year . he went to 1 games last year . how many football games did sam go to in all ? 2 + 1 = x 88 | marlee has 2 guests coming to her halloween party . each table will hold 1 guests . how many tables will marlee need ? 2 / 1 = x 89 | the sumata family took a 2 - day vacation by car . each day they drove 1 miles . how many total miles did they drive ? x = ( 2 * 1 ) 90 | oliver had 2 socks . if he threw away 3 old ones that didn't fit and bought 1 new ones , how many socks would he have ? x = ( ( 2 + 1 ) - 3 ) 91 | joshua has 1 skittles and 3 eggs . if he shares the skittles among 2 friends , how many skittles does each friend get ? x = ( 1 / 2 ) 92 | paul had saved up 1 dollars . if he received another 3 dollars for his allowance , how many 2 dollar toys could he buy ? x = ( ( 1 + 3 ) / 2 ) 93 | terrell hiked 1 miles on saturday . then , on sunday , he hiked another 2 miles . how far did terrell hike all together ? x = 1 + 2 94 | there are 1 crayons in the drawer . benny placed 2 more crayons in the drawer . how many crayons are now there in total ? 1 + 2 = x 95 | mike had 1 quarters and 3 nickels in his bank . his dad borrowed 2 nickels from mike . how many nickels does he have now ? x = 3 - 2 96 | kaleb had 3 dollars . if he spent 1 bucks on a new game , how many 2 dollar toys could he buy with the money he had left ? x = ( ( 3 - 1 ) / 2 ) 97 | mrs . hilt saw 1 bees in the hive . the next day she saw 2 times that many . how many bees did she see on the second day ? 1 * 2 = x 98 | the total number of students in year 2 at a high school is 3 . there are 1 more girls than boys . how many boys are there ? ( 3 - 1 ) / 2.0 = x 99 | a pet supply store has 1 bags of dog food and 2 bags of cat food . how many more bags of dog food are there than cat food ? x = ( 1 - 2 ) 100 | zoe had 2 bottles of water in her fridge . if she drank 1 of them and then bought 3 more , how many bottles would she have ? x = ( ( 2 + 3 ) - 1 ) 101 | mrs . santiago has 2 red roses . mrs . garrett has 1 . how many more red roses does mrs . santiago have than mrs . garrett ? x = ( 2 - 1 ) 102 | scarlett made a fruit salad with 1 pound of melon and 2 pound of berries . how many pounds of fruit did scarlett use in all ? x = 1 + 2 103 | melanie has 2 blue marbles . sandy has 1 times more blue marbles than melanie . how many dozen blue marbles does sandy have ? 2 * 1 = x * 12 104 | edward had 1 books . if he sold 2 of them and used the money he earned to buy 3 new books , how many books would edward have ? x = ( ( 1 + 3 ) - 2 ) 105 | a restaurant made 1 hamburgers to serve during lunch . only 2 were actually served . how many hamburgers were over from lunch ? x = 1 - 2 106 | a waiter had 2 tables he was waiting on , with 2 women and 1 men at each table . how many customers total did the waiter have ? x = ( 2 * ( 2 + 1 ) ) 107 | oscar 's bus ride to school is 2 mile and charlie 's bus ride is 1 mile . how much longer is oscar 's bus ride than charlie 's ? x = 2 - 1 108 | for the school bake sale katie made 1 cupcakes . if she sold 2 of them and then made 2 more , how many cupcakes would she have ? x = ( ( 1 + 2 ) - 2 ) 109 | a pet store has 3 bird cages . if each cage has 1 parrots and 2 parakeets in it , how many birds does the pet store have total ? x = ( 3 * ( 1 + 2 ) ) 110 | 1 evening , a restaurant served a total of 3 loaf of wheat bread and 2 loaf of white bread . how many loaves were served in all ? x = 3 + 2 111 | alyssa's dog had puppies . she gave 2 to her friends . she now has 1 puppies left . how many puppies did she have to start with ? x - 2 = 1 112 | a store had 1 oranges in a bin . if they threw away 2 of the old ones and put 3 new ones in the bin how many would be in the bin ? x = ( ( 1 + 3 ) - 2 ) 113 | jorge scored 2 goals playing soccer last season . this season he scored 1 goals . what is the total number of goals jorge scored ? x = ( 2 + 1 ) 114 | luke made 1 dollars mowing lawns and 2 dollars weed eating . if he only spent 3 dollar a week , how long would the money last him ? x = ( ( 1 + 2 ) / 3 ) 115 | bryan took a look at his books as well . if bryan has 1 books in each of his 2 bookshelves , how many books does he have in total ? 1 * 2 = x 116 | sally has 1 orange balloons and 3 blue balloons . she lost 2 of the orange balloons . how many orange balloons does sally have now ? x = 1 - 2 117 | alyssa has 2 blue balloons , sandy has 1 blue balloons , and sally has 3 blue balloons . how many blue balloons do they have in all ? x = 2 + 1 + 3 118 | tim's cat had kittens . he gave 2 to jessica and 3 to sara . he now has 1 kittens left . how many kittens did he have to start with ? x - 2 - 3 = 1 119 | the litter patrol picked up 2 glass bottles and 1 aluminum cans on saturday . how many pieces of litter did they pick up altogether ? x = ( 2 + 1 ) 120 | each chocolate bar in a box cost $ 1 . if a box had 3 bars total and olivia sold all but 2 bars , how much money would she have made ? x = ( 1 * ( 3 - 2 ) ) 121 | it took amanda 2 hours to stroll to kimberly's house at 1 miles per hour . how far is it between amanda's house and kimberly's house ? x = ( 2 * 1 ) 122 | the first minute of a telephone call costs 1 cents and each additional minute 2 cents . what is the cost of a 3 minute telephone call ? x = 1 + ( 2 * 3 ) 123 | at lindsey 's vacation wear , 2 the garments are bikinis and 1 are trunks . what fraction of the garments are either bikinis or trunks ? x = 2 + 1 124 | a plane is using fuel at the rate of 1 gallons per hour and it has 2 gallons left in its tank . how long can the plane continue to fly ? 1 * x = 2 125 | there are 3 apples in a box . louise has 1 apples in a bag . scott takes 2 apples out of the box . how many apples are left in the box ? x = ( 3 - 2 ) 126 | at the schools book fair sam bought 2 adventure books and 1 mystery books . if 3 of the books were used , how many new books did he buy ? x = ( ( 2 + 1 ) - 3 ) 127 | last year , 2 people were born in a country , and 1 people immigrated to it . how many new people began living in the country last year ? 2 + 1 = x 128 | there are 2 pencils in the drawer and 3 pencils on the desk . dan placed 1 pencils on the desk . how many pencils are now there in total ? x = 2 + 3 + 1 129 | a pet store had 2 puppies . in one day they sold 3 of them and put the rest into cages with 1 in each cage . how many cages did they use ? x = ( ( 2 - 3 ) / 1 ) 130 | there are 2 students in the class and 1 pencils . if the pencils are divided equally among the students , how many does each student get ? x = ( 1 / 2 ) 131 | mike joined his school 's band . he bought a trumpet for $ 1 , and a song book which was $ 2 . how much did mike spend at the music store ? x = 1 + 2 132 | amy had 2 music files and 3 video files on her flash drive . if she deleted 1 of the files , how many files were still on her flash drive ? x = ( ( 2 + 3 ) - 1 ) 133 | mrs . hilt is baking bread . she needs 2 cups of flour to bake 1 loaves of bread . how much flour will she need to make one loaf of bread ? 2 / 1 = x 134 | the school cafeteria had 3 apples . if they used 1 to make lunch for the students and then bought 2 more , how many apples would they have ? x = ( ( 3 + 2 ) - 1 ) 135 | jose strolled to jane's house . it is 1 miles from jose's house to jane's house . it took jose 2 hours to get there . how fast did jose go ? x = ( 1 / 2 ) 136 | a recipe calls for 2 cup of diced green pepper . give the number of cups of diced green pepper that should be used to make 1 of this recipe . x = 2 * 1 137 | april's discount flowers was having a sale where each flower was 2 dollars . if maria bought 3 roses and 1 daisies , how much did she spend ? x = ( 2 * ( 3 + 1 ) ) 138 | one evening , a restaurant served a total of 2 of a loaf of wheat bread and 1 of a loaf of white bread . how many loaves were served in all ? 2 + 1 = x 139 | a restaurant made 1 hamburgers and 3 hot dogs to serve during lunch . only 2 hamburgers were actually served . how many hamburgers were over ? x = 1 - 2 140 | 1 of the cows are grazing grass . 3 of the remaining are sleeping and 2 cows are drinking water from the pond . find the total number of cows . ( ( 1 * x ) + ( 3 * ( 1 * x ) ) ) + 2 = x 141 | this afternoon craig left school , rode the bus 1 miles , and then walked 2 of a mile to get home . how much farther did craig ride than walk ? 1 - 2 = x 142 | from the years 1 to 4 the minimum hourly wage increased about 2 % , to 3 dollars per hour . what was the minimum hourly wage in 1 , in dollars ? x + ( ( 2 * x ) * 0.01 ) = 3 143 | at lunch a waiter had 3 customers and 2 of them didn't leave a tip . if he got $ 1 each from the ones who did tip , how much money did he earn ? x = ( 1 * ( 3 - 2 ) ) 144 | haley picked 3 carrots from her garden . if she threw out 2 of them and then picked 1 more the next day , how many carrots would she have total ? x = ( ( 3 + 1 ) - 2 ) 145 | a waiter had 2 customers in his section . if 3 of them left and the rest of his tables had 1 people at each table , how many tables did he have ? x = ( ( 2 - 3 ) / 1 ) 146 | bianca picked 2 carrots from her garden . if she threw out 1 of them and then picked 3 more the next day , how many carrots would she have total ? x = ( ( 2 + 3 ) - 1 ) 147 | craig walked 2 of a mile from school to david's house and 1 of a mile from david's house to his own house . how many miles did craig walk in all ? 2 + 1 = x 148 | at the town carnival oliver rode the ferris wheel 2 times and the bumper cars 1 times . if each ride cost 3 tickets , how many tickets did he use ? x = ( 3 * ( 2 + 1 ) ) 149 | kimberly went to the store 1 times last month . she buys 2 peanuts each time she goes to the store . how many peanuts did kimberly buy last month ? x = ( 1 * 2 ) 150 | a pet shelter had 3 puppies when another 2 were brought in . if 1 puppies a day are adopted , how long would it take for all of them to be adopted ? x = ( ( 3 + 2 ) / 1 ) 151 | adam bought 1 boxes of chocolate candy and gave 3 to his little brother . if each box has 2 pieces inside it , how many pieces did adam still have ? x = ( 2 * ( 1 - 3 ) ) 152 | benny goes out to lunch with sara and tom . each person orders the $ 1 lunch special . benny agrees to pay the bill . how much will he have to pay ? 3 * 1 = x 153 | priya needs 2 cupcakes for a birthday party . she already has 3 chocolate cupcakes and 1 vanilla cupcakes . how many more cupcakes should priya buy ? 2 - ( 3 + 1 ) = x 154 | the selling price of a pair of pants is 2 dollars . if the store paid 1 dollars less for the pants , find the price that the store paid , in dollars . x = 2 - 1 155 | robin had 3 songs on her mp3 player . if she deleted 1 old songs from it and then added 2 new songs , how many songs does she have on her mp3 player ? x = ( ( 3 + 2 ) - 1 ) 156 | kevin bought 2 watermelons . the first watermelon was 1 pounds , and the second watermelon was 3 pounds . how many pounds of watermelon did kevin buy ? x = 1 + 3 157 | nancy uploaded 2 pictures to facebook . she put 3 pics into one album and put the rest into 1 different albums . how many pictures were in each album ? x = ( ( 2 - 3 ) / 1 ) 158 | joan bought toy cars for $ 1 , a skateboard for $ 2 , and got toy trucks for $ 3 . she spent $ 4 on pants . in total , how much did joan spend on toys ? x = 1 + 2 + 3 159 | for a birthday party jerry bought 3 regular sodas and 2 diet sodas . if his fridge would only hold 1 on each shelf , how many shelves would he fill up ? x = ( ( 3 + 2 ) / 1 ) 160 | patrick jogged to aaron's house . it is 2 miles from patrick's house to aaron's house . it took patrick 1 hours to get there . how fast did patrick go ? x = ( 2 / 1 ) 161 | joan found 1 seashells and 3 starfishes on the beach . she gave tim some of her seashells . she has 2 seashell . how many seashells did she give to tim ? 1 - x = 2 162 | hayley had 1 meatballs on her plate . kirsten stole some of her meatballs . now she has 2 meatballs on her plate . how many meatballs did kirsten steal ? x = ( 1 - 2 ) 163 | john had 1 action figures , but needed 2 total for a complete collection . if each one costs $ 1 , how much money would he need to finish his collection ? x = ( 1 * ( 2 - 1 ) ) 164 | katie had 3 pages of math homework and 2 pages of reading homework . if each page had 1 problems on it , how many problems did she have to complete total ? x = ( 1 * ( 3 + 2 ) ) 165 | vincent bought 3 books about animals , 2 book about outer space , and 4 books about trains . each book cost $ 1 . how much did vincent spend on the books ? ( ( 3 + 2 ) + 4 ) * 1 = x 166 | the number of gears a machine can make varies directly by how long it operates . if it can make 3 gears in 1 hours , how many gears can it make in 2 hours ? x = ( 2 * 3 ) / 1 167 | at a restaurant each adult meal costs $ 1 and kids eat free . if a group of 3 people came in and 2 were kids , how much would it cost for the group to eat ? x = ( 1 * ( 3 - 2 ) ) 168 | martin strolled to lawrence's house . it is 1 miles from martin's house to lawrence's house . it took martin 2 hours to get there . how fast did martin go ? x = ( 1 / 2 ) 169 | sarah's old washing machine could only wash 3 pieces of clothing at a time . if she had to wash 2 shirts and 1 sweaters how many loads would she have to do ? x = ( ( 2 + 1 ) / 3 ) 170 | a ship is filled with 2 tons of cargo . it stops in the bahamas , where sailors load 1 tons of cargo onboard . how many tons of cargo does the ship hold now ? x = 2 + 1 171 | megan's class is going on a field trip to the zoo . if each van can hold 2 people and there are 1 students and 2 adults going , how many vans will they need ? x = ( ( 2 + 1 ) / 2 ) 172 | a magician was selling magic card decks for 1 dollars each . if he started with 2 decks and by the end of the day he had 1 left , how much money did he earn ? x = ( 1 * ( 2 - 1 ) ) 173 | joan found 1 seashells and 3 starfishes on the beach . she gave alyssa some of her seashells . she has 2 seashell . how many seashells did she give to alyssa ? 1 - x = 2 174 | the sum of the reciprocal of a number and the reciprocal of 1 less than the number is 2 times the reciprical of the original number . find the original number ? ( 1.0 / x ) + ( 1.0 / ( x - 1 ) ) = 2 * ( 1.0 / x ) 175 | for the school bake sale katie made pastries . she baked 3 cupcakes and 2 cookies . after the sale she had 1 to take back home . how many pastries did she sell ? x = ( ( 3 + 2 ) - 1 ) 176 | sarah baked 3 cupcakes for her school's bake sale . if her brother , todd , ate 2 of them how many packages could she make if she put 1 cupcake in each package ? x = ( ( 3 - 2 ) / 1 ) 177 | on a recent trip to ca , we averaged 1 miles per hour . on the return trip we averaged 2 miles per hour . determine the average speed of the trip to ca and back . ( 1 + 2 ) / 2.0 = x 178 | tom was putting his spare change into piles . he had 1 piles of quarters and 2 piles of dimes . if each pile had 3 coins in it , how many coins did he have total ? x = ( 3 * ( 1 + 2 ) ) 179 | while making desserts for a bake sale , victor used 2 of a scoop of brown sugar as well as 1 of a scoop of white sugar . how much more brown sugar did victor use ? 2 - 1 = x 180 | at the fair there were 2 people in line for the bumper cars . if 1 of them got tired of waiting and left and 1 more got in line , how many people would be in line ? x = ( ( 2 + 1 ) - 1 ) 181 | there are 2 oak trees currently in the park . park workers will plant 1 more oak trees today . how many oak trees will the park have when the workers are finished ? 2 + 1 = x 182 | roger was putting his spare change into piles . he had 1 piles of quarters and 1 piles of dimes . if each pile had 2 coins in it , how many coins did he have total ? x = ( 2 * ( 1 + 1 ) ) 183 | a painter needed to paint 2 rooms in a building . each room takes 3 hours to paint . if he already painted 1 rooms , how much longer will he take to paint the rest ? x = ( 3 * ( 2 - 1 ) ) 184 | ned had to wash 1 short sleeve shirts and 2 long sleeve shirts before school . if he had only washed 3 of them by the time school started , how many did he not wash ? x = ( ( 1 + 2 ) - 3 ) 185 | a trivia team had 1 members total , but during a game 3 members didn't show up . if each member that did show up scored 2 points , how many points were scored total ? x = ( 2 * ( 1 - 3 ) ) 186 | dave had to wash 3 short sleeve shirts and 2 long sleeve shirts before school . if he had only washed 1 of them by the time school started , how many did he not wash ? x = ( ( 3 + 2 ) - 1 ) 187 | edward was selling his old games . he started out with 2 but sold 3 of them . he packed the rest up putting 1 games into each box . how many boxes did he have to use ? x = ( ( 2 - 3 ) / 1 ) 188 | there are 2 walnut trees currently in the park . park workers will plant 1 walnut trees today . how many walnut trees will the park have when the workers are finished ? x = 2 + 1 189 | megan was selling her necklaces at a garage sale . she sold 3 bead necklaces and 2 gem stone necklaces . if each necklace cost 1 dollars , how much money did she earn ? x = ( 1 * ( 3 + 2 ) ) 190 | there were 2 bales of hay in the barn . jason stacked more bales in the barn today . there are now 1 bales of hay in the barn . how many bales did he store in the barn ? 2 + x = 1 191 | the school cafeteria ordered 3 red apples and 2 green apples for students lunches . but , if only 1 students wanted fruit , how many extra did the cafeteria end up with ? x = ( ( 3 + 2 ) - 1 ) 192 | there school's baseball team had 1 new players and 2 returning players . if the coach put them into groups with 2 players in each group , how many groups would there be ? x = ( ( 1 + 2 ) / 2 ) 193 | there are 1 popular trees currently in the park . park workers will plant 2 popular trees today . how many popular trees will the park have when the workers are finished ? x = 1 + 2 194 | rachel was playing a video game and had 1 lives . in a hard part of the game she lost 2 lives . if she got 3 more lives in the next level , how many lives would she have ? x = ( ( 1 + 3 ) - 2 ) 195 | safety rent a truck costs 1 dollars plus 2 dollars per mile . city rentals rents the truck for 4 dollars plus 3 dollars per mile . for what mileage are the costs the same ? 1 + ( 2 * x ) = 4 + ( 3 * x ) 196 | while shopping for music online , nancy bought 2 country albums and 3 pop albums . each album came with a lyric sheet and had 1 songs . how many songs did nancy buy total ? x = ( 1 * ( 2 + 3 ) ) 197 | the cafeteria had 3 apples . for lunch they handed out 1 to students and decided to use the rest to make pies . if each pie takes 2 apples , how many pies could they make ? x = ( ( 3 - 1 ) / 2 ) 198 | carson's teacher gives out gold stars for great math work . yesterday , carson earned 2 gold stars . today , he earned 1 more . how many gold stars did carson earn in all ? x = ( 2 + 1 ) 199 | there are 1 walnut trees currently in the park . park workers will plant 2 more walnut trees today . how many walnut trees will the park have when the workers are finished ? 1 + 2 = x 200 | at the arcade , jerry won 3 tickets playing 'whack a mole' and 1 tickets playing 'skee ball' . if he spent 2 of his tickets on a hat , how many tickets does jerry have left ? x = ( ( 3 + 1 ) - 2 ) 201 | there are 1 oak trees currently in the park . park workers had to cut down 2 oak trees that were damaged . how many oak trees will the park have when the workers are finished ? x = 1 - 2 202 | suzie found two worms in the yard and measured them with a ruler . one worm was 1 of an inch long . the other worm was 2 of an inch long . how much longer was the longer worm ? 1 - 2 = x 203 | sam was collecting cans for recycling . on saturday he filled 2 bags up and on sunday he filled 3 more bags . if each bag had 1 cans in it , how many cans did he pick up total ? x = ( 1 * ( 2 + 3 ) ) 204 | wendy was playing a video game where she scores 3 points for each treasure she finds . if she found 2 treasures on the first level and 1 on the second , what would her score be ? x = ( 3 * ( 2 + 1 ) ) 205 | frank was collecting cans for recycling . on saturday he filled 2 bags up and on sunday he filled 1 more bags . if each bag had 2 cans in it , how many cans did he pick up total ? x = ( 2 * ( 2 + 1 ) ) 206 | there were a total of 1 soccer games in the season . the season is played for 2 months . how many soccer games were played each month , if each month has the same number of games ? 1 = 2 * x 207 | bryan had 1 precious stones in his collection which he sold to his friend from the jewelry store . if the stones were sold at 2 dollar each , how much money did bryan get in total ? 1 * 2 = x 208 | there are 1 bicycles and 4 tricycles in the storage area at danny's apartment building . each bicycle has 2 wheels and each tricycle has 3 wheels . how many wheels are there in all ? ( 1 * 2 ) + ( 4 * 3 ) = x 209 | in fourth grade there were 1 students at the start of the year . during the year 2 students left and 1 new students came to school . how many students were in fourth grade at the end ? x = ( ( 1 + 1 ) - 2 ) 210 | there were a total of 2 football games in the season . the season is played for 1 months . how many football games were played each month , if each month has the same number of games ? 2 / 1 = x 211 | there is a pole in a lake . 1 of the pole is in the ground , another 3 of it is covered with water , and 2 feet of it is out of the water . what is the total length of the pole in feet ? 1 * x + 3 * x + 2 = x 212 | a plane flies 1 miles against a steady 3 miles per hour headwind and then returns to the same point with the wind . if the entire takes 2 hours , what is the plane 's speed in still air ? ( 1 / ( x - 3 ) ) + ( 1 / ( 3 + x ) ) = 2 213 | there are 2 students trying out for the school's trivia teams . if 3 of them didn't get picked for the team and the rest were put into 1 groups , how many students would be in each group ? x = ( ( 2 - 3 ) / 1 ) 214 | tom bought 1 tickets at the state fair . he spent 3 tickets at the 'dunk a clown' booth and decided to use the rest on rides . if each ride cost 2 tickets , how many rides could he go on ? x = ( ( 1 - 3 ) / 2 ) 215 | a group of 1 friends went into a restaurant . the chef already had 2 chicken wings cooked but cooked 1 more for the group . if they each got the same amount how many would each person get ? x = ( ( 1 + 2 ) / 1 ) 216 | while playing at the arcade , ned won 2 tickets playing 'whack a mole' and 3 tickets playing 'skee ball' . if he was trying to buy candy that cost 1 tickets a piece , how many could he buy ? x = ( ( 2 + 3 ) / 1 ) 217 | edward bought 2 tickets at the state fair . he spent 1 tickets at the 'dunk a clown' booth and decided to use the rest on rides . if each ride cost 3 tickets , how many rides could he go on ? x = ( ( 2 - 1 ) / 3 ) 218 | zoe was unboxing some of her old winter clothes . she found 1 boxes of clothing and inside each box there were 2 scarves and 3 mittens . how many pieces of winter clothing did zoe have total ? x = ( 1 * ( 2 + 3 ) ) 219 | nancy went to 2 football games this month . she went to 1 games last month , and plans to go to 4 games next month . she paid 3 dollars for the tickets . how many games will she attend in all ? x = 2 + 1 + 4 220 | lana was unboxing some of her old winter clothes . she found 1 boxes of clothing and inside each box there were 1 scarves and 2 mittens . how many pieces of winter clothing did lana have total ? x = ( 1 * ( 1 + 2 ) ) 221 | mrs . hilt baked pies last weekend for a holiday dinner . she baked 1 pecan pies and 3 apples pies . if she wants to arrange all of the pies in rows of 2 pies each , how many rows will she have ? x = ( 1 + 3 ) 222 | for halloween katie and her sister combined the candy they received . katie had 1 pieces of candy while her sister had 2 . if they ate 1 pieces the first night , how many pieces do they have left ? x = ( ( 1 + 2 ) - 1 ) 223 | a water flow restrictor has reduced the flow of water to 2 gallons per minute . this amount is 1 gallon per minute less than 3 the original flow rate . find the original rate in gallons per minute . ( 3 * x ) - 1 = 2 224 | gwen was organizing her book case making sure each of the shelves had exactly 2 books on it . if she had 3 shelves of mystery books and 1 shelves of picture books , how many books did she have total ? x = ( 2 * ( 3 + 1 ) ) 225 | mary found 3 seashells , melanie found 2 seashells , and jason found 1 seashells on the beach . when they cleaned them , they discovered that 4 were cracked . how many seashells did they find together ? x = 3 + 2 + 1 226 | haley was planting vegetables in her garden . she started with 1 seeds and planted 2 of them in the big garden and in each of her small gardens put 3 seeds each . how many small gardens did haley have ? x = ( ( 1 - 2 ) / 3 ) 227 | tori is a school janitor . last week , she picked up a total of 2 pieces of trash . if she picked up 1 pieces of trash in the classrooms , how many pieces of trash did tori pick up outside the classrooms ? x = 2 - 1 228 | a store had 1 coloring books in stock . they ended up putting them on sale and getting rid of 2 of them . the put the ones they still had onto shelves with 3 on each shelf . how many shelves did they use ? x = ( ( 1 - 2 ) / 3 ) 229 | diane is a beekeeper . last year , she harvested 2 pounds of honey . this year , she bought some new hives and increased her honey harvest by 1 pounds . how many pounds of honey did diane harvest this year ? x = 2 + 1 230 | diane is a beekeeper . last year , she harvested 2 pounds of honey . this year , she bought some new hives and increased her honey harvest by 1 pounds . how many pounds of honey did diane harvest this year ? 2 + 1 = x 231 | trenton sells electronic supplies . each week he earns 3 dollars plus commission equal to 2 of his sales . this week his goal is to earn no less than 1 dollars . how much sales he must make to reach his goal ? 3 + ( 2 * x ) = 1 232 | gwen and her friends were recycling paper for their class . for every 1 pounds they recycled they earned one point . if gwen recycled 2 pounds and her friends recycled 3 pounds , how many points did they earn ? x = ( ( 2 + 3 ) / 1 ) 233 | paige and her friends were recycling paper for their class . for every 2 pounds they recycled they earned one point . if paige recycled 3 pounds and her friends recycled 1 pounds , how many points did they earn ? x = ( ( 3 + 1 ) / 2 ) 234 | mike is at the library helping put away books . there are 2 book to put away total but a librarian takes 3 of them and leaves mike with the rest . if he can fit 1 books on a shelf , how many shelves will he need ? x = ( ( 2 - 3 ) / 1 ) 235 | wendy uploaded 3 pictures from her phone and 1 from her camera to facebook . if she sorted the pics into 2 different albums with the same amount of pics in each album , how many pictures were in each of the albums ? x = ( ( 3 + 1 ) / 2 ) 236 | isabel uploaded 1 pictures from her phone and 3 from her camera to facebook . if she sorted the pics into 2 different albums with the same amount of pics in each album , how many pictures were in each of the albums ? x = ( ( 1 + 3 ) / 2 ) 237 | tiffany uploaded 1 pictures from her phone and 2 from her camera to facebook . if she sorted the pics into 3 different albums with the same amount of pics in each album , how many pictures were in each of the albums ? x = ( ( 1 + 2 ) / 3 ) 238 | two airplanes left the same airport traveling in opposite directions . if one airplane averages 1 miles per hour and the other 3 miles per hour , how many hours will it take for the distance between them to be 2 miles ? ( 3 * x ) + ( 1 * x ) = 2 239 | the number of kilograms of water in a human body varies directly as the total body weight . a person who weighs 2 kilograms contains 1 kilograms of water . how many kilograms of water are in a person weighing 3 kilograms ? 1 / 2 = x / 3 240 | at the beach , miki and her sister both built sandcastles and then measured their heights . miki's sandcastle was 2 of a foot tall and her sister's was 1 of a foot tall . how much taller was miki's sandcastle than her sister's ? 2 - 1 = x 241 | rupert and ronald aced their math test . so their mother bought for them a wonderful trampoline yesterday . ronald jumped 1 times on the trampoline . rupert jumped 2 more times than ronald . how many times did they jump altogether ? x = ( 1 + 2 ) 242 | mika had 2 stickers . she bought 1 stickers from a store in the mall and got 2 stickers for her birthday . then mika gave 4 of the stickers to her sister and used 3 to decorate a greeting card . how many stickers does mika have left ? ( ( 2 + 1 ) + 2 ) - ( 4 + 3 ) = x 243 | an ice skating rink charges 3 dollars for admission and 1 dollars to rent skates . jill can purchase a new pair of skates for 2 dollars . how many times would she need to go the rink to justify buying the skates rather than renting a pair ? 2 / 1 = x 244 | suppose you are starting an office cleaning service . you have spent 2 dollars on equipment . to clean an office , you use 3 dollars worth of supplies you purchased . you charge 1 dollars per office . how many offices must you clean to break even ? ( ( 0 - 2 ) + ( 1 * x ) ) - ( 3 * x ) = 0.0 245 | juliet has a choice between receiving an 2 dollars monthly salary from furniture by design or a base salary of 1 dollars and a 4 % commission on the amount of furniture she sells during the month . for what amount of sales will the 3 choices be equal ? 1 + ( 4 * 0.01 * x ) = 2 246 | christian's father and the senior ranger gathered firewood as they walked towards the lake in the park and brought with them sacks . if every sack can contain around 2 pieces of wood , how many sacks were they able to fill if they gathered 1 pieces of wood ? 2 * x = 1 247 | a waitress put leftover tarts into the fridge on thursday night . she noticed that the restaurant had 2 of a tart filled with cherries , 1 of a tart filled with blueberries , and 2 of a tart filled with peaches . how many leftover tarts did the restaurant have in all ? 2 + 1 + 2 = x 248 | last saturday , spencer walked all over town running errands . first , he walked 1 of a mile from his house to the library and 3 of a mile from the library to the post office . then he walked 2 of a mile from the post office back home . how many miles did spencer walk in all ? 1 + 3 + 2 = x 249 | a small publishing company has a 2 time product cost for editing and printing of 3 dollars . variable cost per book is 4 dollars . the publisher is selling the book to the store for 1 dollars . how many books must the publisher print and sell so that the production cost will equal the money obtained from sells ? ( 1 * x ) - ( 4 * x ) = 3 250 | a person is choosing between 1 cellular phone plans . one has a monthly fee of 4 dollars for 6 minutes plus 7 dollars for each minute over the 6 . the second plan has a monthly fee of 3 dollars for 2 minutes plus 5 dollars for each minute over the 2 . after how many minutes used are the monthly costs of the plans equal ? 4 + ( 7 * ( x - 6 ) ) = 3 + ( 5 * ( x - 2 ) ) 251 | -------------------------------------------------------------------------------- /data/TextData/vocab.f.txt: -------------------------------------------------------------------------------- 1 | x 1988 2 | 1 1899 3 | = 1874 4 | ) 1861 5 | ( 1861 6 | 2 1798 7 | + 1152 8 | * 779 9 | 3 756 10 | - 753 11 | / 368 12 | 4 93 13 | 0.01 76 14 | 1.0 41 15 | 2.0 23 16 | 12 19 17 | 5 17 18 | 0.5 10 19 | 3.0 9 20 | 100.0 7 21 | 4.0 7 22 | 7.0 6 23 | 5.0 6 24 | 0.25 5 25 | 0.1 4 26 | 8.0 4 27 | 6 4 28 | 7 3 29 | 10.0 3 30 | 25 2 31 | 100 2 32 | 1.5 1 33 | 0.0 1 34 | 0.05 1 35 | 0 1 36 | 8 1 37 | 10 1 38 | 14 1 39 | 9.0 1 40 | 87.0 1 41 | -------------------------------------------------------------------------------- /data/TextData/vocab.q.txt: -------------------------------------------------------------------------------- 1 | . 3145 2 | the 2092 3 | 1 1949 4 | 2 1861 5 | ? 1821 6 | how 1697 7 | of 1393 8 | many 1318 9 | , 1230 10 | a 1162 11 | in 1099 12 | and 1023 13 | to 837 14 | 3 799 15 | she 589 16 | if 581 17 | have 568 18 | he 566 19 | did 546 20 | each 522 21 | are 455 22 | had 446 23 | for 439 24 | has 431 25 | on 422 26 | there 379 27 | dollars 352 28 | does 344 29 | her 333 30 | is 328 31 | they 298 32 | with 287 33 | much 283 34 | at 280 35 | more 280 36 | were 259 37 | total 240 38 | will 235 39 | was 221 40 | from 210 41 | now 203 42 | all 196 43 | $ 191 44 | number 184 45 | them 180 46 | it 179 47 | his 177 48 | would 166 49 | per 166 50 | books 161 51 | bought 160 52 | miles 144 53 | cards 131 54 | what 129 55 | picked 127 56 | left 125 57 | that 120 58 | students 120 59 | games 118 60 | money 116 61 | be 114 62 | long 113 63 | but 111 64 | than 106 65 | game 105 66 | up 102 67 | pounds 101 68 | apples 100 69 | marbles 99 70 | hour 99 71 | buy 99 72 | gave 98 73 | pieces 97 74 | one 95 75 | put 95 76 | - 93 77 | boxes 93 78 | 4 93 79 | into 93 80 | cost 90 81 | store 90 82 | then 89 83 | seashells 89 84 | make 88 85 | hours 88 86 | school 87 87 | points 87 88 | an 87 89 | trees 87 90 | do 86 91 | new 84 92 | 's 84 93 | end 83 94 | can 83 95 | same 83 96 | park 82 97 | day 81 98 | pencils 80 99 | box 78 100 | mile 77 101 | you 75 102 | when 75 103 | balloons 75 104 | spent 74 105 | sold 73 106 | year 72 107 | during 71 108 | tickets 70 109 | got 69 110 | baseball 69 111 | rest 68 112 | workers 67 113 | another 66 114 | found 66 115 | find 66 116 | times 66 117 | people 65 118 | first 65 119 | joan 65 120 | cookies 65 121 | made 64 122 | went 63 123 | costs 63 124 | last 62 125 | need 61 126 | crayons 61 127 | candy 61 128 | car 59 129 | take 59 130 | spend 59 131 | could 59 132 | sam 58 133 | sale 58 134 | get 58 135 | oranges 58 136 | only 57 137 | mary 57 138 | use 57 139 | drawer 56 140 | pictures 56 141 | some 55 142 | jason 55 143 | today 54 144 | blue 53 145 | bottle 53 146 | grew 53 147 | friends 53 148 | problems 52 149 | sara 52 150 | week 51 151 | this 51 152 | out 51 153 | tom 50 154 | lives 50 155 | % 49 156 | used 49 157 | customers 49 158 | second 48 159 | cents 48 160 | by 48 161 | fred 47 162 | mike 47 163 | team 46 164 | takes 46 165 | go 46 166 | caps 44 167 | time 44 168 | video 44 169 | minutes 44 170 | roses 43 171 | dimes 43 172 | already 42 173 | still 42 174 | flowers 42 175 | playing 42 176 | red 42 177 | carrots 42 178 | green 41 179 | shelves 41 180 | plus 41 181 | together 41 182 | mrs 41 183 | melanie 40 184 | scored 40 185 | house 40 186 | eggs 40 187 | their 40 188 | book 40 189 | after 39 190 | inches 39 191 | earn 39 192 | sally 39 193 | finished 39 194 | starts 38 195 | lunch 38 196 | away 37 197 | old 37 198 | alyssa 37 199 | cups 37 200 | dan 37 201 | jessica 37 202 | ate 36 203 | bag 36 204 | water 36 205 | didn't 36 206 | as 36 207 | company 36 208 | nancy 36 209 | party 36 210 | bus 36 211 | grade 35 212 | needed 35 213 | tree 35 214 | erasers 35 215 | friend 35 216 | gives 35 217 | later 35 218 | class 35 219 | must 34 220 | groups 34 221 | pages 34 222 | two 34 223 | added 34 224 | him 34 225 | restaurant 34 226 | garden 34 227 | blocks 34 228 | tim 33 229 | gallons 33 230 | placed 33 231 | before 32 232 | bank 32 233 | took 32 234 | kilometers 32 235 | pears 32 236 | quarters 32 237 | i 32 238 | players 31 239 | trip 31 240 | children 31 241 | pet 31 242 | bananas 31 243 | eat 31 244 | yellow 30 245 | player 30 246 | group 30 247 | wants 30 248 | candies 30 249 | month 30 250 | pick 30 251 | fish 30 252 | hilt 30 253 | while 30 254 | pound 30 255 | cut 30 256 | cupcakes 30 257 | next 30 258 | every 29 259 | over 29 260 | fruit 29 261 | mom 29 262 | plant 29 263 | food 29 264 | line 29 265 | cats 29 266 | beach 28 267 | john 28 268 | altogether 28 269 | songs 28 270 | birthday 28 271 | pokemon 28 272 | keith 28 273 | weighed 28 274 | cup 28 275 | puppies 28 276 | sandy 28 277 | cars 27 278 | price 27 279 | buys 27 280 | emily 27 281 | off 27 282 | currently 27 283 | flour 27 284 | walk 27 285 | piece 27 286 | bags 26 287 | rate 26 288 | feet 26 289 | earned 26 290 | pizza 25 291 | cafeteria 25 292 | chocolate 25 293 | so 25 294 | start 25 295 | far 25 296 | bill 25 297 | pennies 25 298 | skittles 25 299 | drive 25 300 | library 25 301 | dog 24 302 | bake 24 303 | clothing 24 304 | benny 24 305 | birds 24 306 | amount 24 307 | bin 24 308 | started 24 309 | ones 24 310 | equal 24 311 | trays 24 312 | received 23 313 | mother 23 314 | tall 23 315 | where 23 316 | read 23 317 | served 23 318 | dollar 23 319 | sell 23 320 | truck 23 321 | balls 23 322 | seeds 23 323 | collection 23 324 | table 23 325 | dogwood 22 326 | give 22 327 | ice 22 328 | football 22 329 | grow 22 330 | half 22 331 | white 22 332 | paid 22 333 | peaches 22 334 | charges 22 335 | cream 22 336 | family 22 337 | needs 22 338 | albums 22 339 | bales 22 340 | making 22 341 | sister 22 342 | which 22 343 | tons 22 344 | potatoes 21 345 | wanted 21 346 | lawns 21 347 | waiter 21 348 | buying 21 349 | barn 21 350 | walked 21 351 | watermelons 20 352 | came 20 353 | extra 20 354 | nickels 20 355 | cat 20 356 | album 20 357 | turnips 20 358 | small 20 359 | sum 20 360 | gallon 20 361 | plans 20 362 | peanuts 20 363 | weighs 20 364 | basketball 20 365 | tables 20 366 | dad 20 367 | walnut 20 368 | gets 20 369 | less 20 370 | pies 20 371 | pie 20 372 | baked 20 373 | saved 19 374 | phone 19 375 | wash 19 376 | cook 19 377 | shirts 19 378 | zoo 19 379 | boys 19 380 | average 19 381 | shop 19 382 | decks 19 383 | stickers 19 384 | oil 19 385 | speed 19 386 | 5 19 387 | paint 19 388 | ride 19 389 | orange 19 390 | page 19 391 | hold 18 392 | cans 18 393 | dozen 18 394 | decided 18 395 | result 18 396 | worked 18 397 | split 18 398 | trivia 18 399 | deleted 18 400 | working 18 401 | rent 18 402 | your 18 403 | short 18 404 | finds 18 405 | cakes 18 406 | gas 18 407 | files 18 408 | twice 18 409 | shelf 18 410 | mix 18 411 | jar 18 412 | janet 18 413 | monday 18 414 | leaves 17 415 | work 17 416 | saturday 17 417 | days 17 418 | distance 17 419 | maria 17 420 | packages 17 421 | back 17 422 | inside 17 423 | vacation 17 424 | calls 17 425 | adam 17 426 | level 17 427 | flower 17 428 | bars 17 429 | won 17 430 | bianca 17 431 | mowing 17 432 | lost 17 433 | clothes 16 434 | schools 16 435 | score 16 436 | longer 16 437 | filled 16 438 | going 16 439 | farmer 16 440 | show 16 441 | recycled 16 442 | trying 16 443 | bucket 16 444 | toys 16 445 | selling 16 446 | both 16 447 | cages 16 448 | holds 16 449 | should 16 450 | other 16 451 | homework 16 452 | music 15 453 | wind 15 454 | pumpkins 15 455 | scissors 15 456 | girls 15 457 | section 15 458 | karen 15 459 | night 15 460 | tip 15 461 | brother 15 462 | shares 15 463 | fourth 15 464 | online 15 465 | plums 15 466 | concert 15 467 | different 15 468 | pile 15 469 | purchased 15 470 | packs 15 471 | person 15 472 | cage 15 473 | yard 15 474 | agency 15 475 | science 15 476 | equally 15 477 | vase 14 478 | sarah 14 479 | edward 14 480 | loads 14 481 | round 14 482 | teacher 14 483 | season 14 484 | among 14 485 | pay 14 486 | grain 14 487 | or 14 488 | haley 14 489 | run 14 490 | pics 14 491 | paper 14 492 | juice 14 493 | grams 14 494 | lemon 14 495 | having 14 496 | fee 14 497 | connie 14 498 | bears 14 499 | megan 14 500 | tuesday 14 501 | inch 14 502 | oak 14 503 | field 14 504 | home 14 505 | school's 14 506 | markers 14 507 | wendy 14 508 | band 13 509 | ran 13 510 | sugar 13 511 | played 13 512 | rain 13 513 | pipe 13 514 | leave 13 515 | divided 13 516 | rachel 13 517 | roger 13 518 | between 13 519 | package 13 520 | sitting 13 521 | difference 13 522 | joined 13 523 | share 13 524 | orchard 13 525 | houses 13 526 | members 13 527 | bushes 13 528 | weigh 13 529 | kaleb 13 530 | shirt 13 531 | cantelopes 13 532 | eating 13 533 | account 13 534 | martha 13 535 | worksheets 13 536 | worth 12 537 | chef 12 538 | centimeter 12 539 | carton 12 540 | ton 12 541 | wheel 12 542 | install 12 543 | originally 12 544 | card 12 545 | mow 12 546 | case 12 547 | lisa 12 548 | centimeters 12 549 | good 12 550 | bouquets 12 551 | load 12 552 | rulers 12 553 | yesterday 12 554 | kelly 12 555 | t 12 556 | called 12 557 | stock 12 558 | frank 12 559 | ferris 12 560 | adopted 12 561 | desk 12 562 | kids 11 563 | fair 11 564 | three 11 565 | been 11 566 | threw 11 567 | brought 11 568 | fraction 11 569 | ship 11 570 | weekend 11 571 | paige 11 572 | goes 11 573 | henry 11 574 | size 11 575 | recipe 11 576 | wood 11 577 | black 11 578 | liters 11 579 | either 11 580 | fill 11 581 | leaked 11 582 | mp3 11 583 | ticket 11 584 | soccer 11 585 | maple 11 586 | heads 11 587 | grocery 11 588 | plan 11 589 | luke 11 590 | yards 11 591 | receive 11 592 | high 11 593 | exactly 11 594 | coloring 11 595 | add 11 596 | cake 11 597 | slices 10 598 | county 10 599 | baggies 10 600 | george 10 601 | toy 10 602 | bar 10 603 | employees 10 604 | farther 10 605 | hay 10 606 | discount 10 607 | binder 10 608 | muffins 10 609 | pizzas 10 610 | milk 10 611 | father 10 612 | minute 10 613 | limes 10 614 | gum 10 615 | change 10 616 | cases 10 617 | product 10 618 | drove 10 619 | eats 10 620 | orchids 10 621 | come 10 622 | allowance 10 623 | summer 10 624 | amy 10 625 | apartments 10 626 | heather 10 627 | building 10 628 | colored 10 629 | buses 10 630 | ladybugs 10 631 | foot 10 632 | finish 10 633 | part 10 634 | folders 10 635 | movie 10 636 | big 10 637 | ounce 10 638 | ordered 10 639 | organizing 10 640 | cooked 10 641 | uploaded 10 642 | facebook 10 643 | traveling 10 644 | waiting 10 645 | pencil 10 646 | trail 10 647 | women 10 648 | lamp 10 649 | flew 10 650 | contain 10 651 | buckets 10 652 | student 10 653 | trout 10 654 | joyce 10 655 | gardens 10 656 | math 9 657 | lucy 9 658 | onto 9 659 | dogs 9 660 | regular 9 661 | borrowed 9 662 | mixture 9 663 | lemonade 9 664 | towels 9 665 | graded 9 666 | dinner 9 667 | down 9 668 | michelle 9 669 | textbook 9 670 | sunday 9 671 | fast 9 672 | chloe 9 673 | rained 9 674 | morning 9 675 | combined 9 676 | invited 9 677 | coffee 9 678 | rose 9 679 | kittens 9 680 | washing 9 681 | sand 9 682 | mall 9 683 | travels 9 684 | cookie 9 685 | traveled 9 686 | also 9 687 | stones 9 688 | halloween 9 689 | rooms 9 690 | cement 9 691 | helping 9 692 | anne 9 693 | carol 9 694 | katie 9 695 | ellen 9 696 | harvest 9 697 | bridget 9 698 | strawberries 9 699 | riding 9 700 | violet 9 701 | juan 9 702 | seats 9 703 | paul 9 704 | hair 9 705 | about 9 706 | monthly 9 707 | peppers 9 708 | percent 9 709 | budget 8 710 | faye 8 711 | room 8 712 | ernest 8 713 | travel 8 714 | order 8 715 | teresa 8 716 | dave 8 717 | save 8 718 | bottles 8 719 | yen 8 720 | vanessa 8 721 | meters 8 722 | pays 8 723 | pair 8 724 | charles 8 725 | rents 8 726 | april's 8 727 | cinnamon 8 728 | visit 8 729 | fly 8 730 | winter 8 731 | years 8 732 | decreased 8 733 | not 8 734 | james 8 735 | correct 8 736 | zoe 8 737 | lawn 8 738 | daily 8 739 | isabel 8 740 | comes 8 741 | oliver 8 742 | mark 8 743 | shopping 8 744 | ounces 8 745 | kimberly 8 746 | wheat 8 747 | nails 8 748 | pear 8 749 | pool 8 750 | full 8 751 | nina 8 752 | airplane 8 753 | putting 8 754 | its 8 755 | friday 8 756 | serve 8 757 | salmon 8 758 | measured 8 759 | taller 8 760 | recycling 8 761 | kilograms 8 762 | robin 8 763 | questions 8 764 | world 8 765 | scale 8 766 | block 8 767 | raisins 8 768 | recorded 8 769 | victor 8 770 | point 8 771 | onions 8 772 | bathing 8 773 | wedding 8 774 | acres 8 775 | material 8 776 | teams 8 777 | job 8 778 | trips 8 779 | cartons 8 780 | supply 8 781 | blood 8 782 | member 8 783 | ball 8 784 | loses 8 785 | garage 8 786 | pastries 8 787 | ear 8 788 | hiked 8 789 | baking 7 790 | men 7 791 | purchase 7 792 | rental 7 793 | meal 7 794 | sharon 7 795 | service 7 796 | snow 7 797 | bad 7 798 | picking 7 799 | country 7 800 | child 7 801 | defeated 7 802 | jerry 7 803 | jose 7 804 | jane 7 805 | picture 7 806 | scores 7 807 | potato 7 808 | adds 7 809 | wait 7 810 | contained 7 811 | attended 7 812 | plastic 7 813 | turned 7 814 | sells 7 815 | sure 7 816 | treasure 7 817 | collects 7 818 | william 7 819 | enough 7 820 | rosa 7 821 | heavier 7 822 | cd 7 823 | color 7 824 | stand 7 825 | road 7 826 | stars 7 827 | complete 7 828 | orchid 7 829 | harry 7 830 | actually 7 831 | mystery 7 832 | hard 7 833 | bumper 7 834 | play 7 835 | gold 7 836 | march 7 837 | arthur 7 838 | arcade 7 839 | larry 7 840 | steve 7 841 | magic 7 842 | farm 7 843 | playground 7 844 | shortest 7 845 | final 7 846 | subtracted 7 847 | brenda 7 848 | planted 7 849 | april 7 850 | value 7 851 | evelyn 7 852 | like 7 853 | chairs 7 854 | shed 7 855 | van 7 856 | spots 7 857 | construction 7 858 | rabbits 7 859 | four 6 860 | bike 6 861 | wednesday 6 862 | ned 6 863 | engineers 6 864 | coins 6 865 | want 6 866 | hot 6 867 | third 6 868 | vegetables 6 869 | fit 6 870 | weeks 6 871 | caterpillar 6 872 | milan 6 873 | forgot 6 874 | washed 6 875 | free 6 876 | soda 6 877 | stop 6 878 | rings 6 879 | tony 6 880 | trumpet 6 881 | catch 6 882 | tank 6 883 | seven 6 884 | months 6 885 | afternoon 6 886 | sodas 6 887 | necklaces 6 888 | bushels 6 889 | chip 6 890 | classroom 6 891 | shoes 6 892 | window 6 893 | fixed 6 894 | calories 6 895 | carry 6 896 | ring 6 897 | rented 6 898 | city 6 899 | sheet 6 900 | lunches 6 901 | craig 6 902 | hockey 6 903 | sean 6 904 | weed 6 905 | running 6 906 | theater 6 907 | bracelet 6 908 | certain 6 909 | sales 6 910 | missed 6 911 | original 6 912 | painter 6 913 | siamese 6 914 | vegetarian 6 915 | suits 6 916 | lemons 6 917 | hamburgers 6 918 | rentals 6 919 | installed 6 920 | todd 6 921 | fountain 6 922 | earns 6 923 | prairie 6 924 | cleaned 6 925 | eaten 6 926 | windows 6 927 | golf 6 928 | sleeve 6 929 | annie 6 930 | whole 6 931 | collected 6 932 | empty 6 933 | vans 6 934 | fleas 6 935 | piles 6 936 | strolled 6 937 | berries 6 938 | mower 6 939 | mowed 6 940 | greg 6 941 | camera 6 942 | vehicle 6 943 | rode 6 944 | tax 6 945 | pink 6 946 | scoop 6 947 | produced 6 948 | hippopotamus 6 949 | museum 6 950 | loves 6 951 | blades 6 952 | who 6 953 | planning 6 954 | bedroom 6 955 | computer 6 956 | harvested 6 957 | pants 6 958 | owns 6 959 | drink 6 960 | ashley 6 961 | builder 6 962 | five 6 963 | pepper 6 964 | whistles 6 965 | housing 6 966 | cells 6 967 | boom 6 968 | else 6 969 | friend's 5 970 | jack 5 971 | tired 5 972 | zach 5 973 | drew 5 974 | brings 5 975 | join 5 976 | gloria 5 977 | liter 5 978 | song 5 979 | machine 5 980 | diana 5 981 | clarence 5 982 | little 5 983 | returning 5 984 | albert 5 985 | marie 5 986 | mildred 5 987 | pocket 5 988 | blew 5 989 | noodles 5 990 | melissa 5 991 | yogurt 5 992 | asked 5 993 | households 5 994 | puts 5 995 | interest 5 996 | dvds 5 997 | charlie 5 998 | savings 5 999 | just 5 1000 | roadside 5 1001 | apart 5 1002 | shaped 5 1003 | jennifer 5 1004 | removes 5 1005 | sacks 5 1006 | jacket 5 1007 | coach 5 1008 | brown 5 1009 | discovered 5 1010 | drinks 5 1011 | marble 5 1012 | bob 5 1013 | live 5 1014 | basket 5 1015 | sorted 5 1016 | million 5 1017 | carnival 5 1018 | stuffed 5 1019 | starfish 5 1020 | saw 5 1021 | kevin 5 1022 | wandered 5 1023 | destroy 5 1024 | sheets 5 1025 | pumpkin 5 1026 | those 5 1027 | stacked 5 1028 | driven 5 1029 | no 5 1030 | samples 5 1031 | jake 5 1032 | furniture 5 1033 | christine 5 1034 | enemies 5 1035 | stone 5 1036 | elementary 5 1037 | carpenter 5 1038 | shelter 5 1039 | dish 5 1040 | aaron 5 1041 | fence 5 1042 | trick 5 1043 | contains 5 1044 | town 5 1045 | purchases 5 1046 | plane 5 1047 | egg 5 1048 | help 5 1049 | probability 5 1050 | travelling 5 1051 | everyone 5 1052 | debby 5 1053 | florist 5 1054 | miss 5 1055 | banana 5 1056 | treasures 5 1057 | b 5 1058 | enemy 5 1059 | x 5 1060 | pickup 5 1061 | lake 5 1062 | plants 5 1063 | ducks 5 1064 | sprinted 5 1065 | projects 5 1066 | bouncy 5 1067 | anna 5 1068 | oatmeal 5 1069 | daisies 5 1070 | rows 5 1071 | adults 5 1072 | tagalongs 5 1073 | income 5 1074 | lana 5 1075 | scarlett 5 1076 | plays 5 1077 | weren't 5 1078 | stephanie 5 1079 | apple 5 1080 | tomorrow 5 1081 | salad 5 1082 | worksheet 5 1083 | gumballs 5 1084 | length 5 1085 | shorts 5 1086 | bear 5 1087 | ralph 5 1088 | quit 5 1089 | quiz 5 1090 | drank 5 1091 | painted 5 1092 | vanilla 5 1093 | build 5 1094 | expand 5 1095 | own 5 1096 | socks 5 1097 | chris 5 1098 | planting 5 1099 | alloy 5 1100 | jane's 4 1101 | recycle 4 1102 | street 4 1103 | equals 4 1104 | jogging 4 1105 | joshua 4 1106 | adult 4 1107 | mr 4 1108 | my 4 1109 | organized 4 1110 | honey 4 1111 | david 4 1112 | nuts 4 1113 | record 4 1114 | trisha 4 1115 | elizabeth 4 1116 | lab 4 1117 | eugene 4 1118 | break 4 1119 | daniel 4 1120 | sheep 4 1121 | dodgeball 4 1122 | unbroken 4 1123 | luncheon 4 1124 | helen 4 1125 | project 4 1126 | iron 4 1127 | rides 4 1128 | though 4 1129 | metal 4 1130 | aunt 4 1131 | net 4 1132 | ears 4 1133 | stamps 4 1134 | we 4 1135 | fruits 4 1136 | against 4 1137 | gwen 4 1138 | bees 4 1139 | iesha 4 1140 | air 4 1141 | cracked 4 1142 | damaged 4 1143 | plates 4 1144 | smoothies 4 1145 | bobby 4 1146 | trombone 4 1147 | timothy's 4 1148 | scarves 4 1149 | magazines 4 1150 | initial 4 1151 | call 4 1152 | batman 4 1153 | unboxing 4 1154 | developers 4 1155 | began 4 1156 | neighbors 4 1157 | row 4 1158 | flash 4 1159 | answered 4 1160 | jogged 4 1161 | additional 4 1162 | sandcastle 4 1163 | sawed 4 1164 | shift 4 1165 | pints 4 1166 | sports 4 1167 | countertop 4 1168 | heart 4 1169 | valentines 4 1170 | december 4 1171 | sample 4 1172 | pave 4 1173 | candles 4 1174 | shiela 4 1175 | ended 4 1176 | lyric 4 1177 | torn 4 1178 | tori 4 1179 | profit 4 1180 | tulips 4 1181 | montoya 4 1182 | place 4 1183 | kimberly's 4 1184 | given 4 1185 | way 4 1186 | shirley 4 1187 | ann 4 1188 | stanley 4 1189 | wilted 4 1190 | ground 4 1191 | tailor 4 1192 | bracelets 4 1193 | stroll 4 1194 | aluminum 4 1195 | through 4 1196 | emily's 4 1197 | planet 4 1198 | multiplied 4 1199 | sacker 4 1200 | stream 4 1201 | pop 4 1202 | boat 4 1203 | production 4 1204 | acre 4 1205 | kenya 4 1206 | strawberry 4 1207 | handed 4 1208 | fridge 4 1209 | using 4 1210 | postcard 4 1211 | tower 4 1212 | willie 4 1213 | measuring 4 1214 | broken 4 1215 | shells 4 1216 | tiffany 4 1217 | lunchroom 4 1218 | pitcher 4 1219 | shannon 4 1220 | polar 4 1221 | brandy 4 1222 | mandy 4 1223 | parakeets 4 1224 | ron 4 1225 | large 4 1226 | jonah 4 1227 | ranger 4 1228 | kendra 4 1229 | campsite 4 1230 | held 4 1231 | logan 4 1232 | inquiries 4 1233 | flies 4 1234 | olivia 4 1235 | 2d 4 1236 | shipment 4 1237 | mittens 4 1238 | benjamin 4 1239 | computers 4 1240 | paving 4 1241 | superbowl 4 1242 | dina 4 1243 | meadow 4 1244 | hotel 4 1245 | muffs 4 1246 | built 4 1247 | cover 4 1248 | cell 4 1249 | giant 4 1250 | silk 4 1251 | catches 4 1252 | kylie 4 1253 | allie 4 1254 | cubes 4 1255 | demand 4 1256 | frozen 4 1257 | uses 4 1258 | beanie 4 1259 | makes 4 1260 | chemistry 4 1261 | inviting 4 1262 | collect 4 1263 | popular 4 1264 | clown 4 1265 | rolls 4 1266 | question 4 1267 | junior 4 1268 | clips 4 1269 | mustard 4 1270 | tablespoon 4 1271 | fresh 4 1272 | cody 4 1273 | eve 4 1274 | rivers 4 1275 | carla 4 1276 | paintings 4 1277 | experiment 4 1278 | bird 4 1279 | gathered 4 1280 | punch 4 1281 | remains 4 1282 | few 4 1283 | carvings 4 1284 | parrots 4 1285 | bones 4 1286 | skirt 4 1287 | cabbage 4 1288 | light 4 1289 | bakery 4 1290 | perfect 4 1291 | tyler 4 1292 | choose 4 1293 | billy 4 1294 | our 4 1295 | attend 4 1296 | geometry 4 1297 | produce 4 1298 | kendall 4 1299 | owner 4 1300 | herself 4 1301 | collecting 4 1302 | able 4 1303 | mileage 4 1304 | recess 4 1305 | text 4 1306 | chapters 4 1307 | debate 4 1308 | based 4 1309 | chips 4 1310 | taxes 4 1311 | nutmeg 4 1312 | packed 4 1313 | joe 4 1314 | jim 4 1315 | snowfall 4 1316 | jelly 4 1317 | dust 4 1318 | stored 4 1319 | lincoln 4 1320 | almonds 4 1321 | peter 4 1322 | jeremy 4 1323 | brennan 4 1324 | getting 4 1325 | cranberry 4 1326 | brownies 4 1327 | north 4 1328 | brand 4 1329 | places 4 1330 | jenny 4 1331 | circus 4 1332 | erik 4 1333 | waitress 4 1334 | eric 4 1335 | corporation 4 1336 | 4d 4 1337 | teaspoon 3 1338 | upstream 3 1339 | jason's 3 1340 | fred's 3 1341 | omar 3 1342 | golden 3 1343 | julia 3 1344 | guests 3 1345 | charge 3 1346 | type 3 1347 | movies 3 1348 | route 3 1349 | january 3 1350 | lan 3 1351 | becky 3 1352 | popsicle 3 1353 | office 3 1354 | mary's 3 1355 | fix 3 1356 | silver 3 1357 | lillian 3 1358 | rocks 3 1359 | trading 3 1360 | grapes 3 1361 | greasy 3 1362 | hike 3 1363 | even 3 1364 | lewis 3 1365 | bonnie 3 1366 | odometer 3 1367 | cousins 3 1368 | watermelon 3 1369 | onboard 3 1370 | grandmother 3 1371 | rolled 3 1372 | cousin 3 1373 | seashell 3 1374 | dots 3 1375 | sheridan 3 1376 | several 3 1377 | grows 3 1378 | kept 3 1379 | cherry 3 1380 | josh 3 1381 | gift 3 1382 | born 3 1383 | joseph 3 1384 | uncle 3 1385 | sticks 3 1386 | broke 3 1387 | walking 3 1388 | grape 3 1389 | bicycled 3 1390 | worm 3 1391 | bacteria 3 1392 | cargo 3 1393 | supplies 3 1394 | passengers 3 1395 | wanda 3 1396 | classrooms 3 1397 | kenneth 3 1398 | deposit 3 1399 | offers 3 1400 | recipes 3 1401 | hancock 3 1402 | increase 3 1403 | pamela 3 1404 | gram 3 1405 | bahamas 3 1406 | coats 3 1407 | san 3 1408 | librarian 3 1409 | beth 3 1410 | dye 3 1411 | reading 3 1412 | across 3 1413 | spoon' 3 1414 | pcs 3 1415 | pilot 3 1416 | these 3 1417 | pat 3 1418 | dealer 3 1419 | couldn't 3 1420 | business 3 1421 | diet 3 1422 | 'the 3 1423 | neighbor 3 1424 | mixed 3 1425 | coupon 3 1426 | gary 3 1427 | mole' 3 1428 | poured 3 1429 | rush 3 1430 | age 3 1431 | required 3 1432 | johnny 3 1433 | moved 3 1434 | walks 3 1435 | spends 3 1436 | tanner 3 1437 | thursday 3 1438 | returned 3 1439 | cable 3 1440 | louis 3 1441 | action 3 1442 | estimate 3 1443 | attendance 3 1444 | taken 3 1445 | landed 3 1446 | created 3 1447 | hamburger 3 1448 | backyard 3 1449 | susan 3 1450 | scott 3 1451 | dolls 3 1452 | 'whack 3 1453 | cupcake 3 1454 | tomatoes 3 1455 | weight 3 1456 | douglas 3 1457 | algae 3 1458 | airport 3 1459 | copper 3 1460 | story 3 1461 | jet 3 1462 | least 3 1463 | station 3 1464 | couch 3 1465 | without 3 1466 | samoas 3 1467 | randy 3 1468 | quizzes 3 1469 | caramel 3 1470 | see 3 1471 | sea 3 1472 | origami 3 1473 | lexie's 3 1474 | jeff 3 1475 | along 3 1476 | priced 3 1477 | anthony 3 1478 | katherine 3 1479 | batch 3 1480 | rope 3 1481 | pack 3 1482 | repaved 3 1483 | voters 3 1484 | rid 3 1485 | franklin 3 1486 | older 3 1487 | gems 3 1488 | pinball 3 1489 | cheryl 3 1490 | donna 3 1491 | fault 3 1492 | sprint 3 1493 | carob 3 1494 | tommy 3 1495 | handles 3 1496 | sections 3 1497 | ball' 3 1498 | prepared 3 1499 | dvd 3 1500 | rinse 3 1501 | evenly 3 1502 | groceries 3 1503 | michael 3 1504 | nicholas 3 1505 | baskets 3 1506 | jonathan 3 1507 | billed 3 1508 | animals 3 1509 | pour 3 1510 | crickets 3 1511 | 'skee 3 1512 | ronald 3 1513 | pigs 3 1514 | swimming 3 1515 | counted 3 1516 | marsh 3 1517 | snake 3 1518 | slide 3 1519 | betty 3 1520 | glasses 3 1521 | haley's 3 1522 | wander 3 1523 | harold 3 1524 | molly 3 1525 | visited 3 1526 | border 3 1527 | dishes 3 1528 | kristi 3 1529 | linda 3 1530 | snowed 3 1531 | eight 3 1532 | invests 3 1533 | ( 3 1534 | fans 3 1535 | overall 3 1536 | trucks 3 1537 | figures 3 1538 | marta 3 1539 | addition 3 1540 | bathtub 3 1541 | bucks 3 1542 | ) 3 1543 | parts 3 1544 | well 3 1545 | drawing 3 1546 | fishing 3 1547 | increased 3 1548 | checking 3 1549 | works 3 1550 | soft 3 1551 | spilled 3 1552 | strategy 3 1553 | delivery 3 1554 | jesse 3 1555 | francisco 3 1556 | star 3 1557 | june 3 1558 | nintendo 3 1559 | container 3 1560 | swirls 2 1561 | andre 2 1562 | whose 2 1563 | presents 2 1564 | rescue 2 1565 | activation 2 1566 | cornfields 2 1567 | minerva 2 1568 | special 2 1569 | isabella's 2 1570 | feathers 2 1571 | japanese 2 1572 | reported 2 1573 | apartment 2 1574 | daughter 2 1575 | items 2 1576 | divide 2 1577 | unit 2 1578 | marine 2 1579 | debby's 2 1580 | blueberry 2 1581 | relay 2 1582 | me 2 1583 | gasoline 2 1584 | mechanic 2 1585 | oceanside 2 1586 | dough 2 1587 | lap 2 1588 | salon 2 1589 | deck 2 1590 | japan 2 1591 | complex 2 1592 | conner 2 1593 | represents 2 1594 | rocky 2 1595 | carlos 2 1596 | alec 2 1597 | sears 2 1598 | driving 2 1599 | open 2 1600 | bat 2 1601 | content 2 1602 | 7 2 1603 | comic 2 1604 | anyone 2 1605 | ten 2 1606 | intermediate 2 1607 | percentage 2 1608 | estimates 2 1609 | cereal 2 1610 | practiced 2 1611 | begins 2 1612 | kenji 2 1613 | spaceship 2 1614 | oscar's 2 1615 | glass 2 1616 | releases 2 1617 | concrete 2 1618 | brandon 2 1619 | client 2 1620 | derek 2 1621 | niece 2 1622 | y 2 1623 | medical 2 1624 | renting 2 1625 | insects 2 1626 | colors 2 1627 | earth 2 1628 | constant 2 1629 | fields 2 1630 | carrier 2 1631 | checks 2 1632 | mitch 2 1633 | ira 2 1634 | roller 2 1635 | brad 2 1636 | peacefully 2 1637 | bikinis 2 1638 | basic 2 1639 | expected 2 1640 | tallest 2 1641 | sunshine 2 1642 | worker 2 1643 | reciprocal 2 1644 | suppose 2 1645 | armband 2 1646 | b's 2 1647 | basketballs 2 1648 | ella 2 1649 | overs 2 1650 | darnel 2 1651 | kyle 2 1652 | ocean 2 1653 | materials 2 1654 | spencer 2 1655 | rubies 2 1656 | sporting 2 1657 | grades 2 1658 | performance 2 1659 | right 2 1660 | zachary's 2 1661 | crowns 2 1662 | purple 2 1663 | corn 2 1664 | post 2 1665 | plum 2 1666 | connected 2 1667 | managers 2 1668 | aphids 2 1669 | sow 2 1670 | soy 2 1671 | east 2 1672 | america 2 1673 | width 2 1674 | garments 2 1675 | roadster's 2 1676 | hound's 2 1677 | holding 2 1678 | papers 2 1679 | variable 2 1680 | jones 2 1681 | packets 2 1682 | classmate 2 1683 | chain 2 1684 | roy 2 1685 | skim 2 1686 | chair 2 1687 | bicycles 2 1688 | a's 2 1689 | hannah 2 1690 | cunningham 2 1691 | ezra 2 1692 | coral 2 1693 | remain 2 1694 | bargin 2 1695 | sweaters 2 1696 | alone 2 1697 | lizette 2 1698 | boa 2 1699 | doris 2 1700 | macintosh 2 1701 | marked 2 1702 | pitchers 2 1703 | perished 2 1704 | rainfall 2 1705 | milford 2 1706 | club 2 1707 | clients 2 1708 | goods 2 1709 | cap 2 1710 | soup 2 1711 | following 2 1712 | terrell 2 1713 | kaleen 2 1714 | skated 2 1715 | sundae 2 1716 | ensure 2 1717 | pint 2 1718 | crashes 2 1719 | membership 2 1720 | vases 2 1721 | man 2 1722 | irwin 2 1723 | irene 2 1724 | cola 2 1725 | gem 2 1726 | accommodate 2 1727 | peered 2 1728 | bowling 2 1729 | diane's 2 1730 | jackson 2 1731 | opened 2 1732 | factory 2 1733 | internet 2 1734 | clowns 2 1735 | pizzeria 2 1736 | walnuts 2 1737 | milburg 2 1738 | remainder 2 1739 | marla 2 1740 | spending 2 1741 | gordon 2 1742 | earache 2 1743 | saving 2 1744 | molded 2 1745 | returns 2 1746 | nathan 2 1747 | transferred 2 1748 | remained 2 1749 | allen 2 1750 | louis's 2 1751 | superman 2 1752 | speakers 2 1753 | mustang 2 1754 | cheesecake 2 1755 | printed 2 1756 | amanda's 2 1757 | steady 2 1758 | hungry 2 1759 | madison 2 1760 | bedside 2 1761 | drawings 2 1762 | fifth 2 1763 | lansing 2 1764 | nell 2 1765 | amanda 2 1766 | picnic 2 1767 | sport 2 1768 | camping 2 1769 | irwin's 2 1770 | frisky 2 1771 | bricks 2 1772 | pot 2 1773 | colony 2 1774 | learning 2 1775 | geese 2 1776 | west 2 1777 | andrew 2 1778 | goran 2 1779 | covers 2 1780 | installation 2 1781 | shops 2 1782 | metric 2 1783 | sleeping 2 1784 | jeffrey 2 1785 | drain 2 1786 | solve 2 1787 | model 2 1788 | charged 2 1789 | being 2 1790 | alissa 2 1791 | gavin 2 1792 | weekly 2 1793 | around 2 1794 | patrick 2 1795 | souvenirs 2 1796 | reduced 2 1797 | stopped 2 1798 | beka 2 1799 | drums 2 1800 | leftover 2 1801 | manufacturer 2 1802 | favorite 2 1803 | act 2 1804 | log 2 1805 | faster 2 1806 | october 2 1807 | manuel 2 1808 | gone 2 1809 | hound 2 1810 | mathematics 2 1811 | included 2 1812 | dyed 2 1813 | seat 2 1814 | once 2 1815 | starting 2 1816 | cortland 2 1817 | mason 2 1818 | program 2 1819 | safety 2 1820 | woman 2 1821 | tent 2 1822 | kyoko 2 1823 | salesperson 2 1824 | roadster 2 1825 | maggie 2 1826 | neighborhood 2 1827 | tee 2 1828 | investment 2 1829 | dirt 2 1830 | aiyanna 2 1831 | scientists 2 1832 | racing 2 1833 | public 2 1834 | deborah 2 1835 | christian 2 1836 | theresa 2 1837 | november 2 1838 | publisher 2 1839 | sister's 2 1840 | petroleum 2 1841 | competitor 2 1842 | 6 2 1843 | yardley 2 1844 | ellison 2 1845 | none 2 1846 | sweeps 2 1847 | male 2 1848 | minimum 2 1849 | numbers 2 1850 | backpacking 2 1851 | adventure 2 1852 | response 2 1853 | bugs 2 1854 | volleyball 2 1855 | roommates 2 1856 | charlie's 2 1857 | nicholas's 2 1858 | september 2 1859 | style 2 1860 | gerald 2 1861 | return 2 1862 | bryan 2 1863 | dale's 2 1864 | biscuits 2 1865 | barrels 2 1866 | delicious 2 1867 | reduce 2 1868 | campground 2 1869 | studying 2 1870 | heights 2 1871 | lawrence 2 1872 | darius 2 1873 | terrible 2 1874 | feed 2 1875 | doughnuts 2 1876 | passed 2 1877 | mobiles 2 1878 | listed 2 1879 | paul's 2 1880 | storm 2 1881 | norma 2 1882 | vince's 2 1883 | zachary 2 1884 | toward 2 1885 | dana 2 1886 | seth 2 1887 | concentration 2 1888 | shelby 2 1889 | sandwiches 2 1890 | tool 2 1891 | flute 2 1892 | most 2 1893 | pipes 2 1894 | thomas 2 1895 | jellybeans 2 1896 | cds 2 1897 | coaster 2 1898 | blender 2 1899 | gains 2 1900 | snowstorm 2 1901 | arrives 2 1902 | heading 2 1903 | libraries 2 1904 | consecutive 2 1905 | paco's 2 1906 | europe 2 1907 | untouched 2 1908 | aircraft 2 1909 | study 2 1910 | simple 2 1911 | stamp 2 1912 | due 2 1913 | flight 2 1914 | convert 2 1915 | booklets 2 1916 | enrollment 2 1917 | pace 2 1918 | paco 2 1919 | hoping 2 1920 | reads 2 1921 | grant 2 1922 | newberg 2 1923 | classmates 2 1924 | cleaning 2 1925 | recent 2 1926 | canned 2 1927 | hotdog 2 1928 | shape 2 1929 | constrictor 2 1930 | cherries 2 1931 | parents 2 1932 | wings 2 1933 | message 2 1934 | glove 2 1935 | spring 2 1936 | prom 2 1937 | reach 2 1938 | martin 2 1939 | certificate 2 1940 | classics 2 1941 | within 2 1942 | frames 2 1943 | kathleen 2 1944 | infected 2 1945 | suit 2 1946 | toothfairy 2 1947 | mountains 2 1948 | reef 2 1949 | nieces 2 1950 | kathryn 2 1951 | amounts 2 1952 | dale 2 1953 | weights 2 1954 | requires 2 1955 | farms 2 1956 | legos 2 1957 | entire 2 1958 | barbara 2 1959 | carter 2 1960 | elise 2 1961 | chicago 2 1962 | harvests 2 1963 | richmond 2 1964 | capital 2 1965 | respectively 2 1966 | growing 2 1967 | tires 2 1968 | named 2 1969 | nearest 2 1970 | win 2 1971 | decrease 2 1972 | names 2 1973 | lime 2 1974 | snacks 2 1975 | carrying 2 1976 | baby 2 1977 | goal 2 1978 | drill 2 1979 | meet 2 1980 | kenny 2 1981 | professor 2 1982 | sit 2 1983 | brian 2 1984 | animal 2 1985 | administrator 2 1986 | brenda's 2 1987 | realized 2 1988 | necklace 2 1989 | bins 2 1990 | shiela's 2 1991 | isha's 2 1992 | pecans 2 1993 | gumdrops 2 1994 | weather 2 1995 | janet's 2 1996 | jill 2 1997 | york 2 1998 | wading 2 1999 | hilt's 2 2000 | pots 2 2001 | renovation 2 2002 | attack 2 2003 | gear 2 2004 | quarry 2 2005 | ben 2 2006 | bee 2 2007 | comfortably 2 2008 | continents 2 2009 | pupils 2 2010 | sandbox 2 2011 | mariela 2 2012 | soap 2 2013 | allow 2 2014 | neighboring 2 2015 | scrambled 2 2016 | chicken 2 2017 | ethan 2 2018 | local 2 2019 | jacqueline 2 2020 | watercolor 2 2021 | bead 2 2022 | sowing 2 2023 | married 2 2024 | available 2 2025 | national 2 2026 | powder 2 2027 | cindy's 2 2028 | robin's 2 2029 | taking 2 2030 | cm 2 2031 | wall 2 2032 | willy 2 2033 | vince 2 2034 | multi 2 2035 | freeport 2 2036 | sue's 2 2037 | helper 2 2038 | hardware 2 2039 | lambs 2 2040 | paula 2 2041 | nancy's 2 2042 | magician 2 2043 | paycheck 2 2044 | ingredients 2 2045 | latoya 2 2046 | toucans 2 2047 | biologist 2 2048 | lauren 2 2049 | patricia 2 2050 | hall 2 2051 | jars 2 2052 | tail 2 2053 | lose 2 2054 | sandcastles 2 2055 | carnations 2 2056 | detergent 2 2057 | justin 2 2058 | carolyn 2 2059 | trunks 2 2060 | female 2 2061 | utility 2 2062 | mcmoran 2 2063 | skating 2 2064 | replica 2 2065 | contest 2 2066 | misha 2 2067 | stay 2 2068 | trenton 1 2069 | saves 1 2070 | nursery 1 2071 | calculate 1 2072 | swam 1 2073 | under 1 2074 | downstream 1 2075 | fishbowl 1 2076 | fireplace 1 2077 | errands 1 2078 | companies 1 2079 | venus 1 2080 | ups 1 2081 | bicycle 1 2082 | shining 1 2083 | petri 1 2084 | above 1 2085 | tips 1 2086 | grandma's 1 2087 | mel 1 2088 | represented 1 2089 | obtained 1 2090 | changed 1 2091 | credit 1 2092 | depreciated 1 2093 | karin 1 2094 | changes 1 2095 | touchdowns 1 2096 | sweater 1 2097 | negative 1 2098 | pecan 1 2099 | lukas 1 2100 | lillian's 1 2101 | carol's 1 2102 | tornadoes 1 2103 | consumer 1 2104 | answer 1 2105 | albert's 1 2106 | lot 1 2107 | president 1 2108 | types 1 2109 | oliver's 1 2110 | sets 1 2111 | recieved 1 2112 | brecknock 1 2113 | muffin 1 2114 | expects 1 2115 | personal 1 2116 | writing 1 2117 | 87% 1 2118 | snakes 1 2119 | stockbrokers 1 2120 | boiled 1 2121 | millions 1 2122 | hogan 1 2123 | flows 1 2124 | checked 1 2125 | lollipop 1 2126 | headwind 1 2127 | messages 1 2128 | moving 1 2129 | caught 1 2130 | electronic 1 2131 | hawks 1 2132 | fiction 1 2133 | too 1 2134 | cushions 1 2135 | potting 1 2136 | showed 1 2137 | likely 1 2138 | seated 1 2139 | msrp 1 2140 | mini 1 2141 | boston 1 2142 | bleachers 1 2143 | chest 1 2144 | bruce 1 2145 | sue 1 2146 | jean 1 2147 | potluck 1 2148 | treats 1 2149 | released 1 2150 | grove 1 2151 | dos 1 2152 | random 1 2153 | radio 1 2154 | toast 1 2155 | submit 1 2156 | louise 1 2157 | aldo 1 2158 | coast 1 2159 | tammy 1 2160 | runs 1 2161 | sara's 1 2162 | countries 1 2163 | bay 1 2164 | piggy 1 2165 | told 1 2166 | decides 1 2167 | sharpens 1 2168 | jerseys 1 2169 | best 1 2170 | pets 1 2171 | hayley's 1 2172 | souvenir 1 2173 | tripled 1 2174 | aquarium 1 2175 | cot 1 2176 | met 1 2177 | blimp 1 2178 | participating 1 2179 | 2nd 1 2180 | commission 1 2181 | entered 1 2182 | dozens 1 2183 | pro 1 2184 | life 1 2185 | katie's 1 2186 | teachers 1 2187 | buried 1 2188 | cone 1 2189 | caesar 1 2190 | grown 1 2191 | sailors 1 2192 | meets 1 2193 | hang 1 2194 | anil 1 2195 | kim 1 2196 | dylan 1 2197 | photo 1 2198 | distribute 1 2199 | assigned 1 2200 | sunflower 1 2201 | jeweler 1 2202 | potential 1 2203 | hat 1 2204 | julie 1 2205 | carrie's 1 2206 | silvergrove 1 2207 | digimon 1 2208 | crown 1 2209 | topping 1 2210 | election 1 2211 | everything 1 2212 | payed 1 2213 | lindsey's 1 2214 | olsen 1 2215 | paula's 1 2216 | hospital 1 2217 | jacques 1 2218 | puzzle 1 2219 | approximate 1 2220 | payment 1 2221 | crews 1 2222 | halls 1 2223 | lowest 1 2224 | head 1 2225 | tigers 1 2226 | removed 1 2227 | absent 1 2228 | builds 1 2229 | maximum 1 2230 | productions 1 2231 | decorate 1 2232 | servings 1 2233 | pricing 1 2234 | bob's 1 2235 | classic 1 2236 | cobbler 1 2237 | mold 1 2238 | floor 1 2239 | whereas 1 2240 | anna's 1 2241 | test 1 2242 | tess 1 2243 | lollipops 1 2244 | juices 1 2245 | yardage 1 2246 | fell 1 2247 | invested 1 2248 | grapevines 1 2249 | diamonds 1 2250 | younger 1 2251 | mike's 1 2252 | wendy's 1 2253 | horseback 1 2254 | laura 1 2255 | manager 1 2256 | marks 1 2257 | melon 1 2258 | upriver 1 2259 | prepaid 1 2260 | luxury 1 2261 | item 1 2262 | brine 1 2263 | jessica's 1 2264 | heine 1 2265 | current 1 2266 | booklet 1 2267 | hummer 1 2268 | frosting 1 2269 | arcadia 1 2270 | allen's 1 2271 | love 1 2272 | stockton 1 2273 | ipo 1 2274 | seashore 1 2275 | 1st 1 2276 | russell 1 2277 | sharpen 1 2278 | checkout 1 2279 | effort 1 2280 | judy 1 2281 | teaspoons 1 2282 | council 1 2283 | dennis 1 2284 | map 1 2285 | such 1 2286 | liquid 1 2287 | arrange 1 2288 | si 1 2289 | publish 1 2290 | serving 1 2291 | displayed 1 2292 | whats 1 2293 | cold 1 2294 | tourists 1 2295 | rake 1 2296 | discuss 1 2297 | wong 1 2298 | square 1 2299 | living 1 2300 | rachel's 1 2301 | jockey 1 2302 | butterflies 1 2303 | think 1 2304 | brian's 1 2305 | sock 1 2306 | kathy's 1 2307 | grove's 1 2308 | directly 1 2309 | paige's 1 2310 | valentine's 1 2311 | bite 1 2312 | milage 1 2313 | resulted 1 2314 | wide 1 2315 | unfortunately 1 2316 | lexi 1 2317 | calra 1 2318 | manufacture 1 2319 | alley 1 2320 | worms 1 2321 | bonnie's 1 2322 | equipment 1 2323 | animation 1 2324 | butterfly 1 2325 | begin 1 2326 | opposite 1 2327 | track 1 2328 | staffed 1 2329 | multiply 1 2330 | fishbowls 1 2331 | adolfo 1 2332 | lexi's 1 2333 | snack 1 2334 | proportion 1 2335 | regarding 1 2336 | artist 1 2337 | husband 1 2338 | farmers 1 2339 | newspapers 1 2340 | bougainvillea 1 2341 | alyssa's 1 2342 | molds 1 2343 | moment 1 2344 | olsen's 1 2345 | marvin 1 2346 | regional 1 2347 | spare 1 2348 | karin's 1 2349 | hudson 1 2350 | tub 1 2351 | cities 1 2352 | tour 1 2353 | berry 1 2354 | wheels 1 2355 | period 1 2356 | sampling 1 2357 | maintained 1 2358 | chalet 1 2359 | ruby 1 2360 | paying 1 2361 | n't 1 2362 | soil 1 2363 | author 1 2364 | shifts 1 2365 | semesters 1 2366 | pan 1 2367 | closest 1 2368 | drives 1 2369 | scientist 1 2370 | tradition 1 2371 | markup 1 2372 | fixing 1 2373 | nearby 1 2374 | hayley 1 2375 | blow 1 2376 | real 1 2377 | marcus 1 2378 | ruler 1 2379 | betty's 1 2380 | rebecca 1 2381 | christina 1 2382 | greeting 1 2383 | audience 1 2384 | drainage 1 2385 | gross 1 2386 | mph 1 2387 | ryan 1 2388 | stops 1 2389 | nicole 1 2390 | seedlings 1 2391 | bianca's 1 2392 | mixes 1 2393 | researching 1 2394 | determine 1 2395 | hen 1 2396 | bubble 1 2397 | cabinet 1 2398 | bookstore 1 2399 | arranged 1 2400 | intermission 1 2401 | wholesale 1 2402 | assume 1 2403 | bicycling 1 2404 | includes 1 2405 | terry 1 2406 | invest 1 2407 | disc 1 2408 | tours 1 2409 | blueberries 1 2410 | katherine's 1 2411 | azaleas 1 2412 | fat 1 2413 | fall 1 2414 | labor 1 2415 | becky's 1 2416 | dinosaur 1 2417 | ted 1 2418 | past 1 2419 | pass 1 2420 | abe 1 2421 | movement 1 2422 | directions 1 2423 | search 1 2424 | immigrated 1 2425 | scarlett's 1 2426 | producing 1 2427 | include 1 2428 | phillip 1 2429 | nine 1 2430 | sent 1 2431 | states 1 2432 | dress 1 2433 | gino 1 2434 | inventory 1 2435 | brett 1 2436 | coming 1 2437 | coat 1 2438 | patio 1 2439 | pans 1 2440 | rounded 1 2441 | radios 1 2442 | clarinet 1 2443 | hundredth 1 2444 | overhead 1 2445 | late 1 2446 | hunter 1 2447 | inequality 1 2448 | grocer 1 2449 | banquet 1 2450 | hive 1 2451 | alcohol 1 2452 | robert 1 2453 | since 1 2454 | granola 1 2455 | paradise 1 2456 | print 1 2457 | beginning 1 2458 | producers 1 2459 | faucet 1 2460 | car's 1 2461 | pure 1 2462 | thereafter 1 2463 | cade 1 2464 | passes 1 2465 | mildred's 1 2466 | rates 1 2467 | jordan 1 2468 | authors 1 2469 | grace 1 2470 | double 1 2471 | tricycles 1 2472 | booth 1 2473 | ages 1 2474 | virus 1 2475 | seasons 1 2476 | salary 1 2477 | performances 1 2478 | mileable 1 2479 | sumata 1 2480 | crayon 1 2481 | melt 1 2482 | carefully 1 2483 | impact 1 2484 | 8 1 2485 | columns 1 2486 | flowing 1 2487 | merchandise 1 2488 | river 1 2489 | set 1 2490 | advertised 1 2491 | individual 1 2492 | rita 1 2493 | recently 1 2494 | annual 1 2495 | repainted 1 2496 | loan 1 2497 | guzman 1 2498 | likes 1 2499 | expensive 1 2500 | ralph's 1 2501 | finally 1 2502 | publishing 1 2503 | create 1 2504 | mikey 1 2505 | dug 1 2506 | melanie's 1 2507 | joline 1 2508 | kathy 1 2509 | lana's 1 2510 | abe's 1 2511 | brokers 1 2512 | mitch's 1 2513 | tess's 1 2514 | styles 1 2515 | itself 1 2516 | triple 1 2517 | ready 1 2518 | south 1 2519 | molding 1 2520 | ruth 1 2521 | allyson 1 2522 | leopard 1 2523 | helped 1 2524 | dancing 1 2525 | continent 1 2526 | remaining 1 2527 | unlimited 1 2528 | children's 1 2529 | yields 1 2530 | cones 1 2531 | gumdrop 1 2532 | lexie 1 2533 | stables 1 2534 | debra 1 2535 | '52 1 2536 | jean's 1 2537 | subtract 1 2538 | range 1 2539 | messaging 1 2540 | chocolates 1 2541 | significant 1 2542 | aliyah 1 2543 | steven 1 2544 | lesson 1 2545 | impressed 1 2546 | placing 1 2547 | syllabus 1 2548 | himself 1 2549 | lino 1 2550 | cloth 1 2551 | toucan 1 2552 | pickers 1 2553 | entrance 1 2554 | single 1 2555 | cotton 1 2556 | afford 1 2557 | department 1 2558 | lena 1 2559 | m&m's 1 2560 | cremes 1 2561 | leaf 1 2562 | land 1 2563 | geraldine 1 2564 | enrolled 1 2565 | rabbit 1 2566 | jovana 1 2567 | results 1 2568 | desserts 1 2569 | kate 1 2570 | send 1 2571 | gravel 1 2572 | dessert 1 2573 | fewer 1 2574 | race 1 2575 | shelby's 1 2576 | rack 1 2577 | averaged 1 2578 | odd 1 2579 | elisa 1 2580 | hourly 1 2581 | ; 1 2582 | exercise 1 2583 | let 1 2584 | great 1 2585 | bookstores 1 2586 | ceasar 1 2587 | crazy 1 2588 | limb 1 2589 | patrol 1 2590 | figure 1 2591 | consumption 1 2592 | drops 1 2593 | averages 1 2594 | wearing 1 2595 | richmond's 1 2596 | enrique 1 2597 | united 1 2598 | varies 1 2599 | racks 1 2600 | realizes 1 2601 | meter 1 2602 | including 1 2603 | suzie 1 2604 | warren 1 2605 | write 1 2606 | blake 1 2607 | holiday 1 2608 | greater 1 2609 | neale 1 2610 | scenic 1 2611 | university 1 2612 | wafting 1 2613 | patch 1 2614 | tenth 1 2615 | dania 1 2616 | dictionary 1 2617 | completely 1 2618 | retriever 1 2619 | overtake 1 2620 | prepare 1 2621 | area 1 2622 | skateboard 1 2623 | retail 1 2624 | anita 1 2625 | called; 1 2626 | sack 1 2627 | spelling 1 2628 | shell 1 2629 | repaving 1 2630 | lion 1 2631 | bed 1 2632 | spurs 1 2633 | julian 1 2634 | tessa 1 2635 | contact 1 2636 | relatives 1 2637 | camped 1 2638 | cleats 1 2639 | looked 1 2640 | shannon's 1 2641 | jazmin 1 2642 | dorothy 1 2643 | sunflowers 1 2644 | achieve 1 2645 | move 1 2646 | handle 1 2647 | watching 1 2648 | bean 1 2649 | joins 1 2650 | cycles 1 2651 | stations 1 2652 | acquired 1 2653 | packet 1 2654 | smallest 1 2655 | neither 1 2656 | weighing 1 2657 | deliver 1 2658 | rinsed 1 2659 | jog 1 2660 | figured 1 2661 | maggi 1 2662 | benny's 1 2663 | jersey 1 2664 | wear 1 2665 | denise 1 2666 | treat 1 2667 | league 1 2668 | pastry 1 2669 | airplanes 1 2670 | bulk 1 2671 | present 1 2672 | homes 1 2673 | rectangular 1 2674 | wild 1 2675 | draining 1 2676 | matthew 1 2677 | northwest 1 2678 | upon 1 2679 | center 1 2680 | thought 1 2681 | english 1 2682 | emporium 1 2683 | carrie 1 2684 | obtain 1 2685 | arriving 1 2686 | earthquakes 1 2687 | identical 1 2688 | tests 1 2689 | government 1 2690 | increases 1 2691 | know 1 2692 | height 1 2693 | pier 1 2694 | because 1 2695 | searching 1 2696 | leah 1 2697 | assuming 1 2698 | mark's 1 2699 | pasta 1 2700 | actual 1 2701 | roden 1 2702 | toppings 1 2703 | christian's 1 2704 | individually 1 2705 | h1 1 2706 | catherine 1 2707 | transfer 1 2708 | snyder 1 2709 | overtime 1 2710 | gain 1 2711 | foster 1 2712 | kelly's 1 2713 | coffees 1 2714 | joan's 1 2715 | cookbook 1 2716 | 8th 1 2717 | -------------------------------------------------------------------------------- /pics/graph2tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/Graph2Tree/04e5b96134816037aa0dfb41e39fa4f9d60f099d/pics/graph2tree.png -------------------------------------------------------------------------------- /pics/pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/Graph2Tree/04e5b96134816037aa0dfb41e39fa4f9d60f099d/pics/pic1.png -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/Graph2Tree/04e5b96134816037aa0dfb41e39fa4f9d60f099d/src/__init__.py -------------------------------------------------------------------------------- /src/data_utils.py: -------------------------------------------------------------------------------- 1 | import math 2 | import tree 3 | import torch 4 | import sympy 5 | import random 6 | import graph_utils 7 | 8 | import numpy as np 9 | import pickle as pkl 10 | 11 | from random import randint 12 | from operator import itemgetter 13 | from sympy.parsing.sympy_parser import parse_expr 14 | 15 | 16 | class SymbolsManager(): 17 | def __init__(self, whether_add_special_tags): 18 | self.symbol2idx = {} 19 | self.idx2symbol = {} 20 | self.vocab_size = 0 21 | self.whether_add_special_tags = whether_add_special_tags 22 | if whether_add_special_tags: 23 | # PAD: padding token = 0 24 | self.add_symbol('

') 25 | # GO: start token = 1 26 | self.add_symbol('') 27 | # EOS: end token = 2 28 | self.add_symbol('') 29 | # UNK: unknown token = 3 30 | self.add_symbol('') 31 | # NON: non-terminal token = 4 32 | self.add_symbol('') 33 | 34 | def add_symbol(self,s): 35 | if s not in self.symbol2idx: 36 | self.symbol2idx[s] = self.vocab_size 37 | self.idx2symbol[self.vocab_size] = s 38 | self.vocab_size += 1 39 | return self.symbol2idx[s] 40 | 41 | def get_symbol_idx(self,s): 42 | if s not in self.symbol2idx: 43 | if self.whether_add_special_tags: 44 | return self.symbol2idx[''] 45 | else: 46 | print("not reached!") 47 | return 0 48 | return self.symbol2idx[s] 49 | 50 | def get_idx_symbol(self, idx): 51 | if idx not in self.idx2symbol: 52 | return '' 53 | return self.idx2symbol[idx] 54 | 55 | def init_from_file(self, fn, min_freq, max_vocab_size): 56 | # the vocab file is sorted by word_freq 57 | print "loading vocabulary file: {}".format(fn) 58 | with open(fn,"r") as f: 59 | for line in f: 60 | l_list = line.strip().split('\t') 61 | c = int(l_list[1]) 62 | if c >= min_freq: 63 | self.add_symbol(l_list[0]) 64 | if self.vocab_size > max_vocab_size: 65 | break 66 | 67 | def get_symbol_idx_for_list(self,l): 68 | r = [] 69 | for i in range(len(l)): 70 | r.append(self.get_symbol_idx(l[i])) 71 | return r 72 | 73 | class MinibatchLoader(): 74 | def __init__(self, opt, mode, using_gpu, word_manager): 75 | data = pkl.load(open("{}/{}.pkl".format(opt.data_dir, mode), "rb" )) 76 | graph_data = graph_utils.read_graph_data("{}/graph.{}".format(opt.data_dir, mode)) 77 | 78 | self.enc_batch_list = [] 79 | self.enc_len_batch_list = [] 80 | self.dec_batch_list = [] 81 | 82 | p = 0 83 | while p + opt.batch_size <= len(data): 84 | 85 | batch_graph = [graph_data[p + idx] for idx in range(opt.batch_size)] 86 | combine_batch_graph = graph_utils.cons_batch_graph(batch_graph) 87 | vector_batch_graph = graph_utils.vectorize_batch_graph(combine_batch_graph,word_manager) 88 | 89 | self.enc_batch_list.append(vector_batch_graph) 90 | self.enc_len_batch_list.append(len(batch_graph[0]['g_ids'])) 91 | 92 | tree_batch = [] 93 | for i in range(opt.batch_size): 94 | tree_batch.append(data[p+i][2]) 95 | self.dec_batch_list.append(tree_batch) 96 | p += opt.batch_size 97 | self.num_batch = len(self.enc_batch_list) 98 | assert(len(self.enc_batch_list) == len(self.dec_batch_list)) 99 | 100 | def random_batch(self): 101 | p = randint(0,self.num_batch-1) 102 | return self.enc_batch_list[p], self.enc_len_batch_list[p], self.dec_batch_list[p] 103 | 104 | def all_batch(self): 105 | r = [] 106 | for p in range(self.num_batch): 107 | r.append([self.enc_batch_list[p], self.enc_len_batch_list[p], self.dec_batch_list[p]]) 108 | return r 109 | 110 | def convert_to_tree(r_list, i_left, i_right, form_manager): 111 | t = tree.Tree() 112 | level = 0 113 | left = -1 114 | for i in range(i_left, i_right): 115 | if r_list[i] == form_manager.get_symbol_idx('('): 116 | if level == 0: 117 | left = i 118 | level = level + 1 119 | elif r_list[i] == form_manager.get_symbol_idx(')'): 120 | level = level -1 121 | if level == 0: 122 | if i == left+1: 123 | c = r_list[i] 124 | else: 125 | c = convert_to_tree(r_list, left + 1, i, form_manager) 126 | t.add_child(c) 127 | elif level == 0: 128 | t.add_child(r_list[i]) 129 | return t 130 | 131 | def is_all_same(c1, c2, form_manager): 132 | all_same = False 133 | if len(c1) == len(c2): 134 | all_same = True 135 | for j in range(len(c1)): 136 | if c1[j] != c2[j]: 137 | all_same = False 138 | break 139 | if all_same == False: 140 | if is_solution_same(c1, c2, form_manager): 141 | return True 142 | return False 143 | else: 144 | return True 145 | 146 | def is_solution_same(i1, i2, form_manager): 147 | c1 = " ".join([form_manager.get_idx_symbol(x) for x in i1]) 148 | c2 = " ".join([form_manager.get_idx_symbol(x) for x in i2]) 149 | if ('=' not in c1) or ('=' not in c2): 150 | return False 151 | elif ('' in c1) or ('' in c2): 152 | return False 153 | else: 154 | try: 155 | s1 = c1.split('=') 156 | s2 = c2.split('=') 157 | eq1 = [] 158 | eq2 = [] 159 | x = sympy.Symbol('x') 160 | eq1.append(parse_expr(s1[0])) 161 | eq1.append(parse_expr(s1[1])) 162 | eq2.append(parse_expr(s2[0])) 163 | eq2.append(parse_expr(s2[1])) 164 | res1 = sympy.solve(sympy.Eq(eq1[0], eq1[1]), x) 165 | res2 = sympy.solve(sympy.Eq(eq2[0], eq2[1]), x) 166 | 167 | if not res1 or not res2: 168 | return False 169 | 170 | return res1[0] == res2[0] 171 | 172 | except BaseException: 173 | print c1 174 | print c2 175 | return False 176 | 177 | 178 | def compute_accuracy(candidate_list, reference_list, form_manager): 179 | if len(candidate_list) != len(reference_list): 180 | print("candidate list has length {}, reference list has length {}\n".format(len(candidate_list), len(reference_list))) 181 | 182 | len_min = min(len(candidate_list), len(reference_list)) 183 | c = 0 184 | for i in range(len_min): 185 | # print "length:", len_min 186 | 187 | if is_all_same(candidate_list[i], reference_list[i], form_manager): 188 | # print "{}->True".format(i) 189 | c = c+1 190 | else: 191 | # print "{}->False".format(i) 192 | pass 193 | return c/float(len_min) 194 | 195 | 196 | def compute_tree_accuracy(candidate_list_, reference_list_, form_manager): 197 | candidate_list = [] 198 | 199 | for i in range(len(candidate_list_)): 200 | candidate_list.append(candidate_list_[i]) 201 | reference_list = [] 202 | for i in range(len(reference_list_)): 203 | reference_list.append(reference_list_[i]) 204 | return compute_accuracy(candidate_list, reference_list, form_manager) 205 | -------------------------------------------------------------------------------- /src/graph2tree.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import time 4 | import random 5 | import warnings 6 | import argparse 7 | import data_utils 8 | import graph_utils 9 | 10 | import numpy as np 11 | import pickle as pkl 12 | from tree import Tree 13 | 14 | import torch 15 | import torch.nn as nn 16 | import torch.nn.init as init 17 | import torch.nn.functional as F 18 | from torch import optim 19 | 20 | from graph_encoder import GraphEncoder 21 | 22 | warnings.filterwarnings('ignore') 23 | 24 | class Dec_LSTM(nn.Module): 25 | def __init__(self, opt): 26 | super(Dec_LSTM, self).__init__() 27 | self.opt = opt 28 | self.word_embedding_size = 300 29 | self.i2h = nn.Linear(self.word_embedding_size+2*opt.rnn_size, 4*opt.rnn_size) 30 | self.h2h = nn.Linear(opt.rnn_size, 4*opt.rnn_size) 31 | 32 | if opt.dropout_de_out > 0: 33 | self.dropout = nn.Dropout(opt.dropout_de_out) 34 | 35 | def forward(self, x, prev_c, prev_h, parent_h, sibling_state): 36 | input_cat = torch.cat((x, parent_h, sibling_state),1) 37 | gates = self.i2h(input_cat) + self.h2h(prev_h) 38 | ingate, forgetgate, cellgate, outgate = gates.chunk(4,1) 39 | ingate = F.sigmoid(ingate) 40 | forgetgate = F.sigmoid(forgetgate) 41 | cellgate = F.tanh(cellgate) 42 | outgate = F.sigmoid(outgate) 43 | if self.opt.dropout_de_out > 0: 44 | cellgate = self.dropout(cellgate) 45 | cy = (forgetgate * prev_c) + (ingate * cellgate) 46 | hy = outgate * F.tanh(cy) 47 | return cy, hy 48 | 49 | class DecoderRNN(nn.Module): 50 | def __init__(self, opt, input_size): 51 | super(DecoderRNN, self).__init__() 52 | self.opt = opt 53 | self.hidden_size = opt.rnn_size 54 | self.word_embedding_size = 300 55 | self.embedding = nn.Embedding(input_size, self.word_embedding_size, padding_idx=0) 56 | 57 | self.lstm = Dec_LSTM(self.opt) 58 | if opt.dropout_de_in > 0: 59 | self.dropout = nn.Dropout(opt.dropout_de_in) 60 | 61 | def forward(self, input_src, prev_c, prev_h, parent_h, sibling_state): 62 | 63 | src_emb = self.embedding(input_src) 64 | if self.opt.dropout_de_in > 0: 65 | src_emb = self.dropout(src_emb) 66 | prev_cy, prev_hy = self.lstm(src_emb, prev_c, prev_h, parent_h, sibling_state) 67 | return prev_cy, prev_hy 68 | 69 | class AttnUnit(nn.Module): 70 | def __init__(self, opt, output_size): 71 | super(AttnUnit, self).__init__() 72 | self.opt = opt 73 | self.hidden_size = opt.rnn_size 74 | self.separate_attention = True 75 | if self.separate_attention: 76 | self.linear_att = nn.Linear(3*self.hidden_size, self.hidden_size) 77 | else: 78 | self.linear_att = nn.Linear(2*self.hidden_size, self.hidden_size) 79 | 80 | self.linear_out = nn.Linear(self.hidden_size, output_size) 81 | if opt.dropout_for_predict > 0: 82 | self.dropout = nn.Dropout(opt.dropout_for_predict) 83 | 84 | self.softmax = nn.Softmax(dim=1) 85 | self.logsoftmax = nn.LogSoftmax(dim=1) 86 | 87 | def forward(self, enc_s_top, dec_s_top, enc_2): 88 | dot = torch.bmm(enc_s_top, dec_s_top.unsqueeze(2)) 89 | attention = self.softmax(dot.squeeze(2)).unsqueeze(2) 90 | enc_attention = torch.bmm(enc_s_top.permute(0,2,1), attention) 91 | 92 | if self.separate_attention: 93 | dot_2 = torch.bmm(enc_2, dec_s_top.unsqueeze(2)) 94 | attention_2 = self.softmax(dot_2.squeeze(2)).unsqueeze(2) 95 | enc_attention_2 = torch.bmm(enc_2.permute(0,2,1), attention_2) 96 | 97 | if self.separate_attention: 98 | hid = F.tanh(self.linear_att(torch.cat((enc_attention.squeeze(2), enc_attention_2.squeeze(2),dec_s_top), 1))) 99 | else: 100 | hid = F.tanh(self.linear_att(torch.cat((enc_attention.squeeze(2),dec_s_top), 1))) 101 | h2y_in = hid 102 | if self.opt.dropout_for_predict > 0: 103 | h2y_in = self.dropout(h2y_in) 104 | h2y = self.linear_out(h2y_in) 105 | pred = self.logsoftmax(h2y) 106 | 107 | return pred 108 | 109 | def get_dec_batch(dec_tree_batch, opt, using_gpu, form_manager): 110 | queue_tree = {} 111 | for i in range(1, opt.batch_size+1): 112 | queue_tree[i] = [] 113 | queue_tree[i].append({"tree" : dec_tree_batch[i-1], "parent": 0, "child_index": 1}) 114 | 115 | cur_index, max_index = 1,1 116 | dec_batch = {} 117 | # max_index: the max number of sequence decoder in one batch 118 | while (cur_index <= max_index): 119 | max_w_len = -1 120 | batch_w_list = [] 121 | for i in range(1, opt.batch_size+1): 122 | w_list = [] 123 | if (cur_index <= len(queue_tree[i])): 124 | t = queue_tree[i][cur_index - 1]["tree"] 125 | 126 | for ic in range (t.num_children): 127 | if isinstance(t.children[ic], Tree): 128 | w_list.append(4) 129 | queue_tree[i].append({"tree" : t.children[ic], "parent" : cur_index, "child_index": ic + 1}) 130 | else: 131 | w_list.append(t.children[ic]) 132 | if len(queue_tree[i]) > max_index: 133 | max_index = len(queue_tree[i]) 134 | if len(w_list) > max_w_len: 135 | max_w_len = len(w_list) 136 | batch_w_list.append(w_list) 137 | dec_batch[cur_index] = torch.zeros((opt.batch_size, max_w_len + 2), dtype=torch.long) 138 | for i in range(opt.batch_size): 139 | w_list = batch_w_list[i] 140 | if len(w_list) > 0: 141 | for j in range(len(w_list)): 142 | dec_batch[cur_index][i][j+1] = w_list[j] 143 | # add , 144 | if cur_index == 1: 145 | dec_batch[cur_index][i][0] = 1 146 | else: 147 | dec_batch[cur_index][i][0] = form_manager.get_symbol_idx('(') 148 | dec_batch[cur_index][i][len(w_list) + 1] = 2 149 | 150 | if using_gpu: 151 | dec_batch[cur_index] = dec_batch[cur_index].cuda() 152 | cur_index += 1 153 | 154 | return dec_batch, queue_tree, max_index 155 | 156 | 157 | def eval_training(opt, train_loader, encoder, decoder, attention_decoder, encoder_optimizer, decoder_optimizer, attention_decoder_optimizer, criterion, using_gpu, word_manager, form_manager): 158 | encoder_optimizer.zero_grad() 159 | decoder_optimizer.zero_grad() 160 | attention_decoder_optimizer.zero_grad() 161 | enc_batch, enc_len_batch, dec_tree_batch = train_loader.random_batch() 162 | 163 | enc_max_len = enc_len_batch 164 | 165 | enc_outputs = torch.zeros((opt.batch_size, enc_max_len, encoder.hidden_layer_dim), requires_grad=True) 166 | if using_gpu: 167 | enc_outputs = enc_outputs.cuda() 168 | 169 | fw_adj_info = torch.tensor(enc_batch['g_fw_adj']) 170 | bw_adj_info = torch.tensor(enc_batch['g_bw_adj']) 171 | feature_info = torch.tensor(enc_batch['g_ids_features']) 172 | batch_nodes = torch.tensor(enc_batch['g_nodes']) 173 | 174 | node_embedding, graph_embedding, structural_info = encoder((fw_adj_info,bw_adj_info,feature_info,batch_nodes)) 175 | 176 | enc_outputs = node_embedding 177 | 178 | graph_cell_state = torch.zeros((opt.batch_size, opt.rnn_size), dtype=torch.float, requires_grad=True) 179 | graph_hidden_state = torch.zeros((opt.batch_size, opt.rnn_size), dtype=torch.float, requires_grad=True) 180 | if using_gpu: 181 | graph_cell_state = graph_cell_state.cuda() 182 | graph_hidden_state = graph_hidden_state.cuda() 183 | 184 | graph_cell_state = graph_embedding 185 | graph_hidden_state = graph_embedding 186 | 187 | dec_s = {} 188 | for i in range(opt.dec_seq_length + 1): 189 | dec_s[i] = {} 190 | for j in range(opt.dec_seq_length + 1): 191 | dec_s[i][j] = {} 192 | 193 | loss = 0 194 | cur_index = 1 195 | 196 | dec_batch, queue_tree, max_index = get_dec_batch(dec_tree_batch, opt, using_gpu, form_manager) 197 | 198 | while (cur_index <= max_index): 199 | for j in range(1, 3): 200 | dec_s[cur_index][0][j] = torch.zeros((opt.batch_size, opt.rnn_size), dtype=torch.float, requires_grad=True) 201 | if using_gpu: 202 | dec_s[cur_index][0][j] = dec_s[cur_index][0][j].cuda() 203 | 204 | sibling_state = torch.zeros((opt.batch_size, opt.rnn_size), dtype=torch.float, requires_grad=True) 205 | if using_gpu: 206 | sibling_state = sibling_state.cuda() 207 | 208 | if cur_index == 1: 209 | for i in range(opt.batch_size): 210 | dec_s[1][0][1][i, :] = graph_cell_state[i] 211 | dec_s[1][0][2][i, :] = graph_hidden_state[i] 212 | 213 | else: 214 | for i in range(1, opt.batch_size+1): 215 | if (cur_index <= len(queue_tree[i])): 216 | par_index = queue_tree[i][cur_index - 1]["parent"] 217 | child_index = queue_tree[i][cur_index - 1]["child_index"] 218 | 219 | dec_s[cur_index][0][1][i-1,:] = \ 220 | dec_s[par_index][child_index][1][i-1,:] 221 | dec_s[cur_index][0][2][i-1,:] = dec_s[par_index][child_index][2][i-1,:] 222 | 223 | flag_sibling = False 224 | for q_index in range(len(queue_tree[i])): 225 | if (cur_index <= len(queue_tree[i])) and (q_index < cur_index - 1) and (queue_tree[i][q_index]["parent"] == queue_tree[i][cur_index - 1]["parent"]) and (queue_tree[i][q_index]["child_index"] < queue_tree[i][cur_index - 1]["child_index"]): 226 | flag_sibling = True 227 | sibling_index = q_index 228 | if flag_sibling: 229 | sibling_state[i - 1, :] = dec_s[sibling_index][dec_batch[sibling_index].size(1) - 1][2][i - 1,:] 230 | 231 | parent_h = dec_s[cur_index][0][2] 232 | for i in range(dec_batch[cur_index].size(1) - 1): 233 | teacher_force = random.random() < opt.teacher_force_ratio 234 | if teacher_force != True and i > 0: 235 | input_word = pred.argmax(1) 236 | else: 237 | input_word = dec_batch[cur_index][:, i] 238 | 239 | dec_s[cur_index][i+1][1], dec_s[cur_index][i+1][2] = decoder(input_word, dec_s[cur_index][i][1], dec_s[cur_index][i][2], parent_h, sibling_state) 240 | pred = attention_decoder(enc_outputs, dec_s[cur_index][i+1][2], structural_info) 241 | loss += criterion(pred, dec_batch[cur_index][:,i+1]) 242 | cur_index = cur_index + 1 243 | 244 | loss = loss / opt.batch_size 245 | loss.backward() 246 | torch.nn.utils.clip_grad_value_(encoder.parameters(),opt.grad_clip) 247 | torch.nn.utils.clip_grad_value_(decoder.parameters(),opt.grad_clip) 248 | torch.nn.utils.clip_grad_value_(attention_decoder.parameters(),opt.grad_clip) 249 | encoder_optimizer.step() 250 | decoder_optimizer.step() 251 | attention_decoder_optimizer.step() 252 | return loss 253 | 254 | def convert_to_string(idx_list, form_manager): 255 | w_list = [] 256 | for i in range(len(idx_list)): 257 | w_list.append(form_manager.get_idx_symbol(int(idx_list[i]))) 258 | return " ".join(w_list) 259 | 260 | def do_generate(encoder, decoder, attention_decoder, graph_input, word_manager, form_manager, opt, using_gpu, checkpoint): 261 | prev_c = torch.zeros((1, encoder.hidden_layer_dim), requires_grad=False) 262 | prev_h = torch.zeros((1, encoder.hidden_layer_dim), requires_grad=False) 263 | if using_gpu: 264 | prev_c = prev_c.cuda() 265 | prev_h = prev_h.cuda() 266 | 267 | graph_size = len(graph_input['g_nodes'][0]) 268 | enc_outputs = torch.zeros((1, graph_size, encoder.hidden_layer_dim), requires_grad=False) 269 | if using_gpu: 270 | enc_outputs = enc_outputs.cuda() 271 | 272 | if graph_input['g_fw_adj'] == []: 273 | return "None" 274 | fw_adj_info = torch.tensor(graph_input['g_fw_adj']) 275 | bw_adj_info = torch.tensor(graph_input['g_bw_adj']) 276 | feature_info = torch.tensor(graph_input['g_ids_features']) 277 | batch_nodes = torch.tensor(graph_input['g_nodes']) 278 | 279 | node_embedding, graph_embedding, structural_info = encoder((fw_adj_info,bw_adj_info,feature_info,batch_nodes)) 280 | enc_outputs = node_embedding 281 | prev_c = graph_embedding 282 | prev_h = graph_embedding 283 | 284 | queue_decode = [] 285 | queue_decode.append({"s": (prev_c, prev_h), "parent":0, "child_index":1, "t": Tree()}) 286 | head = 1 287 | while head <= len(queue_decode) and head <=100: 288 | s = queue_decode[head-1]["s"] 289 | parent_h = s[1] 290 | t = queue_decode[head-1]["t"] 291 | 292 | sibling_state = torch.zeros((1, encoder.hidden_layer_dim), dtype=torch.float, requires_grad=False) 293 | 294 | if using_gpu: 295 | sibling_state = sibling_state.cuda() 296 | flag_sibling = False 297 | for q_index in range(len(queue_decode)): 298 | if (head <= len(queue_decode)) and (q_index < head - 1) and (queue_decode[q_index]["parent"] == queue_decode[head - 1]["parent"]) and (queue_decode[q_index]["child_index"] < queue_decode[head - 1]["child_index"]): 299 | flag_sibling = True 300 | sibling_index = q_index 301 | if flag_sibling: 302 | sibling_state = queue_decode[sibling_index]["s"][1] 303 | 304 | if head == 1: 305 | prev_word = torch.tensor([form_manager.get_symbol_idx('')], dtype=torch.long) 306 | else: 307 | prev_word = torch.tensor([form_manager.get_symbol_idx('(')], dtype=torch.long) 308 | if using_gpu: 309 | prev_word = prev_word.cuda() 310 | i_child = 1 311 | while True: 312 | curr_c, curr_h = decoder(prev_word, s[0], s[1], parent_h, sibling_state) 313 | prediction = attention_decoder(enc_outputs, curr_h, structural_info) 314 | 315 | s = (curr_c, curr_h) 316 | _, _prev_word = prediction.max(1) 317 | prev_word = _prev_word 318 | 319 | if int(prev_word[0]) == form_manager.get_symbol_idx('') or t.num_children >= checkpoint["opt"].dec_seq_length: 320 | break 321 | elif int(prev_word[0]) == form_manager.get_symbol_idx(''): 322 | queue_decode.append({"s": (s[0].clone(), s[1].clone()), "parent": head, "child_index":i_child, "t": Tree()}) 323 | t.add_child(int(prev_word[0])) 324 | else: 325 | t.add_child(int(prev_word[0])) 326 | i_child = i_child + 1 327 | head = head + 1 328 | for i in range(len(queue_decode)-1, 0, -1): 329 | cur = queue_decode[i] 330 | queue_decode[cur["parent"]-1]["t"].children[cur["child_index"]-1] = cur["t"] 331 | return queue_decode[0]["t"].to_list(form_manager) 332 | 333 | def main(opt): 334 | random.seed(opt.seed) 335 | np.random.seed(opt.seed) 336 | torch.manual_seed(opt.seed) 337 | managers = pkl.load( open("{}/map.pkl".format(opt.data_dir), "rb" ) ) 338 | word_manager, form_manager = managers 339 | using_gpu = False 340 | if opt.gpuid > -1: 341 | using_gpu = True 342 | 343 | encoder = GraphEncoder(opt, word_manager.vocab_size) 344 | decoder = DecoderRNN(opt, form_manager.vocab_size) 345 | attention_decoder = AttnUnit(opt, form_manager.vocab_size) 346 | 347 | if using_gpu: 348 | encoder = encoder.cuda() 349 | decoder = decoder.cuda() 350 | attention_decoder = attention_decoder.cuda() 351 | 352 | # print(encoder) 353 | # print(decoder) 354 | # print(attention_decoder) 355 | 356 | for name, param in encoder.named_parameters(): 357 | if param.requires_grad: 358 | if ("embedding.weight" in name): 359 | # print("Do not initialize pretrained embedding parameters") 360 | pass 361 | else: 362 | init.uniform_(param, -opt.init_weight, opt.init_weight) 363 | for name, param in decoder.named_parameters(): 364 | if param.requires_grad: 365 | init.uniform_(param, -opt.init_weight, opt.init_weight) 366 | for name, param in attention_decoder.named_parameters(): 367 | if param.requires_grad: 368 | init.uniform_(param, -opt.init_weight, opt.init_weight) 369 | 370 | train_loader = data_utils.MinibatchLoader(opt, 'train', using_gpu, word_manager) 371 | 372 | if not os.path.exists(opt.checkpoint_dir): 373 | os.makedirs(opt.checkpoint_dir) 374 | 375 | step = 0 376 | epoch = 0 377 | optim_state = {"learningRate" : opt.learning_rate} 378 | 379 | print("using adam") 380 | encoder_optimizer = optim.Adam(encoder.parameters(), lr=optim_state["learningRate"], weight_decay=1e-5) 381 | decoder_optimizer = optim.Adam(decoder.parameters(), lr=optim_state["learningRate"]) 382 | attention_decoder_optimizer = optim.Adam(attention_decoder.parameters(), lr=optim_state["learningRate"]) 383 | 384 | criterion = nn.NLLLoss(size_average=False, ignore_index=0) 385 | 386 | print("Starting training.") 387 | encoder.train() 388 | decoder.train() 389 | attention_decoder.train() 390 | iterations = opt.max_epochs * train_loader.num_batch 391 | start_time = time.time() 392 | restarted = False 393 | 394 | best_val_acc = 0 395 | loss_to_print = 0 396 | for i in range(iterations): 397 | 398 | epoch = i // train_loader.num_batch 399 | train_loss = eval_training(opt, train_loader, encoder, decoder, attention_decoder, encoder_optimizer, decoder_optimizer, attention_decoder_optimizer, criterion, using_gpu, word_manager, form_manager) 400 | 401 | loss_to_print += train_loss 402 | 403 | if i == iterations - 1 or i % opt.print_every == 0: 404 | checkpoint = {} 405 | checkpoint["encoder"] = encoder 406 | checkpoint["decoder"] = decoder 407 | checkpoint["attention_decoder"] = attention_decoder 408 | checkpoint["opt"] = opt 409 | checkpoint["i"] = i 410 | checkpoint["epoch"] = epoch 411 | torch.save(checkpoint, "{}/valid/model_g2t".format(opt.checkpoint_dir) + str(i)) 412 | 413 | if i % opt.print_every == 0: 414 | end_time = time.time() 415 | print("{}/{}, train_loss = {}, time since last print = {}".format( i, iterations, loss_to_print/opt.print_every, (end_time - start_time)/60)) 416 | loss_to_print = 0 417 | start_time = time.time() 418 | 419 | print "best_acc: ",best_val_acc 420 | 421 | 422 | if __name__ == "__main__": 423 | start = time.time() 424 | main_arg_parser = argparse.ArgumentParser(description="parser") 425 | main_arg_parser.add_argument('-gpuid', type=int, default=0, help='which gpu to use. -1 = use CPU') 426 | main_arg_parser.add_argument('-data_dir', type=str, default='../data/GraphConstruction', help='data path') 427 | main_arg_parser.add_argument('-seed',type=int,default=400,help='torch manual random number generator seed') 428 | main_arg_parser.add_argument('-checkpoint_dir',type=str, default= 'checkpoint_dir', help='output directory where checkpoints get written') 429 | main_arg_parser.add_argument('-print_every',type=int, default=100,help='how many steps/minibatches between printing out the loss') 430 | main_arg_parser.add_argument('-rnn_size', type=int,default=300, help='size of LSTM internal state') 431 | main_arg_parser.add_argument('-num_layers', type=int, default=1, help='number of layers in the LSTM') 432 | 433 | main_arg_parser.add_argument('-teacher_force_ratio',type=float, default=1.0) 434 | 435 | main_arg_parser.add_argument('-dropout_en_in',type=float, default=0.1,help='dropout for encoder, input') 436 | main_arg_parser.add_argument('-dropout_en_out',type=float, default=0.3,help='dropout for encoder, output') 437 | main_arg_parser.add_argument('-dropout_de_in',type=float, default=0.1,help='dropout for decoder, input') 438 | main_arg_parser.add_argument('-dropout_de_out',type=float, default=0.3,help='dropout for decoder, output') 439 | main_arg_parser.add_argument('-dropout_for_predict',type=float, default=0.1,help='dropout used in attention decoder, in prediction') 440 | 441 | main_arg_parser.add_argument('-dropoutagg',type=float,default=0,help='dropout for regularization, used after each aggregator. 0 = no dropout') 442 | main_arg_parser.add_argument('-dec_seq_length',type=int, default=35,help='number of timesteps to unroll for') 443 | main_arg_parser.add_argument('-batch_size',type=int, default=30,help='number of sequences to train on in parallel') 444 | 445 | main_arg_parser.add_argument('-max_epochs',type=int, default=800,help='number of full passes through the training data') 446 | main_arg_parser.add_argument('-learning_rate',type=float, default=1e-3,help='learning rate') 447 | main_arg_parser.add_argument('-init_weight',type=float, default=0.08,help='initailization weight') 448 | main_arg_parser.add_argument('-grad_clip',type=int, default=5,help='clip gradients at this value') 449 | 450 | # some arguments of graph encoder 451 | main_arg_parser.add_argument('-graph_encode_direction',type=str, default='uni',help='graph encode direction: bi or uni') 452 | main_arg_parser.add_argument('-sample_size_per_layer',type=int, default=10,help='sample_size_per_layer') 453 | main_arg_parser.add_argument('-sample_layer_size',type=int, default=3,help='sample_layer_size') 454 | main_arg_parser.add_argument('-concat',type=bool, default=True,help='concat in aggregators settings') 455 | 456 | args = main_arg_parser.parse_args() 457 | print(args) 458 | main(args) 459 | end = time.time() 460 | print("total time: {} minutes\n".format((end - start)/60)) 461 | -------------------------------------------------------------------------------- /src/graph_encoder.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import random 4 | import data_utils 5 | import nn_modules 6 | import numpy as np 7 | import pickle as pkl 8 | from tree import Tree 9 | from pretrained_embedding import make_pretrained_embedding 10 | 11 | import torch 12 | import torch.nn as nn 13 | import torch.nn.init as init 14 | import torch.nn.functional as F 15 | from torch import optim 16 | 17 | class GraphEncoder(nn.Module): 18 | def __init__(self, opt, input_size): 19 | super(GraphEncoder, self).__init__() 20 | self.opt = opt 21 | 22 | if opt.dropoutagg > 0: 23 | self.dropout = nn.Dropout(opt.dropoutagg) 24 | 25 | self.graph_encode_direction = opt.graph_encode_direction 26 | self.sample_size_per_layer = opt.sample_size_per_layer 27 | self.sample_layer_size = opt.sample_layer_size 28 | self.hidden_layer_dim = opt.rnn_size 29 | 30 | if self.opt.dropout_en_in > 0: 31 | self.input_dropout = nn.Dropout(opt.dropout_en_in) 32 | self.word_embedding_size = 300 33 | self.embedding = nn.Embedding( 34 | input_size, self.word_embedding_size, padding_idx=0) 35 | self.embedding.weight.data = make_pretrained_embedding(self.embedding.weight.size(), opt) 36 | 37 | self.fw_aggregators = [] 38 | self.bw_aggregators = [] 39 | 40 | self.fw_aggregator_0 = nn_modules.MeanAggregator( 41 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 42 | self.fw_aggregator_1 = nn_modules.MeanAggregator( 43 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 44 | self.fw_aggregator_2 = nn_modules.MeanAggregator( 45 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 46 | self.fw_aggregator_3 = nn_modules.MeanAggregator( 47 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 48 | self.fw_aggregator_4 = nn_modules.MeanAggregator( 49 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 50 | self.fw_aggregator_5 = nn_modules.MeanAggregator( 51 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 52 | self.fw_aggregator_6 = nn_modules.MeanAggregator( 53 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 54 | 55 | self.bw_aggregator_0 = nn_modules.MeanAggregator( 56 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 57 | self.bw_aggregator_1 = nn_modules.MeanAggregator( 58 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 59 | self.bw_aggregator_2 = nn_modules.MeanAggregator( 60 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 61 | self.bw_aggregator_3 = nn_modules.MeanAggregator( 62 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 63 | self.bw_aggregator_4 = nn_modules.MeanAggregator( 64 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 65 | self.bw_aggregator_5 = nn_modules.MeanAggregator( 66 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 67 | self.bw_aggregator_6 = nn_modules.MeanAggregator( 68 | 2*self.hidden_layer_dim, self.hidden_layer_dim, concat=True) 69 | self.fw_aggregators = [self.fw_aggregator_0, self.fw_aggregator_1, self.fw_aggregator_2, 70 | self.fw_aggregator_3, self.fw_aggregator_4, self.fw_aggregator_5, self.fw_aggregator_6] 71 | self.bw_aggregators = [self.bw_aggregator_0, self.bw_aggregator_1, self.bw_aggregator_2, 72 | self.bw_aggregator_3, self.bw_aggregator_4, self.bw_aggregator_5, self.bw_aggregator_6] 73 | 74 | self.Linear_hidden = nn.Linear( 75 | 2 * self.hidden_layer_dim, self.hidden_layer_dim) 76 | 77 | self.concat = opt.concat 78 | 79 | self.using_gpu = False 80 | if self.opt.gpuid > -1: 81 | self.using_gpu = True 82 | 83 | self.embedding_bilstm = nn.LSTM(input_size=self.word_embedding_size, hidden_size=self.hidden_layer_dim/2, bidirectional=True, bias = True, batch_first = True, dropout= self.opt.dropout_en_out, num_layers=1) 84 | self.padding_vector = torch.randn(1,self.hidden_layer_dim, dtype = torch.float, requires_grad=True) 85 | 86 | def forward(self, graph_batch): 87 | fw_adj_info, bw_adj_info, feature_info, batch_nodes = graph_batch 88 | 89 | # print self.hidden_layer_dim 90 | 91 | if self.using_gpu: 92 | fw_adj_info = fw_adj_info.cuda() 93 | bw_adj_info = bw_adj_info.cuda() 94 | feature_info = feature_info.cuda() 95 | batch_nodes = batch_nodes.cuda() 96 | 97 | feature_by_sentence = feature_info[:-1,:].view(batch_nodes.size()[0], -1) 98 | feature_sentence_vector = self.embedding(feature_by_sentence) 99 | if self.opt.dropout_en_in > 0: 100 | feature_sentence_vector = self.input_dropout(feature_sentence_vector) 101 | output_vector, (ht,_) = self.embedding_bilstm(feature_sentence_vector) 102 | 103 | feature_vector = output_vector.contiguous().view(-1, self.hidden_layer_dim) 104 | if self.using_gpu: 105 | feature_embedded = torch.cat([feature_vector, self.padding_vector.cuda()], 0) 106 | else: 107 | feature_embedded = torch.cat([feature_vector, self.padding_vector], 0) 108 | 109 | batch_size = feature_embedded.size()[0] 110 | node_repres = feature_embedded.view(batch_size, -1) 111 | 112 | fw_sampler = nn_modules.UniformNeighborSampler(fw_adj_info) 113 | bw_sampler = nn_modules.UniformNeighborSampler(bw_adj_info) 114 | nodes = batch_nodes.view(-1, ) 115 | 116 | fw_hidden = F.embedding(nodes, node_repres) 117 | bw_hidden = F.embedding(nodes, node_repres) 118 | 119 | fw_sampled_neighbors = fw_sampler((nodes, self.sample_size_per_layer)) 120 | bw_sampled_neighbors = bw_sampler((nodes, self.sample_size_per_layer)) 121 | 122 | fw_sampled_neighbors_len = torch.tensor(0) 123 | bw_sampled_neighbors_len = torch.tensor(0) 124 | 125 | # begin sampling 126 | for layer in range(self.sample_layer_size): 127 | if layer == 0: 128 | dim_mul = 1 129 | else: 130 | dim_mul = 1 131 | if self.using_gpu and layer <= 6: 132 | self.fw_aggregators[layer] = self.fw_aggregators[layer].cuda() 133 | if layer == 0: 134 | neigh_vec_hidden = F.embedding( 135 | fw_sampled_neighbors, node_repres) 136 | tmp_sum = torch.sum(F.relu(neigh_vec_hidden), 2) 137 | tmp_mask = torch.sign(tmp_sum) 138 | fw_sampled_neighbors_len = torch.sum(tmp_mask, 1) 139 | else: 140 | if self.using_gpu: 141 | neigh_vec_hidden = F.embedding(fw_sampled_neighbors, torch.cat([fw_hidden, torch.zeros( 142 | [1, dim_mul * self.hidden_layer_dim]).cuda()], 0)) 143 | else: 144 | neigh_vec_hidden = F.embedding(fw_sampled_neighbors, torch.cat([fw_hidden, torch.zeros( 145 | [1, dim_mul * self.hidden_layer_dim])], 0)) 146 | 147 | if layer > 6: 148 | fw_hidden = self.fw_aggregators[6]( 149 | (fw_hidden, neigh_vec_hidden, fw_sampled_neighbors_len)) 150 | else: 151 | fw_hidden = self.fw_aggregators[layer]( 152 | (fw_hidden, neigh_vec_hidden, fw_sampled_neighbors_len)) 153 | 154 | if self.graph_encode_direction == "bi": 155 | if self.using_gpu and layer <= 6: 156 | self.bw_aggregators[layer] = self.bw_aggregators[layer].cuda( 157 | ) 158 | 159 | if layer == 0: 160 | neigh_vec_hidden = F.embedding( 161 | bw_sampled_neighbors, node_repres) 162 | tmp_sum = torch.sum(F.relu(neigh_vec_hidden), 2) 163 | tmp_mask = torch.sign(tmp_sum) 164 | bw_sampled_neighbors_len = torch.sum(tmp_mask, 1) 165 | else: 166 | if self.using_gpu: 167 | neigh_vec_hidden = F.embedding(bw_sampled_neighbors, torch.cat([bw_hidden, torch.zeros( 168 | [1, dim_mul * self.hidden_layer_dim]).cuda()], 0)) 169 | else: 170 | neigh_vec_hidden = F.embedding(bw_sampled_neighbors, torch.cat([bw_hidden, torch.zeros( 171 | [1, dim_mul * self.hidden_layer_dim])], 0)) 172 | if self.opt.dropoutagg > 0: 173 | bw_hidden = self.dropout(bw_hidden) 174 | neigh_vec_hidden = self.dropout(neigh_vec_hidden) 175 | 176 | if layer > 6: 177 | bw_hidden = self.bw_aggregators[6]( 178 | (bw_hidden, neigh_vec_hidden, bw_sampled_neighbors_len)) 179 | else: 180 | bw_hidden = self.bw_aggregators[layer]( 181 | (bw_hidden, neigh_vec_hidden, bw_sampled_neighbors_len)) 182 | fw_hidden = fw_hidden.view(-1, batch_nodes.size() 183 | [1], self.hidden_layer_dim) 184 | 185 | if self.graph_encode_direction == "bi": 186 | bw_hidden = bw_hidden.view(-1, batch_nodes.size() 187 | [1], self.hidden_layer_dim) 188 | hidden = torch.cat([fw_hidden, bw_hidden], 2) 189 | else: 190 | hidden = fw_hidden 191 | 192 | pooled = torch.max(hidden, 1)[0] 193 | graph_embedding = pooled.view(-1, self.hidden_layer_dim) 194 | 195 | return hidden, graph_embedding, output_vector 196 | -------------------------------------------------------------------------------- /src/graph_utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | import numpy as np 3 | import networkx as nx 4 | from collections import OrderedDict 5 | 6 | word_size_max = 1 7 | sample_size_per_layer = 10 8 | 9 | def read_graph_data(input_file): 10 | # transform the keys to string 11 | graphs_new = [] 12 | with open(input_file, "r") as f: 13 | lines = f.readlines() 14 | for line in lines: 15 | line = line.strip() 16 | jo = json.loads(line, object_pairs_hook=OrderedDict) 17 | graph_i = {} 18 | graph_i['g_ids'] = jo['g_ids'] 19 | graph_i['g_ids_features'] = jo['g_ids_features'] 20 | graph_i['g_adj'] = jo['g_adj'] 21 | graphs_new.append(graph_i) 22 | return graphs_new 23 | 24 | def cons_batch_graph(graphs): 25 | g_ids = {} 26 | g_ids_features = {} 27 | g_fw_adj = {} 28 | g_bw_adj = {} 29 | g_nodes = [] 30 | for g in graphs: 31 | ids = g['g_ids'] 32 | id_adj = g['g_adj'] 33 | features = g['g_ids_features'] 34 | nodes = [] 35 | 36 | # we first add all nodes into batch_graph and create a mapping from graph id to batch_graph id, this mapping will be 37 | # used in the creation of fw_adj and bw_adj 38 | 39 | id_gid_map = {} 40 | offset = len(g_ids.keys()) 41 | for id in ids: 42 | id = int(id) 43 | g_ids[offset + id] = len(g_ids.keys()) 44 | g_ids_features[offset + id] = features[str(id)] 45 | id_gid_map[id] = offset + id 46 | nodes.append(offset + id) 47 | g_nodes.append(nodes) 48 | 49 | for id in id_adj: 50 | adj = id_adj[id] 51 | id = int(id) 52 | g_id = id_gid_map[id] 53 | if g_id not in g_fw_adj: 54 | g_fw_adj[g_id] = [] 55 | for t in adj: 56 | t = int(t) 57 | g_t = id_gid_map[t] 58 | g_fw_adj[g_id].append(g_t) 59 | if g_t not in g_bw_adj: 60 | g_bw_adj[g_t] = [] 61 | g_bw_adj[g_t].append(g_id) 62 | 63 | node_size = len(g_ids.keys()) 64 | for id in range(node_size): 65 | if id not in g_fw_adj: 66 | g_fw_adj[id] = [] 67 | if id not in g_bw_adj: 68 | g_bw_adj[id] = [] 69 | 70 | graph = {} 71 | graph['g_ids'] = g_ids 72 | graph['g_ids_features'] = g_ids_features 73 | graph['g_nodes'] = g_nodes 74 | graph['g_fw_adj'] = g_fw_adj 75 | graph['g_bw_adj'] = g_bw_adj 76 | return graph 77 | 78 | def vectorize_batch_graph(graph, word_manager): 79 | # vectorize the graph feature and normalize the adj info 80 | id_features = graph['g_ids_features'] 81 | gv = {} 82 | nv = [] 83 | word_max_len = 0 84 | for id in id_features: 85 | feature = id_features[id] 86 | word_max_len = max(word_max_len, len(feature.split())) 87 | word_max_len = min(word_max_len, word_size_max) 88 | 89 | for id in graph['g_ids_features']: 90 | feature = graph['g_ids_features'][id] 91 | fv = [] 92 | for token in feature.split(): 93 | if len(token) == 0: 94 | continue 95 | # if token in word_idx: 96 | # fv.append(word_idx[token]) 97 | # else: 98 | # fv.append(word_idx['']) 99 | fv.append(word_manager.get_symbol_idx(token)) 100 | for _ in range(word_max_len - len(fv)): 101 | fv.append(0) 102 | fv = fv[:word_max_len] 103 | nv.append(fv) 104 | 105 | nv.append([0 for temp in range(word_max_len)]) 106 | gv['g_ids_features'] = np.array(nv) 107 | 108 | g_fw_adj = graph['g_fw_adj'] 109 | g_fw_adj_v = [] 110 | 111 | degree_max_size = 0 112 | for id in g_fw_adj: 113 | degree_max_size = max(degree_max_size, len(g_fw_adj[id])) 114 | 115 | g_bw_adj = graph['g_bw_adj'] 116 | for id in g_bw_adj: 117 | degree_max_size = max(degree_max_size, len(g_bw_adj[id])) 118 | 119 | degree_max_size = min(degree_max_size, sample_size_per_layer) 120 | 121 | for id in g_fw_adj: 122 | adj = g_fw_adj[id] 123 | for _ in range(degree_max_size - len(adj)): 124 | adj.append(len(g_fw_adj.keys())) 125 | adj = adj[:degree_max_size] 126 | g_fw_adj_v.append(adj) 127 | 128 | # PAD node directs to the PAD node 129 | g_fw_adj_v.append([len(g_fw_adj.keys()) for _ in range(degree_max_size)]) 130 | 131 | g_bw_adj_v = [] 132 | for id in g_bw_adj: 133 | adj = g_bw_adj[id] 134 | for _ in range(degree_max_size - len(adj)): 135 | adj.append(len(g_bw_adj.keys())) 136 | adj = adj[:degree_max_size] 137 | g_bw_adj_v.append(adj) 138 | 139 | # PAD node directs to the PAD node 140 | g_bw_adj_v.append([len(g_bw_adj.keys()) for _ in range(degree_max_size)]) 141 | 142 | gv['g_ids'] = graph['g_ids'] 143 | gv['g_nodes'] =np.array(graph['g_nodes']) 144 | gv['g_bw_adj'] = np.array(g_bw_adj_v) 145 | gv['g_fw_adj'] = np.array(g_fw_adj_v) 146 | return gv 147 | -------------------------------------------------------------------------------- /src/nn_modules.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | from torch.nn import functional as F 4 | from torch.autograd import Variable 5 | 6 | import numpy as np 7 | from scipy import sparse 8 | 9 | # -- 10 | # Samplers 11 | 12 | def combine_fn(x, dim=1): 13 | return torch.cat(x, dim) 14 | 15 | class UniformNeighborSampler(object): 16 | def __init__(self, adj): 17 | self.adj = adj 18 | 19 | def __call__(self, inputs): 20 | ids, n_samples = inputs 21 | tmp = self.adj[ids] 22 | perm = torch.randperm(tmp.size(1)) 23 | tmp = tmp[:,perm] 24 | return tmp[:,:n_samples] 25 | 26 | 27 | class SparseUniformNeighborSampler(object): 28 | def __init__(self, adj,): 29 | assert sparse.issparse(adj), "SparseUniformNeighborSampler: not sparse.issparse(adj)" 30 | self.adj = adj 31 | 32 | idx, partial_degrees = np.unique(adj.nonzero()[0], return_counts=True) 33 | self.degrees = np.zeros(adj.shape[0]).astype(int) 34 | self.degrees[idx] = partial_degrees 35 | 36 | def __call__(self, ids, n_samples=128): 37 | assert n_samples > 0, 'SparseUniformNeighborSampler: n_samples must be set explicitly' 38 | # ids = to_numpy(ids) 39 | tmp = self.adj[ids] 40 | 41 | sel = np.random.choice(self.adj.shape[1], (ids.shape[0], n_samples)) 42 | sel = sel % self.degrees[ids].reshape(-1, 1) 43 | tmp = tmp[ 44 | np.arange(ids.shape[0]).repeat(n_samples).reshape(-1), 45 | np.array(sel).reshape(-1) 46 | ] 47 | tmp = np.asarray(tmp).squeeze() 48 | 49 | tmp = Variable(torch.LongTensor(tmp)) 50 | 51 | return tmp 52 | 53 | 54 | sampler_lookup = { 55 | "uniform_neighbor_sampler" : UniformNeighborSampler, 56 | "sparse_uniform_neighbor_sampler" : SparseUniformNeighborSampler, 57 | } 58 | 59 | # -- 60 | # Preprocessers 61 | 62 | class IdentityPrep(nn.Module): 63 | def __init__(self, input_dim, n_nodes=None): 64 | """ Example of preprocessor -- doesn't do anything """ 65 | super(IdentityPrep, self).__init__() 66 | self.input_dim = input_dim 67 | 68 | @property 69 | def output_dim(self): 70 | return self.input_dim 71 | 72 | def forward(self, ids, feats, layer_idx=0): 73 | return feats 74 | 75 | 76 | class NodeEmbeddingPrep(nn.Module): 77 | def __init__(self, input_dim, n_nodes, embedding_dim=64): 78 | """ adds node embedding """ 79 | super(NodeEmbeddingPrep, self).__init__() 80 | 81 | self.n_nodes = n_nodes 82 | self.input_dim = input_dim 83 | self.embedding_dim = embedding_dim 84 | self.embedding = nn.Embedding(num_embeddings=n_nodes + 1, embedding_dim=embedding_dim) 85 | self.fc = nn.Linear(embedding_dim, embedding_dim) # Affine transform, for changing scale + location 86 | 87 | @property 88 | def output_dim(self): 89 | if self.input_dim: 90 | return self.input_dim + self.embedding_dim 91 | else: 92 | return self.embedding_dim 93 | 94 | def forward(self, ids, feats, layer_idx=0): 95 | if layer_idx > 0: 96 | embs = self.embedding(ids) 97 | else: 98 | # Don't look at node's own embedding for prediction, or you'll probably overfit a lot 99 | embs = self.embedding(Variable(ids.clone().data.zero_() + self.n_nodes)) 100 | 101 | embs = self.fc(embs) 102 | if self.input_dim: 103 | return torch.cat([feats, embs], dim=1) 104 | else: 105 | return embs 106 | 107 | 108 | class LinearPrep(nn.Module): 109 | def __init__(self, input_dim, n_nodes, output_dim=32): 110 | """ adds node embedding """ 111 | super(LinearPrep, self).__init__() 112 | self.fc = nn.Linear(input_dim, output_dim, bias=False) 113 | self.output_dim = output_dim 114 | 115 | def forward(self, ids, feats, layer_idx=0): 116 | return self.fc(feats) 117 | 118 | 119 | prep_lookup = { 120 | "identity" : IdentityPrep, 121 | "node_embedding" : NodeEmbeddingPrep, 122 | "linear" : LinearPrep, 123 | } 124 | 125 | # -- 126 | # Aggregators 127 | 128 | class AggregatorMixin(object): 129 | @property 130 | def output_dim_func(self): 131 | tmp = torch.zeros((1, self.output_dim)) 132 | return self.combine_fn([tmp, tmp]).size(1) 133 | 134 | class MeanAggregator(nn.Module, AggregatorMixin): 135 | def __init__(self, input_dim, output_dim, activation = F.relu, concat = False): 136 | super(MeanAggregator, self).__init__() 137 | 138 | self.concat = concat 139 | self.fc_x = nn.Linear(input_dim, output_dim, bias=True) 140 | self.activation = activation 141 | self.combine_fn = combine_fn 142 | 143 | def forward(self, inputs): 144 | x, neibs, _ = inputs 145 | agg_neib = neibs.mean(dim=1) 146 | if self.concat: 147 | out_tmp = self.combine_fn([x, agg_neib]) 148 | out = self.fc_x(out_tmp) 149 | else: 150 | out = self.fc_x(x) + self.fc_neib(agg_neib) 151 | if self.activation: 152 | out = self.activation(out) 153 | return out 154 | 155 | 156 | class PoolAggregator(nn.Module, AggregatorMixin): 157 | def __init__(self, input_dim, output_dim, pool_fn, activation, hidden_dim=512): 158 | super(PoolAggregator, self).__init__() 159 | 160 | self.mlp = nn.Sequential(*[ 161 | nn.Linear(input_dim, hidden_dim, bias=True), 162 | nn.ReLU() 163 | ]) 164 | self.fc_x = nn.Linear(input_dim, output_dim, bias=False) 165 | self.fc_neib = nn.Linear(hidden_dim, output_dim, bias=False) 166 | 167 | self.output_dim_ = output_dim 168 | self.activation = activation 169 | self.pool_fn = pool_fn 170 | self.combine_fn = combine_fn 171 | 172 | def forward(self, x, neibs): 173 | h_neibs = self.mlp(neibs) 174 | agg_neib = h_neibs.view(x.size(0), -1, h_neibs.size(1)) 175 | agg_neib = self.pool_fn(agg_neib) 176 | 177 | out = self.combine_fn([self.fc_x(x), self.fc_neib(agg_neib)]) 178 | if self.activation: 179 | out = self.activation(out) 180 | 181 | return out 182 | 183 | 184 | class MaxPoolAggregator(PoolAggregator): 185 | def __init__(self, input_dim, output_dim, activation, hidden_dim=512): 186 | super(MaxPoolAggregator, self).__init__(**{ 187 | "input_dim" : input_dim, 188 | "output_dim" : output_dim, 189 | "pool_fn" : lambda x: x.max(dim=1)[0], 190 | "activation" : activation, 191 | "hidden_dim" : hidden_dim, 192 | "combine_fn" : combine_fn, 193 | }) 194 | 195 | 196 | class MeanPoolAggregator(PoolAggregator): 197 | def __init__(self, input_dim, output_dim, activation, hidden_dim=512): 198 | super(MeanPoolAggregator, self).__init__(**{ 199 | "input_dim" : input_dim, 200 | "output_dim" : output_dim, 201 | "pool_fn" : lambda x: x.mean(dim=1), 202 | "activation" : activation, 203 | "hidden_dim" : hidden_dim, 204 | "combine_fn" : combine_fn, 205 | }) 206 | 207 | 208 | class LSTMAggregator(nn.Module, AggregatorMixin): 209 | def __init__(self, input_dim, output_dim, activation, 210 | hidden_dim=512, bidirectional=False): 211 | 212 | super(LSTMAggregator, self).__init__() 213 | assert not hidden_dim % 2, "LSTMAggregator: hiddem_dim % 2 != 0" 214 | 215 | self.lstm = nn.LSTM(input_dim, hidden_dim // (1 + bidirectional), bidirectional=bidirectional, batch_first=True) 216 | self.fc_x = nn.Linear(input_dim, output_dim, bias=False) 217 | self.fc_neib = nn.Linear(hidden_dim, output_dim, bias=False) 218 | 219 | self.output_dim_ = output_dim 220 | self.activation = activation 221 | self.combine_fn = combine_fn 222 | 223 | def forward(self, x, neibs): 224 | x_emb = self.fc_x(x) 225 | 226 | agg_neib = neibs.view(x.size(0), -1, neibs.size(1)) 227 | agg_neib, _ = self.lstm(agg_neib) 228 | agg_neib = agg_neib[:,-1,:] # !! Taking final state, but could do something better (eg attention) 229 | neib_emb = self.fc_neib(agg_neib) 230 | 231 | out = self.combine_fn([x_emb, neib_emb]) 232 | if self.activation: 233 | out = self.activation(out) 234 | 235 | return out 236 | 237 | 238 | class AttentionAggregator(nn.Module, AggregatorMixin): 239 | def __init__(self, input_dim, output_dim, activation, hidden_dim=32): 240 | super(AttentionAggregator, self).__init__() 241 | 242 | self.att = nn.Sequential(*[ 243 | nn.Linear(input_dim, hidden_dim, bias=False), 244 | nn.Tanh(), 245 | nn.Linear(hidden_dim, hidden_dim, bias=False), 246 | ]) 247 | self.fc_x = nn.Linear(input_dim, output_dim, bias=False) 248 | self.fc_neib = nn.Linear(input_dim, output_dim, bias=False) 249 | 250 | self.output_dim_ = output_dim 251 | self.activation = activation 252 | self.combine_fn = combine_fn 253 | 254 | def forward(self, x, neibs): 255 | # Compute attention weights 256 | neib_att = self.att(neibs) 257 | x_att = self.att(x) 258 | neib_att = neib_att.view(x.size(0), -1, neib_att.size(1)) 259 | x_att = x_att.view(x_att.size(0), x_att.size(1), 1) 260 | ws = F.softmax(torch.bmm(neib_att, x_att).squeeze()) 261 | 262 | # Weighted average of neighbors 263 | agg_neib = neibs.view(x.size(0), -1, neibs.size(1)) 264 | agg_neib = torch.sum(agg_neib * ws.unsqueeze(-1), dim=1) 265 | 266 | out = self.combine_fn([self.fc_x(x), self.fc_neib(agg_neib)]) 267 | if self.activation: 268 | out = self.activation(out) 269 | 270 | return out 271 | 272 | 273 | aggregator_lookup = { 274 | "mean" : MeanAggregator, 275 | "max_pool" : MaxPoolAggregator, 276 | "mean_pool" : MeanPoolAggregator, 277 | "lstm" : LSTMAggregator, 278 | "attention" : AttentionAggregator, 279 | } 280 | -------------------------------------------------------------------------------- /src/pretrained_embedding.py: -------------------------------------------------------------------------------- 1 | import os 2 | import torch 3 | import argparse 4 | import data_utils 5 | import numpy as np 6 | import pickle as pkl 7 | 8 | from sys import path 9 | from torch import nn 10 | from tqdm import tqdm 11 | 12 | def generate_embedding_from_glove(args): 13 | data_dir = args.data_dir 14 | min_freq = 2 15 | max_vocab_size = 15000 16 | pretrained_embedding_dir = args.pretrained_embedding 17 | 18 | word_manager = data_utils.SymbolsManager(True) 19 | word_manager.init_from_file("{}/vocab.q.txt".format(data_dir), min_freq, max_vocab_size) 20 | 21 | glove2vec = {} 22 | words_arr = [] 23 | cnt_find = 0 24 | with open(pretrained_embedding_dir, "r") as f: 25 | for l in tqdm(f): 26 | line = l.split() 27 | word = line[0] 28 | words_arr.append(word) 29 | vect = np.array(line[1:]).astype(np.float) 30 | glove2vec[word] = vect 31 | 32 | word2vec = {} 33 | word_arr = word_manager.symbol2idx.keys() 34 | for w in tqdm(word_arr): 35 | if w in glove2vec.keys(): 36 | word2vec[w] = glove2vec[w] 37 | 38 | print len(word2vec) 39 | out_file = "{}/pretrain.pkl".format(data_dir) 40 | with open(out_file, "wb") as out_data: 41 | pkl.dump(word2vec, out_data) 42 | 43 | def make_pretrained_embedding(embedding_size, opt): 44 | # use glove pretrained embedding and vocabulary to generate a embedding matrix 45 | data_dir = opt.data_dir 46 | min_freq = 2 47 | max_vocab_size = 15000 48 | torch.manual_seed(opt.seed) 49 | 50 | word2vec = pkl.load( open("{}/pretrain.pkl".format("../data/TextData"), "rb" ) ) 51 | managers = pkl.load( open("{}/map.pkl".format(data_dir), "rb" ) ) 52 | word_manager, form_manager = managers 53 | 54 | num_embeddings, embedding_dim = embedding_size 55 | weight_matrix = torch.zeros((num_embeddings, embedding_dim), dtype=torch.float) 56 | cnt_change = 0 57 | for i in range(num_embeddings): 58 | word = word_manager.idx2symbol[i] 59 | if word in word2vec: 60 | weight_matrix[i] = torch.from_numpy(word2vec[word]) 61 | cnt_change += 1 62 | else: 63 | weight_matrix[i] = torch.randn((embedding_dim, )) 64 | print cnt_change 65 | return weight_matrix 66 | 67 | if __name__ == "__main__": 68 | main_arg_parser = argparse.ArgumentParser(description="parser") 69 | main_arg_parser.add_argument('-data_dir', type=str, default='../data/TextData', help='data path') 70 | main_arg_parser.add_argument('-pretrained_embedding', type=str, default="/home/lishucheng/projects/Tools-and-Resources/glove/glove.6B.300d.txt") 71 | 72 | args = main_arg_parser.parse_args() 73 | if os.path.exists("{}/pretrain.pkl".format(args.data_dir)): 74 | print "word embedding has been generated !" 75 | else: 76 | generate_embedding_from_glove(args) -------------------------------------------------------------------------------- /src/sample_test.py: -------------------------------------------------------------------------------- 1 | import copy 2 | import torch 3 | import random 4 | import warnings 5 | import argparse 6 | import data_utils 7 | import graph_utils 8 | import numpy as np 9 | import pickle as pkl 10 | 11 | from tree import Tree 12 | from graph2tree import * 13 | 14 | warnings.filterwarnings('ignore') 15 | 16 | if __name__ == "__main__": 17 | main_arg_parser = argparse.ArgumentParser(description="parser") 18 | main_arg_parser.add_argument('-data_dir', type=str, default='../data/GraphConstruction', help='data path') 19 | main_arg_parser.add_argument('-model', type=str, default='checkpoint_dir/output_model', help='model checkpoint to use for sampling') 20 | main_arg_parser.add_argument('-seed',type=int,default=123,help='torch manual random number generator seed') 21 | 22 | args = main_arg_parser.parse_args() 23 | 24 | random.seed(args.seed) 25 | np.random.seed(args.seed) 26 | torch.manual_seed(args.seed) 27 | 28 | checkpoint = torch.load(args.model) 29 | encoder = checkpoint["encoder"] 30 | decoder = checkpoint["decoder"] 31 | attention_decoder = checkpoint["attention_decoder"] 32 | 33 | encoder.eval() 34 | decoder.eval() 35 | attention_decoder.eval() 36 | 37 | managers = pkl.load( open("{}/map.pkl".format(args.data_dir), "rb" ) ) 38 | word_manager, form_manager = managers 39 | 40 | data = pkl.load(open("{}/test.pkl".format(args.data_dir), "rb")) 41 | graph_test_list = graph_utils.read_graph_data("{}/graph.test".format(args.data_dir)) 42 | 43 | reference_list = [] 44 | candidate_list = [] 45 | 46 | for i in range(len(data)): 47 | x = data[i] 48 | reference = x[1] 49 | graph_batch = graph_utils.cons_batch_graph([graph_test_list[i]]) 50 | graph_input = graph_utils.vectorize_batch_graph(graph_batch, word_manager) 51 | 52 | candidate = do_generate(encoder, decoder, attention_decoder, graph_input, word_manager, form_manager, args, True, checkpoint) 53 | candidate = [int(c) for c in candidate] 54 | 55 | num_left_paren = sum(1 for c in candidate if form_manager.idx2symbol[int(c)]== "(") 56 | num_right_paren = sum(1 for c in candidate if form_manager.idx2symbol[int(c)]== ")") 57 | diff = num_left_paren - num_right_paren 58 | 59 | if diff > 0: 60 | for i in range(diff): 61 | candidate.append(form_manager.symbol2idx[")"]) 62 | elif diff < 0: 63 | candidate = candidate[:diff] 64 | ref_str = convert_to_string(reference, form_manager) 65 | cand_str = convert_to_string(candidate, form_manager) 66 | 67 | reference_list.append(reference) 68 | candidate_list.append(candidate) 69 | 70 | print("Test accuracy: ", data_utils.compute_tree_accuracy(candidate_list, reference_list, form_manager)) 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/sample_valid.py: -------------------------------------------------------------------------------- 1 | import copy 2 | import torch 3 | import random 4 | import warnings 5 | import argparse 6 | import data_utils 7 | import graph_utils 8 | import numpy as np 9 | import pickle as pkl 10 | 11 | from tree import Tree 12 | from graph2tree import * 13 | 14 | warnings.filterwarnings('ignore') 15 | 16 | if __name__ == "__main__": 17 | main_arg_parser = argparse.ArgumentParser(description="parser") 18 | main_arg_parser.add_argument('-data_dir', type=str, default='../data/GraphConstruction', help='data path') 19 | main_arg_parser.add_argument('-model_dir', type=str, default='checkpoint_dir/valid/', help='model checkpoint to use for sampling') 20 | main_arg_parser.add_argument('-seed',type=int,default=123,help='torch manual random number generator seed') 21 | main_arg_parser.add_argument('-output_model', type=str, default='checkpoint_dir/output_model', help='best model output') 22 | 23 | args = main_arg_parser.parse_args() 24 | 25 | managers = pkl.load( open("{}/map.pkl".format(args.data_dir), "rb" ) ) 26 | word_manager, form_manager = managers 27 | 28 | data = pkl.load(open("{}/valid.pkl".format(args.data_dir), "rb")) 29 | graph_test_list = graph_utils.read_graph_data("{}/graph.valid".format(args.data_dir)) 30 | 31 | max_acc = 0 32 | max_index = 0 33 | 34 | model_num = 0 35 | while(1): 36 | random.seed(args.seed) 37 | np.random.seed(args.seed) 38 | torch.manual_seed(args.seed) 39 | 40 | print model_num 41 | try: 42 | checkpoint = torch.load(args.model_dir + "model_g2t" + str(model_num)) 43 | except BaseException: 44 | break 45 | 46 | encoder = checkpoint["encoder"] 47 | decoder = checkpoint["decoder"] 48 | attention_decoder = checkpoint["attention_decoder"] 49 | 50 | encoder.eval() 51 | decoder.eval() 52 | attention_decoder.eval() 53 | 54 | reference_list = [] 55 | candidate_list = [] 56 | add_acc = 0.0 57 | 58 | for i in range(len(data)): 59 | x = data[i] 60 | reference = x[1] 61 | graph_batch = graph_utils.cons_batch_graph([graph_test_list[i]]) 62 | graph_input = graph_utils.vectorize_batch_graph(graph_batch, word_manager) 63 | candidate = do_generate(encoder, decoder, attention_decoder, graph_input, word_manager, form_manager, args, True, checkpoint) 64 | candidate = [int(c) for c in candidate] 65 | num_left_paren = sum(1 for c in candidate if form_manager.idx2symbol[int(c)]== "(") 66 | num_right_paren = sum(1 for c in candidate if form_manager.idx2symbol[int(c)]== ")") 67 | diff = num_left_paren - num_right_paren 68 | if diff > 0: 69 | for i in range(diff): 70 | candidate.append(form_manager.symbol2idx[")"]) 71 | elif diff < 0: 72 | candidate = candidate[:diff] 73 | ref_str = convert_to_string(reference, form_manager) 74 | cand_str = convert_to_string(candidate, form_manager) 75 | reference_list.append(reference) 76 | candidate_list.append(candidate) 77 | val_acc = data_utils.compute_tree_accuracy(candidate_list, reference_list, form_manager) 78 | print("ACCURACY = {}\n".format(val_acc)) 79 | if val_acc >= max_acc: 80 | max_acc = val_acc 81 | max_index = model_num 82 | 83 | model_num += 100 84 | print "max accuracy:", max_acc 85 | best_valid_model = torch.load(args.model_dir + "model_g2t" + str(max_index)) 86 | torch.save(best_valid_model, args.output_model) 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/tree.py: -------------------------------------------------------------------------------- 1 | # tree structure in decoder side 2 | # divide sub-node by brackets "()" 3 | 4 | class Tree(): 5 | def __init__(self): 6 | self.parent = None 7 | self.num_children = 0 8 | self.children = [] 9 | 10 | def __str__(self, level = 0): 11 | ret = "" 12 | for child in self.children: 13 | if isinstance(child,type(self)): 14 | ret += child.__str__(level+1) 15 | else: 16 | ret += "\t"*level + str(child) + "\n" 17 | return ret 18 | 19 | def add_child(self,c): 20 | if isinstance(c,type(self)): 21 | c.parent = self 22 | self.children.append(c) 23 | self.num_children = self.num_children + 1 24 | 25 | def to_string(self): 26 | r_list = [] 27 | for i in range(self.num_children): 28 | if isinstance(self.children[i], Tree): 29 | r_list.append("( " + self.children[i].to_string() + " )") 30 | else: 31 | r_list.append(str(self.children[i])) 32 | return "".join(r_list) 33 | 34 | def to_list(self, form_manager): 35 | r_list = [] 36 | for i in range(self.num_children): 37 | if isinstance(self.children[i], type(self)): 38 | r_list.append(form_manager.get_symbol_idx("(")) 39 | cl = self.children[i].to_list(form_manager) 40 | for k in range(len(cl)): 41 | r_list.append(cl[k]) 42 | r_list.append(form_manager.get_symbol_idx(")")) 43 | else: 44 | r_list.append(self.children[i]) 45 | return r_list -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd src 4 | python sample_test.py -------------------------------------------------------------------------------- /train.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd data/GraphConstruction 4 | python constituency.py 5 | 6 | cd ../../src 7 | mkdir checkpoint_dir 8 | mkdir checkpoint_dir/valid 9 | mkdir output 10 | 11 | # echo -----------pretrained embedding generating----------- 12 | python pretrained_embedding.py -pretrained_embedding="*where your glove text saved*" 13 | # echo ------------Begin training--------------------------- 14 | python graph2tree.py 15 | # echo ----------------------------------------------------- 16 | python sample_valid.py --------------------------------------------------------------------------------