在 Google Colab 中运行 python 参数

Mas*_*s17 5 python python-3.x google-colaboratory bert-language-model

我正在 Google Colab 中运行 python 文件并收到错误。我正在关注此链接中的 bert 文本分类示例;

https://appliedmachinelearning.blog/2019/03/04/state-of-the-art-text-classification-using-bert-model-predict-the-happiness-hackerearth-challenge/
Run Code Online (Sandbox Code Playgroud)

我按照描述的教程进行操作,现在是在 colab 中运行下面的代码片段的最后一步,

python run_classifier.py 
--task_name=cola 
--do_train=true 
--do_eval=true 
--do_predict=true 
--data_dir=./data/ 
--vocab_file=./cased_L-12_H-768_A-12/vocab.txt 
--bert_config_file=./cased_L-12_H-768_A-12/bert_config.json 
--init_checkpoint=./cased_L-12_H-768_A-12/bert_model.ckpt 
--max_seq_length=400 
--train_batch_size=8 
--learning_rate=2e-5 
--num_train_epochs=3.0 
--output_dir=./bert_output/ 
--do_lower_case=False
Run Code Online (Sandbox Code Playgroud)

我知道在 Colab 中我必须像这样运行 python 文件;

!python run_classifier.py 
Run Code Online (Sandbox Code Playgroud)

但我如何像脚本中那样设置其他参数。它会经历错误。感谢您的帮助。

mao*_*o95 4

您应该将\符号放在参数之间。例如,您的代码将是:

!python run_classifier.py \
--task_name=cola \
--do_train=true \
--do_eval=true \
--do_predict=true \
--data_dir=./data/ \
--vocab_file=./cased_L-12_H-768_A-12/vocab.txt \
--bert_config_file=./cased_L-12_H-768_A-12/bert_config.json \
--init_checkpoint=./cased_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length=400 \
--train_batch_size=8 \
--learning_rate=2e-5 \
--num_train_epochs=3.0 \
--output_dir=./bert_output/ \
--do_lower_case=False
Run Code Online (Sandbox Code Playgroud)

这在另一个例子中对我有用。