NB-MLM: Efficient Domain Adaptation of Masked Language Models for Sentiment Analysis
Paper · 2021 · Nikolay Arefyev, Dmitrii Kharchev and Artem Shelmanov
Summary
A system that has already learned to fill in blanks in general text can improve at judging whether a review is positive or negative by practising on reviews. The usual procedure hides tokens at randomly selected positions and asks the system to recover them from the surrounding text. Since common words appear in so many positions, much of that practice goes into recovering articles, prepositions, and other words that can be predicted without knowing much about the reviewer's opinion. The authors ask whether the same training time could do more for sentiment analysis if the blanks fell more frequently on words that help distinguish positive reviews from negative ones.
Their method, NB-MLM, uses a Naive Bayes classifier to identify those words. A token receives a high score when its estimated frequency differs substantially between positive and negative reviews. The score can be high for a token associated with either class. During continued training of a masked language model, the method uses these scores to favour some positions over others. The system still has to recover the original token, and final fine-tuning still teaches it to predict review labels. The change concerns what it practises recovering between general pretraining and the final classification task.
The clearest gain came from adapting RoBERTa-base on Amazon reviews before evaluating it on IMDB movie reviews. The short NB-MLM run used 4K adaptation steps and yielded a median-run IMDB test error of 4.14. Uniform masking at that budget gave 4.42, and the longer uniform run at 20K steps gave 4.19. At the full domain-adaptation budget, NB-MLM brought the error down to 3.85. Gains were smaller when adaptation used the target dataset itself and on Yelp. The best test results on both benchmarks came from adapting on Amazon first and then on the target reviews. With NB-MLM, that sequence gave test errors of 3.54 on IMDB and 1.51 on Yelp.
A comparison on IMDB helps explain why the choice of blanks mattered. Giving rare tokens priority on the basis of frequency alone produced test results comparable to ordinary uniform masking. The successful method gave priority to tokens whose distribution depended on the review label. The experiments establish that this label-informed sampling can make continued training more effective for the review tasks studied, especially under a short domain-adaptation budget. The strongest results for adaptation on the target dataset used the evaluation reviews as unlabeled training text, so those results describe a setting in which the texts to be classified are already available.
Deep dive: NB-MLM: Efficient Domain Adaptation of Masked Language Models for Sentiment Analysis
NB-MLM uses Naive Bayes to choose which words to hide during domain adaptation, improving sentiment classification on IMDB and Yelp. · about 33 minutes to read
The problem and its context
Why continued training can be expensive
A system trained to recover missing words from a broad collection of texts starts with capabilities that can carry over to many applications. It can frequently infer that a particular grammatical form belongs in a blank, or that the surrounding words make some completions more plausible than others. Review classification places a narrower demand on those capabilities. The system has to use the wording of a particular review to infer the writer's overall judgment. Continued training on reviews gives it a chance to become familiar with the language it will encounter before labeled examples teach it how to assign that judgment.
The paper distinguishes general pretraining, adaptation, and final supervised training by the work each stage is supposed to do. General pretraining can be shared across applications. Adaptation exposes the system to text appropriate to a particular domain or dataset. Final supervised training adjusts it for the actual prediction, which here is the polarity of a review. The adaptation stage is expensive in a different way from general pretraining because it may need to be repeated as the target changes. The authors describe conventional adaptation as potentially taking several GPU days, while the final supervised stage can frequently be completed in several GPU hours.
There are two closely related decisions in an adaptation run. One is which documents the system will read. The other is which parts of those documents it will have to predict. Choosing reviews makes the document collection more relevant to sentiment, but a review still contains all the ordinary connective language found in other prose. A sampling rule that gives the same chance to every eligible position will regularly select that language. In aggregate, a frequent token receives many opportunities to contribute to the training loss because it occupies many positions. Uniform sampling is uniform over positions in an example, while the identity of the tokens selected over many examples reflects how often they occur.
That distinction motivates the paper's efficiency argument. Recovering a determiner or an auxiliary verb can be useful during general pretraining, when the system may eventually be used for many different tasks. During adaptation, the application is already known. If the system is being prepared to classify opinions, the authors reason that recovering more of the language associated with those opinions may be a better use of a limited stage of training. Every selected token asks the system to make a prediction. Changing the mix of those requests could change what the same sequence of training documents teaches it.
The authors offer a further hypothesis about what happens when a strongly sentiment-bearing token is hidden. A classification system might ordinarily lean on that token as a direct clue. To reconstruct it from a blank, the system may have to attend to supporting information elsewhere in the review. That information could include wording that gives the same impression less directly. The paper's mechanism operates on the token chosen as a target, while this hypothesis concerns the surrounding features the system might learn to exploit. They are distinct claims, and the experimental measures address the first more directly than the second.
What earlier adaptation changed
The authors place their work in the line of Transformer pretraining represented by BERT. BERT trains on a reconstruction exercise that can draw on context on either side of a selected token. The paper also points to earlier instances of learning from context on both sides with other architectures, including the work on distributed representations of words and phrases and context2vec. NB-MLM inherits this basic idea of learning from a missing or corrupted token and changes how often different tokens become the subject of that exercise.
RoBERTa is the principal starting point for the paper's experiments. In the authors' account, RoBERTa extends BERT pretraining with more text and a longer schedule, removes the next-sentence prediction task, and uses dynamic masking. Dynamic masking allows an example to yield different prediction positions when it is seen again. That feature matters here because a biased selection rule can still offer some variation between visits. How much variation survives depends on how sharply the sampler favours a review's highest-scored tokens.
The earlier work on fine-tuning BERT for text classification examined continued pretraining using text from the downstream dataset and using text from its domain. Gururangan and colleagues studied the corresponding choice for RoBERTa. They distinguished adaptation on the target dataset, adaptation on a larger collection from a related domain, and continued training on material from a different domain. In that framing, task adaptation and domain adaptation differ in their source of text. The token recovery objective within those texts can be held fixed.
As the authors describe the earlier results, training on the smaller target collection was often a strong option despite its lower computational cost. Task adaptation could outperform domain adaptation, and combining the stages sometimes offered only a modest gain over task adaptation alone. A large related corpus supplies more varied examples but typically permits few passes at a practical budget. A small target corpus permits many passes, giving even rarely selected positions more opportunities to become prediction targets. This raises a question about domain adaptation: how much of the large collection's relevant information can the objective use during the limited time available?
Why a sentiment classifier enters the picture
The source of the token scores comes from a different line of work. The paper draws on the Naive Bayes and bigram baselines of Wang and Manning. In the earlier approach, Naive Bayes weights scaled bag-of-n-gram features before a linear classifier used them. The weights represented how differently a feature occurred across the labels. The authors of NB-MLM take that familiar estimate of class association and give it a new role in the training process.
For text classification, a signed weight can indicate which label a feature supports. For choosing prediction targets, the authors need to know how informative the feature might be regardless of the label it favours. A token associated with favourable judgments and a token associated with unfavourable judgments can both be worth recovering. Taking the magnitude of the weight gives a common measure of priority. The downstream task thus helps decide how review text is used, even at a stage when individual reviews are presented without their class labels.
Binary review polarity provides a practical test of that proposal. The paper can draw on a large set of product reviews for domain adaptation and on collections closely tied to the classification task for task adaptation. It can compare the same type of classifier after changing the masking rule, the source of the review text, or the length of adaptation. That makes it possible to look for a difference in efficiency as well as a difference at the end of training. A method that reaches similar downstream performance earlier answers a different practical question from one that obtains the strongest score when both methods are allowed to run to the same endpoint.
The method, step by step
From review labels to missing tokens
NB-MLM begins with a general-purpose pretrained system and a labeled sentiment task. The labels provide evidence about which pieces of text are distributed differently in positive and negative reviews. The pieces used by the masking procedure are sub-words, the units produced by subword tokenization. A sub-word may correspond to a complete word or a piece of one. Each occurrence has its own position in an input sequence. The importance score belongs to the vocabulary unit, and the sampling decision concerns a particular occurrence of it.
The same unit therefore carries the same underlying score into different reviews, even though its local meaning or relevance may change. Within each review, the relative chance of choosing that occurrence depends on what other tokens are present and how strongly they are weighted. When a token occurs repeatedly, each occurrence is eligible at its own position. The system still makes predictions from the actual surrounding sequence. The Naive Bayes component supplies a vocabulary-level estimate of relevance, and the masked predictor learns from contextual examples of how those units are used.
For a reader following a single review through training, the proposal amounts to a change in where the blanks tend to fall. Suppose a review contains ordinary grammatical material and a term that occurs preferentially in one class of the labeled data. Uniform masking gives each position the same chance at the start of selection. NB-MLM favours the position occupied by the class-associated term. If selected, that position contributes a reconstruction target. The relevant class does not appear as the target of that prediction. The answer for that position is the sub-word that was present in the review.
The process can use the larger review collection, the target dataset, or the two in sequence. After adaptation, the authors use the resulting checkpoint, meaning the saved parameters at a particular point in training, to start a classifier. Supervised training then uses the available labels to teach review polarity directly. The test metric belongs to that classifier. This distinction matters at intermediate checkpoints as well: a point on an adaptation curve represents the performance of a classifier trained from that point, instead of a direct score for the token recovery exercise.
From labeled reviews to sentiment classification with NB-MLM
The steps in order.
The uniform procedure used for comparison
In standard masked training, the paper samples 15% of the sub-word positions in each example. The positions are drawn without replacement, so the same occurrence cannot fill several places in the sample. The starting distribution is uniform across positions.
P(pos) ∝ 1
Here P is the sampling probability, and pos identifies an eligible position. The sign ∝ means that the probability is proportional to the weight on its right. The constant 1 gives every eligible position the same weight. As positions are drawn without replacement, the still-available positions continue to have equal weights under the uniform rule.
The sampled positions define where the training loss will apply. The standard corruption procedure replaces the input token with the dedicated [MASK] symbol at 80% of those positions. At 10%, it substitutes a vocabulary token chosen uniformly at random. At the remaining 10%, it leaves the original input intact. The target for prediction is the original token in each case. A selected position can thus contribute to the training objective while still showing its original token in the input.
This separation between selection and corruption is an important part of the comparison. Selection determines which original tokens the system is asked to recover. Corruption determines what the system sees at those locations. NB-MLM keeps the share of selected positions at 15% and retains the standard treatment of selected inputs. It shifts where the learning signal is concentrated while using the same basic token recovery task. Its efficiency claim concerns the value of those training examples for subsequent sentiment classification.
Estimating which subwords matter
The authors estimate probabilities with multinomial Naive Bayes. In this use, the classifier yields an estimated distribution of sub-words for each class on the basis of occurrences associated with that class. The authors apply additive smoothing with alpha = 0.1. Smoothing assigns some probability mass even when a token is unseen in one class, allowing the logarithmic comparison to remain finite. It also keeps the estimate from depending entirely on whether a token happened to occur at all on one side of the labeled data.
fᵢ(w) = |log P(w | 1) − log P(w | 0)|
Here w is a sub-word and fᵢ(w) is its feature-importance score. The subscript ᵢ marks the importance function. P(w | 1) and P(w | 0) are the estimated probabilities of the sub-word conditional on the respective binary classes, labeled 1 and 0. The vertical bar within each probability means “given.” The function log takes the logarithm, and − gives the difference between the two log probabilities. The outer bars take the absolute value, and = defines the score. Exchanging the class identifiers switches the sign of the difference but preserves the importance score.
The logarithmic comparison rewards a token whose probability is large relative to its probability in the other class. It can give little importance to a common token when that token's probabilities are similar across classes. A token that occurs less frequently can receive a high score when it is substantially more characteristic of either class. In this way the method uses labeled distinctions to give frequency a meaning specific to the task. Raw occurrence counts alone would leave the two kinds of evidence mixed together.
The paper also applies a minimum-support rule. A sub-word that occurs in fewer than m examples receives a score of zero. Here m is a tunable threshold on the number of examples containing the feature. A token might occur mainly in one class by chance when it appears in very few reviews. Smoothing regularizes the probabilities, and the threshold separately prevents low-support features from gaining priority through a large apparent disparity. Setting the score to zero leaves a position eligible for selection under the exponential sampling rule. It removes the extra preference based on a potentially unreliable class association.
The distinction between class association and context remains important at this point. The estimated probabilities summarize how a token is distributed across labeled reviews. They give the sampler no way to tell whether a particular occurrence is central to the meaning of its sentence, quoted from someone else, or used in a context that changes its usual implication. Those contextual distinctions are left to the system that recovers tokens and later classifies reviews. The score acts before either of those predictions.
Deciding how strongly to favour a position
The sampler transforms the importance score into a positive weight. It does this separately for the positions in the example being processed.
P(pos) ∝ exp(fᵢ(wₚₒₛ) / T)
Here P(pos) is the probability of selecting position pos, and ∝ means that the expression on the right gives a relative weight that must be normalized over the available positions. wₚₒₛ is the sub-word currently at that position, and fᵢ is the importance function defined above. T is the temperature, a positive hyper-parameter that controls how strongly score differences affect the weights. The slash denotes division by T, and exp is the exponential function. The selected positions supply the same share of prediction targets as in Uniform MLM.
A large temperature makes the exponent for each position smaller in magnitude, bringing the sampling weights closer together. As the temperature becomes small, the exponent magnifies score differences and concentrates the draws on the highest-scoring positions. The threshold and the temperature address different decisions. The threshold governs which estimates are considered supported enough to give a feature extra weight. The temperature governs how much extra weight the supported features actually receive relative to other positions in the review.
This construction allows the authors to tune the method for how adaptation text will be used. During task adaptation, a relatively small collection can be revisited many times. A sharply concentrated distribution can repeatedly select the same occurrences in a particular review, even if new draws are made each time. The authors use a higher temperature in their main task experiments to preserve more variation across visits. For domain adaptation, a broad review collection is seen for only one epoch, or full pass, at the long budget. The paper reports that smaller temperatures worked better there, where making one visit count is more important and the opportunity to repeat the same targets across visits is limited.
A sub-word's importance is also relative to the available choices in its current example. A review full of strongly weighted terms offers several likely targets. In a review with little class-associated language, the method still has to draw the required share of positions. It can therefore learn from less distinctive material even with a strong preference for class-associated tokens. At the level of the whole training corpus, the shift in target frequencies depends on the interaction of the learned scores, the temperature, and the distribution of tokens across documents.
The adaptation and fine-tuning procedure
For domain-adaptive pretraining, abbreviated DAPT, the authors use the Amazon Reviews collection. They remove duplicates and discard reviews shorter than 500 characters. They set aside 10K reviews for validation, leaving a training collection of 21M reviews. The held-out Amazon reviews are used to monitor perplexity during adaptation. Perplexity reflects how much probability the system assigns to the tokens it has to recover. A lower value indicates better predictions under the token recovery exercise being evaluated. It is a separate quantity from the error made when classifying a review's sentiment.
For task adaptation, the main configuration is called all-TAPT. It exposes the system to text from across the target dataset, either IMDB or Yelp, with sentiment labels withheld from the reconstruction exercise. For IMDB the authors use the split adopted by Gururangan and colleagues in the main experiments. They use the binary Yelp benchmark associated with the work on character-level convolutional networks for text classification and set aside a development sample of 5K positive and 5K negative examples. Development examples are used to make training decisions before reporting the test metrics.
In all-TAPT, the training text also includes reviews from the test split. The protocol is transductive, meaning that the inputs whose labels will later be predicted can already influence adaptation through their wording. There are two different uses of supervision to keep track of here. The token scores reflect label information from the sentiment task, and final supervised training uses labels to teach polarity directly. The individual test reviews used for token recovery enter as unlabeled text. Both Uniform MLM and NB-MLM receive that text in the all-TAPT comparison.
The authors use an adaptation batch size of 1024 for both domain and task adaptation. A batch is the collection of examples processed for a training update. The domain-adaptation learning rate is 2e-4, and the task-adaptation rate is 1e-4. The learning rate controls the size of parameter updates. For the final supervised stage, the batch size is 32 and the learning rate is 1e-5. According to the reported schedules, classifier fine-tuning takes 4 epochs for IMDB and 2 for Yelp. The authors choose these stage-specific settings on the basis of preliminary work and use development performance for early stopping.
For main task adaptation with NB-MLM, the paper sets T = 0.4 and m = 50. The grid used for domain adaptation spans temperature values of 0.05, 0.1, 0.2, 0.4, and 0.8, and support thresholds of 10 and 50. The selected domain temperature is T = 0.1 for both benchmarks. The minimum support is m = 10 for IMDB and m = 50 for Yelp. The authors identify their implementation as the nb-mlm repository. The preliminary reproduction of the earlier BERT task-adaptation procedure used the Transformers library.
Experiments and results
What the reported scores measure
The main evaluation asks how accurately the resulting classifier assigns binary sentiment labels to IMDB and Yelp reviews. The controlled baseline uses the ordinary uniform masking rule during adaptation. It starts from the same kind of pretrained checkpoint and is compared at corresponding stages and durations. DAPT uses Amazon review text. All-TAPT uses text from the benchmark on which the classifier will be evaluated. The combined procedure runs domain adaptation first and then task adaptation, so the task stage begins from a checkpoint that has already learned from the larger review collection.
The authors report classification error and macro-F1 on the test splits. Classification error is the share of reviews assigned the wrong polarity, so lower values are better. F1 for a class combines precision, the share of predictions for that class that are correct, with recall, the share of true instances of the class that are found. Macro-F1 averages the classwise F1 scores with equal weight for each class. Higher values are better. The test comparisons present both metrics on a percentage scale. The adaptation curves use accuracy, the share of correctly classified reviews, to show how downstream performance develops across saved checkpoints.
A change in the order of the training reviews or in the sampled positions can affect the outcome. To measure that variation, the authors repeat training with different random seeds. For each masking rule, they aggregate 15 runs for IMDB domain adaptation, 3 for the combined schedule on each benchmark, and 6 for the other scenarios. The curves display means and standard deviations, which give a sense of the typical performance and its spread. The main test comparison uses a particular run near the middle of each system's results. With an even number of runs, the authors take the run immediately above the median.
This choice gives a concrete set of predictions for each system in the comparison. McNemar's test uses paired predictions on the same reviews. Cases where the systems disagree about which prediction is right provide the evidence for the test. The paper marks comparisons at p < 0.05 and p < 0.01. These thresholds concern the selected pair of runs. The repeated-run curves give another view of the evidence by showing the variability of estimated performance across runs and by following it through adaptation.
Domain adaptation has the clearest effect on IMDB
The long Amazon schedule takes one epoch, or 20K steps. The paper reports 38h for that schedule on one V100 GPU. The short schedule ends at 4K steps. By then the system has seen 20% of the Amazon training data according to the paper. Comparing the short and long conditions therefore addresses what can be accomplished with fewer updates and less exposure to the corpus. Comparing the objectives at either common duration addresses the effect of selecting different reconstruction targets.
RoBERTa-base domain adaptation on Amazon reviews, measured by IMDB test error
Short NB-MLM adaptation reaches an error comparable to full Uniform MLM, and full NB-MLM gives the lowest error.
The numbers
| System or setting | error % |
|---|---|
| Uniform short DAPT | 4.42 |
| NB-MLM short DAPT | 4.14 |
| Uniform DAPT | 4.19 |
| NB-MLM DAPT (this paper) | 3.85 |
On the IMDB test split, the short domain runs yield macro-F1 scores of 95.58 for Uniform MLM and 95.86 for NB-MLM. At the full domain budget, the corresponding scores are 95.81 and 96.15. The paired tests mark the short uniform versus short NB-MLM comparison and the full uniform versus full NB-MLM comparison at p < 0.01. The comparison between the short NB-MLM run and the full uniform run is the result the authors use to illustrate similar performance with fewer steps. The significance markings apply to the comparisons within the corresponding schedules.
The two comparisons support complementary claims about efficiency. With the short budget held constant, changing the sampling rule can improve the resulting classifier. With the objective and duration both allowed to vary, the shorter NB-MLM schedule can reach performance similar to that of the long uniform schedule. With both systems allowed to finish the full epoch, the benefit of NB-MLM persists. The authors describe the cross-budget result as obtaining similar performance in 5x fewer steps on this IMDB domain-adaptation comparison.
For Yelp, the same form of comparison yields a smaller numerical change. At the short domain budget, test error is 1.78 for uniform masking and 1.77 for NB-MLM. The associated test macro-F1 scores are 98.22 and 98.23. At the full domain budget, test error is 1.73 and 1.71, respectively, with test macro-F1 of 98.27 and 98.29. The direction of the median results is consistent with IMDB, while the reported paired significance markings apply to IMDB. The Yelp curves also show small improvements across adaptation, giving a broader view of how the two methods track each other.
Task adaptation offers smaller gains
The long task schedules use 100 epochs on IMDB and 24 epochs on Yelp. The paper reports 18h for IMDB and 14h for Yelp under those schedules. For the short versions, the epoch counts are 20 for IMDB and 6 for Yelp. An epoch has a different cost on each corpus, so the number of epochs specifies how frequently that collection is traversed. The paper's shorter schedules ask whether a change to the objective helps in the early part of learning, within the same dataset and starting setup.
On IMDB, the short all-TAPT schedule gives a test error of 3.92 under uniform masking and 3.82 under NB-MLM. Test macro-F1 is 96.08 and 96.18, respectively. On the full schedule, the test errors are 3.74 and 3.66, with macro-F1 scores of 96.26 and 96.34. The gains are smaller than those in IMDB domain adaptation, and the paper describes the task-adaptation curves as differing by an amount within two standard deviations. The means tend to favour NB-MLM during adaptation, while the runs occupy substantially overlapping ranges.
RoBERTa-base task adaptation on Yelp, measured by Yelp test macro-F1
Longer task adaptation improves the scores for both samplers, with NB-MLM slightly ahead at each budget.
The numbers
| System or setting | macro-F1 |
|---|---|
| Uniform short all-TAPT | 98.30 |
| NB-MLM short all-TAPT | 98.31 |
| Uniform all-TAPT | 98.41 |
| NB-MLM all-TAPT (this paper) | 98.42 |
On the Yelp test split, error for short task adaptation is 1.70 with uniform masking and 1.69 with NB-MLM. With the full task schedule, the corresponding test error values are 1.59 and 1.58. These results describe a slight advantage for NB-MLM within each budget. The main test comparison does not mark a statistically significant difference for these task-only conditions. In this setting, the difference associated with running task adaptation longer is more apparent in the results than the difference associated with changing the sampler.
The IMDB results also clarify why the authors separate access to relevant text from the choice of targets. Uniform all-TAPT performs better than uniform DAPT even though DAPT has access to a much larger body of reviews. The smaller target collection is closely matched to the eventual classification task and is revisited extensively. The full NB-MLM domain result approaches the task results more closely than the uniform domain result does. That pattern is consistent with the idea that targeted prediction can help exploit related text during a short pass through a large corpus. The domain and task settings differ in their material and training cadence, so their comparison cannot isolate the contribution of either difference on its own.
Combining the domain and task stages
The combined experiment takes the endpoint of Amazon adaptation as the starting point for adaptation on the target benchmark. Its results address whether the two sources of review text can be useful in succession. If the general product-review stage and the target-review stage contribute complementary information, the classifier can benefit from both. The paper compares this sequence under uniform masking and NB-MLM at both durations.
Combined domain and task adaptation, measured by IMDB test macro-F1
The full NB-MLM sequence achieves the highest score, and short NB-MLM also improves on the corresponding uniform schedule.
The numbers
| System or setting | macro-F1 |
|---|---|
| Uniform short DAPT+all-TAPT | 96.04 |
| NB-MLM short DAPT+all-TAPT | 96.27 |
| Uniform DAPT+all-TAPT | 96.38 |
| NB-MLM DAPT+all-TAPT (this paper) | 96.46 |
On the IMDB test split, the short combined schedules give error rates of 3.96 with uniform masking and 3.73 with NB-MLM. The full combined schedules give 3.62 and 3.54. The short IMDB comparison is marked at p < 0.05 in the paired test. The full NB-MLM sequence has the lowest error and highest macro-F1 among the RoBERTa-base configurations reported by the authors on IMDB. The contrast between the short and full comparisons also shows that the largest improvement from changing the sampler within a combined schedule appears at the shorter budget.
The Yelp test results follow the same ordering within the combined schedules. The short uniform run yields error of 1.69 and macro-F1 of 98.31. With NB-MLM those values are 1.66 and 98.34. Under the full schedule, the uniform results are 1.55 error and 98.45 macro-F1, and NB-MLM gives 1.51 error and 98.49 macro-F1. These are the strongest Yelp results among the paper's own configurations. The paired test does not mark the differences between the uniform and NB-MLM Yelp runs as statistically significant.
The highest score and the shortest route to a given score answer different questions. The best endpoints in the paper use both adaptation stages at their full budgets. The strongest example of a comparable result with a shorter schedule comes from domain adaptation on IMDB. Combining the observations gives a more precise account of the paper's contribution. The sampling rule can improve the return from a constrained encounter with a large corpus, and it can remain useful when further adaptation to the target text is possible.
How the published comparisons fit
The authors set their experiments alongside earlier classification results. The earlier BERT-base within-task procedure reports test error of 4.37 on IMDB and 1.92 on Yelp. The earlier BERT-base in-domain procedure reports test error of 4.88 on IMDB and 1.87 on Yelp. The earlier RoBERTa-base domain and task procedures are compared on IMDB test macro-F1. Gururangan and colleagues report 95.4 for domain adaptation, 95.5 for task adaptation, and 95.6 for their combination. With curated unlabeled target text, the earlier report gives 95.7 for task adaptation and 95.8 when domain adaptation precedes it.
The table also places larger systems in a separate comparison. BERT-large with within-task pretraining has IMDB test error of 4.21 and Yelp test error of 1.81. XLNet-large has test error of 3.20 on IMDB and 1.37 on Yelp. The paper treats these as context for the scale of the scores because the architectures or sizes differ from the RoBERTa-base experiments. The internal Uniform MLM comparisons more directly estimate the effect of the masking rule, since they hold the starting system and adaptation setting fixed within each matched pair.
What the ablations show
What the system is asked to recover
The authors begin their analysis with an illustration of the tokens most often selected for recovery. In this example they use task adaptation on IMDB and set NB-MLM to T = 0.1 and m = 5. With uniform sampling, commonly occurring functional words dominate the targets. When the Naive Bayes scores drive the draws, the highly represented targets shift toward language associated with sentiment. This is an illustration of the change in training examples, using settings chosen for that comparison. The main task-adaptation experiment uses a higher temperature and a higher support threshold.
This target analysis sits closer to the proposed mechanism than a final classification score does. The premise of the method is that picking random positions can devote a large share of predictions to commonly occurring pieces of language. The observed target mix supports that premise and shows that the supervised weights can change it in the intended direction. The result concerns what the system has to predict. It gives no direct measurement of which context clues the system then learns, or whether its reliance on explicit sentiment words changes during final classification.
The distinction matters because several explanations are compatible with the improvement. The system may acquire better representations of the selected tokens as they are used in reviews. It may learn to use the context that predicts them. It may also benefit from the frequency with which entire training examples present a difficult reconstruction task. The experiments compare alternative samplers and track their effect on downstream learning. They leave the contribution of each possible internal mechanism open.
Whether lowering the share of common words is enough
The frequency-based baseline is the most direct comparison for the role of the sentiment labels. It changes the probability of selecting a position as a function of the rarity of its token. The intuition is that if the main problem were simply domination by common words, prioritizing infrequent tokens could capture the same advantage. In the reported comparison, the baseline uses the same adaptation setup and estimates token frequencies from the IMDB training split.
P(pos) ∝ 1 / freq(wₚₒₛ)ⁿ
Here P(pos) is the probability of choosing the eligible position pos. The sign ∝ indicates that the right side is a relative weight. The constant 1 is divided by the token frequency raised to the power n. The function freq gives the estimated frequency, and wₚₒₛ denotes the sub-word occupying the position. The exponent n controls the strength of the preference for rare tokens. Increasing it increases the advantage of a low-frequency token over a more common one.
The authors tune n on the IMDB development split separately for the two protocols. The selected value is n = 3.5 for all-TAPT and n = 2.5 for DAPT. In the plots, the frequency-based sampler sometimes yields an improvement in the best development accuracy. Those improvements fail to carry through to the test split, where the baseline performs about as well as uniform masking. This comparison supports a more specific account of the method's value. Among the tested rules, rewarding a sub-word's association with the labels was more effective than rewarding its rarity.
The paper also examines a selection rule based on conditional pointwise mutual information. It compares that rule with the other objectives for IMDB all-TAPT on the development and test splits, showing mean performance and variation over 6 runs. The paper's account of the preliminary comparisons identifies NB-MLM as the alternative that outperformed uniform masking. The tested alternatives establish that merely altering the distribution of targets is insufficient to reproduce the reported gain. They leave room for other ways of estimating which targets are valuable.
What changes when sampling becomes more concentrated
The preliminary experiments compare adaptation on a separate IMDB split with BERT and RoBERTa. The authors reproduce the earlier within-task procedure for BERT, using dynamic masking and leaving out next-sentence prediction. They use their own development set for selecting the NB-MLM settings and for early stopping because the earlier setup did not supply a split they could follow. For adaptation, they use the dataset while reserving half of that development set to monitor perplexity. The plotted development error is the best achieved across 10 epochs of classifier fine-tuning.
With BERT, the figure uses a support threshold of m = 100. The authors report that NB-MLM at its best temperature reaches, after 60K adaptation steps, development error as good as or better than the best uniform result observed across 150K steps. They also describe substantial variance in the difference. This preliminary comparison shows why they considered the method worth testing beyond its first implementation. Its endpoint, selection procedure, and split differ from those in the main test comparison.
In the RoBERTa preliminary comparison, the support threshold shown is m = 50. At T = 0.2, the authors see a strong early development result at 20K adaptation steps. Performance at that small temperature later declines. Their inspection of perplexity indicates that overfitting begins after 20K steps. They suggest that repeatedly sampling the same positions could contribute to it. At T = 0.4, the early benefit is smaller, while the improvement holds up better and the endpoint is stronger. At that temperature, the preliminary RoBERTa experiment reaches, after 20K steps, development performance similar to Uniform MLM trained for 75K steps.
The contrast shows why temperature controls more than the definition of a useful word. The underlying class-related scores can stay the same while the exposure to other parts of the review changes over training. A concentrated distribution can produce early gains by placing an emphasis on class-associated tokens. If the same reviews recur under that distribution for many passes, the resulting exercises can become repetitive. The evidence is strongest for the change in the learning curve as temperature varies. The account of repeated positions is the authors' explanation for that change.
How much the available target text matters
An additional comparison varies the IMDB subsets used during task adaptation. The benchmark portions in this analysis are the labeled training set of 20K reviews, the unlabeled set of 50K, the development set of 5K, and the test set of 25K. In the all-TAPT protocol the authors include text from across those portions, holding out 1K examples from the unlabeled set for validation of the token recovery objective. They compare this with adaptation on the training text alone, adaptation on the training text plus the extra unlabeled collection, and adaptation using training, development, and test reviews together.
Both samplers benefit when the task stage draws on more unlabeled examples than the training split alone. Adding the development and test reviews to the pool improves performance further. To examine whether the match to the evaluation inputs matters alongside the amount of data, the authors compare adaptation on the training, development, and test subsets, which contain 50K examples, with Curated-TAPT, described as using 70k examples from the training and unlabeled subsets. The two achieve similar results. Adding development and test reviews to Curated-TAPT also yields a further improvement.
These observations suggest that the particular reviews included in adaptation can matter in addition to the size of the collection. A smaller pool that contains the evaluation inputs reaches a similar result to a larger pool built with other reviews, according to the paper's comparison. The authors treat this result as suggestive and say that the question requires further experiments. The subsets differ in their contents and their relationship to the evaluation, and the comparison is designed to explore that relationship rather than to isolate all differences between those collections.
For each subset condition, the authors select NB-MLM settings on the development split. They use T = 0.4 and m = 50 for all-TAPT and for the combination of training, development, and test text. For the other alternatives they choose T = 0.8 and m = 50. The subset analysis therefore compares each adaptation pool with an independently tuned sampler. Its clearest finding is shared by the uniform and label-informed procedures: the additional text available to adaptation materially affects the resulting classifier.
Limitations
Limits identified by the authors
The authors distinguish the strong IMDB domain effect from the smaller differences in task adaptation and on Yelp. In the task curves, the advantage is small relative to variation between runs. On Yelp the direction of the improvement is similar across the reported comparisons, with small differences in test performance. The strongest evidence for faster adaptation comes from a specific arrangement: a large related corpus, a limited number of training steps, and IMDB as the downstream task. It gives a concrete efficiency result under those conditions.
The authors discuss the risk of overfitting when adaptation becomes too repetitive. In the preliminary RoBERTa experiment, a more concentrated sampling rule does well early and then loses performance with continued training. The temperature that works well for one pass through the broad Amazon collection is consequently a separate choice from the temperature suitable for many passes through target reviews. The supervised stage is also sensitive to training length. The authors report that longer classifier fine-tuning led to higher metric variance and worse final performance, which they attribute to overfitting.
The paper explicitly urges caution about interpreting development results. The development split is used both to choose hyper-parameters and to control early stopping during the supervised stage. In the IMDB domain-adaptation curves, the gap between NB-MLM and uniform masking on the development split is described as twice as large as on the test split. The authors suggest that variation during fine-tuning, together with choosing a stopping point on the development set, may contribute. The development table also has coarser precision because of logging problems. For example, the full combined IMDB conditions both show development error of 3.4 and macro-F1 of 96.6. The main test table and the repeated-run curves answer questions that the rounded development endpoints alone cannot settle.
In their analysis of the target subsets, the authors leave open how much of all-TAPT's benefit comes from including the exact test reviews, compared with expanding the unlabeled pool more generally. Their additional comparisons suggest a role for the identity of the reviews. They explicitly call for more evidence before drawing a firm conclusion about this distinction. This limit applies to the explanation of the transductive gain. The result for the all-TAPT setup itself is a measurement of performance under the specified access to target text.
Limits visible in the experimental design
The central evidence concerns binary review polarity. A subword-level association is plausible as a way to identify useful training targets in that setting because sentiment and wording can be connected even before context is taken into account. Tasks whose labels depend on relations between entities, on the order of events, or on a distinction expressed across a larger passage may offer a weaker signal at the level of a single sub-word. The reported results establish a use for label-informed masking in review classification. How well the same scoring rule identifies useful targets in other tasks remains untested here.
The method also assumes access to labeled examples from which to derive the class-conditional probabilities. Its adaptation stage can learn from unlabeled reviews, while its target selection rule still depends on supervision from the task. The paper's formula is specified for a binary distinction. An application with more labels would require a definition of importance across those labels, and the experiments offer no direct comparison of such definitions. When labels are sparse or unevenly represented, the reliability of the vocabulary scores would also become an empirical question. Smoothing and the minimum-support rule address extreme estimates within the reported setup.
Access to future inputs affects how the task-adaptation results can be used. In the main all-TAPT comparison, the test texts are available before final classification. This access is common to the two samplers, so it does not explain the difference between them within that matched protocol. It can affect the absolute result and the comparison with a workflow in which future reviews have yet to arrive. The subset analysis provides evidence for alternatives on IMDB and shows that additional unlabeled training material can help, but the strongest combined figures still belong to the all-TAPT setting.
The consistency of the sampling rule also limits the scope of the mechanism claim. Every occurrence of a given vocabulary unit starts from the same class-association estimate, with the probability changing according to the other positions available. A score derived from aggregate counts has no direct representation of whether a feature is a genuine expression of sentiment in a particular sentence or a recurring topic correlated with one label. The downstream results show that the heuristic is useful on average in these benchmarks. They do not identify which of those associations the classifier uses or whether the same associations persist under another distribution of reviews.
The statistical comparison and the repeated-run analysis answer related questions with different units of evidence. The paired significance test addresses disagreements between the selected representative runs on the same test examples. The adaptation curves describe variation over training runs. In the combined condition there are fewer runs than in the IMDB domain-only condition. A significant paired result gives evidence that the selected systems differ on the test reviews. It does not quantify how frequently that difference would appear in fresh runs, and an unmarked comparison can still be numerically consistent in direction across the reported settings.
Finally, the resource claim is grounded in the adaptation schedules. At a common budget, the samplers select the same share of sub-word positions. Each improvement in error at that budget reflects a better downstream outcome from the changed exercise. The 4K-step versus 20K-step comparison shows that a shorter run can reach a comparable IMDB result. A full accounting of implementation cost would also consider estimating the feature scores, tuning the sampler, and running adaptation on other hardware. The paper gives timings for its training schedules and supports an efficiency claim in steps and corpus exposure, with the clearest evidence coming from the IMDB domain experiment.
What came after
UMUTeam at SemEval-2023 Task 10: Fine-grained detection of sexism in English cites NB-MLM in work on fine-grained sexism detection in English. The downstream question differs from the one in NB-MLM. A review polarity classifier predicts whether an expressed judgment is positive or negative. The later work addresses distinctions within sexism detection. That is a setting in which the broader question raised by NB-MLM can arise again: whether the labels for a particular task can help determine which language is most valuable to recover during adaptation.
The citation establishes that the later study drew on NB-MLM as prior work. It leaves open whether the authors implemented its Naive Bayes sampler, adapted the scoring rule to finer labels, or used the paper to situate a different approach. The measured evidence for the method itself remains the review-classification comparison, where the most pronounced test improvement occurs when the sampler helps use a large related corpus within a limited adaptation schedule.
Cite
Cite as Nikolay Arefyev, Dmitrii Kharchev and Artem Shelmanov. 2021. NB-MLM: Efficient Domain Adaptation of Masked Language Models for Sentiment Analysis. Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing.
@inproceedings{arefyev2021nb,
title = {{NB-MLM: Efficient Domain Adaptation of Masked Language Models for Sentiment Analysis}},
author = {Nikolay Arefyev, Dmitrii Kharchev and Artem Shelmanov},
booktitle = {Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing},
year = {2021},
doi = {10.18653/v1/2021.emnlp-main.717},
url = {https://doi.org/10.18653/v1/2021.emnlp-main.717}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/arefyev-2021-nb-mlm-efficient-domain-adaptation/