A new algorithm for the determination of the initial flavour of Bs0 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 Bs0 meson. The second network combines the kaon charges to assign the Bs0 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 Bs0-Bˉs0 flavour oscillations in Bs0→Ds−π+ decays, and by analysing flavour-specific Bs2∗(5840)0→B+K− decays. The tagging power measured in Bs0→Ds−π+ 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