The present invention relates to techniques for augmenting textual data that may be used for textual classification tasks.
Text classification may include tasks such as the classification of emails into spam and not-spam. It may encompass a variety of other tasks such as intent classification, sentiment analysis, topic classification, relation classification, etc. Depending upon the problem at hand, good fit of a classifier model may require relatively large amounts of labeled data. However, in many cases, and especially when developing machine learning or other AI systems for specific applications, labeled data may be scarce and costly to obtain. One example is intent classification in the growing market of automated chatbot platforms. In this example, a developer of an intent classifier for a new chatbot may start with a dataset containing 2, 3, or 5 samples per class, and in some cases no data at all.
Data augmentation is a common strategy for handling scarce data situations. Data augmentation may include synthesizing new data from existing training data with the objective of improving the performance of the downstream model. This strategy has been a key factor in performance improvement of various neural network models, mainly in the domains of computer vision and speech recognition. Specifically, for these domains there exist well-established and conventional labeled-data synthesizing methods for improving classification tasks, among others. The simpler of these methods include applying transformations on existing training examples, such as cropping, padding, flipping, and shifting along time and space dimensions, as these transformations are usually class preserving. However, for textual data, such transformations usually invalidate and distort the text, making it grammatically and semantically incorrect, hence, making data augmentation more challenging. In fact, textual augmentation may do more harm than good, as it is not an easy task to synthesize good artificial textual data. Thus, data augmentation methods for text usually involve replacing a single word with a synonym, deleting a word, or changing word order.
Accordingly, a need arises for techniques for augmenting textual data that may be used for textual classification tasks.
Embodiments of the present systems and methods may provide techniques for augmenting textual data that may be used for textual classification tasks. Embodiments of such techniques may provide the capability to synthesize labeled data to improve text classification tasks. Embodiments may be specifically useful when only a small amount of data is available, and provide improved performance in such cases.
For example, in an embodiment, a method implemented in a computer system may comprise a processor, memory accessible by the processor, and computer program instructions stored in the memory and executable by the processor, and the method may comprise fine-tuning a language model using a training dataset, synthesizing a plurality of samples using the fine-tuned language model, filtering the plurality of synthesized samples, and generating an augmented training dataset comprising the training dataset and the filtered plurality of synthesized sentences.
In embodiments, fine-tuning of the language model may comprise concatenating sentences in the training dataset according to: U*=y1 SEP x1 EOS y2 SEP x2 EOS y3 . . . yn SEP xn EOS, wherein SEP is an auxiliary token that separates between a class label and a corresponding sentence, and EOS is a token terminates a sentence and separates it from a label that follows; and synthesizing a plurality of samples may comprise generating a set of new labeled sentences starting from “y SEP”. The training dataset may comprise a small quantity of training data. The language model may be pre-trained on a large quantity of training data. The fine-tuning may comprise adapting the language model to the linguistic domain of the training dataset. The plurality of synthesized samples may be filtered using a classifier model trained using the training dataset to score the quality of the synthesized samples. The plurality of synthesized samples may be filtered using a filtering method selected from a sentence length, vocabulary constraints, plausibility, and human filtering.
In an embodiment, a system may comprise a processor, memory accessible by the processor, and computer program instructions stored in the memory and executable by the processor to perform fine-tuning a language model using a training dataset, synthesizing a plurality of samples using the fine-tuned language model, filtering the plurality of synthesized samples, and generating an augmented training dataset comprising the training dataset and the filtered plurality of synthesized sentences.
In an embodiment, a computer program product may comprise a non-transitory computer readable storage having program instructions embodied therewith, the program instructions executable by a computer, to cause the computer to perform a method that may comprise fine-tuning a language model using a training dataset, synthesizing a plurality of samples using the fine-tuned language model, filtering the plurality of synthesized samples, and generating an augmented training dataset comprising the training dataset and the filtered plurality of synthesized sentences.
The details of the present invention, both as to its structure and operation, can best be understood by referring to the accompanying drawings, in which like reference numbers and designations refer to like elements.
Embodiments of the present systems and methods may provide techniques for augmenting textual data that may be used for textual classification tasks. Embodiments of such techniques may provide the capability to synthesize labeled data to improve text classification tasks. Embodiments may be specifically useful when only a small amount of data is available, and provide improved performance in such cases.
Embodiments may include a data augmentation pipeline that builds upon a powerful language model—generative pre-training (GPT) model. This neural-network model may be pre-trained on huge bodies of text. As such, it captures the structure of natural language to a great extent, producing deeply coherent sentences and paragraphs. Embodiments may adapt GPT by fine-tuning it on the existing, small, training data set. Embodiments may then use the fine-tuned model to synthesize new labeled sentences. Independently, embodiments may train a classifier on the same original small train dataset and use it to filter the synthesized data corpus, retaining only data that appears to be qualitative enough. Further, embodiments may retrain the task classifier on both the existing and synthesized data.
Text classification is an instance of the supervised learning problem over textual data. In this context, we are given a training dataset Dtrain={(xi,yi}i=1n containing n labeled sentences. Each xi is a string of text, or, specifically, a sequence of tokens (roughly, words) xi1 . . . xil
The objective of a supervised learning problem is to approximate ƒ on the entire X, given only the dataset Dtrain. That is, generalizing from the domain of Dtrain to the entire X. Formally, a classification algorithm A receives the training dataset Dtrain, and after a training period, it outputs a classifier function h=(Dtrain), whereas h: X→{1, . . . , q}, also known as a hypothesis. In order to estimate to what extent h approximates ƒ on X, it is customary to initially leave out, in addition to the training dataset Dtrain, a test dataset Dtest={({circumflex over (x)}i,ŷi)}i=1{circumflex over (n)}, which is chosen randomly and has the same structure as Dtrain. Both parts are usually drawn from a single, grand, dataset. There are different ways of measuring the quality of classifier h as an approximation to ƒ using Dtest. The most straightforward way is accuracy:
where δ(⋅,˜) is the Kronecker delta (equals 1 when both arguments are equal, or 0 otherwise), and {circumflex over (x)}i, ŷi are drawn from the test set. When the test set is large, accuracy approximates the probability of having h(x) equal ƒ(x), namely, PX(h(x)=ƒ(x)). Accuracy may be used as an estimate of classifier performance.
Regardless of how performance is measured, if the training set Dtrain is small, it will dramatically affect the performance of the algorithm . Data augmentation tries to solve this problem by synthesizing additional training pairs that, together with the existing dataset, better reflect the underlying distribution of the data while refraining from introducing too much noise.
The present techniques do not directly relate to the classification algorithm per se. Rather, given a training dataset Dtrain and an algorithm , the present techniques may provide a general method to synthesize an artificial dataset, Dsynthesized. The goal may be that applying algorithm
on Dtrain∪Dsynthesized, denoted by
(Dtrain∪Dsynthesized), would yield a relatively good classifier, and particularly, better than the baseline classifier h.
An exemplary system 100 in which the present techniques may be implemented is shown in ) baseline classifier 108 (h), language model 110 (
), synthesized sentences 112, filter 114, synthesized training dataset 116, augmented training data 118, and improved classifier 120. Training dataset Dtrain 102 may include one or more small training datasets, perhaps miniature, with, for example, only a few examples per class. Feature extractor 104 may extract features from the input data to generate feature vectors 106. Feature vectors 106 may be input to classification algorithm
107 to train, first baseline classifier 108 using training dataset 120, and later improved classifier 120 using augmented training dataset 118. Further, feature vectors 106 may be input to language model
110 to fine tune model
110 to form
tuned 110, which may then be used to generate synthesized sentences 112. Synthesized sentences 112 may be filtered 114 to form synthesized training dataset 116. Then the union of training dataset 102 and synthesized training dataset 116 may form augmented training dataset 118, which may be used to train improved classifier 120. This process is described in greater detail below.
An exemplary flow diagram a process 200 of generating Dsynthesized from Dtrain 102 and is shown in
107 may be used. As far as process 200 is concerned,
107 is arbitrary. However, embodiments may synthesize data that is optimized for the algorithm
107, and the latter is given as a second input to process 200. This is a distinctive feature of our method. Both Dtrain 102 and
107 are described below.
In order to synthesize new data, embodiments may use pre-defined language model 110. A language model is an estimate of the probability of the appearance of a token (word), in accordance with a given distribution of text Ptext, conditioned on the preceding and/or succeeding tokens. More formally, given a token w, and the preceding k tokens (or fewer) wl, . . . , wk, one would like
(w|w1, . . . , wk) to approximate the conditional probability Ptext(w|wl, . . . , wk) of the appearance of w in accordance with Ptext.
110 is usually calculated using a concrete corpus of text U, sampled from distribution Ptext.
In contrast to 107,
110 is far from being arbitrary. From a generality perspective, different types of language models and even different sizes of the same language models can be used. The only requirement is that it should be a generative language model pre-trained on a large corpus so that small corpus would be enough to finetune it. For example, embodiments may use GPT-2—a recent pre-trained neural-network model, where Dtrain 102 is scarce. Of course, GPT-2 is merely an example of a suitable language model that may be used. GPT-2 is pre-trained on an enormous body of text, downloaded from the Web. The corpus is organized as a long sequence of tokens, and denoted by U=wl . . . wj . . . , GPT-2, like GPT, is a right-to-left model based on the transformer architecture. It is pre-trained on U with loss defined by
where θ is the set of learnable parameters in the neural network of GPT2, and Pθ is the trained language model—an estimate of the conditional probability distribution on the set of tokens, as calculated by the network. Specifically, take =Pθ*, where θ* indicates the state of the learnable parameters after pre-training. Nonetheless, from a technical standpoint, the language model and its underlying technology can differ to a great extent, and it is thus presented as a third input to process 200. Finally, process 200 may be given the number of labeled sentences to synthesize per class Nl, . . . , Nq.
At 204, a baseline classifier h 108 may be trained. This is the classifier model that is to be improved by process 200. For example, a baseline classifier h=(Dtrain) may be trained using the existing data Dtrain 102.
At 206, language model 110 may be fine-tuned independently of 204 in a way that is specific to the problem at hand, and to the data that is to be generated. As 204 and 206 are performed independently, embodiments may perform 204 and 206 in parallel or serially in any order. In embodiments, language model
110 may be fine-tuned to the task of synthesizing labeled sentences, so as to obtain the adapted language model
tuned 110. In embodiments,
may be specifically adapted to the linguistic domain of Dtrain 102 (that is, the sentences, vocabulary, style, etc.), as well as the particular classes in Dtrain 102. Generally speaking,
tuned 110 may be used in order to generate a set of sentences, each labeled with a class label, of any size.
Fine-tuning involves further training the language model g 110 (for example, GPT2), in order to adjust to a different distribution of words in the language—corresponding to the data generation task. In embodiments, 110 is the neural model of GPT-2. In this step, we fine-tune GPT-2 by training it using the data in Dtrain={(xi,yi)}i=1n. The training method that may be used does not need to change, however. In embodiments, the sentences in Dtrain 102 may be concatenated into a long chain in order to form U*, in the following way (where SEP and EOS are token separators):
U*=y
1SEPxiEOSy2SEPx2EOSy3 . . . ynSEPxnEOS (2)
Here, the auxiliary token SEP separates between a class label and a corresponding sentence, while token EOS terminates a sentence, and separates it from the label that follows. Embodiments may further train the learnable parameters of GPT-2 to predict the next token. Embodiments may perform additional training in the same way that GPT-2 was pre-trained on a huge linguistic corpus—using the loss function in Equation 1 (with the same training procedure and hyperparameters). Fine tuning adjusts it to the language, and the distribution of words, within the domain of dataset Dtrain 102, and within its different classes. However, U* may be used instead of U, and the learnable parameters are already initialized. The resulting language model is referred to as tuned 110.
At 208, using the fine-tuned language model tuned, a set 112 of new labeled sentences may be synthesized. Specifically, for each classy, sentences 112 may be synthesized by letting
tuned generate sentences starting from “y SEP”. This corresponds to how
tuned was fine-tuned in 206. For example, a set of labeled sentences may be synthesized, denoted by D*={(xi′,yi′)}i=1n, and may have the same structure as Dtrain 102. The exact number of sentences that are generated per class may be determined in various ways. One way is synthesizing, for example, for each class y, ten times (or any other factor) more sentences than are to be added to the class (for example, 10Ny). Accordingly, the total number of generated sentences is N=10Σy=1qNy. More sophisticated heuristics may be utilized. This is also where the power of GPT-2 comes into play. GPT-2 generates labeled sentences 112 that are, generally speaking, both high quality and diverse, facilitating the relative success of our method.
At 210, the synthesized data 112 may be filtered 114 using, for example, filtering classifier 115. It is important to clarify that baseline classifier 108 and filtering classifier 115 that is being used to score the sentences are independent and need not implement the same classification algorithm. Baseline classifier and improved or augmented classifier 120 are being used for assessing the value of the synthesized data, while filtering classifier 115 (also known as scorer) is being used to determine what ends up in the synthesized data. Note that (in an embodiment) filtering may be done in two steps: first a classifier 115 (the filter or scorer classifier) may be used score the generated sentences, and then a filtering method 114, which may be any one of various methods, may be applied to leave only some of the sentences, based on their scores. Filtering may be done by methods that do not use filtering classifier 115. For example, embodiments may use simple heuristic methods, such as sentence length, vocabulary constraints, plausibility, etc., or more complex filtering techniques, even including human filtering, etc.
The major obstacle to using synthesized text is the noise and error it may introduce. Here, embodiments may filter the data in D*, which was synthesized by tuned 110 at 208, leaving only the instances of the highest quality to form synthesized training dataset Dsynthesized 116.
For each class y, the top Ny sentences from D* that are labeled by y may be selected, as follows: Given a synthesized sentence (x,y)∈D*, first verify that h(x)=y (the predicted class matches), and then, the confidence score given by h serves as a rank for (x,y). Thus, the top ranked Ny sentences for class y may be selected. At 212, this may result in a synthesized dataset Dsynthesized⊆D*, consisting of labeled sentences and having the same structure as Dtrain 102. The confidence score given to a data instance by h may be regarded as the extent the instance is conservative with respect to h. h, in turn, takes into account both Dtrain 102 and the algorithm that is to be used with the augmented dataset. Note, however, that
tuned 110 generates sentences conditioned on a class label. This may provide a sort of double voting mechanism.
At 214, Dsynthesized 116 may be used to train or re-train baseline classifier 108, or similar classifier model, to form improved classifier 120. Process 200 may generally be repeated, and may be further applied on Dtrain 102 [Dsynthesized to obtain Dsynthesized′, Dsynthesized″ and so on, so as to further improve improved classifier 120.
In order to assess the quality of Dsynthesized 116, one may train a classifier on D U Dsynthesized (using the classification algorithm 107 that was given as input to process 200), and check its performance one way or another (for example, via the accuracy of Fα). This may be compared with the performance of the baseline classifier h, which was trained at 204 of process 200 on D alone.
For example, in a series of experiments on several datasets (3) and several classification algorithms (SVM, LSTM, BERT), the effectiveness of the present techniques was verified. First, embodiments may be more effective when the available data D contains a small number of examples per class (5-10). Second, for any size of D that was tested, the augmented data outperformed the baseline. Third, when D is small, embodiments outperformed in most circumstances all conventional methods for textual data augmentation that were tested (EDA, CBERT, CVAE).
An exemplary block diagram of a computer system 300, in which processes involved in the embodiments described herein may be implemented, is shown in
Input/output circuitry 304 provides the capability to input data to, or output data from, computer system 300. For example, input/output circuitry may include input devices, such as keyboards, mice, touchpads, trackballs, scanners, analog to digital converters, etc., output devices, such as video adapters, monitors, printers, etc., and input/output devices, such as, modems, etc. Network adapter 306 interfaces device 300 with a network 310. Network 310 may be any public or proprietary LAN or WAN, including, but not limited to the Internet.
Memory 308 stores program instructions that are executed by, and data that are used and processed by, CPU 302 to perform the functions of computer system 300. Memory 308 may include, for example, electronic memory devices, such as random-access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), flash memory, etc., and electro-mechanical memory, such as magnetic disk drives, tape drives, optical disk drives, etc., which may use an integrated drive electronics (IDE) interface, or a variation or enhancement thereof, such as enhanced IDE (EIDE) or ultra-direct memory access (UDMA), or a small computer system interface (SCSI) based interface, or a variation or enhancement thereof, such as fast-SCSI, wide-SCSI, fast and wide-SCSI, etc., or Serial Advanced Technology Attachment (SATA), or a variation or enhancement thereof, or a fiber channel-arbitrated loop (FC-AL) interface.
The contents of memory 308 may vary depending upon the function that computer system 300 is programmed to perform. In the example shown in
In the example shown in
As shown in
The present invention may be a system, a method, and/or a computer program product at any possible technical detail level of integration. The computer program product may include a computer readable storage medium (or media) having computer readable program instructions thereon for causing a processor to carry out aspects of the present invention. The computer readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device.
The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire. §
Computer readable program instructions described herein can be downloaded to respective computing/processing devices from a computer readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers, and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
Computer readable program instructions for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, configuration data for integrated circuitry, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++, or the like, and procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer readable program instructions.
These computer readable program instructions may be provided to a processor of a general-purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the blocks may occur out of the order noted in the Figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
Although specific embodiments of the present invention have been described, it will be understood by those of skill in the art that there are other embodiments that are equivalent to the described embodiments. Accordingly, it is to be understood that the invention is not to be limited by the specific illustrated embodiments, but only by the scope of the appended claims.