A new algorithm for the determination of the initial flavour of B0s mesons is presented. The algorithm is based on two neural networks and exploits the b hadron production mechanism at a hadron collider. The first network is trained to select charged kaons produced in association with the B0s meson. The second network combines the kaon charges to assign the B0s flavour and estimates the probability of a wrong assignment. The algorithm is calibrated using data corresponding to an integrated luminosity of 3 fb−1 collected by the LHCb experiment in proton-proton collisions at 7 and 8 TeV centre-of-mass energies. The calibration is performed in two ways: by resolving the B0s-B¯0s flavour oscillations in B0s→D−sπ+ decays, and by analysing flavour-specific B∗s2(5840)0→B+K− decays. The tagging power measured in B0s→D−sπ+ decays is found to be (1.80±0.19(stat)±0.18(syst))%, which is an improvement of about 50% compared to a similar algorithm previously used in the LHCb experiment.