(
self,
model_path,
label_path,
model_name="model.onnx",
multi_label=False,
model_type="bert",
use_fast_tokenizer=True,
do_lower_case=True,
device=None,
)
| 89 | |
| 90 | class BertOnnxClassificationPredictor(object): |
| 91 | def __init__( |
| 92 | self, |
| 93 | model_path, |
| 94 | label_path, |
| 95 | model_name="model.onnx", |
| 96 | multi_label=False, |
| 97 | model_type="bert", |
| 98 | use_fast_tokenizer=True, |
| 99 | do_lower_case=True, |
| 100 | device=None, |
| 101 | ): |
| 102 | if device is None: |
| 103 | device = ( |
| 104 | torch.device("cuda") |
| 105 | if torch.cuda.is_available() |
| 106 | else torch.device("cpu") |
| 107 | ) |
| 108 | |
| 109 | self.model_path = model_path |
| 110 | self.label_path = label_path |
| 111 | self.multi_label = multi_label |
| 112 | self.model_type = model_type |
| 113 | self.do_lower_case = do_lower_case |
| 114 | self.device = device |
| 115 | self.labels = [] |
| 116 | |
| 117 | # Use auto-tokenizer |
| 118 | self.tokenizer = AutoTokenizer.from_pretrained( |
| 119 | self.model_path, use_fast=use_fast_tokenizer |
| 120 | ) |
| 121 | |
| 122 | with open(label_path / "labels.csv", "r") as f: |
| 123 | self.labels = f.read().split("\n") |
| 124 | |
| 125 | self.model = load_model(Path(self.model_path) / model_name) |
| 126 | |
| 127 | def predict(self, text, verbose=False): |
| 128 | # Inputs are provided through numpy array |
nothing calls this directly
no test coverage detected