├── .idea ├── DCNN.iml ├── misc.xml └── modules.xml ├── data ├── test ├── train └── trained_vecs.PICKLE ├── dataUtils.py ├── model.py ├── test.py └── train.py /.idea/DCNN.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /data/test: -------------------------------------------------------------------------------- 1 | NUM:dist How far is it from Denver to Aspen ? 2 | LOC:city What county is Modesto , California in ? 3 | HUM:desc Who was Galileo ? 4 | DESC:def What is an atom ? 5 | NUM:date When did Hawaii become a state ? 6 | NUM:dist How tall is the Sears Building ? 7 | HUM:gr George Bush purchased a small interest in which baseball team ? 8 | ENTY:plant What is Australia 's national flower ? 9 | DESC:reason Why does the moon turn orange ? 10 | DESC:def What is autism ? 11 | LOC:city What city had a world fair in 1900 ? 12 | HUM:ind What person 's head is on a dime ? 13 | NUM:weight What is the average weight of a Yellow Labrador ? 14 | HUM:ind Who was the first man to fly across the Pacific Ocean ? 15 | NUM:date When did Idaho become a state ? 16 | NUM:other What is the life expectancy for crickets ? 17 | ENTY:substance What metal has the highest melting point ? 18 | HUM:ind Who developed the vaccination against polio ? 19 | DESC:def What is epilepsy ? 20 | NUM:date What year did the Titanic sink ? 21 | HUM:ind Who was the first American to walk in space ? 22 | DESC:def What is a biosphere ? 23 | LOC:other What river in the US is known as the Big Muddy ? 24 | DESC:def What is bipolar disorder ? 25 | DESC:def What is cholesterol ? 26 | HUM:ind Who developed the Macintosh computer ? 27 | DESC:def What is caffeine ? 28 | LOC:other What imaginary line is halfway between the North and South Poles ? 29 | LOC:other Where is John Wayne airport ? 30 | LOC:other What hemisphere is the Philippines in ? 31 | NUM:speed What is the average speed of the horses at the Kentucky Derby ? 32 | LOC:mount Where are the Rocky Mountains ? 33 | DESC:def What are invertebrates ? 34 | NUM:temp What is the temperature at the center of the earth ? 35 | NUM:date When did John F. Kennedy get elected as President ? 36 | NUM:period How old was Elvis Presley when he died ? 37 | LOC:other Where is the Orinoco River ? 38 | NUM:dist How far is the service line from the net in tennis ? 39 | NUM:count How much fiber should you have per day ? 40 | NUM:count How many Great Lakes are there ? 41 | ENTY:plant Material called linen is made from what plant ? 42 | DESC:def What is Teflon ? 43 | DESC:def What is amitriptyline ? 44 | DESC:def What is a shaman ? 45 | ENTY:animal What is the proper name for a female walrus ? 46 | ENTY:animal What is a group of turkeys called ? 47 | NUM:period How long did Rip Van Winkle sleep ? 48 | DESC:def What are triglycerides ? 49 | NUM:count How many liters in a gallon ? 50 | HUM:gr What is the name of the chocolate company in San Francisco ? 51 | DESC:def What are amphibians ? 52 | HUM:ind Who discovered x-rays ? 53 | HUM:ind Which comedian 's signature line is `` Can we talk '' ? 54 | DESC:def What is fibromyalgia ? 55 | DESC:desc What is done with worn or outdated flags ? 56 | DESC:def What does cc in engines mean ? 57 | NUM:date When did Elvis Presley die ? 58 | LOC:city What is the capital of Yugoslavia ? 59 | LOC:city Where is Milan ? 60 | NUM:speed What is the speed hummingbirds fly ? 61 | LOC:city What is the oldest city in the United States ? 62 | HUM:ind What was W.C. Fields ' real name ? 63 | LOC:other What river flows between Fargo , North Dakota and Moorhead , Minnesota ? 64 | ENTY:food What do bats eat ? 65 | LOC:state What state did the Battle of Bighorn take place in ? 66 | HUM:desc Who was Abraham Lincoln ? 67 | ENTY:termeq What do you call a newborn kangaroo ? 68 | DESC:def What are spider veins ? 69 | NUM:date What day and month did John Lennon die ? 70 | LOC:other What strait separates North America from Asia ? 71 | NUM:other What is the population of Seattle ? 72 | NUM:money How much was a ticket for the Titanic ? 73 | LOC:city What is the largest city in the world ? 74 | HUM:ind What American composer wrote the music for `` West Side Story '' ? 75 | LOC:other Where is the Mall of the America ? 76 | DESC:def What is the pH scale ? 77 | ENTY:currency What type of currency is used in Australia ? 78 | NUM:dist How tall is the Gateway Arch in St. Louis , MO ? 79 | NUM:weight How much does the human adult female brain weigh ? 80 | HUM:ind Who was the first governor of Alaska ? 81 | DESC:def What is a prism ? 82 | NUM:date When was the first liver transplant ? 83 | HUM:ind Who was elected president of South Africa in 1994 ? 84 | NUM:other What is the population of China ? 85 | NUM:date When was Rosa Parks born ? 86 | DESC:reason Why is a ladybug helpful ? 87 | DESC:def What is amoxicillin ? 88 | HUM:ind Who was the first female United States Representative ? 89 | DESC:def What are xerophytes ? 90 | LOC:country What country did Ponce de Leon come from ? 91 | ENTY:event The U.S. Department of Treasury first issued paper currency for the U.S. during which war ? 92 | DESC:def What is desktop publishing ? 93 | NUM:temp What is the temperature of the sun 's surface ? 94 | NUM:date What year did Canada join the United Nations ? 95 | HUM:gr What is the oldest university in the US ? 96 | LOC:other Where is Prince Edward Island ? 97 | NUM:date Mercury , what year was it discovered ? 98 | DESC:def What is cryogenics ? 99 | DESC:def What are coral reefs ? 100 | ENTY:other What is the longest major league baseball-winning streak ? 101 | DESC:def What is neurology ? 102 | HUM:ind Who invented the calculator ? 103 | DESC:manner How do you measure earthquakes ? 104 | HUM:desc Who is Duke Ellington ? 105 | LOC:city What county is Phoenix , AZ in ? 106 | DESC:def What is a micron ? 107 | NUM:temp The sun 's core , what is the temperature ? 108 | ENTY:animal What is the Ohio state bird ? 109 | NUM:date When were William Shakespeare 's twins born ? 110 | LOC:other What is the highest dam in the U.S. ? 111 | ENTY:color What color is a poison arrow frog ? 112 | DESC:def What is acupuncture ? 113 | NUM:dist What is the length of the coastline of the state of Alaska ? 114 | HUM:ind What is the name of Neil Armstrong 's wife ? 115 | ENTY:plant What is Hawaii 's state flower ? 116 | HUM:ind Who won Ms. American in 1989 ? 117 | NUM:date When did the Hindenberg crash ? 118 | ENTY:substance What mineral helps prevent osteoporosis ? 119 | NUM:date What was the last year that the Chicago Cubs won the World Series ? 120 | LOC:other Where is Perth ? 121 | NUM:date What year did WWII begin ? 122 | NUM:dist What is the diameter of a golf ball ? 123 | DESC:def What is an eclipse ? 124 | HUM:ind Who discovered America ? 125 | NUM:dist What is the earth 's diameter ? 126 | HUM:ind Which president was unmarried ? 127 | NUM:dist How wide is the Milky Way galaxy ? 128 | NUM:date During which season do most thunderstorms occur ? 129 | DESC:def What is Wimbledon ? 130 | NUM:period What is the gestation period for a cat ? 131 | NUM:dist How far is a nautical mile ? 132 | HUM:ind Who was the abolitionist who led the raid on Harper 's Ferry in 1859 ? 133 | DESC:def What does target heart rate mean ? 134 | ENTY:product What was the first satellite to go into space ? 135 | DESC:def What is foreclosure ? 136 | ENTY:other What is the major fault line near Kentucky ? 137 | LOC:other Where is the Holland Tunnel ? 138 | HUM:ind Who wrote the hymn `` Amazing Grace '' ? 139 | HUM:title What position did Willie Davis play in baseball ? 140 | DESC:def What are platelets ? 141 | DESC:def What is severance pay ? 142 | ENTY:animal What is the name of Roy Roger 's dog ? 143 | LOC:other Where are the National Archives ? 144 | ENTY:animal What is a baby turkey called ? 145 | DESC:def What is poliomyelitis ? 146 | ENTY:body What is the longest bone in the human body ? 147 | HUM:ind Who is a German philosopher ? 148 | ENTY:veh What were Christopher Columbus ' three ships ? 149 | DESC:def What does Phi Beta Kappa mean ? 150 | DESC:def What is nicotine ? 151 | ENTY:termeq What is another name for vitamin B1 ? 152 | HUM:ind Who discovered radium ? 153 | DESC:def What are sunspots ? 154 | NUM:date When was Algeria colonized ? 155 | HUM:gr What baseball team was the first to make numbers part of their uniform ? 156 | LOC:other What continent is Egypt on ? 157 | LOC:city What is the capital of Mongolia ? 158 | DESC:def What is nanotechnology ? 159 | LOC:other In the late 1700 's British convicts were used to populate which colony ? 160 | LOC:state What state is the geographic center of the lower 48 states ? 161 | DESC:def What is an obtuse angle ? 162 | DESC:def What are polymers ? 163 | NUM:date When is hurricane season in the Caribbean ? 164 | LOC:other Where is the volcano Mauna Loa ? 165 | ENTY:termeq What is another astronomic term for the Northern Lights ? 166 | LOC:other What peninsula is Spain part of ? 167 | NUM:date When was Lyndon B. Johnson born ? 168 | DESC:def What is acetaminophen ? 169 | LOC:state What state has the least amount of rain per year ? 170 | HUM:ind Who founded American Red Cross ? 171 | NUM:date What year did the Milwaukee Braves become the Atlanta Braves ? 172 | NUM:speed How fast is alcohol absorbed ? 173 | NUM:date When is the summer solstice ? 174 | DESC:def What is supernova ? 175 | LOC:other Where is the Shawnee National Forest ? 176 | LOC:state What U.S. state 's motto is `` Live free or Die '' ? 177 | LOC:other Where is the Lourve ? 178 | NUM:date When was the first stamp issued ? 179 | ENTY:color What primary colors do you mix to make orange ? 180 | NUM:dist How far is Pluto from the sun ? 181 | LOC:other What body of water are the Canary Islands in ? 182 | DESC:def What is neuropathy ? 183 | LOC:other Where is the Euphrates River ? 184 | DESC:def What is cryptography ? 185 | ENTY:substance What is natural gas composed of ? 186 | HUM:ind Who is the Prime Minister of Canada ? 187 | HUM:ind What French ruler was defeated at the battle of Waterloo ? 188 | DESC:def What is leukemia ? 189 | LOC:other Where did Howard Hughes die ? 190 | ENTY:substance What is the birthstone for June ? 191 | ENTY:other What is the sales tax in Minnesota ? 192 | NUM:dist What is the distance in miles from the earth to the sun ? 193 | NUM:period What is the average life span for a chicken ? 194 | NUM:date When was the first Wal-Mart store opened ? 195 | DESC:def What is relative humidity ? 196 | LOC:city What city has the zip code of 35824 ? 197 | ENTY:currency What currency is used in Algeria ? 198 | HUM:ind Who invented the hula hoop ? 199 | ENTY:product What was the most popular toy in 1957 ? 200 | ENTY:substance What is pastrami made of ? 201 | ENTY:product What is the name of the satellite that the Soviet Union sent into space in 1957 ? 202 | LOC:city What city 's newspaper is called `` The Enquirer '' ? 203 | HUM:ind Who invented the slinky ? 204 | ENTY:animal What are the animals that don 't have backbones called ? 205 | NUM:other What is the melting point of copper ? 206 | LOC:other Where is the volcano Olympus Mons located ? 207 | HUM:ind Who was the 23rd president of the United States ? 208 | NUM:temp What is the average body temperature ? 209 | DESC:desc What does a defibrillator do ? 210 | DESC:desc What is the effect of acid rain ? 211 | NUM:date What year did the United States abolish the draft ? 212 | NUM:speed How fast is the speed of light ? 213 | LOC:state What province is Montreal in ? 214 | LOC:other What New York City structure is also known as the Twin Towers ? 215 | DESC:def What is fungus ? 216 | ENTY:lang What is the most frequently spoken language in the Netherlands ? 217 | DESC:def What is sodium chloride ? 218 | ENTY:termeq What are the spots on dominoes called ? 219 | NUM:count How many pounds in a ton ? 220 | DESC:def What is influenza ? 221 | DESC:def What is ozone depletion ? 222 | NUM:date What year was the Mona Lisa painted ? 223 | DESC:def What does `` Sitting Shiva '' mean ? 224 | ENTY:other What is the electrical output in Madrid , Spain ? 225 | LOC:mount Which mountain range in North America stretches from Maine to Georgia ? 226 | ENTY:substance What is plastic made of ? 227 | NUM:other What is the population of Nigeria ? 228 | DESC:desc What does your spleen do ? 229 | LOC:other Where is the Grand Canyon ? 230 | HUM:ind Who invented the telephone ? 231 | NUM:date What year did the U.S. buy Alaska ? 232 | HUM:ind What is the name of the leader of Ireland ? 233 | DESC:def What is phenylalanine ? 234 | NUM:count How many gallons of water are there in a cubic foot ? 235 | ENTY:other What are the two houses of the Legislative branch ? 236 | DESC:def What is sonar ? 237 | LOC:other In Poland , where do most people live ? 238 | DESC:def What is phosphorus ? 239 | LOC:other What is the location of the Sea of Tranquility ? 240 | NUM:speed How fast is sound ? 241 | LOC:state What French province is cognac produced in ? 242 | DESC:def What is Valentine 's Day ? 243 | DESC:reason What causes gray hair ? 244 | DESC:def What is hypertension ? 245 | DESC:def What is bandwidth ? 246 | LOC:other What is the longest suspension bridge in the U.S. ? 247 | DESC:def What is a parasite ? 248 | DESC:def What is home equity ? 249 | DESC:desc What do meteorologists do ? 250 | ENTY:other What is the criterion for being legally blind ? 251 | HUM:ind Who is the tallest man in the world ? 252 | LOC:city What are the twin cities ? 253 | ENTY:other What did Edward Binney and Howard Smith invent in 1903 ? 254 | ENTY:substance What is the statue of liberty made of ? 255 | DESC:def What is pilates ? 256 | LOC:other What planet is known as the `` red '' planet ? 257 | NUM:dist What is the depth of the Nile river ? 258 | ENTY:termeq What is the colorful Korean traditional dress called ? 259 | DESC:def What is Mardi Gras ? 260 | NUM:money Mexican pesos are worth what in U.S. dollars ? 261 | HUM:ind Who was the first African American to play for the Brooklyn Dodgers ? 262 | HUM:ind Who was the first Prime Minister of Canada ? 263 | NUM:count How many Admirals are there in the U.S. Navy ? 264 | ENTY:instru What instrument did Glenn Miller play ? 265 | NUM:period How old was Joan of Arc when she died ? 266 | DESC:def What does the word fortnight mean ? 267 | DESC:def What is dianetics ? 268 | LOC:city What is the capital of Ethiopia ? 269 | NUM:period For how long is an elephant pregnant ? 270 | DESC:manner How did Janice Joplin die ? 271 | ENTY:lang What is the primary language in Iceland ? 272 | DESC:desc What is the difference between AM radio stations and FM radio stations ? 273 | DESC:def What is osteoporosis ? 274 | HUM:ind Who was the first woman governor in the U.S. ? 275 | DESC:def What is peyote ? 276 | DESC:reason What is the esophagus used for ? 277 | DESC:def What is viscosity ? 278 | NUM:date What year did Oklahoma become a state ? 279 | ABBR:abb What is the abbreviation for Texas ? 280 | ENTY:substance What is a mirror made out of ? 281 | LOC:other Where on the body is a mortarboard worn ? 282 | HUM:ind What was J.F.K. 's wife 's name ? 283 | ABBR:exp What does I.V. stand for ? 284 | DESC:def What is the chunnel ? 285 | LOC:other Where is Hitler buried ? 286 | DESC:def What are antacids ? 287 | DESC:def What is pulmonary fibrosis ? 288 | DESC:def What are Quaaludes ? 289 | DESC:def What is naproxen ? 290 | DESC:def What is strep throat ? 291 | LOC:city What is the largest city in the U.S. ? 292 | ENTY:dismed What is foot and mouth disease ? 293 | NUM:other What is the life expectancy of a dollar bill ? 294 | ENTY:termeq What do you call a professional map drawer ? 295 | DESC:def What are Aborigines ? 296 | DESC:def What is hybridization ? 297 | ENTY:color What color is indigo ? 298 | NUM:period How old do you have to be in order to rent a car in Italy ? 299 | ENTY:other What does a barometer measure ? 300 | ENTY:color What color is a giraffe 's tongue ? 301 | ABBR:exp What does USPS stand for ? 302 | NUM:date What year did the NFL go on strike ? 303 | DESC:def What is solar wind ? 304 | NUM:date What date did Neil Armstrong land on the moon ? 305 | NUM:date When was Hiroshima bombed ? 306 | LOC:other Where is the Savannah River ? 307 | HUM:ind Who was the first woman killed in the Vietnam War ? 308 | LOC:other What planet has the strongest magnetic field of all the planets ? 309 | HUM:ind Who is the governor of Alaska ? 310 | NUM:date What year did Mussolini seize power in Italy ? 311 | LOC:city What is the capital of Persia ? 312 | LOC:other Where is the Eiffel Tower ? 313 | NUM:count How many hearts does an octopus have ? 314 | DESC:def What is pneumonia ? 315 | LOC:other What is the deepest lake in the US ? 316 | DESC:def What is a fuel cell ? 317 | HUM:ind Who was the first U.S. president to appear on TV ? 318 | LOC:other Where is the Little League Museum ? 319 | ENTY:other What are the two types of twins ? 320 | LOC:other What is the brightest star ? 321 | DESC:def What is diabetes ? 322 | NUM:date When was President Kennedy shot ? 323 | ABBR:exp What is TMJ ? 324 | ENTY:color What color is yak milk ? 325 | NUM:date What date was Dwight D. Eisenhower born ? 326 | ABBR:exp What does the technical term ISDN mean ? 327 | DESC:reason Why is the sun yellow ? 328 | NUM:money What is the conversion rate between dollars and pounds ? 329 | NUM:date When was Abraham Lincoln born ? 330 | DESC:def What is the Milky Way ? 331 | DESC:def What is mold ? 332 | NUM:date What year was Mozart born ? 333 | ENTY:animal What is a group of frogs called ? 334 | ENTY:veh What is the name of William Penn 's ship ? 335 | NUM:other What is the melting point of gold ? 336 | LOC:other What is the street address of the White House ? 337 | DESC:def What is semolina ? 338 | ENTY:food What fruit is Melba sauce made from ? 339 | DESC:def What is Ursa Major ? 340 | NUM:perc What is the percentage of water content in the human body ? 341 | NUM:weight How much does water weigh ? 342 | ENTY:event What was President Lyndon Johnson 's reform program called ? 343 | NUM:perc What is the murder rate in Windsor , Ontario ? 344 | HUM:ind Who is the only president to serve 2 non-consecutive terms ? 345 | NUM:other What is the population of Australia ? 346 | HUM:ind Who painted the ceiling of the Sistine Chapel ? 347 | ENTY:dismed Name a stimulant . 348 | DESC:desc What is the effect of volcanoes on the climate ? 349 | NUM:date What year did the Andy Griffith show begin ? 350 | DESC:def What is acid rain ? 351 | NUM:date What is the date of Mexico 's independence ? 352 | LOC:other What is the location of Lake Champlain ? 353 | ENTY:plant What is the Illinois state flower ? 354 | ENTY:animal What is Maryland 's state bird ? 355 | DESC:def What is quicksilver ? 356 | HUM:ind Who wrote `` The Divine Comedy '' ? 357 | NUM:speed What is the speed of light ? 358 | NUM:dist What is the width of a football field ? 359 | DESC:reason Why in tennis are zero points called love ? 360 | ENTY:animal What kind of dog was Toto in the Wizard of Oz ? 361 | DESC:def What is a thyroid ? 362 | DESC:def What does ciao mean ? 363 | ENTY:body What is the only artery that carries blue blood from the heart to the lungs ? 364 | NUM:other How often does Old Faithful erupt at Yellowstone National Park ? 365 | DESC:def What is acetic acid ? 366 | NUM:dist What is the elevation of St. Louis , MO ? 367 | ENTY:color What color does litmus paper turn when it comes into contact with a strong acid ? 368 | ENTY:color What are the colors of the German flag ? 369 | DESC:def What is the Moulin Rouge ? 370 | LOC:other What soviet seaport is on the Black Sea ? 371 | NUM:weight What is the atomic weight of silver ? 372 | ENTY:currency What currency do they use in Brazil ? 373 | DESC:def What are pathogens ? 374 | DESC:def What is mad cow disease ? 375 | ENTY:food Name a food high in zinc . 376 | NUM:date When did North Carolina enter the union ? 377 | LOC:other Where do apple snails live ? 378 | DESC:def What are ethics ? 379 | ABBR:exp What does CPR stand for ? 380 | DESC:def What is an annuity ? 381 | HUM:ind Who killed John F. Kennedy ? 382 | HUM:ind Who was the first vice president of the U.S. ? 383 | ENTY:substance What birthstone is turquoise ? 384 | HUM:ind Who was the first US President to ride in an automobile to his inauguration ? 385 | NUM:period How old was the youngest president of the United States ? 386 | NUM:date When was Ulysses S. Grant born ? 387 | DESC:def What is Muscular Dystrophy ? 388 | HUM:ind Who lived in the Neuschwanstein castle ? 389 | DESC:def What is propylene glycol ? 390 | DESC:def What is a panic disorder ? 391 | HUM:ind Who invented the instant Polaroid camera ? 392 | DESC:def What is a carcinogen ? 393 | ENTY:animal What is a baby lion called ? 394 | NUM:other What is the world 's population ? 395 | DESC:def What is nepotism ? 396 | DESC:def What is die-casting ? 397 | DESC:def What is myopia ? 398 | NUM:other What is the sales tax rate in New York ? 399 | NUM:perc Developing nations comprise what percentage of the world 's population ? 400 | LOC:mount What is the fourth highest mountain in the world ? 401 | HUM:ind What is Shakespeare 's nickname ? 402 | ENTY:substance What is the heaviest naturally occurring element ? 403 | NUM:date When is Father 's Day ? 404 | ABBR:exp What does the acronym NASA stand for ? 405 | NUM:dist How long is the Columbia River in miles ? 406 | LOC:city What city 's newspaper is called `` The Star '' ? 407 | DESC:def What is carbon dioxide ? 408 | LOC:other Where is the Mason/Dixon line ? 409 | NUM:date When was the Boston tea party ? 410 | DESC:def What is metabolism ? 411 | HUM:ind Which U.S.A. president appeared on `` Laugh-In '' ? 412 | ENTY:substance What are cigarettes made of ? 413 | LOC:city What is the capital of Zimbabwe ? 414 | ABBR:exp What does NASA stand for ? 415 | ENTY:plant What is the state flower of Michigan ? 416 | DESC:def What are semiconductors ? 417 | DESC:def What is nuclear power ? 418 | DESC:def What is a tsunami ? 419 | HUM:ind Who is the congressman from state of Texas on the armed forces committee ? 420 | HUM:ind Who was president in 1913 ? 421 | NUM:date When was the first kidney transplant ? 422 | LOC:other What are Canada 's two territories ? 423 | ENTY:veh What was the name of the plane Lindbergh flew solo across the Atlantic ? 424 | DESC:def What is genocide ? 425 | LOC:other What continent is Argentina on ? 426 | ENTY:other What monastery was raided by Vikings in the late eighth century ? 427 | DESC:def What is an earthquake ? 428 | LOC:other Where is the tallest roller coaster located ? 429 | DESC:def What are enzymes ? 430 | HUM:ind Who discovered oxygen ? 431 | DESC:def What is bangers and mash ? 432 | ENTY:animal What is the name given to the Tiger at Louisiana State University ? 433 | LOC:other Where are the British crown jewels kept ? 434 | HUM:ind Who was the first person to reach the North Pole ? 435 | DESC:def What is an ulcer ? 436 | DESC:def What is vertigo ? 437 | DESC:def What is the spirometer test ? 438 | NUM:date When is the official first day of summer ? 439 | ABBR:exp What does the abbreviation SOS mean ? 440 | ENTY:animal What is the smallest bird in Britain ? 441 | HUM:ind Who invented Trivial Pursuit ? 442 | ENTY:substance What gasses are in the troposphere ? 443 | LOC:country Which country has the most water pollution ? 444 | ENTY:animal What is the scientific name for elephant ? 445 | HUM:ind Who is the actress known for her role in the movie `` Gypsy '' ? 446 | ENTY:animal What breed of hunting dog did the Beverly Hillbillies own ? 447 | LOC:other What is the rainiest place on Earth ? 448 | HUM:ind Who was the first African American to win the Nobel Prize in literature ? 449 | NUM:date When is St. Patrick 's Day ? 450 | ENTY:animal What was FDR 's dog 's name ? 451 | ENTY:color What colors need to be mixed to get the color pink ? 452 | ENTY:sport What is the most popular sport in Japan ? 453 | ENTY:food What is the active ingredient in baking soda ? 454 | NUM:date When was Thomas Jefferson born ? 455 | NUM:temp How cold should a refrigerator be ? 456 | NUM:date When was the telephone invented ? 457 | ENTY:color What is the most common eye color ? 458 | LOC:other Where was the first golf course in the United States ? 459 | DESC:def What is schizophrenia ? 460 | DESC:def What is angiotensin ? 461 | HUM:gr What did Jesse Jackson organize ? 462 | ENTY:animal What is New York 's state bird ? 463 | LOC:other What is the National Park in Utah ? 464 | NUM:date What is Susan B. Anthony 's birthday ? 465 | LOC:state In which state would you find the Catskill Mountains ? 466 | ENTY:termeq What do you call a word that is spelled the same backwards and forwards ? 467 | DESC:def What are pediatricians ? 468 | HUM:gr What chain store is headquartered in Bentonville , Arkansas ? 469 | DESC:def What are solar cells ? 470 | DESC:def What is compounded interest ? 471 | DESC:def What are capers ? 472 | DESC:def What is an antigen ? 473 | ENTY:currency What currency does Luxembourg use ? 474 | NUM:other What is the population of Venezuela ? 475 | ENTY:other What type of polymer is used for bulletproof vests ? 476 | ENTY:currency What currency does Argentina use ? 477 | DESC:def What is a thermometer ? 478 | LOC:city What Canadian city has the largest population ? 479 | ENTY:color What color are crickets ? 480 | LOC:country Which country gave New York the Statue of Liberty ? 481 | ENTY:product What was the name of the first U.S. satellite sent into space ? 482 | ENTY:substance What precious stone is a form of pure carbon ? 483 | ENTY:substance What kind of gas is in a fluorescent bulb ? 484 | DESC:def What is rheumatoid arthritis ? 485 | LOC:other What river runs through Rowe , Italy ? 486 | DESC:def What is cerebral palsy ? 487 | LOC:city What city is also known as `` The Gateway to the West '' ? 488 | NUM:dist How far away is the moon ? 489 | ENTY:other What is the source of natural gas ? 490 | ENTY:veh In what spacecraft did U.S. astronaut Alan Shepard make his historic 1961 flight ? 491 | DESC:def What is pectin ? 492 | DESC:def What is bio-diversity ? 493 | ENTY:techmeth What 's the easiest way to remove wallpaper ? 494 | NUM:date What year did the Titanic start on its journey ? 495 | NUM:count How much of an apple is water ? 496 | HUM:ind Who was the 22nd President of the US ? 497 | ENTY:currency What is the money they use in Zambia ? 498 | NUM:count How many feet in a mile ? 499 | ENTY:substance What is the birthstone of October ? 500 | DESC:def What is e-coli ? 501 | -------------------------------------------------------------------------------- /data/train: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lc222/Dynamic-CNN-Sentence-Classification-TF/f14fb54d3918cb14ed0e860dbd623fb019b6f2b3/data/train -------------------------------------------------------------------------------- /data/trained_vecs.PICKLE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lc222/Dynamic-CNN-Sentence-Classification-TF/f14fb54d3918cb14ed0e860dbd623fb019b6f2b3/data/trained_vecs.PICKLE -------------------------------------------------------------------------------- /dataUtils.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | import itertools 3 | import numpy as np 4 | import re 5 | 6 | def clean_str(string): 7 | string = re.sub(r"[^A-Za-z0-9:(),!?\'\`]", " ", string) 8 | string = re.sub(r" : ", ":", string) 9 | string = re.sub(r"\'s", " \'s", string) 10 | string = re.sub(r"\'ve", " \'ve", string) 11 | string = re.sub(r"n\'t", " n\'t", string) 12 | string = re.sub(r"\'re", " \'re", string) 13 | string = re.sub(r"\'d", " \'d", string) 14 | string = re.sub(r"\'ll", " \'ll", string) 15 | string = re.sub(r",", " , ", string) 16 | string = re.sub(r"!", " ! ", string) 17 | string = re.sub(r"\(", " \( ", string) 18 | string = re.sub(r"\)", " \) ", string) 19 | string = re.sub(r"\?", " \? ", string) 20 | string = re.sub(r"\s{2,}", " ", string) 21 | return string.strip().lower() 22 | 23 | def load_data_and_labels(): 24 | """ 25 | Loads data from files, splits the data into words and generates labels. 26 | Returns split sentences and labels. 27 | """ 28 | # Load data from files 29 | folder_prefix = 'data/' 30 | x_train = list(open(folder_prefix+"train").readlines()) 31 | x_test = list(open(folder_prefix+"test").readlines()) 32 | test_size = len(x_test) 33 | x_text = x_train + x_test 34 | 35 | x_text = [clean_str(sent) for sent in x_text] 36 | y = [s.split(' ')[0].split(':')[0] for s in x_text] 37 | x_text = [s.split(" ")[1:] for s in x_text] 38 | # Generate labels 39 | all_label = dict() 40 | for label in y: 41 | if not label in all_label: 42 | all_label[label] = len(all_label) + 1 43 | one_hot = np.identity(len(all_label)) 44 | y = [one_hot[ all_label[label]-1 ] for label in y] 45 | return [x_text, y, test_size] 46 | 47 | def pad_sentences(sentences, padding_word=""): 48 | """ 49 | Pads all sentences to the same length. The length is defined by the longest sentence. 50 | Returns padded sentences. 51 | """ 52 | sequence_length = max(len(x) for x in sentences) 53 | padded_sentences = [] 54 | for i in range(len(sentences)): 55 | sentence = sentences[i] 56 | num_padding = sequence_length - len(sentence) 57 | new_sentence = sentence + [padding_word] * num_padding 58 | padded_sentences.append(new_sentence) 59 | return padded_sentences 60 | 61 | def build_vocab(sentences): 62 | """ 63 | Builds a vocabulary mapping from word to index based on the sentences. 64 | Returns vocabulary mapping and inverse vocabulary mapping. 65 | """ 66 | # Build vocabulary 67 | word_counts = Counter(itertools.chain(*sentences)) 68 | # Mapping from index to word 69 | # vocabulary_inv=['', 'the', ....] 70 | vocabulary_inv = [x[0] for x in word_counts.most_common()] 71 | # Mapping from word to index 72 | # vocabulary = {'': 0, 'the': 1, ',': 2, 'a': 3, 'and': 4, ..} 73 | vocabulary = {x: i for i, x in enumerate(vocabulary_inv)} 74 | return [vocabulary, vocabulary_inv] 75 | 76 | def build_input_data(sentences, labels, vocabulary): 77 | """ 78 | Maps sentences and labels to vectors based on a vocabulary. 79 | """ 80 | x = np.array([[vocabulary[word] for word in sentence] for sentence in sentences]) 81 | y = np.array(labels) 82 | return [x, y] 83 | 84 | def load_data(): 85 | """ 86 | Loads and preprocessed data 87 | Returns input vectors, labels, vocabulary, and inverse vocabulary. 88 | """ 89 | # Load and preprocess data 90 | sentences, labels, test_size = load_data_and_labels() 91 | sentences_padded = pad_sentences(sentences) 92 | vocabulary, vocabulary_inv = build_vocab(sentences_padded) 93 | x, y = build_input_data(sentences_padded, labels, vocabulary) 94 | return [x, y, vocabulary, vocabulary_inv, test_size] 95 | 96 | def batch_iter(data, batch_size, num_epochs): 97 | """ 98 | Generates a batch iterator for a dataset. 99 | """ 100 | data = np.array(data) 101 | data_size = len(data) 102 | num_batches_per_epoch = int(len(data)/batch_size) + 1 103 | for epoch in range(num_epochs): 104 | # Shuffle the data at each epoch 105 | shuffle_indices = np.random.permutation(np.arange(data_size)) 106 | shuffled_data = data[shuffle_indices] 107 | for batch_num in range(num_batches_per_epoch): 108 | start_index = batch_num * batch_size 109 | end_index = (batch_num + 1) * batch_size 110 | if end_index > data_size: 111 | end_index = data_size 112 | start_index = end_index - batch_size 113 | yield shuffled_data[start_index:end_index] -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | 3 | class DCNN(): 4 | def __init__(self, batch_size, sentence_length, num_filters, embed_size, top_k, k1): 5 | self.batch_size = batch_size 6 | self.sentence_length = sentence_length 7 | self.num_filters = num_filters 8 | self.embed_size = embed_size 9 | self.top_k = top_k 10 | self.k1 = k1 11 | 12 | def per_dim_conv_k_max_pooling_layer(self, x, w, b, k): 13 | self.k1 = k 14 | input_unstack = tf.unstack(x, axis=2) 15 | w_unstack = tf.unstack(w, axis=1) 16 | b_unstack = tf.unstack(b, axis=1) 17 | convs = [] 18 | with tf.name_scope("per_dim_conv_k_max_pooling"): 19 | for i in range(self.embed_size): 20 | conv = tf.nn.relu(tf.nn.conv1d(input_unstack[i], w_unstack[i], stride=1, padding="SAME") + b_unstack[i]) 21 | #conv:[batch_size, sent_length+ws-1, num_filters] 22 | conv = tf.reshape(conv, [self.batch_size, self.num_filters[0], self.sentence_length])#[batch_size, sentence_length, num_filters] 23 | values = tf.nn.top_k(conv, k, sorted=False).values 24 | values = tf.reshape(values, [self.batch_size, k, self.num_filters[0]]) 25 | #k_max pooling in axis=1 26 | convs.append(values) 27 | conv = tf.stack(convs, axis=2) 28 | #[batch_size, k1, embed_size, num_filters[0]] 29 | #print conv.get_shape() 30 | return conv 31 | 32 | def per_dim_conv_layer(self, x, w, b): 33 | input_unstack = tf.unstack(x, axis=2) 34 | w_unstack = tf.unstack(w, axis=1) 35 | b_unstack = tf.unstack(b, axis=1) 36 | convs = [] 37 | with tf.name_scope("per_dim_conv"): 38 | for i in range(len(input_unstack)): 39 | conv = tf.nn.relu(tf.nn.conv1d(input_unstack[i], w_unstack[i], stride=1, padding="SAME") + b_unstack[i])#[batch_size, k1+ws2-1, num_filters[1]] 40 | convs.append(conv) 41 | conv = tf.stack(convs, axis=2) 42 | #[batch_size, k1+ws-1, embed_size, num_filters[1]] 43 | return conv 44 | 45 | def fold_k_max_pooling(self, x, k): 46 | input_unstack = tf.unstack(x, axis=2) 47 | out = [] 48 | with tf.name_scope("fold_k_max_pooling"): 49 | for i in range(0, len(input_unstack), 2): 50 | fold = tf.add(input_unstack[i], input_unstack[i+1])#[batch_size, k1, num_filters[1]] 51 | conv = tf.transpose(fold, perm=[0, 2, 1]) 52 | values = tf.nn.top_k(conv, k, sorted=False).values #[batch_size, num_filters[1], top_k] 53 | values = tf.transpose(values, perm=[0, 2, 1]) 54 | out.append(values) 55 | fold = tf.stack(out, axis=2)#[batch_size, k2, embed_size/2, num_filters[1]] 56 | return fold 57 | 58 | def full_connect_layer(self, x, w, b, wo, dropout_keep_prob): 59 | with tf.name_scope("full_connect_layer"): 60 | h = tf.nn.tanh(tf.matmul(x, w) + b) 61 | h = tf.nn.dropout(h, dropout_keep_prob) 62 | o = tf.matmul(h, wo) 63 | return o 64 | 65 | def DCNN(self, sent, W1, W2, b1, b2, k1, top_k, Wh, bh, Wo, dropout_keep_prob): 66 | conv1 = self.per_dim_conv_layer(sent, W1, b1) 67 | conv1 = self.fold_k_max_pooling(conv1, k1) 68 | conv2 = self.per_dim_conv_layer(conv1, W2, b2) 69 | fold = self.fold_k_max_pooling(conv2, top_k) 70 | fold_flatten = tf.reshape(fold, [-1, top_k*100*14/4]) 71 | print fold_flatten.get_shape() 72 | out = self.full_connect_layer(fold_flatten, Wh, bh, Wo, dropout_keep_prob) 73 | return out 74 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import embedding as emb 4 | def qselect(A, k): 5 | if len(A) < k: return A 6 | pivot = A[-1] 7 | right = [pivot] + [x for x in A[:-1] if x >= pivot] 8 | rlen = len(right) 9 | if rlen == k: 10 | return right 11 | if rlen > k: 12 | return qselect(right, k) 13 | else: 14 | left = [x for x in A[:-1] if x < pivot] 15 | return qselect(left, k - rlen) + right 16 | 17 | # a = np.array([[1,2,3], [3,4,5]]) 18 | # print a.shape 19 | # a = tf.placeholder(tf.float32, [120]) 20 | # b = tf.reshape(a, [2,3,4,5]) 21 | # values, indices = tf.nn.top_k(b, 2) 22 | # with tf.Session() as sess: 23 | # print sess.run(b, feed_dict={a:np.arange(120, dtype="float32")}) 24 | # print sess.run(tf.nn.top_k(b, 2, sorted=False), feed_dict={a:np.arange(120, dtype="float32")}) 25 | 26 | embed_dim = 50 27 | ws = [4, 5] 28 | top_k = 4 29 | k1 = 5 30 | num_filters = [3, 14] 31 | batch_size = 2 32 | num_hidden = 100 33 | sentence_length = 10 34 | num_class = 6 35 | lr = 0.01 36 | 37 | 38 | def init_weights(shape, name): 39 | return tf.Variable(tf.truncated_normal(shape, stddev=0.01), name=name) 40 | 41 | glove = emb.GloVe(N=embed_dim) 42 | 43 | with tf.Session() as sess: 44 | sent = tf.placeholder(tf.int32, [batch_size, sentence_length]) 45 | 46 | sent_embed = tf.nn.embedding_lookup(glove.g, sent) 47 | input_x = tf.reshape(sent_embed, [batch_size, sentence_length, embed_dim, 1]) 48 | 49 | W1 = init_weights([ws[0], embed_dim, 1, num_filters[0]], "W1") 50 | b1 = tf.Variable(tf.constant(0.1, shape=[num_filters[0], embed_dim]), "b1") 51 | init = tf.global_variables_initializer().run() 52 | print W1.eval(), b1.eval() 53 | 54 | input_unstack = tf.unstack(input_x, axis=2) 55 | w_unstack = tf.unstack(W1, axis=1) 56 | b_unstack = tf.unstack(b1, axis=1) 57 | convs = [] 58 | 59 | conv = tf.nn.relu(tf.nn.conv1d(input_unstack[0], w_unstack[0], stride=1, padding="SAME") + b_unstack[0]) 60 | #print conv.eval() 61 | # conv:[batch_size, sent_length+ws-1, num_filters] 62 | conv1 = tf.reshape(conv, [batch_size, num_filters[0], 63 | sentence_length]) # [batch_size, sentence_length, num_filters] 64 | values, indices = tf.nn.top_k(conv1, k1, sorted=False) 65 | #print values.eval() 66 | values1 = tf.reshape(values, [batch_size, k1, num_filters[0]]) 67 | # k_max pooling in axis=1 68 | convs.append(values1) 69 | conv2 = tf.stack(convs, axis=2) 70 | 71 | a, b, c ,d, e = sess.run([input_x, conv, conv1, values, indices], feed_dict={sent:[[1,2,3,4,5,6,7,8,9,10],[11,12,13,14,15,16,17,18,19,20]]}) 72 | print a,b,c,d,e -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | #coding=utf8 2 | from model import * 3 | import dataUtils 4 | import numpy as np 5 | import time 6 | import os 7 | 8 | embed_dim = 100 9 | ws = [7, 5] 10 | top_k = 4 11 | k1 = 19 12 | num_filters = [6, 14] 13 | dev = 300 14 | batch_size = 50 15 | n_epochs = 30 16 | num_hidden = 100 17 | sentence_length = 37 18 | num_class = 6 19 | lr = 0.01 20 | evaluate_every = 100 21 | checkpoint_every = 100 22 | num_checkpoints = 5 23 | 24 | # Load data 25 | print("Loading data...") 26 | x_, y_, vocabulary, vocabulary_inv, test_size = dataUtils.load_data() 27 | #x_:长度为5952的np.array。(包含5452个训练集和500个测试集)其中每个句子都是padding成长度为37的list(padding的索引为0) 28 | #y_:长度为5952的np.array。每一个都是长度为6的onehot编码表示其类别属性 29 | #vocabulary:长度为8789的字典,说明语料库中一共包含8789各单词。key是单词,value是索引 30 | #vocabulary_inv:长度为8789的list,是按照单词出现次数进行排列。依次为:,\\?,the,what,is,of,in,a.... 31 | #test_size:500,测试集大小 32 | 33 | # Randomly shuffle data 34 | x, x_test = x_[:-test_size], x_[-test_size:] 35 | y, y_test = y_[:-test_size], y_[-test_size:] 36 | shuffle_indices = np.random.permutation(np.arange(len(y))) 37 | x_shuffled = x[shuffle_indices] 38 | y_shuffled = y[shuffle_indices] 39 | 40 | x_train, x_dev = x_shuffled[:-dev], x_shuffled[-dev:] 41 | y_train, y_dev = y_shuffled[:-dev], y_shuffled[-dev:] 42 | 43 | print("Train/Dev/Test split: {:d}/{:d}/{:d}".format(len(y_train), len(y_dev), len(y_test))) 44 | #--------------------------------------------------------------------------------------# 45 | 46 | def init_weights(shape, name): 47 | return tf.Variable(tf.truncated_normal(shape, stddev=0.01), name=name) 48 | 49 | sent = tf.placeholder(tf.int64, [None, sentence_length]) 50 | y = tf.placeholder(tf.float64, [None, num_class]) 51 | dropout_keep_prob = tf.placeholder(tf.float32, name="dropout") 52 | 53 | 54 | with tf.name_scope("embedding_layer"): 55 | W = tf.Variable(tf.random_uniform([len(vocabulary), embed_dim], -1.0, 1.0), name="embed_W") 56 | sent_embed = tf.nn.embedding_lookup(W, sent) 57 | #input_x = tf.reshape(sent_embed, [batch_size, -1, embed_dim, 1]) 58 | input_x = tf.expand_dims(sent_embed, -1) 59 | #[batch_size, sentence_length, embed_dim, 1] 60 | 61 | W1 = init_weights([ws[0], embed_dim, 1, num_filters[0]], "W1") 62 | b1 = tf.Variable(tf.constant(0.1, shape=[num_filters[0], embed_dim]), "b1") 63 | 64 | W2 = init_weights([ws[1], embed_dim/2, num_filters[0], num_filters[1]], "W2") 65 | b2 = tf.Variable(tf.constant(0.1, shape=[num_filters[1], embed_dim]), "b2") 66 | 67 | Wh = init_weights([top_k*embed_dim*num_filters[1]/4, num_hidden], "Wh") 68 | bh = tf.Variable(tf.constant(0.1, shape=[num_hidden]), "bh") 69 | 70 | Wo = init_weights([num_hidden, num_class], "Wo") 71 | 72 | model = DCNN(batch_size, sentence_length, num_filters, embed_dim, top_k, k1) 73 | out = model.DCNN(input_x, W1, W2, b1, b2, k1, top_k, Wh, bh, Wo, dropout_keep_prob) 74 | 75 | with tf.name_scope("cost"): 76 | cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=out, labels=y)) 77 | # train_step = tf.train.AdamOptimizer(lr).minimize(cost) 78 | 79 | predict_op = tf.argmax(out, axis=1, name="predictions") 80 | with tf.name_scope("accuracy"): 81 | acc = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(y, 1), tf.argmax(out, 1)), tf.float32)) 82 | #-------------------------------------------------------------------------------------------# 83 | 84 | print('Started training') 85 | with tf.Session() as sess: 86 | #init = tf.global_variables_initializer().run() 87 | 88 | global_step = tf.Variable(0, name="global_step", trainable=False) 89 | optimizer = tf.train.AdamOptimizer(1e-3) 90 | grads_and_vars = optimizer.compute_gradients(cost) 91 | train_op = optimizer.apply_gradients(grads_and_vars, global_step=global_step) 92 | 93 | # Keep track of gradient values and sparsity 94 | grad_summaries = [] 95 | for g, v in grads_and_vars: 96 | if g is not None: 97 | grad_hist_summary = tf.summary.histogram("{}/grad/hist".format(v.name), g) 98 | sparsity_summary = tf.summary.scalar("{}/grad/sparsity".format(v.name), tf.nn.zero_fraction(g)) 99 | grad_summaries.append(grad_hist_summary) 100 | grad_summaries.append(sparsity_summary) 101 | grad_summaries_merged = tf.summary.merge(grad_summaries) 102 | 103 | # Output directory for models and summaries 104 | timestamp = str(int(time.time())) 105 | out_dir = os.path.abspath(os.path.join(os.path.curdir, "runs", timestamp)) 106 | print("Writing to {}\n".format(out_dir)) 107 | 108 | # Summaries for loss and accuracy 109 | loss_summary = tf.summary.scalar("loss", cost) 110 | acc_summary = tf.summary.scalar("accuracy", acc) 111 | 112 | # Train Summaries 113 | train_summary_op = tf.summary.merge([loss_summary, acc_summary, grad_summaries_merged]) 114 | train_summary_dir = os.path.join(out_dir, "summaries", "train") 115 | train_summary_writer = tf.summary.FileWriter(train_summary_dir, sess.graph) 116 | 117 | # Dev summaries 118 | dev_summary_op = tf.summary.merge([loss_summary, acc_summary]) 119 | dev_summary_dir = os.path.join(out_dir, "summaries", "dev") 120 | dev_summary_writer = tf.summary.FileWriter(dev_summary_dir, sess.graph) 121 | 122 | # Checkpoint directory. Tensorflow assumes this directory already exists so we need to create it 123 | checkpoint_dir = os.path.abspath(os.path.join(out_dir, "checkpoints")) 124 | checkpoint_prefix = os.path.join(checkpoint_dir, "model") 125 | if not os.path.exists(checkpoint_dir): 126 | os.makedirs(checkpoint_dir) 127 | saver = tf.train.Saver(tf.global_variables(), max_to_keep=num_checkpoints) 128 | 129 | # Initialize all variables 130 | sess.run(tf.global_variables_initializer()) 131 | 132 | def train_step(x_batch, y_batch): 133 | feed_dict = { 134 | sent: x_batch, 135 | y: y_batch, 136 | dropout_keep_prob: 0.5 137 | } 138 | _, step, summaries, loss, accuracy = sess.run( 139 | [train_op, global_step, train_summary_op, cost, acc], 140 | feed_dict) 141 | print("TRAIN step {}, loss {:g}, acc {:g}".format(step, loss, accuracy)) 142 | train_summary_writer.add_summary(summaries, step) 143 | 144 | def dev_step(x_batch, y_batch, writer=None): 145 | """ 146 | Evaluates model on a dev set 147 | """ 148 | feed_dict = { 149 | sent: x_batch, 150 | y: y_batch, 151 | dropout_keep_prob: 1.0 152 | } 153 | step, summaries, loss, accuracy = sess.run( 154 | [global_step, dev_summary_op, cost, acc], 155 | feed_dict) 156 | print("VALID step {}, loss {:g}, acc {:g}".format(step, loss, accuracy)) 157 | if writer: 158 | writer.add_summary(summaries, step) 159 | return accuracy, loss 160 | 161 | 162 | batches = dataUtils.batch_iter(zip(x_train, y_train), batch_size, n_epochs) 163 | 164 | # Training loop. For each batch... 165 | max_acc = 0 166 | best_at_step = 0 167 | for batch in batches: 168 | x_batch, y_batch = zip(*batch) 169 | train_step(x_batch, y_batch) 170 | current_step = tf.train.global_step(sess, global_step) 171 | if current_step % evaluate_every == 0: 172 | print("\nEvaluation:") 173 | acc_dev, _ = dev_step(x_dev, y_dev, writer=dev_summary_writer) 174 | if acc_dev >= max_acc: 175 | max_acc = acc_dev 176 | best_at_step = current_step 177 | path = saver.save(sess, checkpoint_prefix, global_step=current_step) 178 | print("") 179 | if current_step % checkpoint_every == 0: 180 | print 'Best of valid = {}, at step {}'.format(max_acc, best_at_step) 181 | 182 | saver.restore(sess, checkpoint_prefix + '-' + str(best_at_step)) 183 | print 'Finish training. On test set:' 184 | acc, loss = dev_step(x_test, y_test, writer=None) 185 | print acc, loss --------------------------------------------------------------------------------