occasions stopping you from implementing Bayesian fashions in manufacturing? You’re not alone. Whereas Bayesian fashions provide a robust software for incorporating prior data and uncertainty quantification, their adoption in trade has been restricted by one crucial issue: conventional inference strategies are extraordinarily gradual, particularly when scaled to high-dimensional areas. On this information, I’ll present you the best way to speed up your Bayesian inference by as much as 10,000 occasions utilizing multi-GPU Stochastic Variational Inference (SVI) in comparison with CPU-based Markov Chain Monte Carlo (MCMC) strategies.
What You’ll Be taught:
- Variations between Monte Carlo and Variational Inference approaches.
- The right way to implement knowledge parallelism throughout a number of GPUs.
- Step-by-step strategies (and code) to scale your fashions to deal with hundreds of thousands or billions of observations/parameters.
- Efficiency benchmarks throughout CPU, single GPU, and multi-GPU implementations
This text continues our sensible collection on hierarchical Bayesian modeling, constructing on our earlier price elasticity of demand example. Whether or not you’re an information scientist working with large datasets or a tutorial researcher trying discover beforehand intractable issues, these strategies will remodel the way you method estimating Bayesian fashions.
Wish to skip the speculation and leap straight to implementation? You’ll discover the sensible code examples within the implementation part under.
Inference Strategies
Recall our baseline specification:
$$log(textrm{Demand}_{it})= beta_i log(textrm{Value})_{it} +gamma_{c(i),t} + delta_i + epsilon_{it}$$
The place:
- (textrm{Items Bought}_{it} sim textrm{Poisson}(textrm{Demand}_{it}, sigma_D) )
- (beta_i sim textual content{Regular}(beta_{c(i)},sigma_i))
- $beta_{c(i)}sim textual content{Regular}(beta_g,sigma_{c(i)})$
- $beta_gsim textual content{Regular}(mu,sigma)$
We wish to estimate the parameters vector (and their variance) $z = { beta_g, beta_{c(i)}, beta_i, gamma_{c(i),t}, delta_i, textual content{Demand}_{it} }$ utilizing the information $x = { textual content{Items}_{it}, textual content{Value}_{it}}$. One benefit in utilizing Bayesian strategies in comparison with frequentist approaches is that we will straight mannequin depend/gross sales knowledge with distributions like Poisson, avoiding points with zero values which may come up when utilizing log-transformed fashions. Utilizing Bayesian, we specify a previous distribution (based mostly on our beliefs) $p(z)$ that includes our data concerning the vector $z$ earlier than seeing any knowledge. Then, given the noticed knowledge $x$, we generate a probability $p(x|z)$ that tells us how doubtless it’s that we observe the information $x$ given our specification of $z$. We then apply Bayes’ rule $p(z|x) = fracz){p(x)}$ to acquire the posterior distribution, which represents our up to date beliefs concerning the parameters given the information. The denominator can be written as $p(x) = int p(z,x) , dz = int p(z)p(x|z) , dz$. This reduces our equation to:
$$p(z|x) = fracz)z) , dz$$
This equation requires calculating the posterior distribution of the parameters conditional on the noticed knowledge $p(z|x)$, which is the same as the prior distribution $p(z)$ multiplied by the probability of the information given some parameters $z$. We then divide that product by the marginal probability (proof), which is the entire chance of the information throughout all doable parameter values. The issue in calculating $p(z|x)$ is that the proof requires computing a high-dimensional integral $p(x) = int p(x|z)p(z)dz$. Many fashions with a hierarchical construction or advanced parameter relationships additionally should not have closed type options for the integral. Moreover, the computational complexity will increase exponentially with the variety of parameters, making direct calculation intractable for high-dimensional fashions. Subsequently, Bayesian inference is carried out in observe by approximating the integral.
We now discover the 2 hottest strategies for Bayesian inference; Markov-Chain Monte Carlo (MCMC) and Stochastic Variational Inference (SVI) within the following sections. Whereas these are the most well-liked strategies, different strategies exist, similar to Importance Sampling, particle filters (sequential Monte Carlo), and Expectation Propagation however is not going to be coated on this article.
Markov-Chain Monte Carlo
MCMC strategies are a category of algorithms that permit us to pattern from a chance distribution when direct sampling is tough. In Bayesian inference, MCMC permits us to attract samples from the posterior distribution $p(z|x)$ with out explicitly calculating the integral within the denominator. The core thought is to assemble a Markov chain whose stationary distribution equals our goal posterior distribution. Mathematically, our goal distribution $p(z|x)$ may be represented by $pi$, and we try to assemble a transition matrix $P$ such that $pi = pi P$. As soon as the chain has reached its stationary distribution (after discarding the burn-in samples, the place the chain may not be stationary), every successive state of the chain shall be roughly distributed in keeping with our goal distribution $pi$. By amassing sufficient of those samples, we will assemble an empirical approximation of our posterior that turns into asymptotically unbiased because the variety of samples will increase.
Markov-chain strategies are sorts of samplers that present completely different approaches for setting up the transition matrix $P$. Probably the most basic is the Metropolis-Hastings (MH) algorithm, which proposes new states from a proposal distribution and accepts or rejects them based mostly on chance ratios that make sure the chain converges to the goal distribution. Whereas MH is the inspiration of Markov-chain strategies, current developments within the subject have moved to extra subtle samplers like Hamiltonian Monte Carlo (HMC) that includes ideas from physics by together with gradient data to extra effectively discover the parameter house. Lastly, the default sampler lately is the No U-Turn sampler (NUTS) that improves HMC by routinely tuning HMC’s hyperparameters.
Regardless of their fascinating theoretical properties, MCMC strategies face important limitations when scaling to massive datasets and high-dimensional parameter areas. The sequential nature of MCMC creates a computational bottleneck as every step within the chain depends upon the earlier state, making parallelization tough. Moreover, MCMC strategies usually require evaluating the probability operate utilizing your complete dataset at every iteration. Whereas ongoing analysis has proposed strategies to beat this limitation similar to stochastic gradient and mini-batching, it has not seen widespread adoption. These scaling points have made making use of conventional Bayesian inference a problem in massive knowledge settings.
Stochastic Variational Inference
The second class of generally used strategies for Bayesian inference is Stochastic Variational Inference. As a substitute of sampling from the unknown posterior distribution, we posit that there exists a household of distributions $mathcal{Q}$ that may approximate the unknown posterior $p(z|x)$. This household is parameterized by variational parameters $phi$ (also called a information in Pyro/Numpyro), and our purpose is to search out the member $q_phi(z) in mathcal{Q}$ that almost all carefully resembles the true posterior. The usual proposed distribution makes use of a mean-field approximation, in that it assumes that each one latent variables are mutually impartial. This assumption implies that the joint distribution factorizes right into a product of marginal distributions, making computation extra tractable. For instance, we will have a Diagonal Multivariate Regular because the information, and the parameters $phi$ can be the situation and scale parameter of every diagonal component. Since all covariance phrases are set to be zero, this household of distribution has mutually impartial parameters. That is particularly problematic for gross sales knowledge, since spillover results are rampant.
Not like MCMC which makes use of sampling, SVI formulates Bayesian inference as an optimization drawback by minimizing the Kullback-Leibler (KL) divergence between our approximation and the true posterior: $textual content{KL}(q_phi(z) || p(z|x))$. Whereas we can not tractably compute the complete divergence, minimizing the KL-divergence is equal to maximizing the proof decrease sure (ELBO) (derivation) stochastically utilizing established optimization strategies.
Analysis alongside this route tends to concentrate on two foremost instructions: enhancing the variational household $mathcal{Q}$ or creating higher variations of the ELBO. Extra expressive households like normalizing flows can seize advanced posterior geometries however include greater computational prices. Importance Weighted ELBO derives a tighter sure on the log marginal probability, lowering the bias of SVI. Since SVI is basically a minimization approach, it additionally advantages from optimization algorithms developed for deep studying. These enhancements permit SVI to scale to extraordinarily massive datasets, nonetheless at the price of some approximation high quality. Moreover, the mean-field assumption implies that the posterior uncertainty of SVI tends to be underestimated. Which means that the credible intervals are too slim and should not correctly seize the true parameter values, one thing we present in Half 1 of this collection.
Which one to make use of
Since our purpose of this text is scaling, we are going to use SVI for future purposes. As famous in Blei et al. (2016), “variational inference is suited to massive knowledge units and situations the place we wish to rapidly discover many fashions; MCMC is suited to smaller knowledge units and situations the place we fortunately pay a heavier computational value for extra exact samples”. Papers making use of SVI have proven important speedups in inference (as much as 3 orders of magnitude) when utilized to multinomial logit models, astrophysics, and big data marketing.
Knowledge Sharding
JAX is a Python library for accelerator-oriented array computation that mixes NumPy’s acquainted API with GPU/TPU acceleration and computerized differentiation. Below the hood, JAX makes use of each JIT and XLA to effectively compile and optimize calculations. Key to this text is JAX’s capability to distribute knowledge throughout a number of gadgets (data sharding), which permits parallel processing by splitting computation throughout {hardware} assets. Within the context of our mannequin, because of this we will partition our $X$ vector throughout gadgets to speed up convergence of SVI. JAX additionally permits for replication, which duplicates the information throughout all gadgets. That is essential for some parameters of our mannequin (world elasticity, class elasticity, and subcategory-by-time mounted impact), that are data that would doubtlessly be wanted by all gadgets. For our worth elasticity instance, we are going to shard the indexes and knowledge whereas replicating the coefficients.
One final level to notice is that the main dimension of sharded arrays in JAX have to be divisible by the variety of gadgets within the system. For a 2D array, because of this variety of rows have to be divisible by the variety of gadgets. Subsequently we should write a customized helper operate to pad the arrays that we feed into our demand operate, in any other case we are going to obtain an error. This computation additionally have to be accomplished outdoors the mannequin, in any other case each single iteration of SVI will repeat the padding and decelerate the computation. Subsequently, as a substitute of passing our DataFrame
straight into the mannequin, we are going to pre-compute all required transformations outdoors and feed that into the mannequin.
Implementation and Analysis
The prior model of the mannequin may be seen within the previous article. Along with our DGP from the earlier instance we add in two features to create a dict
from our DataFrame
and to pad the arrays to be divisible by the variety of gadgets. We then transfer all computations (calculating plate sizes, taking log costs, indexing) to outdoors the mannequin, then feed it again right into a mannequin as a dict
.
import jax
import jax.numpy as jnp
def pad_array(arr):
num_devices = jax.device_count()
the rest = arr.form[0] % num_devices
if the rest == 0:
return arr
pad_size = num_devices - the rest
padding = [(0, pad_size)] + [(0, 0)] * (arr.ndim - 1)
# Select applicable padding worth based mostly on knowledge sort
pad_value = -1 if arr.dtype in (jnp.int32, jnp.int64) else -1.0
return jnp.pad(arr, padding, constant_values=pad_value)
def create_dict(df):
# Outline indexes
product_idx, unique_product = pd.factorize(df['product'])
cat_idx, unique_category = pd.factorize(df['category'])
time_cat_idx, unique_time_cat = pd.factorize(df['cat_by_time'])
# Convert the value and models collection to jax numpy arrays
log_price = jnp.log(df.worth.values)
final result = jnp.array(df.units_sold.values, dtype=jnp.int32)
# Generate mapping
product_to_category = jnp.array(pd.DataFrame({'product': product_idx, 'class': cat_idx}).drop_duplicates().class.values, dtype=np.int16)
return {
'product_idx': pad_array(product_idx),
'time_cat_idx': pad_array(time_cat_idx),
'log_price': pad_array(log_price),
'product_to_category': product_to_category,
'final result': final result,
'cat_idx': cat_idx,
'n_obs': final result.form[0],
'n_product': unique_product.form[0],
'n_cat': unique_category.form[0],
'n_time_cat': unique_time_cat.form[0],
}
data_dict = create_dict(df)
data_dict
{'product_idx': Array([ 0, 0, 0, ..., 11986, 11986, -1], dtype=int32),
'time_cat_idx': Array([ 0, 1, 2, ..., 1254, 1255, -1], dtype=int32),
'log_price': Array([ 6.629865 , 6.4426994, 6.4426994, ..., 5.3833475, 5.3286524,
-1. ], dtype=float32),
'product_to_category': Array([0, 1, 2, ..., 8, 8, 7], dtype=int16),
'final result': Array([ 9, 13, 11, ..., 447, 389, 491], dtype=int32),
'cat_idx': array([0, 0, 0, ..., 7, 7, 7]),
'n_obs': 1881959,
'n_product': 11987,
'n_cat': 10,
'n_time_cat': 1570}
After altering the mannequin inputs, we even have to vary some parts of the mannequin. First, the sizes for every plate is now pre-computed and we will simply feed these into the plate creation. To use knowledge sharding and replication, we might want to add a mesh (an N-dimensional array that determines how knowledge needs to be cut up) and outline which inputs must be sharded and which one to be replicated. The in_spec
variable defines which enter argments to be sharded/replicated throughout the ‘batch’ dimension outlined in our mesh. We then re-define the calculate_demand
operate, ensuring that every argument corresponds to the right in_spec
order. We use jax.experimental.shard_map.shard_map
to inform JAX that it ought to routinely paralleize the computation of our operate over the shards, then use the sharded operate to calculate demand if the mannequin argument parallel
is True. Lastly, we alter the data_plate
to solely take non-padded indexes by together with the ind
, because the measurement of the unique knowledge is saved within the n_obs
variable of the dictionary.
from jax.sharding import Mesh
from jax.sharding import PartitionSpec as P
import jax.experimental.shard_map
import numpyro
import numpyro.distributions as dist
from numpyro.infer.reparam import LocScaleReparam
def mannequin(data_dict, final result: None, parallel:bool = False):
# get information from dict
product_to_category = data_dict['product_to_category']
product_idx = data_dict['product_idx']
log_price = data_dict['log_price']
time_cat_idx = data_dict['time_cat_idx']
# Create the plates to retailer parameters
category_plate = numpyro.plate("class", data_dict['n_cat'])
time_cat_plate = numpyro.plate("time_cat", data_dict['n_time_cat'])
product_plate = numpyro.plate("product", data_dict['n_product'])
data_plate = numpyro.plate("knowledge", measurement=data_dict['n_obs'])
# DEFINING MODEL PARAMETERS
global_a = numpyro.pattern("global_a", dist.Regular(-2, 1), infer={"reparam": LocScaleReparam()})
with category_plate:
category_a = numpyro.pattern("category_a", dist.Regular(global_a, 1), infer={"reparam": LocScaleReparam()})
with product_plate:
product_a = numpyro.pattern("product_a", dist.Regular(category_a[product_to_category], 2), infer={"reparam": LocScaleReparam()})
product_effect = numpyro.pattern("product_effect", dist.Regular(0, 3), infer={"reparam": LocScaleReparam()})
with time_cat_plate:
time_cat_effects = numpyro.pattern("time_cat_effects", dist.Regular(0, 3), infer={"reparam": LocScaleReparam()})
# Calculating anticipated demand
# Outline infomrmation concerning the system
gadgets = np.array(jax.gadgets())
num_gpus = len(gadgets)
mesh = Mesh(gadgets, ("batch",))
# Outline the sharding/replicating of enter and output
in_spec=(
P(), # product_a: replicate
P("batch"), # product_idx: shard
P("batch"), # log_price: shard
P(), # time_cat_effects: replicate
P("batch"), # time_cat_idx: shard
P(), # product_effect: replicate
)
out_spec=P("batch") # expected_demand: shard
def calculate_demand(
product_a,
product_idx,
log_price,
time_cat_effects,
time_cat_idx,
product_effect,
):
log_demand = product_a[product_idx]*log_price + time_cat_effects[time_cat_idx] + product_effect[product_idx]
expected_demand = jnp.exp(jnp.clip(log_demand, -4, 20)) # clip for stability and exponentiate
return expected_demand
shard_calc = jax.experimental.shard_map.shard_map(
calculate_demand,
mesh=mesh,
in_specs=in_spec,
out_specs=out_spec
)
calculate_fn = shard_calc if parallel else calculate_demand
demand = calculate_fn(
product_a,
product_idx,
log_price,
time_cat_effects,
time_cat_idx,
product_effect,
)
with data_plate as ind:
# Pattern observations
numpyro.pattern(
"obs",
dist.Poisson(demand[ind]),
obs=final result
)
numpyro.render_model(
mannequin=mannequin,
model_kwargs={"data_dict": data_dict,"final result": data_dict['outcome']},
render_distributions=True,
render_params=True,
)
Analysis
To get entry to distributed GPU assets, we run this pocket book on a SageMaker Pocket book occasion in AWS utilizing a G5.24xlarge occasion. This G5 occasion has 192 vCPUs and 4 NVIDIA A10G GPUs. Since NumPyro offers us a useful progress bar, we are going to examine the velocity of optimization over three completely different mannequin sizes: working both in parallel throughout all CPU cores, on a single GPU, or distributed throughout all 4 GPUs. We are going to consider the anticipated time it takes to complete a million observations throughout the three dataset sizes. All datasets may have 156 intervals, with rising variety of merchandise from 10k, 100k, and 1 million. The smallest dataset may have 1.56MM observations, and the biggest dataset may have 156MM observations. For the optimizer, we use optax
‘s weighted ADAM with an exponentially decaying schedule for the training fee. When working the SVI algorithm, take into account that Numpyro
takes a while to compile all of the code and knowledge, so there’s some overhead as the information measurement and mannequin complexity will increase.
As a substitute of optimizing over the usual ELBO, we use the RenyiELBO
loss to implement Renyi’s $alpha$-divergence. Because the default argument, $alpha=0$ implements the Importance-Weighted ELBO, giving us a tighter sure and fewer bias. For the information, we go along with the usual AutoNormal information that parameterizes a Diagonal Multivariate Regular for the posterior distribution. AutoMultivariateNormal and normalizing flows (AutoBNAFNormal, AutoIAFNormal) all requires $O(n^2)$ reminiscence, which we can not do on massive fashions. AutoLowRankMultivariateNormal might enhance posterior inference and solely makes use of $O(kn)$ reminiscence, the place $okay$ is the rank hyperparameter. Nonetheless for this instance, we go along with the usual formulation.
100%|██████████| 10000/10000 [00:36<00:00, 277.49it/s,
init loss: 131118161920.0000, avg. loss [9501-10000]: 10085247.5700] #pattern progress bar
## SVI
import gc
from numpyro.infer import SVI, autoguide, init_to_median, RenyiELBO
import optax
import matplotlib.pyplot as plt
numpyro.set_platform('gpu') # Tells numpyro/JAX to make use of GPU because the default system
rng_key = jax.random.PRNGKey(42)
information = autoguide.AutoNormal(mannequin)
learning_rate_schedule = optax.exponential_decay(
init_value=0.01,
transition_steps=1000,
decay_rate=0.99,
staircase = False,
end_value = 1e-5,
)
# Outline the optimizer
optimizer = optax.adamw(learning_rate=learning_rate_schedule)
# Code for working the 4 GPU computations
gc.acquire()
jax.clear_caches()
svi = SVI(mannequin, information, optimizer, loss=RenyiELBO(num_particles=4))
svi_result = svi.run(rng_key, 1_000_000, data_dict, data_dict['outcome'], parallel = True)
# Code for working the 1 GPU computations
gc.acquire()
jax.clear_caches()
svi = SVI(mannequin, information, optimizer, loss=RenyiELBO(num_particles=4))
svi_result = svi.run(rng_key, 1_000_000, data_dict, data_dict['outcome'], parallel = False)
# Code for working the parallel CPU computations (parallel = False) since all CPUs are seen as 1 system
with jax.default_device(jax.gadgets('cpu')[0]):
gc.acquire()
jax.clear_caches()
svi = SVI(mannequin, information, optimizer, loss=RenyiELBO(num_particles=4))
svi_result = svi.run(rng_key, 1_000_000, data_dict, data_dict['outcome'], parallel = False)
Dataset Measurement | CPU (192 cores) | 1 GPU (A10G) | 4 GPUs (A10G) |
---|---|---|---|
Small (10K merchandise, 1.56M obs, 21.6k params) | ~22:05 | ~0:41 [32.3x] | ~0:21 [63.1x] |
Medium (100K merchandise, 15.6M obs, 201.5k params) | ~202:20 | ~6:05 [33.3x] | ~2:14 [90.6x] |
Giant (1M merchandise, 156M obs, 2M params) | ~2132:30 | ~60:18 [35.4x] | ~20:50 [102.4x] |

