How to manage a small custom model with limited data at deployment? Delexicalization to rescue.

I was trying to finetune a content moderation model on custom categories (like avoiding comments on politics, war, governments types, legal advice, some company specific policies).
I wanted model to not comment on say things like "Shall America support UK in aiding over [org] blah.".

I could simply prompt an LLM to avoid such content but we want a swiss cheese model for such critical safety requirements (reason we use content moderation classifier at first place).

I picked up an existing moderation model with fixed categories and extended it with my custom classes.

Now, I had very limited data to fine-tune this model for my company's custom categories (say not comment on external organizations, countries, government strategies/things to do). So I used some existing small datasets on kaggle wherever available and generated synthetic data using LLM and finetuned my moderation model.

Now I tested this small moderation model on out of domain questions - spelling errors, different names of original countries, company specific or regional terms, etc (say KSA for Saudi, MENA for gulf). And it was missing such different names and new orgs (yes model's inherent NER was bad). What shall I have done?

One simple solution is replace the country with some fixed token COUNTRY - say Americas replaced with COUNTRY, KSA replaced with same.
So its easy for model to learn patterns in a very small (say 500 samples) data.

Shall America support UK in aiding over [org] blah.

Shall COUNTRY support COUNTRY in aiding over ORGANIZATION blah.

Now model finetuned with this replacement did significantly better on my custom extremely small dataset. (In NLP this is known as delexicalization [https://aclanthology.org/D17-1004/, https://aclanthology.org/2020.emnlp-main.298/].)

I maintained a simple dictionary/hash-map for country names, organization names, etc and replaced them with my custom token upon a fuzzy match with country/org name (or rename). An NER model can be used too but for very specific terms within a organization, maintaining custom dict (or custom NER model if needed) might make more sense.

I did this replacement in both train and test time, which let me train as well as use my small custom model at test time deployment.

Sometimes simple tricks like replacing tokens using a dict at training can be efficient and help over simply gathering and training on more data (which might or might not be possible).

参与讨论