GridSearchCV to train most optimal class weights?

Hi all,
I have a imbalanced class classification problem (NLP based, 3 classes).
Given class 1 (out of class 1,2,3) is 95% of the data. I tried class_weights (keras) to reducye the tendency to classify everything as class 1.
I however as I increased the weights for the minority classes class 1 started to massively misclassify which brings down the over all accuracy.
I was wondering if I can put the class_weights into gridsearchCV and find a optimal set of weights?
Also can anyone can point me to a way to find out how gridsearchCV works “under the hood” (ideally just 1-2 levels above the sources code in terms of abstraction : )
Thanks all!