Whenever you decide to deduct money from a tenant's security deposit, you must be prepared to do so in strict compliance with the law on security deposits. You also want to make sure that you have been handling the security deposit properly throughout the tenancy (i.e., providing bank name and location of money, paying yearly interest to tenant, etc.).
Deductions can not be made to perform routine maintenance on the apartment, like cleaning and applying fresh coats of paint between tenancies, but are for damage caused by the tenant beyond normal wear and tear. I think if the carpets are unusually dirty (i.e, more than usual wear and tear after 4 years of use), then you can probably feel comfortable deducting the reasonable cost of cleaning.
I agree with my brothers comments, who answered previously.
I would like to reiterate that keeping a tenants security deposit (or any part thereof) is for DAMAGE to the premises, not cleaning.
In light of Massachusetts Court views toward the tenant's rights to the return of their security deposit, unless the carpets are extremely filthy, bordering on needing to be replaced, best practice would be to just chalk it up to a bad experience and move on.
Law Office of Glenn F. Russell, Jr.
38 Rock Street, Suite #12
Fall River, MA 02720