RICHMOND, Va. (AP) _ R. Everett Gravelle, director of the Defense Security Institute, describes himself as a ''sort of classified schoolmarm'' and his school as ''the little red schoolhouse that seems to be a deep dark secret.''

Gravelle teaches government investigators how to separate potential spies from loyal Americans, and his latest project involves collecting information from the file of John A. Walker Jr. and three others, including two Walker family members, who have been arrested in the past three weeks on espionage charges.

Gravelle's students, who must have top-secret clearances, use role-playing exercises to learn their trade. In one exercise, students pretend to be Christopher Boyce, whose sale of satellite secrets to the Soviet Union inspired the movie, ''The Falcon and the Snowman.''

Alumni of the institute are the first wave of foot soldiers in a $117 million a year effort by the Pentagon's Defense Investigative Service to safeguard secrets in government and the defense industry.

Investigators receive four weeks of basic training at the institute, which is located at the Defense General Supply Center near Richmond. They then become responsible for probing the backgrounds of all military personnel being considered for access to sensitive information.

The DIS has declined to discuss any role its investigators may have played in the granting of security clearances to Walker, 47, who had top-secret access to coded communications when he retired from the Navy; his son, Michael L. Walker, 22, who had a secret clearance and access to documents intended for destruction aboard the aircraft carrier Nimitz; Arthur J. Walker, 50, John Walker's brother, who had top-secret clearance in the Navy and security clearance at a Chesapeake, Va., defense contractor; and Jerry A. Whitworth, 45, a retired Navy radioman who had retained a top-secret military clearance.

In addition to its military investigations, the DIS covers 18 other government agencies, and trains people to keep an eye on 14,200 defense contractor facilities.

''We're a small agency with a very big mission, so there are bound to be a few bad apples,'' said Dale Hartig, spokesman for the DIS in Washington. ''You always have the bad apples, but you hope to screen them out.''

The DIS has field offices nationwide, and its 1,700 agents will conduct 215,000 investigations this year.

More than 4.3 million Americans have clearances to handle confidential government papers.

Gravelle's research in the Walker case is part of a continuing effort to learn more about spying and to train its people to find spies before any damage is done.

''There are always lessons learned that come out of these situations, and they are rapidly developed into the program,'' Hartig said. ''As to what specific lessons will come out of this incident, I don't know. It will take time to know.''