if __name__ == '__main__':
torch.cuda.empty_cache()
"""Parameters"""
parser = argparse.ArgumentParser(description = "Emotion Classifier" )
parser.add_argument( "--batch", type=int, help = "batch_size", default = 1)
parser.add_argument( "--epoch", type=int, help = 'training epohcs', default = 10) # 12 for iemocap
parser.add_argument( "--norm", type=int, help = "max_grad_norm", default = 10)
parser.add_argument( "--lr", type=float, help = "learning rate", default = 1e-6) # 1e-5
parser.add_argument( "--sample", type=float, help = "sampling trainign dataset", default = 1.0) #
parser.add_argument( "--dataset", help = 'MELD or EMORY or iemocap or dailydialog', default = 'MELD')
parser.add_argument( "--pretrained", help = 'roberta-large or bert-large-uncased or gpt2 or gpt2-large or gpt2-medium', default = 'roberta-large')
parser.add_argument( "--initial", help = 'pretrained or scratch', default = 'pretrained')
parser.add_argument('-dya', '--dyadic', action='store_true', help='dyadic conversation')
parser.add_argument('-fr', '--freeze', action='store_true', help='freezing PM')
parser.add_argument( "--cls", help = 'emotion or sentiment', default = 'emotion')
args = parser.parse_args()
logger = logging.getLogger(__name__)
streamHandler = logging.StreamHandler()
# Add the line below to fix the issue.
sys.exit(main())
这是 colab 显示的错误
usage: colab_kernel_launcher.py [-h] [--batch BATCH] [--epoch EPOCH] [--norm NORM] [--lr LR]
[--sample SAMPLE] [--dataset DATASET] [--pretrained PRETRAINED]
[--initial INITIAL] [-dya] [-fr] [--cls CLS]
colab_kernel_launcher.py: error: unrecognized arguments: /root/.local/share/jupyter/runtime/kernel-1fba85a1-85fd-4471-a790-9c103c9dcac9.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
/usr/local/lib/python3.10/dist-packages/IPython/core/interactiveshell.py:3561: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
我有一个
train.py
文件,我想在我的 colab
上运行该文件。
当您运行
parse_args()
时,将从 sys.argv
获取值。colab
时,它会放入 sys.argv
的一些信息 colab
这会产生问题。
但是您可以将您的值直接放入
parse_args()
,例如
args = parser.parse_args( ["--sample", "your_filename"] )
顺便说一句:
我看不到您的代码是否在任何地方使用
args
- 所以我不知道您是否真的需要 ArgumentParser
并休息。也许你应该删除它。
如果您确实在
args
中使用 main()
那么将其作为参数发送会更具可读性,例如
def main(args): # get `args` in function
# ... code ...
# ...
sys.exit(main(args)) # send `args` to function