My judge just ruled it as consensual sex and let us both go, but I get the feeling it was an arbitrary decision, so different judge could mean potentially different outcome.
If it's a situation where you will be at ongoing risk from the rapist (like prison or within a family) and attacking back sexually is what makes the most sense to deter future attacks, then maybe. If you could avoid the rapist after the attempted rape then no, absolutely not.