Skip to content

Instantly share code, notes, and snippets.

@dhruvdcoder
Last active May 13, 2021 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhruvdcoder/dd3ecd5b3db52a4004da0680ada02a0d to your computer and use it in GitHub Desktop.
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.
# 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