如何在 Jupyter Notebook 中运行 GitHub 代码?

我尝试在我自己的电脑上运行这段代码:https ://github.com/yicheng-w/CommonSenseMultiHopQA

我已经下载了 zip 文件,但我不知道如何在 Jupyter notebook 中运行这段代码。这是我第一次想从 Github 运行代码。我找不到任何完整的指南。

我在 Windows 上安装了 Python 3.6。


慕的地10843
浏览 1563回答 2
2回答

芜湖不芜

您只能.ipynb在 jupyter notebook 中使用该文件。尝试按照给出的说明并在终端/cmd 中运行代码。我所说的说明是指该 GitHub 存储库的README.md文件中所写的内容。看,这个 repo 中的文件是.py文件而不是.ipynb文件。运行它们的正确方法是,如果您在 Windows 机器上,则在命令提示符下运行它们;如果您在 Linux/Mac 上,则在终端中运行。第 0 步:Clone the repo克隆您已链接的回购协议,即CommonSenseMultiHopQA.&nbsp;要克隆 repo,您必须在系统上安装 git。如果您没有它,请从这里获取。在 Github 上工作时,有必要了解如何使用 git。如果您不这样做,请按照本教程进行操作。步骤1:首先,要设置目录结构,请运行 setup.sh 以创建适当的目录。.sh文件是包含 bash 脚本的 bash 文件。使用命令运行这些./setup.sh。这是有关运行它们的教程。运行此命令将自动创建必要的目录(文件夹结构)。第2步:cd&nbsp;raw_data git&nbsp;clone&nbsp;https://github.com/deepmind/narrativeqa.git第一个命令将您的目录更改为raw_data.&nbsp;这些 Linux 命令(在 Windows 中也可用)您可以在此处cd了解它们。第二个命令将 克隆到文件夹中。narrativeqaraw_data第 3 步:对于此步骤,您必须知道如何.py从 cmd/终端运行文件。观看此视频。我们需要使用提取的常识信息来构建经过处理的数据集。对于 NarrativeQA,我们运行:python src/config.py \&nbsp; &nbsp; --mode build_dataset \&nbsp; &nbsp; --data_dir raw_data/narrativeqa \&nbsp; &nbsp; --load_commonsense \&nbsp; &nbsp; --commonsense_file data/cn_relations_orig.txt \&nbsp; &nbsp; --processed_dataset_train data/narrative_qa_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/narrative_qa_valid.jsonl \&nbsp; &nbsp; --processed_dataset_test data/narrative_qa_test.jsonl要为 WikiHop 构建具有提取常识的处理过的数据集,我们运行:python src/config.py \&nbsp; &nbsp; --mode build_wikihop_dataset \&nbsp; &nbsp; --data_dir raw_data/qangaroo_v1.1 \&nbsp; &nbsp; --load_commonsense \&nbsp; &nbsp; --commonsense_file data/cn_relations_orig.txt \&nbsp; &nbsp; --processed_dataset_train data/wikihop_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/wikihop_valid.jsonl两个长命令都在文件夹config.py内运行文件src。是--something传递给python <filename>命令的参数。第一个 :python src/config.py \&nbsp; &nbsp; --mode build_dataset \&nbsp; &nbsp; --data_dir raw_data/narrativeqa \&nbsp; &nbsp; --load_commonsense \&nbsp; &nbsp; --commonsense_file data/cn_relations_orig.txt \&nbsp; &nbsp; --processed_dataset_train data/narrative_qa_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/narrative_qa_valid.jsonl \&nbsp; &nbsp; --processed_dataset_test data/narrative_qa_test.jsonl提取 narrativeqa 和第二个的常识:python src/config.py \&nbsp; &nbsp; --mode build_wikihop_dataset \&nbsp; &nbsp; --data_dir raw_data/qangaroo_v1.1 \&nbsp; &nbsp; --load_commonsense \&nbsp; &nbsp; --commonsense_file data/cn_relations_orig.txt \&nbsp; &nbsp; --processed_dataset_train data/wikihop_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/wikihop_valid.jsonl为 WikiHop 提取常识...最后,以下命令用于训练和评估:训练要为 NarrativeQA 训练模型,请运行:python src/config.py \&nbsp; &nbsp; --version {commonsense_nqa, baseline_nqa} \&nbsp; &nbsp; --model_name <model_name> \&nbsp; &nbsp; --processed_dataset_train data/narrative_qa_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/narrative_qa_valid.jsonl \&nbsp; &nbsp; --batch_size 24 \&nbsp; &nbsp; --max_target_iterations 15 \&nbsp; &nbsp; --dropout_rate 0.2要为 WikiHop 训练模型,请运行:python src/config.py \&nbsp; &nbsp; --version {commonsense_wh, baseline_wh} \&nbsp; &nbsp; --model_name <model_name> \&nbsp; &nbsp; --elmo_options_file lm_data/wh/elmo_2x4096_512_2048cnn_2xhighway_options.json \&nbsp; &nbsp; --elmo_weight_file lm_data/wh/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5 \&nbsp; &nbsp; --elmo_token_embedding_file lm_data/wh/elmo_token_embeddings.hdf5 \&nbsp; &nbsp; --elmo_vocab_file lm_data/wh/wikihop_vocab.txt \&nbsp; &nbsp; --processed_dataset_train data/wikihop_train.jsonl \&nbsp; &nbsp; --processed_dataset_valid data/wikihop_valid.jsonl \&nbsp; &nbsp; --multiple_choice \&nbsp; &nbsp; --max_target_iterations 4 \&nbsp; &nbsp; --max_iterations 8 \&nbsp; &nbsp; --batch_size 16 \&nbsp; &nbsp; --max_target_iterations 4 \&nbsp; &nbsp; --max_iterations 8 \&nbsp; &nbsp; --max_context_iterations 1300 \&nbsp; &nbsp; --dropout_rate 0.2评估为了评估 NarrativeQA,我们需要先在测试集上生成官方答案。为此,请运行:python src/config.py \&nbsp; &nbsp; --mode generate_answers \&nbsp; &nbsp; --processed_dataset_valid data/narrative_qa_valid.jsonl \&nbsp; &nbsp; --processed_dataset_test data/narrative_qa_test.jsonl或者,如果您真的想在其中运行这些命令jupyter notebook,那么您需要做的就是!在所有命令之前添加一个并在不同的单元格中运行它们。

PIPIONE

当您在 Jupyter notebook 的任何单元格中使用 ('!') 时,它充当一个命令 slimier as Terminal Here a sample example Example 如何在 Jupyter Notebook 中克隆 git 文件。!&nbsp;git&nbsp;clone&nbsp;https://github.com/yicheng-w/CommonSenseMultiHopQA.git在 Cell 中写入 Upper Command 后,您需要运行 cell 来执行命令,您的 Git Repo 已成功克隆到您的笔记本中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python