1. A system, comprising: one or more computers including one or more storage devices storing instructions that when executed by the one or more computers cause the one or more computers to perform operations comprising: obtaining a plurality of class instance pairs derived from a plurality of documents by applying one or more extraction patterns to the plurality of documents, each class-instance pair comprising class text naming an entity class and entity text naming a particular instance of the entity class; calculating a weight for each class-instance pair according to a frequency score and a diversity score for the class-instance pair, wherein the frequency score of the class-instance pair is based on a number of times the class-instance pair was derived from the plurality of documents, and wherein the diversity score of the class-instance pair is based on a number of distinct extraction patterns used to extract the class-instance pair; receiving a plurality of candidate text queries; generating one or more query specializations from the plurality of candidate text queries and the plurality of class-instance pairs, wherein each query specialization is the text of one of the candidate text queries modified so that an n-gram in the text of the candidate text query is replaced by the entity text from a class-instance pair having class text matching the n-gram, wherein generating a query specialization from a candidate text query and the class instance pairs comprises: extracting a plurality of n-grams from the candidate text query and extracting a respective context for each extracted n-gram from the candidate text query, the respective context for an extracted n-gram including a prefix context and a suffix context; comparing the extracted n-grams to the class text of the class-instance pairs; identifying an n-gram that matches class text of a first class-instance pair; and generating the query specialization from the entity text of the first class-instance pair and the respective context for the identified n-gram; and storing specialization data, the specialization data associating each of one or more of the candidate text queries with one or more query specializations identified from the candidate text query.