first commit
Browse files- code/inference.py +30 -0
- code/requirements.txt +1 -0
- fasttext_model_300.bin +3 -0
code/inference.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import fasttext
|
4 |
+
from typing import Union, List
|
5 |
+
|
6 |
+
|
7 |
+
def model_fn(model_dir):
|
8 |
+
loaded_model = fasttext.load_model(
|
9 |
+
os.path.join(model_dir, "fasttext_model_300.bin")
|
10 |
+
)
|
11 |
+
return loaded_model
|
12 |
+
|
13 |
+
|
14 |
+
def input_fn(input_data, content_type):
|
15 |
+
data = json.loads(input_data)
|
16 |
+
return data['inputs']
|
17 |
+
|
18 |
+
|
19 |
+
def predict_fn(data: Union[List[str], str], model):
|
20 |
+
if isinstance(data, str):
|
21 |
+
return model.get_sentence_vector(data).tolist()
|
22 |
+
elif isinstance(data, list):
|
23 |
+
return [model.get_sentence_vector(sentence).tolist() for sentence in data]
|
24 |
+
else:
|
25 |
+
raise ValueError(f"Unsupported data type: {type(data)}")
|
26 |
+
|
27 |
+
|
28 |
+
def output_fn(prediction, accept):
|
29 |
+
response = json.dumps(prediction, ensure_ascii=False, default=str)
|
30 |
+
return response
|
code/requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fasttext-wheel==0.9.2
|
fasttext_model_300.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4a9ad8161c6206cef166d452cf68508f8b621a811abc99e7bc67994195be49cf
|
3 |
+
size 3186472204
|