Measurements of the cross section for producing b quarks in the reaction pp→bbX are reported in 7 and 13 TeV collisions at the LHC as a function of the pseudorapidity η in the range 2<η<5 covered by the acceptance of the LHCb experiment. The measurements are done using semileptonic decays of b-flavored hadrons decaying into a ground-state charmed hadron in association with a muon. The cross sections in the covered η range are 72.0±0.3±6.8 and 154.3±1.5±14.3 μb for 7 and 13 TeV. The ratio is 2.14±0.02±0.13, where the quoted uncertainties are statistical and systematic, respectively. The agreement with theoretical expectation is good at 7 TeV, but differs somewhat at 13 TeV. The measured ratio of cross sections is larger at lower η than the model prediction.