As with any conservation law, you can see get it from Noether's theorem by noticing a symmetry in the Lagrangian. By looking at how the symmetry acts on the fields, you can deduce the charge.
For the baryon number, it's the $U(1)$ symmetry obtained by multiplying the quark fields by the same phase (and the conjugate fields by the conjugate phase). The corresponding current is the sum of each individual quark current. Since you never observe an individual quark, it's natural to divide it by $3$ so that you can interpret it as a baryon number. By the action of the group, all quarks have baryon number $1/3$ (what matters is that it is equal), their antiparticles $-1/3$ (what matters is the relative sign) and the rest $0$.
Similarly, for the lepton number, it's the $U(1)$ symmetry obtained by multiplying all the lepton fields by the same phase (and the conjugate fields by the conjugate phase). The corresponding current is the sum of each individual lepton current. By the action of the group, all leptons have lepton number $1$ (what matters is that it is equal), their antiparticles $-1$ (what matters is the relative sign) and the rest $0$.
Hope this helps.