data-silence commited on
Commit
851dcd9
1 Parent(s): 885aa20

Add FastText model and inference code

Browse files
Files changed (3) hide show
  1. fasttext_news_classifier.bin +3 -0
  2. inference.py +23 -0
  3. requirements.txt +2 -0
fasttext_news_classifier.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a8a08402f84bf8a4e0864090e14634ba702b2432abb54c289b313b6865a2486
3
+ size 1051714927
inference.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fasttext
2
+ from transformers import pipeline
3
+
4
+
5
+ class FastTextClassifierPipeline(pipeline):
6
+ def __init__(self, model_path):
7
+ self.model = fasttext.load_model(model_path)
8
+
9
+ def __call__(self, texts):
10
+ if isinstance(texts, str):
11
+ texts = [texts]
12
+
13
+ results = []
14
+ for text in texts:
15
+ prediction = self.model.predict(text)
16
+ label = prediction[0][0].replace("__label__", "")
17
+ score = prediction[1][0]
18
+ results.append({"label": label, "score": score})
19
+
20
+ return results
21
+
22
+
23
+ classifier = FastTextClassifierPipeline("fasttext_news_classifier.bin")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fasttext
2
+ transformers