In the movie The Animatrix, it happens by mistake. What they didn’t realize was that having certain skills would make the robots sentient. Unless it's known exactly what is necessary for consciousness, and then this is intentionally avoided, someone could stumble into creating sentient machines in the same way