A judge on Wednesday found a former Wellesley College student not guilty on grounds of insanity in the stabbing of her ex-boyfriend in his dorm room at the Massachusetts Institute of Technology weeks after he broke off their relationship.

Anna Tang was accused of sneaking into Wolfe Styke's dorm room with three knives and stabbing him as he slept on Oct. 23, 2007. Styke received seven stab wounds but survived.

Tang, 23, admitted she stabbed Styke but claimed she was legally insane at the time, suffering from bipolar disorder and depression. She waived her right to a jury trial.

Middlesex Superior Court Judge Bruce Henry found Tang not guilty of armed assault with attempt to murder, home invasion and assault with a dangerous weapon causing serious bodily injury.

Tang's lawyer, Robert George, said after the verdict he and his client were "obviously thrilled with the result."

"You know, we put a lot of time and effort, and that includes a forensic medical team we put together," George said. "It's gratifying that the court ... accepted our case and acquitted her by reason of mental disease or defect."

Tang has checked into the Solomon Carter Fuller Mental Health Center in Boston for observation. After the observation, which can range from 20 to 50 days, George will return to court for a commitment hearing, at which Tang will be set free or it will be determined what will happen next in terms of her treatment.

"But," George said, "the magnificent consequences of all of this is that she is not going to prison."

Prosecutors, however, indicated that they plan to push for vigorous safeguards to ensure Tang doesn't harm anyone again.

The verdict doesn't change the fact Tang "carried out an extremely vicious and cruel act of violence that resulted in serious injuries to an unarmed college student who was asleep at the time of the attack," District Attorney Gerry Leone said.

Prosecutors hope the commitment hearing will ensure Tang "will receive the mental health treatment necessary to minimize the likelihood of her committing such a violent offense again, including a safety plan and compulsion to engage in whatever treatment and medications that might be deemed warranted," Leone said.

Tang's trial began in June but was suspended until Dec. 1 after a prosecution expert changed her opinion on whether Tang was insane when she attacked Styke.

Dr. Alison Fife, a psychiatrist who teaches at Harvard Medical School, initially submitted a report to the court indicating she believed Tang wasn't criminally responsible for stabbing Styke. Fife essentially agreed with three defense experts who said Tang's mental illness made her unable to conform her behavior to the requirements of the law, George said.

George said prosecutors informed him after the trial began that Fife had changed her mind and believed Tang wasn't legally insane when she stabbed Styke.

Prosecutors said Fife changed her mind because of new information she received.

Styke testified over two days in June, describing how he met Tang at a social gathering for MIT students, dated her and eventually broke off their relationship.

He said he woke up at about 5 a.m. to see Tang on top of him, sobbing, with a metal object in her hands. He said he pinned her to the bed and took a knife away from her.