As a reference level, we additionally ran the smallest dataset utilizing the NUTS sampler with 3,000 attracts (1,000 burn-in), which might take roughly 20 hours on a 192-core CPU, however doesn’t assure convergence. MCMC should additionally enhance the variety of attracts and burn-in because the posterior house turns into extra advanced, so correct time estimates for MCMC are powerful to measure. For SVI, our findings display a considerable efficiency enchancment when transitioning from CPU to GPU, with roughly 32-35x speedup relying on dataset measurement. Scaling from a single GPU to 4 GPUs yields additional important efficiency good points, starting from a 2x speedup for the small dataset to a 2.9x speedup for the big dataset. This means that the overhead of distributing computation turns into more and more justified as drawback measurement grows.
These outcomes recommend that multi-GPU setups are important for estimating massive hierarchical Bayesian fashions inside affordable timeframes. The efficiency benefits turn out to be much more pronounced with extra superior {hardware}. For instance, in my work utility, transitioning from an A10 4-GPU setup to an H100 8-GPU configuration elevated inference velocity from 5 iterations per second to 260 iterations per second—a 52x speedup! When in comparison with conventional CPU-based MCMC approaches for big fashions, the potential acceleration might attain as much as 10,000 occasions, enabling scientists to sort out beforehand intractable issues.
Word on Mini-Batch Coaching: I’ve gotten this code working with minibatching, however the velocity of the mannequin truly slows down considerably as in comparison with loading the complete dataset on GPU. I assume that there’s some loss in creating the indexes for batching, transferring knowledge from CPU to GPU, then distributing the information and indexes throughout GPUs. From what I’ve seen in observe, the minibatching with 1024 per batch is takes 2-3x longer than the 4 GPU case, and batching with 1048576 per batch takes 8x longer than the 4 GPU case. Subsequently, if the dataset can match on reminiscence, it’s higher to not incorporate minibatching.
This information demonstrates the best way to dramatically speed up hierarchical Bayesian fashions utilizing a mixture of SVI and a multi-GPU setup. This method is as much as 102x sooner than conventional CPU-based SVI when working with massive datasets containing hundreds of thousands of parameters. When mixed with the speedup SVI affords over MCMC, we will presumably have efficiency good points as much as 10,000 occasions. These enhancements make beforehand intractable hierarchical fashions sensible for real-world industrial purposes.
This text has a number of key take-aways. (1) SVI is crucial for scale over MCMC, on the expense of accuracy. (2) The advantages of a multi-GPU setup will increase considerably as the information turns into bigger. (3) The implementation of the code issues, since solely by transferring all pre-computations outdoors of the mannequin permits us to attain this velocity. Nonetheless, whereas this method affords important velocity enhancements, a number of key drawbacks nonetheless exist. Incorporating mini-batching reduces distributed efficiency, however is likely to be obligatory in observe for datasets which can be too massive to suit on GPU reminiscence. This drawback may be considerably mitigated by utilizing extra superior GPUs (A100, H100) with 80GB of reminiscence as a substitute of 24GB that the A10G affords. This integration of mini-batching and distributed computing is a promising space for future work. Second, the mean-field assumption in our SVI method tends to underestimate posterior uncertainty in comparison with full MCMC, which can influence purposes the place uncertainty quantification is crucial. Different guides can incorporate extra advanced posterior, however comes at the price of memory-scaling (often exponential) and wouldn’t be possible for big datasets. As soon as I’ve found out the easiest way to appropriate posterior uncertainty via post-processing, I will even write an article about that…
Software: The strategies demonstrated on this article opens doorways to quite a few purposes that had been beforehand computationally prohibitive. Advertising groups can now construct granular Advertising Combine Fashions that seize variation throughout areas and buyer profiles and supply localized estimates of channel effectiveness. Monetary establishments can implement large-scale Worth-at-Threat calculations that mannequin advanced dependencies throughout hundreds of securities whereas capturing segment-specific modifications in market habits. Tech firms can develop hybrid suggestion programs that combine each collaborative and content-based filtering with Bayesian uncertainty, enabling higher exploration-exploitation trade-offs. In macroeconomics, researchers can estimate absolutely heterogeneous agent (HANK) fashions that measure how financial and monetary insurance policies differentially influence various financial actors as a substitute of simply utilizing consultant brokers.
If in case you have the chance to use this idea in your personal work, I’d love to listen to about it. Please don’t hesitate to succeed in out with questions, insights, or tales via my email or LinkedIn. If in case you have any suggestions on this text, or wish to request one other matter in causal inference/machine studying, please additionally be happy to succeed in out. Thanks for studying!
Word: All pictures used on this article is generated by the writer.