Last active
May 13, 2021 01:12
-
-
Save dhruvdcoder/dd3ecd5b3db52a4004da0680ada02a0d to your computer and use it in GitHub Desktop.
Template to start a notebook which will ultimately be converted into a script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# utils.py | |
from typing import List, Tuple, Union, Dict, Any, Optional | |
def isnotebook() -> bool: | |
try: | |
shell = get_ipython().__class__.__name__ # type:ignore | |
if shell == "ZMQInteractiveShell": | |
return True # Jupyter notebook or qtconsole | |
elif shell == "TerminalInteractiveShell": | |
return False # Terminal running IPython | |
else: | |
return False # Other type (?) | |
except NameError: | |
return False # Probably standard Python interpreter | |
# import stuff | |
import sys | |
import argparse | |
try: | |
from .utils import isnotebook | |
except ImportError: | |
from utils import isnotebook | |
sys.path.append('../') | |
import logging | |
logging.basicConfig(format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
def get_args() -> argparse.Namespace: | |
parser = argparse.ArgumentParser( | |
description="Normalize arff 10 fold meka files' feature space" | |
) | |
parser.add_argument("-i", "--input-file", type=Path, help="name of the glob file path") | |
parser.add_argument( | |
"-n", | |
"--num-labels", | |
type=int, | |
default=None, | |
help='No. of labels in the dataset', | |
) | |
parser.add_argument( | |
'-s', | |
'--save-sparse', | |
action="store_true", | |
default=False, | |
help="Save output in the sparse format") | |
if isnotebook(): | |
import shlex # noqa | |
args_str = ( | |
"-i ../.data/blurb_genre_collection/sample_train.json -o " | |
"../.data/blurb_genre_collection/sample_train_cooccurrences.csv " | |
"-t from-blurb-genre" | |
) | |
args = parser.parse_args(shlex.split(args_str)) | |
else: | |
args = parser.parse_args() | |
return args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment