Commit ·
0fc93e6
1
Parent(s): b935f27
Create pipeline.py
Browse files- pipeline.py +21 -0
pipeline.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import fasttext.util
|
| 5 |
+
|
| 6 |
+
class PreTrainedPipeline():
|
| 7 |
+
def __init__(self, path=""):
|
| 8 |
+
"""
|
| 9 |
+
Initialize model
|
| 10 |
+
"""
|
| 11 |
+
self.model = fasttext.load_model(os.path.join(path, 'ubertext.fiction_news_wikipedia.filter_rus+short.tokens.txt.algo-skipgram.epochs-15.subwords-2..5.wordngram-3.neg_sampling-15'))
|
| 12 |
+
|
| 13 |
+
def __call__(self, inputs: str) -> List[float]:
|
| 14 |
+
"""
|
| 15 |
+
Args:
|
| 16 |
+
inputs (:obj:`str`):
|
| 17 |
+
a string to get the features of.
|
| 18 |
+
Return:
|
| 19 |
+
A :obj:`list` of floats: The features computed by the model.
|
| 20 |
+
"""
|
| 21 |
+
return self.model.get_sentence_vector(inputs).tolist()
|