Skip to content

Commit

Permalink
fix tutorials only as needs.
Browse files Browse the repository at this point in the history
Signed-off-by: Xuesong Yang <[email protected]>
  • Loading branch information
XuesongYang committed Mar 10, 2023
1 parent 48af0e5 commit 233322c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 49 deletions.
18 changes: 4 additions & 14 deletions tutorials/asr/ASR_CTC_Language_Finetuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,17 @@
"source": [
"# Manifest Utils\n",
"from tqdm.auto import tqdm\n",
"from nemo.collections.asr.parts.utils.manifest_utils import read_manifest, write_manifest\n",
"import json\n",
"\n",
"def read_manifest(path):\n",
" manifest = []\n",
" with open(path, 'r') as f:\n",
" for line in tqdm(f, desc=\"Reading manifest data\"):\n",
" line = line.replace(\"\\n\", \"\")\n",
" data = json.loads(line)\n",
" manifest.append(data)\n",
" return manifest\n",
"\n",
"\n",
"def write_processed_manifest(data, original_path):\n",
" original_manifest_name = os.path.basename(original_path)\n",
" new_manifest_name = original_manifest_name.replace(\".json\", \"_processed.json\")\n",
"\n",
" manifest_dir = os.path.split(original_path)[0]\n",
" filepath = os.path.join(manifest_dir, new_manifest_name)\n",
" with open(filepath, 'w') as f:\n",
" for datum in tqdm(data, desc=\"Writing manifest data\"):\n",
" datum = json.dumps(datum)\n",
" f.write(f\"{datum}\\n\")\n",
" write_manifest(filepath, data)\n",
" print(f\"Finished writing manifest: {filepath}\")\n",
" return filepath"
],
Expand Down Expand Up @@ -2164,4 +2153,5 @@
]
}
]
}
}

19 changes: 2 additions & 17 deletions tutorials/asr/Buffered_Transducer_Inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1408,23 +1408,6 @@
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5GZ2smcq4IZE"
},
"outputs": [],
"source": [
"def read_manifest(manifest_path):\n",
" manifest_data = []\n",
" with open(manifest_path, 'r') as f:\n",
" for line in f:\n",
" data = json.loads(line)\n",
" manifest_data.append(data)\n",
" return manifest_data"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1433,6 +1416,8 @@
},
"outputs": [],
"source": [
"from nemo.collections.asr.parts.utils.manifest_utils import read_manifest\n",
"\n",
"manifest_data = read_manifest(manifest)\n",
"print(f\"Read {len(manifest_data)} samples from manifest {manifest}\")"
]
Expand Down
13 changes: 3 additions & 10 deletions tutorials/asr/Buffered_Transducer_Inference_with_LCS_Merge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,7 @@
"#@title Manifest helper\n",
"import json\n",
"import numpy as np\n",
"\n",
"\n",
"def read_manifest(manifest_path):\n",
" manifest_data = []\n",
" with open(manifest_path, 'r') as f:\n",
" for line in f:\n",
" data = json.loads(line)\n",
" manifest_data.append(data)\n",
" return manifest_data\n",
"from nemo.collections.asr.parts.utils.manifest_utils import read_manifest\n",
"\n",
"\n",
"def subset_manifest(manifest, num_samples):\n",
Expand Down Expand Up @@ -1299,4 +1291,5 @@
}
}
]
}
}

11 changes: 3 additions & 8 deletions tutorials/asr/asr_adapters/ASR_with_Adapters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,7 @@
"source": [
"# utility method\n",
"import json\n",
"\n",
"def read_manifest(manifest_filepath):\n",
" data = []\n",
" with open(manifest_filepath, 'r', encoding='utf8') as f:\n",
" for line in f:\n",
" data.append(json.loads(line))\n",
" return data"
"from nemo.collections.asr.parts.utils.manifest_utils import read_manifest\n",
],
"metadata": {
"id": "tJBriqr3tQV7"
Expand Down Expand Up @@ -1313,4 +1307,5 @@
}
}
]
}
}

0 comments on commit 233322c

Please sign in to comment.