init
Browse files- README.md +7 -0
- pipeline.py +24 -0
- pytorch_model.bin +3 -0
- requirements.txt +1 -0
README.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- text-classification
|
4 |
+
library_name: generic
|
5 |
+
---
|
6 |
+
|
7 |
+
# Test
|
pipeline.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from flash.text import TextClassifier
|
3 |
+
|
4 |
+
# ⚠️ You need this to access the state key
|
5 |
+
from flash.core.data.data_source import LabelsState
|
6 |
+
|
7 |
+
|
8 |
+
class PreTrainedPipeline():
|
9 |
+
|
10 |
+
def __init__(self, path=""):
|
11 |
+
self.device = 'cpu'
|
12 |
+
self.model = TextClassifier.load_from_checkpoint(os.path.join(path, "pytorch_model.bin"))
|
13 |
+
self.data_pipeline = self.model.build_data_pipeline()
|
14 |
+
self.labels = self.model._data_pipeline_state._state[LabelsState].labels
|
15 |
+
self.top_k = 5
|
16 |
+
|
17 |
+
def __call__(self, inputs):
|
18 |
+
x = self.data_pipeline._deserializer(inputs)
|
19 |
+
x = self.data_pipeline.worker_preprocessor('predict')(x)
|
20 |
+
x = self.model.transfer_batch_to_device(x, self.device, 0)
|
21 |
+
x = self.data_pipeline.device_preprocessor('predict')(x)
|
22 |
+
out = self.model.predict_step(x, 0)
|
23 |
+
proba = out['logits'].softmax(1)[0].tolist()
|
24 |
+
return [{'score': s, 'label': l} for s, l in sorted(zip(proba, self.labels), reverse=True)[:self.top_k]]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:783e24a9d32146f692d994e4bd807e54da084a0ab76743584b32da01e1c93dda
|
3 |
+
size 165569317
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
lightning-flash[text]
|