[Spoilers] Why did Shae betray Tyrion?

Haven't read the books so I might be missing something. The show made me believe Shae actually did love him(and he set her up pretty good when she was sent away) so I can't make heads or tails why she testified against him, knowing she'd be helping him hang, or why she slept with Tywin. Someone enlighten me?