A search for new physics in top quark production is performed in proton-proton collisions at $13\,\text {TeV} $ . The data set corresponds to an integrated luminosity of $35.9{\,\text {fb}^{-1}} $ collected in 2016 with the CMS detector. Events with two opposite-sign isolated leptons (electrons or muons), and $\mathrm{b}$ quark jets in the final state are selected. The search is sensitive to new physics in top quark pair production and in single top quark production in association with a $\mathrm{W}$ boson. No significant deviation from the standard model expectation is observed. Results are interpreted in the framework of effective field theory and constraints on the relevant effective couplings are set, one at a time, using a dedicated multivariate analysis. This analysis differs from previous searches for new physics in the top quark sector by explicitly separating $\mathrm{t}\mathrm{W}$ from $\mathrm{t}{\bar{\mathrm{t}}}$  events and exploiting the specific sensitivity of the $\mathrm{t}\mathrm{W}$ process to new physics.