Spaces:
Running
Running
wissamantoun
commited on
Commit
·
5ede0fb
1
Parent(s):
d963694
fixes
Browse files- backend/services.py +7 -7
- backend/utils.py +8 -13
backend/services.py
CHANGED
@@ -190,7 +190,7 @@ class SentimentAnalyzer:
|
|
190 |
"sar_trial10",
|
191 |
"sa_no_AOA",
|
192 |
]
|
193 |
-
|
194 |
# fmt: off
|
195 |
self.processors = {
|
196 |
"sa_trial5_1": Trial5ArabicPreprocessor(model_name='UBC-NLP/MARBERT'),
|
@@ -202,12 +202,12 @@ class SentimentAnalyzer:
|
|
202 |
}
|
203 |
|
204 |
self.pipelines = {
|
205 |
-
"sa_trial5_1": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format(
|
206 |
-
"sa_no_aoa_in_neutral": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format(
|
207 |
-
"sa_cnnbert": [CNNTextClassificationPipeline("{}/train_{}/best_model".format(
|
208 |
-
"sa_sarcasm": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format(
|
209 |
-
"sar_trial10": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format(
|
210 |
-
"sa_no_AOA": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format(
|
211 |
}
|
212 |
# fmt: on
|
213 |
|
|
|
190 |
"sar_trial10",
|
191 |
"sa_no_AOA",
|
192 |
]
|
193 |
+
download_models(self.sa_models)
|
194 |
# fmt: off
|
195 |
self.processors = {
|
196 |
"sa_trial5_1": Trial5ArabicPreprocessor(model_name='UBC-NLP/MARBERT'),
|
|
|
202 |
}
|
203 |
|
204 |
self.pipelines = {
|
205 |
+
"sa_trial5_1": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format("sa_trial5_1",i), device=-1,return_all_scores =True) for i in range(0,5)],
|
206 |
+
"sa_no_aoa_in_neutral": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format("sa_no_aoa_in_neutral",i), device=-1,return_all_scores =True) for i in range(0,5)],
|
207 |
+
"sa_cnnbert": [CNNTextClassificationPipeline("{}/train_{}/best_model".format("sa_cnnbert",i), device=-1, return_all_scores =True) for i in range(0,5)],
|
208 |
+
"sa_sarcasm": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format("sa_sarcasm",i), device=-1,return_all_scores =True) for i in range(0,5)],
|
209 |
+
"sar_trial10": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format("sar_trial10",i), device=-1,return_all_scores =True) for i in range(0,5)],
|
210 |
+
"sa_no_AOA": [pipeline("sentiment-analysis", model="{}/train_{}/best_model".format("sa_no_AOA",i), device=-1,return_all_scores =True) for i in range(0,5)],
|
211 |
}
|
212 |
# fmt: on
|
213 |
|
backend/utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import psutil
|
2 |
import os
|
|
|
3 |
|
4 |
|
5 |
def get_current_ram_usage():
|
@@ -8,31 +9,25 @@ def get_current_ram_usage():
|
|
8 |
|
9 |
|
10 |
def download_models(models):
|
11 |
-
|
12 |
-
for model in models:
|
13 |
-
model_dirs = {
|
14 |
-
model: model
|
15 |
-
} # useless i know, but i don't want to change the code
|
16 |
for i in range(0, 5):
|
17 |
curr_dir = f"{model}/train_{i}/best_model/"
|
18 |
os.makedirs(curr_dir)
|
19 |
os.system(
|
20 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/config.json -P {curr_dir}"
|
21 |
)
|
22 |
os.system(
|
23 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/pytorch_model.bin -P {curr_dir}"
|
24 |
)
|
25 |
os.system(
|
26 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/special_tokens_map.json -P {curr_dir}"
|
27 |
)
|
28 |
os.system(
|
29 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/tokenizer_config.json -P {curr_dir}"
|
30 |
)
|
31 |
os.system(
|
32 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/training_args.bin -P {curr_dir}"
|
33 |
)
|
34 |
os.system(
|
35 |
-
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/vocab.txt -P {curr_dir}"
|
36 |
)
|
37 |
-
|
38 |
-
return model_dirs
|
|
|
1 |
import psutil
|
2 |
import os
|
3 |
+
from tqdm.auto import tqdm
|
4 |
|
5 |
|
6 |
def get_current_ram_usage():
|
|
|
9 |
|
10 |
|
11 |
def download_models(models):
|
12 |
+
for model in tqdm(models, desc="Downloading models"):
|
|
|
|
|
|
|
|
|
13 |
for i in range(0, 5):
|
14 |
curr_dir = f"{model}/train_{i}/best_model/"
|
15 |
os.makedirs(curr_dir)
|
16 |
os.system(
|
17 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/config.json -P {curr_dir} >/dev/null"
|
18 |
)
|
19 |
os.system(
|
20 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/pytorch_model.bin -P {curr_dir} >/dev/null"
|
21 |
)
|
22 |
os.system(
|
23 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/special_tokens_map.json -P {curr_dir} >/dev/null"
|
24 |
)
|
25 |
os.system(
|
26 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/tokenizer_config.json -P {curr_dir} >/dev/null"
|
27 |
)
|
28 |
os.system(
|
29 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/training_args.bin -P {curr_dir} >/dev/null"
|
30 |
)
|
31 |
os.system(
|
32 |
+
f"wget https://huggingface.co/researchaccount/{model}/resolve/main/train_{i}/best_model/vocab.txt -P {curr_dir} >/dev/null"
|
33 |
)
|
|
|
|