how do you know whether a spider is male or female when they are babies?

In short, you don't. You need to have a fully developed adult to say definitively whether a spider is male or female. Only adult females have fully developed epigynes and only adults males have fully developed 'boxing glove' like pedipalps. Studying the structures of these is very important in accurately identifying spiders to species level.