Spaces:
Sleeping
Sleeping
File size: 888 Bytes
4a1df2e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
"""
scikit-learn Model Wrapper
--------------------------
"""
import pandas as pd
from .model_wrapper import ModelWrapper
class SklearnModelWrapper(ModelWrapper):
"""Loads a scikit-learn model and tokenizer (tokenizer implements
`transform` and model implements `predict_proba`).
May need to be extended and modified for different types of
tokenizers.
"""
def __init__(self, model, tokenizer):
self.model = model
self.tokenizer = tokenizer
def __call__(self, text_input_list, batch_size=None):
encoded_text_matrix = self.tokenizer.transform(text_input_list).toarray()
tokenized_text_df = pd.DataFrame(
encoded_text_matrix, columns=self.tokenizer.get_feature_names()
)
return self.model.predict_proba(tokenized_text_df)
def get_grad(self, text_input):
raise NotImplementedError()
|