Skip to content

Commit 140ac70

Browse files
committed
arparse error solved
1 parent e08eb23 commit 140ac70

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

get_embeddings.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import argparse
1212

13-
from utils import create_fold
13+
from utils import create_fold,str2bool
1414
import csv
1515
from tqdm import tqdm
1616
import os
@@ -32,13 +32,15 @@
3232
parser.add_argument('-f','--files_path', default='./texts/',help='File folder of the set of documents', action="store")
3333
parser.add_argument('-sv','--save_path', default='./bert_embeddings/',help='Path to save the embeddings', action="store")
3434
parser.add_argument('-bm','--bert_model', default='Bert',help='Choose between three different BERT models: Bert, Beto and SciBert. By default BERT', choices=('Bert','Beto', 'SciBert'))
35-
parser.add_argument('-d','--dynamic', default=True, help='Boolean value to get dynamic features= True. By default True.', choices=(True, False))
36-
parser.add_argument('-st','--static', default=False, help='Boolean value to get static features= True from the embeddings such as mean, standard deviation, kurtosis, skeweness, min and max. By default False.', choices=(True, False))
35+
parser.add_argument('-d','--dynamic', type=str2bool, nargs='?',const=False, default=True, help='Boolean value to get dynamic features= True. By default True.', choices=(True, False))
36+
parser.add_argument('-st','--static', type=str2bool, nargs='?',const=True, default=False, help='Boolean value to get static features= True from the embeddings such as mean, standard deviation, kurtosis, skeweness, min and max. By default False.', choices=(True, False))
3737
parser.add_argument('-l','--language', default='english',help='Chosen language (only available for BERT model). Here is available only english or spanish. By default english.', choices=('english', 'spanish'))
38-
parser.add_argument('-sw','--stopwords', default=False, help='Boolean value, set True if you want to remove stopwords, By default False.' , choices=(True, False))
38+
parser.add_argument('-sw','--stopwords', type=str2bool, nargs='?',const=True, default=False, help='Boolean value, set True if you want to remove stopwords, By default False.' , choices=(True, False))
3939
parser.add_argument('-m','--model', default='base', help='Bert models, two options base and large. By default base.', choices=('base', 'large'))
40-
parser.add_argument('-ca','--cased', default=False, help='Boolean value for cased= True o lower-cased= False models. By defaul False.', choices=(True, False))
41-
parser.add_argument('-cu','--cuda', default=False, help='Boolean value for using cuda to compute the embeddings (True). By defaul False.', choices=(True, False))
40+
parser.add_argument('-ca','--cased', type=str2bool, nargs='?',const=True, default=False, help='Boolean value for cased= True o lower-cased= False models. By defaul False.', choices=(True, False))
41+
parser.add_argument('-cu','--cuda', type=str2bool, nargs='?', const=True, default=False, help='Boolean value for using cuda to compute the embeddings (True). By defaul False.', choices=(True, False))
42+
43+
4244

4345
#parser.print_help()
4446
args = parser.parse_args()

utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import unicodedata
2828
import re
2929
import os
30+
import argparse
31+
3032
#%% noPunctuation
3133
def noPunctuation(text):
3234

@@ -137,8 +139,18 @@ def HesitationsRemoval(text):
137139

138140
return text
139141

140-
142+
#%%
141143
def create_fold(new_folder):
142144

143145
if os.path.isdir(new_folder)==False:
144146
os.makedirs(new_folder)
147+
#%%
148+
def str2bool(v):
149+
if isinstance(v, bool):
150+
return v
151+
if v.lower() in ('yes', 'True','true', 't', 'y', '1'):
152+
return True
153+
elif v.lower() in ('no', 'False', 'false', 'f', 'n', '0'):
154+
return False
155+
else:
156+
raise argparse.ArgumentTypeError('Boolean value expected.')

0 commit comments

Comments
 (0)