id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
13,800 | pysal/mapclassify | mapclassify/classifiers.py | Max_P_Classifier._ss | def _ss(self, class_def):
"""calculates sum of squares for a class"""
yc = self.y[class_def]
css = yc - yc.mean()
css *= css
return sum(css) | python | def _ss(self, class_def):
"""calculates sum of squares for a class"""
yc = self.y[class_def]
css = yc - yc.mean()
css *= css
return sum(css) | [
"def",
"_ss",
"(",
"self",
",",
"class_def",
")",
":",
"yc",
"=",
"self",
".",
"y",
"[",
"class_def",
"]",
"css",
"=",
"yc",
"-",
"yc",
".",
"mean",
"(",
")",
"css",
"*=",
"css",
"return",
"sum",
"(",
"css",
")"
] | calculates sum of squares for a class | [
"calculates",
"sum",
"of",
"squares",
"for",
"a",
"class"
] | 5b22ec33f5802becf40557614d90cd38efa1676e | https://github.com/pysal/mapclassify/blob/5b22ec33f5802becf40557614d90cd38efa1676e/mapclassify/classifiers.py#L2178-L2183 |
13,801 | pysal/mapclassify | mapclassify/classifiers.py | Max_P_Classifier._swap | def _swap(self, class1, class2, a):
"""evaluate cost of moving a from class1 to class2"""
ss1 = self._ss(class1)
ss2 = self._ss(class2)
tss1 = ss1 + ss2
class1c = copy.copy(class1)
class2c = copy.copy(class2)
class1c.remove(a)
class2c.append(a)
ss1... | python | def _swap(self, class1, class2, a):
"""evaluate cost of moving a from class1 to class2"""
ss1 = self._ss(class1)
ss2 = self._ss(class2)
tss1 = ss1 + ss2
class1c = copy.copy(class1)
class2c = copy.copy(class2)
class1c.remove(a)
class2c.append(a)
ss1... | [
"def",
"_swap",
"(",
"self",
",",
"class1",
",",
"class2",
",",
"a",
")",
":",
"ss1",
"=",
"self",
".",
"_ss",
"(",
"class1",
")",
"ss2",
"=",
"self",
".",
"_ss",
"(",
"class2",
")",
"tss1",
"=",
"ss1",
"+",
"ss2",
"class1c",
"=",
"copy",
".",
... | evaluate cost of moving a from class1 to class2 | [
"evaluate",
"cost",
"of",
"moving",
"a",
"from",
"class1",
"to",
"class2"
] | 5b22ec33f5802becf40557614d90cd38efa1676e | https://github.com/pysal/mapclassify/blob/5b22ec33f5802becf40557614d90cd38efa1676e/mapclassify/classifiers.py#L2185-L2200 |
13,802 | abarker/pdfCropMargins | src/pdfCropMargins/calculate_bounding_boxes.py | get_bounding_box_list_render_image | def get_bounding_box_list_render_image(pdf_file_name, input_doc):
"""Calculate the bounding box list by directly rendering each page of the PDF as
an image file. The MediaBox and CropBox values in input_doc should have
already been set to the chosen page size before the rendering."""
program_to_use = ... | python | def get_bounding_box_list_render_image(pdf_file_name, input_doc):
"""Calculate the bounding box list by directly rendering each page of the PDF as
an image file. The MediaBox and CropBox values in input_doc should have
already been set to the chosen page size before the rendering."""
program_to_use = ... | [
"def",
"get_bounding_box_list_render_image",
"(",
"pdf_file_name",
",",
"input_doc",
")",
":",
"program_to_use",
"=",
"\"pdftoppm\"",
"# default to pdftoppm",
"if",
"args",
".",
"gsRender",
":",
"program_to_use",
"=",
"\"Ghostscript\"",
"# Threshold value set in range 0-255, ... | Calculate the bounding box list by directly rendering each page of the PDF as
an image file. The MediaBox and CropBox values in input_doc should have
already been set to the chosen page size before the rendering. | [
"Calculate",
"the",
"bounding",
"box",
"list",
"by",
"directly",
"rendering",
"each",
"page",
"of",
"the",
"PDF",
"as",
"an",
"image",
"file",
".",
"The",
"MediaBox",
"and",
"CropBox",
"values",
"in",
"input_doc",
"should",
"have",
"already",
"been",
"set",
... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/calculate_bounding_boxes.py#L116-L206 |
13,803 | abarker/pdfCropMargins | src/pdfCropMargins/calculate_bounding_boxes.py | render_pdf_file_to_image_files | def render_pdf_file_to_image_files(pdf_file_name, output_filename_root, program_to_use):
"""Render all the pages of the PDF file at pdf_file_name to image files with
path and filename prefix given by output_filename_root. Any directories must
have already been created, and the calling program is responsibl... | python | def render_pdf_file_to_image_files(pdf_file_name, output_filename_root, program_to_use):
"""Render all the pages of the PDF file at pdf_file_name to image files with
path and filename prefix given by output_filename_root. Any directories must
have already been created, and the calling program is responsibl... | [
"def",
"render_pdf_file_to_image_files",
"(",
"pdf_file_name",
",",
"output_filename_root",
",",
"program_to_use",
")",
":",
"res_x",
"=",
"str",
"(",
"args",
".",
"resX",
")",
"res_y",
"=",
"str",
"(",
"args",
".",
"resY",
")",
"if",
"program_to_use",
"==",
... | Render all the pages of the PDF file at pdf_file_name to image files with
path and filename prefix given by output_filename_root. Any directories must
have already been created, and the calling program is responsible for
deleting any directories or image files. The program program_to_use,
currently ei... | [
"Render",
"all",
"the",
"pages",
"of",
"the",
"PDF",
"file",
"at",
"pdf_file_name",
"to",
"image",
"files",
"with",
"path",
"and",
"filename",
"prefix",
"given",
"by",
"output_filename_root",
".",
"Any",
"directories",
"must",
"have",
"already",
"been",
"creat... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/calculate_bounding_boxes.py#L208-L237 |
13,804 | abarker/pdfCropMargins | src/pdfCropMargins/calculate_bounding_boxes.py | calculate_bounding_box_from_image | def calculate_bounding_box_from_image(im, curr_page):
"""This function uses a PIL routine to get the bounding box of the rendered
image."""
xMax, y_max = im.size
bounding_box = im.getbbox() # note this uses ltrb convention
if not bounding_box:
#print("\nWarning: could not calculate a boundin... | python | def calculate_bounding_box_from_image(im, curr_page):
"""This function uses a PIL routine to get the bounding box of the rendered
image."""
xMax, y_max = im.size
bounding_box = im.getbbox() # note this uses ltrb convention
if not bounding_box:
#print("\nWarning: could not calculate a boundin... | [
"def",
"calculate_bounding_box_from_image",
"(",
"im",
",",
"curr_page",
")",
":",
"xMax",
",",
"y_max",
"=",
"im",
".",
"size",
"bounding_box",
"=",
"im",
".",
"getbbox",
"(",
")",
"# note this uses ltrb convention",
"if",
"not",
"bounding_box",
":",
"#print(\"... | This function uses a PIL routine to get the bounding box of the rendered
image. | [
"This",
"function",
"uses",
"a",
"PIL",
"routine",
"to",
"get",
"the",
"bounding",
"box",
"of",
"the",
"rendered",
"image",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/calculate_bounding_boxes.py#L239-L270 |
13,805 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | samefile | def samefile(path1, path2):
"""Test if paths refer to the same file or directory."""
if system_os == "Linux" or system_os == "Cygwin":
return os.path.samefile(path1, path2)
return (get_canonical_absolute_expanded_path(path1) ==
get_canonical_absolute_expanded_path(path2)) | python | def samefile(path1, path2):
"""Test if paths refer to the same file or directory."""
if system_os == "Linux" or system_os == "Cygwin":
return os.path.samefile(path1, path2)
return (get_canonical_absolute_expanded_path(path1) ==
get_canonical_absolute_expanded_path(path2)) | [
"def",
"samefile",
"(",
"path1",
",",
"path2",
")",
":",
"if",
"system_os",
"==",
"\"Linux\"",
"or",
"system_os",
"==",
"\"Cygwin\"",
":",
"return",
"os",
".",
"path",
".",
"samefile",
"(",
"path1",
",",
"path2",
")",
"return",
"(",
"get_canonical_absolute... | Test if paths refer to the same file or directory. | [
"Test",
"if",
"paths",
"refer",
"to",
"the",
"same",
"file",
"or",
"directory",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L135-L140 |
13,806 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | convert_windows_path_to_cygwin | def convert_windows_path_to_cygwin(path):
"""Convert a Windows path to a Cygwin path. Just handles the basic case."""
if len(path) > 2 and path[1] == ":" and path[2] == "\\":
newpath = cygwin_full_path_prefix + "/" + path[0]
if len(path) > 3: newpath += "/" + path[3:]
path = newpath
... | python | def convert_windows_path_to_cygwin(path):
"""Convert a Windows path to a Cygwin path. Just handles the basic case."""
if len(path) > 2 and path[1] == ":" and path[2] == "\\":
newpath = cygwin_full_path_prefix + "/" + path[0]
if len(path) > 3: newpath += "/" + path[3:]
path = newpath
... | [
"def",
"convert_windows_path_to_cygwin",
"(",
"path",
")",
":",
"if",
"len",
"(",
"path",
")",
">",
"2",
"and",
"path",
"[",
"1",
"]",
"==",
"\":\"",
"and",
"path",
"[",
"2",
"]",
"==",
"\"\\\\\"",
":",
"newpath",
"=",
"cygwin_full_path_prefix",
"+",
"... | Convert a Windows path to a Cygwin path. Just handles the basic case. | [
"Convert",
"a",
"Windows",
"path",
"to",
"a",
"Cygwin",
"path",
".",
"Just",
"handles",
"the",
"basic",
"case",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L167-L174 |
13,807 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | remove_program_temp_directory | def remove_program_temp_directory():
"""Remove the global temp directory and all its contents."""
if os.path.exists(program_temp_directory):
max_retries = 3
curr_retries = 0
time_between_retries = 1
while True:
try:
shutil.rmtree(program_temp_directory... | python | def remove_program_temp_directory():
"""Remove the global temp directory and all its contents."""
if os.path.exists(program_temp_directory):
max_retries = 3
curr_retries = 0
time_between_retries = 1
while True:
try:
shutil.rmtree(program_temp_directory... | [
"def",
"remove_program_temp_directory",
"(",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"program_temp_directory",
")",
":",
"max_retries",
"=",
"3",
"curr_retries",
"=",
"0",
"time_between_retries",
"=",
"1",
"while",
"True",
":",
"try",
":",
"sh... | Remove the global temp directory and all its contents. | [
"Remove",
"the",
"global",
"temp",
"directory",
"and",
"all",
"its",
"contents",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L191-L208 |
13,808 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | call_external_subprocess | def call_external_subprocess(command_list,
stdin_filename=None, stdout_filename=None, stderr_filename=None,
env=None):
"""Run the command and arguments in the command_list. Will search the system
PATH for commands to execute, but no shell is started. Redirects any... | python | def call_external_subprocess(command_list,
stdin_filename=None, stdout_filename=None, stderr_filename=None,
env=None):
"""Run the command and arguments in the command_list. Will search the system
PATH for commands to execute, but no shell is started. Redirects any... | [
"def",
"call_external_subprocess",
"(",
"command_list",
",",
"stdin_filename",
"=",
"None",
",",
"stdout_filename",
"=",
"None",
",",
"stderr_filename",
"=",
"None",
",",
"env",
"=",
"None",
")",
":",
"if",
"stdin_filename",
":",
"stdin",
"=",
"open",
"(",
"... | Run the command and arguments in the command_list. Will search the system
PATH for commands to execute, but no shell is started. Redirects any selected
outputs to the given filename. Waits for command completion. | [
"Run",
"the",
"command",
"and",
"arguments",
"in",
"the",
"command_list",
".",
"Will",
"search",
"the",
"system",
"PATH",
"for",
"commands",
"to",
"execute",
"but",
"no",
"shell",
"is",
"started",
".",
"Redirects",
"any",
"selected",
"outputs",
"to",
"the",
... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L279-L306 |
13,809 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | run_external_subprocess_in_background | def run_external_subprocess_in_background(command_list, env=None):
"""Runs the command and arguments in the list as a background process."""
if system_os == "Windows":
DETACHED_PROCESS = 0x00000008
p = subprocess.Popen(command_list, shell=False, stdin=None, stdout=None,
stderr=No... | python | def run_external_subprocess_in_background(command_list, env=None):
"""Runs the command and arguments in the list as a background process."""
if system_os == "Windows":
DETACHED_PROCESS = 0x00000008
p = subprocess.Popen(command_list, shell=False, stdin=None, stdout=None,
stderr=No... | [
"def",
"run_external_subprocess_in_background",
"(",
"command_list",
",",
"env",
"=",
"None",
")",
":",
"if",
"system_os",
"==",
"\"Windows\"",
":",
"DETACHED_PROCESS",
"=",
"0x00000008",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"command_list",
",",
"shell",
"... | Runs the command and arguments in the list as a background process. | [
"Runs",
"the",
"command",
"and",
"arguments",
"in",
"the",
"list",
"as",
"a",
"background",
"process",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L308-L317 |
13,810 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | function_call_with_timeout | def function_call_with_timeout(fun_name, fun_args, secs=5):
"""Run a Python function with a timeout. No interprocess communication or
return values are handled. Setting secs to 0 gives infinite timeout."""
from multiprocessing import Process, Queue
p = Process(target=fun_name, args=tuple(fun_args))
... | python | def function_call_with_timeout(fun_name, fun_args, secs=5):
"""Run a Python function with a timeout. No interprocess communication or
return values are handled. Setting secs to 0 gives infinite timeout."""
from multiprocessing import Process, Queue
p = Process(target=fun_name, args=tuple(fun_args))
... | [
"def",
"function_call_with_timeout",
"(",
"fun_name",
",",
"fun_args",
",",
"secs",
"=",
"5",
")",
":",
"from",
"multiprocessing",
"import",
"Process",
",",
"Queue",
"p",
"=",
"Process",
"(",
"target",
"=",
"fun_name",
",",
"args",
"=",
"tuple",
"(",
"fun_... | Run a Python function with a timeout. No interprocess communication or
return values are handled. Setting secs to 0 gives infinite timeout. | [
"Run",
"a",
"Python",
"function",
"with",
"a",
"timeout",
".",
"No",
"interprocess",
"communication",
"or",
"return",
"values",
"are",
"handled",
".",
"Setting",
"secs",
"to",
"0",
"gives",
"infinite",
"timeout",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L331-L349 |
13,811 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | fix_pdf_with_ghostscript_to_tmp_file | def fix_pdf_with_ghostscript_to_tmp_file(input_doc_fname):
"""Attempt to fix a bad PDF file with a Ghostscript command, writing the output
PDF to a temporary file and returning the filename. Caller is responsible for
deleting the file."""
if not gs_executable: init_and_test_gs_executable(exit_on_fail=... | python | def fix_pdf_with_ghostscript_to_tmp_file(input_doc_fname):
"""Attempt to fix a bad PDF file with a Ghostscript command, writing the output
PDF to a temporary file and returning the filename. Caller is responsible for
deleting the file."""
if not gs_executable: init_and_test_gs_executable(exit_on_fail=... | [
"def",
"fix_pdf_with_ghostscript_to_tmp_file",
"(",
"input_doc_fname",
")",
":",
"if",
"not",
"gs_executable",
":",
"init_and_test_gs_executable",
"(",
"exit_on_fail",
"=",
"True",
")",
"temp_file_name",
"=",
"get_temporary_filename",
"(",
"extension",
"=",
"\".pdf\"",
... | Attempt to fix a bad PDF file with a Ghostscript command, writing the output
PDF to a temporary file and returning the filename. Caller is responsible for
deleting the file. | [
"Attempt",
"to",
"fix",
"a",
"bad",
"PDF",
"file",
"with",
"a",
"Ghostscript",
"command",
"writing",
"the",
"output",
"PDF",
"to",
"a",
"temporary",
"file",
"and",
"returning",
"the",
"filename",
".",
"Caller",
"is",
"responsible",
"for",
"deleting",
"the",
... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L532-L554 |
13,812 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | get_bounding_box_list_ghostscript | def get_bounding_box_list_ghostscript(input_doc_fname, res_x, res_y, full_page_box):
"""Call Ghostscript to get the bounding box list. Cannot set a threshold
with this method."""
if not gs_executable: init_and_test_gs_executable(exit_on_fail=True)
res = str(res_x) + "x" + str(res_y)
box_arg = "-dU... | python | def get_bounding_box_list_ghostscript(input_doc_fname, res_x, res_y, full_page_box):
"""Call Ghostscript to get the bounding box list. Cannot set a threshold
with this method."""
if not gs_executable: init_and_test_gs_executable(exit_on_fail=True)
res = str(res_x) + "x" + str(res_y)
box_arg = "-dU... | [
"def",
"get_bounding_box_list_ghostscript",
"(",
"input_doc_fname",
",",
"res_x",
",",
"res_y",
",",
"full_page_box",
")",
":",
"if",
"not",
"gs_executable",
":",
"init_and_test_gs_executable",
"(",
"exit_on_fail",
"=",
"True",
")",
"res",
"=",
"str",
"(",
"res_x"... | Call Ghostscript to get the bounding box list. Cannot set a threshold
with this method. | [
"Call",
"Ghostscript",
"to",
"get",
"the",
"bounding",
"box",
"list",
".",
"Cannot",
"set",
"a",
"threshold",
"with",
"this",
"method",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L556-L602 |
13,813 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | render_pdf_file_to_image_files_pdftoppm_ppm | def render_pdf_file_to_image_files_pdftoppm_ppm(pdf_file_name, root_output_file_path,
res_x=150, res_y=150, extra_args=None):
"""Use the pdftoppm program to render a PDF file to .png images. The
root_output_file_path is prepended to all the output files, which have nu... | python | def render_pdf_file_to_image_files_pdftoppm_ppm(pdf_file_name, root_output_file_path,
res_x=150, res_y=150, extra_args=None):
"""Use the pdftoppm program to render a PDF file to .png images. The
root_output_file_path is prepended to all the output files, which have nu... | [
"def",
"render_pdf_file_to_image_files_pdftoppm_ppm",
"(",
"pdf_file_name",
",",
"root_output_file_path",
",",
"res_x",
"=",
"150",
",",
"res_y",
"=",
"150",
",",
"extra_args",
"=",
"None",
")",
":",
"if",
"extra_args",
"is",
"None",
":",
"extra_args",
"=",
"[",... | Use the pdftoppm program to render a PDF file to .png images. The
root_output_file_path is prepended to all the output files, which have numbers
and extensions added. Extra arguments can be passed as a list in extra_args.
Return the command output. | [
"Use",
"the",
"pdftoppm",
"program",
"to",
"render",
"a",
"PDF",
"file",
"to",
".",
"png",
"images",
".",
"The",
"root_output_file_path",
"is",
"prepended",
"to",
"all",
"the",
"output",
"files",
"which",
"have",
"numbers",
"and",
"extensions",
"added",
".",... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L604-L624 |
13,814 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | render_pdf_file_to_image_files_pdftoppm_pgm | def render_pdf_file_to_image_files_pdftoppm_pgm(pdf_file_name, root_output_file_path,
res_x=150, res_y=150):
"""Same as renderPdfFileToImageFile_pdftoppm_ppm but with -gray option for pgm."""
comm_output = render_pdf_file_to_image_files_pdftoppm_ppm(pdf_file_name,
... | python | def render_pdf_file_to_image_files_pdftoppm_pgm(pdf_file_name, root_output_file_path,
res_x=150, res_y=150):
"""Same as renderPdfFileToImageFile_pdftoppm_ppm but with -gray option for pgm."""
comm_output = render_pdf_file_to_image_files_pdftoppm_ppm(pdf_file_name,
... | [
"def",
"render_pdf_file_to_image_files_pdftoppm_pgm",
"(",
"pdf_file_name",
",",
"root_output_file_path",
",",
"res_x",
"=",
"150",
",",
"res_y",
"=",
"150",
")",
":",
"comm_output",
"=",
"render_pdf_file_to_image_files_pdftoppm_ppm",
"(",
"pdf_file_name",
",",
"root_outp... | Same as renderPdfFileToImageFile_pdftoppm_ppm but with -gray option for pgm. | [
"Same",
"as",
"renderPdfFileToImageFile_pdftoppm_ppm",
"but",
"with",
"-",
"gray",
"option",
"for",
"pgm",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L626-L632 |
13,815 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | render_pdf_file_to_image_files__ghostscript_png | def render_pdf_file_to_image_files__ghostscript_png(pdf_file_name,
root_output_file_path,
res_x=150, res_y=150):
"""Use Ghostscript to render a PDF file to .png images. The root_output_file_path
is prepended... | python | def render_pdf_file_to_image_files__ghostscript_png(pdf_file_name,
root_output_file_path,
res_x=150, res_y=150):
"""Use Ghostscript to render a PDF file to .png images. The root_output_file_path
is prepended... | [
"def",
"render_pdf_file_to_image_files__ghostscript_png",
"(",
"pdf_file_name",
",",
"root_output_file_path",
",",
"res_x",
"=",
"150",
",",
"res_y",
"=",
"150",
")",
":",
"# For gs commands see",
"# http://ghostscript.com/doc/current/Devices.htm#File_formats",
"# http://ghostscr... | Use Ghostscript to render a PDF file to .png images. The root_output_file_path
is prepended to all the output files, which have numbers and extensions added.
Return the command output. | [
"Use",
"Ghostscript",
"to",
"render",
"a",
"PDF",
"file",
"to",
".",
"png",
"images",
".",
"The",
"root_output_file_path",
"is",
"prepended",
"to",
"all",
"the",
"output",
"files",
"which",
"have",
"numbers",
"and",
"extensions",
"added",
".",
"Return",
"the... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L634-L648 |
13,816 | abarker/pdfCropMargins | src/pdfCropMargins/external_program_calls.py | show_preview | def show_preview(viewer_path, pdf_file_name):
"""Run the PDF viewer at the path viewer_path on the file pdf_file_name."""
try:
cmd = [viewer_path, pdf_file_name]
run_external_subprocess_in_background(cmd)
except (subprocess.CalledProcessError, OSError, IOError) as e:
print("\nWarning... | python | def show_preview(viewer_path, pdf_file_name):
"""Run the PDF viewer at the path viewer_path on the file pdf_file_name."""
try:
cmd = [viewer_path, pdf_file_name]
run_external_subprocess_in_background(cmd)
except (subprocess.CalledProcessError, OSError, IOError) as e:
print("\nWarning... | [
"def",
"show_preview",
"(",
"viewer_path",
",",
"pdf_file_name",
")",
":",
"try",
":",
"cmd",
"=",
"[",
"viewer_path",
",",
"pdf_file_name",
"]",
"run_external_subprocess_in_background",
"(",
"cmd",
")",
"except",
"(",
"subprocess",
".",
"CalledProcessError",
",",... | Run the PDF viewer at the path viewer_path on the file pdf_file_name. | [
"Run",
"the",
"PDF",
"viewer",
"at",
"the",
"path",
"viewer_path",
"on",
"the",
"file",
"pdf_file_name",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/external_program_calls.py#L673-L682 |
13,817 | abarker/pdfCropMargins | src/pdfCropMargins/pdfCropMargins.py | main | def main():
"""Run main, catching any exceptions and cleaning up the temp directories."""
cleanup_and_exit = sys.exit # Function to do cleanup and exit before the import.
exit_code = 0
# Imports are done here inside the try block so some ugly (and useless)
# traceback info is avoided on user's ^C ... | python | def main():
"""Run main, catching any exceptions and cleaning up the temp directories."""
cleanup_and_exit = sys.exit # Function to do cleanup and exit before the import.
exit_code = 0
# Imports are done here inside the try block so some ugly (and useless)
# traceback info is avoided on user's ^C ... | [
"def",
"main",
"(",
")",
":",
"cleanup_and_exit",
"=",
"sys",
".",
"exit",
"# Function to do cleanup and exit before the import.",
"exit_code",
"=",
"0",
"# Imports are done here inside the try block so some ugly (and useless)",
"# traceback info is avoided on user's ^C (KeyboardInterr... | Run main, catching any exceptions and cleaning up the temp directories. | [
"Run",
"main",
"catching",
"any",
"exceptions",
"and",
"cleaning",
"up",
"the",
"temp",
"directories",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/pdfCropMargins.py#L70-L113 |
13,818 | abarker/pdfCropMargins | src/pdfCropMargins/main_pdfCropMargins.py | get_full_page_box_list_assigning_media_and_crop | def get_full_page_box_list_assigning_media_and_crop(input_doc, quiet=False):
"""Get a list of all the full-page box values for each page. The argument
input_doc should be a PdfFileReader object. The boxes on the list are in the
simple 4-float list format used by this program, not RectangleObject format.""... | python | def get_full_page_box_list_assigning_media_and_crop(input_doc, quiet=False):
"""Get a list of all the full-page box values for each page. The argument
input_doc should be a PdfFileReader object. The boxes on the list are in the
simple 4-float list format used by this program, not RectangleObject format.""... | [
"def",
"get_full_page_box_list_assigning_media_and_crop",
"(",
"input_doc",
",",
"quiet",
"=",
"False",
")",
":",
"full_page_box_list",
"=",
"[",
"]",
"rotation_list",
"=",
"[",
"]",
"if",
"args",
".",
"verbose",
"and",
"not",
"quiet",
":",
"print",
"(",
"\"\\... | Get a list of all the full-page box values for each page. The argument
input_doc should be a PdfFileReader object. The boxes on the list are in the
simple 4-float list format used by this program, not RectangleObject format. | [
"Get",
"a",
"list",
"of",
"all",
"the",
"full",
"-",
"page",
"box",
"values",
"for",
"each",
"page",
".",
"The",
"argument",
"input_doc",
"should",
"be",
"a",
"PdfFileReader",
"object",
".",
"The",
"boxes",
"on",
"the",
"list",
"are",
"in",
"the",
"sim... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/main_pdfCropMargins.py#L207-L236 |
13,819 | abarker/pdfCropMargins | src/pdfCropMargins/main_pdfCropMargins.py | set_cropped_metadata | def set_cropped_metadata(input_doc, output_doc, metadata_info):
"""Set the metadata for the output document. Mostly just copied over, but
"Producer" has a string appended to indicate that this program modified the
file. That allows for the undo operation to make sure that this
program cropped the file... | python | def set_cropped_metadata(input_doc, output_doc, metadata_info):
"""Set the metadata for the output document. Mostly just copied over, but
"Producer" has a string appended to indicate that this program modified the
file. That allows for the undo operation to make sure that this
program cropped the file... | [
"def",
"set_cropped_metadata",
"(",
"input_doc",
",",
"output_doc",
",",
"metadata_info",
")",
":",
"# Setting metadata with pyPdf requires low-level pyPdf operations, see",
"# http://stackoverflow.com/questions/2574676/change-metadata-of-pdf-file-with-pypdf",
"if",
"not",
"metadata_info... | Set the metadata for the output document. Mostly just copied over, but
"Producer" has a string appended to indicate that this program modified the
file. That allows for the undo operation to make sure that this
program cropped the file in the first place. | [
"Set",
"the",
"metadata",
"for",
"the",
"output",
"document",
".",
"Mostly",
"just",
"copied",
"over",
"but",
"Producer",
"has",
"a",
"string",
"appended",
"to",
"indicate",
"that",
"this",
"program",
"modified",
"the",
"file",
".",
"That",
"allows",
"for",
... | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/main_pdfCropMargins.py#L448-L494 |
13,820 | abarker/pdfCropMargins | src/pdfCropMargins/main_pdfCropMargins.py | apply_crop_list | def apply_crop_list(crop_list, input_doc, page_nums_to_crop,
already_cropped_by_this_program):
"""Apply the crop list to the pages of the input PdfFileReader object."""
if args.restore and not already_cropped_by_this_program:
print("\nWarning from pdfCropMargin... | python | def apply_crop_list(crop_list, input_doc, page_nums_to_crop,
already_cropped_by_this_program):
"""Apply the crop list to the pages of the input PdfFileReader object."""
if args.restore and not already_cropped_by_this_program:
print("\nWarning from pdfCropMargin... | [
"def",
"apply_crop_list",
"(",
"crop_list",
",",
"input_doc",
",",
"page_nums_to_crop",
",",
"already_cropped_by_this_program",
")",
":",
"if",
"args",
".",
"restore",
"and",
"not",
"already_cropped_by_this_program",
":",
"print",
"(",
"\"\\nWarning from pdfCropMargins: T... | Apply the crop list to the pages of the input PdfFileReader object. | [
"Apply",
"the",
"crop",
"list",
"to",
"the",
"pages",
"of",
"the",
"input",
"PdfFileReader",
"object",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/main_pdfCropMargins.py#L497-L562 |
13,821 | abarker/pdfCropMargins | src/pdfCropMargins/main_pdfCropMargins.py | setup_output_document | def setup_output_document(input_doc, tmp_input_doc, metadata_info,
copy_document_catalog=True):
"""Create the output `PdfFileWriter` objects and copy over the relevant info."""
# NOTE: Inserting pages from a PdfFileReader into multiple PdfFileWriters
# see... | python | def setup_output_document(input_doc, tmp_input_doc, metadata_info,
copy_document_catalog=True):
"""Create the output `PdfFileWriter` objects and copy over the relevant info."""
# NOTE: Inserting pages from a PdfFileReader into multiple PdfFileWriters
# see... | [
"def",
"setup_output_document",
"(",
"input_doc",
",",
"tmp_input_doc",
",",
"metadata_info",
",",
"copy_document_catalog",
"=",
"True",
")",
":",
"# NOTE: Inserting pages from a PdfFileReader into multiple PdfFileWriters",
"# seems to cause problems (writer can hang on write), so only... | Create the output `PdfFileWriter` objects and copy over the relevant info. | [
"Create",
"the",
"output",
"PdfFileWriter",
"objects",
"and",
"copy",
"over",
"the",
"relevant",
"info",
"."
] | 55aca874613750ebf4ae69fd8851bdbb7696d6ac | https://github.com/abarker/pdfCropMargins/blob/55aca874613750ebf4ae69fd8851bdbb7696d6ac/src/pdfCropMargins/main_pdfCropMargins.py#L564-L689 |
13,822 | miracle2k/flask-assets | src/flask_assets.py | FlaskConfigStorage.setdefault | def setdefault(self, key, value):
"""We may not always be connected to an app, but we still need
to provide a way to the base environment to set it's defaults.
"""
try:
super(FlaskConfigStorage, self).setdefault(key, value)
except RuntimeError:
self._defau... | python | def setdefault(self, key, value):
"""We may not always be connected to an app, but we still need
to provide a way to the base environment to set it's defaults.
"""
try:
super(FlaskConfigStorage, self).setdefault(key, value)
except RuntimeError:
self._defau... | [
"def",
"setdefault",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"try",
":",
"super",
"(",
"FlaskConfigStorage",
",",
"self",
")",
".",
"setdefault",
"(",
"key",
",",
"value",
")",
"except",
"RuntimeError",
":",
"self",
".",
"_defaults",
".",
"__s... | We may not always be connected to an app, but we still need
to provide a way to the base environment to set it's defaults. | [
"We",
"may",
"not",
"always",
"be",
"connected",
"to",
"an",
"app",
"but",
"we",
"still",
"need",
"to",
"provide",
"a",
"way",
"to",
"the",
"base",
"environment",
"to",
"set",
"it",
"s",
"defaults",
"."
] | ea9ff985bc96b79edb12ad4bed69403173f75562 | https://github.com/miracle2k/flask-assets/blob/ea9ff985bc96b79edb12ad4bed69403173f75562/src/flask_assets.py#L75-L82 |
13,823 | miracle2k/flask-assets | src/flask_assets.py | Environment._app | def _app(self):
"""The application object to work with; this is either the app
that we have been bound to, or the current application.
"""
if self.app is not None:
return self.app
ctx = _request_ctx_stack.top
if ctx is not None:
return ctx.app
... | python | def _app(self):
"""The application object to work with; this is either the app
that we have been bound to, or the current application.
"""
if self.app is not None:
return self.app
ctx = _request_ctx_stack.top
if ctx is not None:
return ctx.app
... | [
"def",
"_app",
"(",
"self",
")",
":",
"if",
"self",
".",
"app",
"is",
"not",
"None",
":",
"return",
"self",
".",
"app",
"ctx",
"=",
"_request_ctx_stack",
".",
"top",
"if",
"ctx",
"is",
"not",
"None",
":",
"return",
"ctx",
".",
"app",
"try",
":",
... | The application object to work with; this is either the app
that we have been bound to, or the current application. | [
"The",
"application",
"object",
"to",
"work",
"with",
";",
"this",
"is",
"either",
"the",
"app",
"that",
"we",
"have",
"been",
"bound",
"to",
"or",
"the",
"current",
"application",
"."
] | ea9ff985bc96b79edb12ad4bed69403173f75562 | https://github.com/miracle2k/flask-assets/blob/ea9ff985bc96b79edb12ad4bed69403173f75562/src/flask_assets.py#L310-L330 |
13,824 | miracle2k/flask-assets | src/flask_assets.py | Environment.from_yaml | def from_yaml(self, path):
"""Register bundles from a YAML configuration file"""
bundles = YAMLLoader(path).load_bundles()
for name in bundles:
self.register(name, bundles[name]) | python | def from_yaml(self, path):
"""Register bundles from a YAML configuration file"""
bundles = YAMLLoader(path).load_bundles()
for name in bundles:
self.register(name, bundles[name]) | [
"def",
"from_yaml",
"(",
"self",
",",
"path",
")",
":",
"bundles",
"=",
"YAMLLoader",
"(",
"path",
")",
".",
"load_bundles",
"(",
")",
"for",
"name",
"in",
"bundles",
":",
"self",
".",
"register",
"(",
"name",
",",
"bundles",
"[",
"name",
"]",
")"
] | Register bundles from a YAML configuration file | [
"Register",
"bundles",
"from",
"a",
"YAML",
"configuration",
"file"
] | ea9ff985bc96b79edb12ad4bed69403173f75562 | https://github.com/miracle2k/flask-assets/blob/ea9ff985bc96b79edb12ad4bed69403173f75562/src/flask_assets.py#L361-L365 |
13,825 | miracle2k/flask-assets | src/flask_assets.py | Environment.from_module | def from_module(self, path):
"""Register bundles from a Python module"""
bundles = PythonLoader(path).load_bundles()
for name in bundles:
self.register(name, bundles[name]) | python | def from_module(self, path):
"""Register bundles from a Python module"""
bundles = PythonLoader(path).load_bundles()
for name in bundles:
self.register(name, bundles[name]) | [
"def",
"from_module",
"(",
"self",
",",
"path",
")",
":",
"bundles",
"=",
"PythonLoader",
"(",
"path",
")",
".",
"load_bundles",
"(",
")",
"for",
"name",
"in",
"bundles",
":",
"self",
".",
"register",
"(",
"name",
",",
"bundles",
"[",
"name",
"]",
")... | Register bundles from a Python module | [
"Register",
"bundles",
"from",
"a",
"Python",
"module"
] | ea9ff985bc96b79edb12ad4bed69403173f75562 | https://github.com/miracle2k/flask-assets/blob/ea9ff985bc96b79edb12ad4bed69403173f75562/src/flask_assets.py#L367-L371 |
13,826 | persephone-tools/persephone | persephone/__init__.py | handle_unhandled_exception | def handle_unhandled_exception(exc_type, exc_value, exc_traceback):
"""Handler for unhandled exceptions that will write to the logs"""
if issubclass(exc_type, KeyboardInterrupt):
# call the default excepthook saved at __excepthook__
sys.__excepthook__(exc_type, exc_value, exc_traceback)
... | python | def handle_unhandled_exception(exc_type, exc_value, exc_traceback):
"""Handler for unhandled exceptions that will write to the logs"""
if issubclass(exc_type, KeyboardInterrupt):
# call the default excepthook saved at __excepthook__
sys.__excepthook__(exc_type, exc_value, exc_traceback)
... | [
"def",
"handle_unhandled_exception",
"(",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
")",
":",
"if",
"issubclass",
"(",
"exc_type",
",",
"KeyboardInterrupt",
")",
":",
"# call the default excepthook saved at __excepthook__",
"sys",
".",
"__excepthook__",
"(",
"... | Handler for unhandled exceptions that will write to the logs | [
"Handler",
"for",
"unhandled",
"exceptions",
"that",
"will",
"write",
"to",
"the",
"logs"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/__init__.py#L6-L13 |
13,827 | persephone-tools/persephone | persephone/utterance.py | write_transcriptions | def write_transcriptions(utterances: List[Utterance],
tgt_dir: Path, ext: str, lazy: bool) -> None:
""" Write the utterance transcriptions to files in the tgt_dir. Is lazy and
checks if the file already exists.
Args:
utterances: A list of Utterance objects to be written.
... | python | def write_transcriptions(utterances: List[Utterance],
tgt_dir: Path, ext: str, lazy: bool) -> None:
""" Write the utterance transcriptions to files in the tgt_dir. Is lazy and
checks if the file already exists.
Args:
utterances: A list of Utterance objects to be written.
... | [
"def",
"write_transcriptions",
"(",
"utterances",
":",
"List",
"[",
"Utterance",
"]",
",",
"tgt_dir",
":",
"Path",
",",
"ext",
":",
"str",
",",
"lazy",
":",
"bool",
")",
"->",
"None",
":",
"tgt_dir",
".",
"mkdir",
"(",
"parents",
"=",
"True",
",",
"e... | Write the utterance transcriptions to files in the tgt_dir. Is lazy and
checks if the file already exists.
Args:
utterances: A list of Utterance objects to be written.
tgt_dir: The directory in which to write the text of the utterances,
one file per utterance.
ext: The file ... | [
"Write",
"the",
"utterance",
"transcriptions",
"to",
"files",
"in",
"the",
"tgt_dir",
".",
"Is",
"lazy",
"and",
"checks",
"if",
"the",
"file",
"already",
"exists",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utterance.py#L45-L65 |
13,828 | persephone-tools/persephone | persephone/utterance.py | remove_duplicates | def remove_duplicates(utterances: List[Utterance]) -> List[Utterance]:
""" Removes utterances with the same start_time, end_time and text. Other
metadata isn't considered.
"""
filtered_utters = []
utter_set = set() # type: Set[Tuple[int, int, str]]
for utter in utterances:
if (utter.sta... | python | def remove_duplicates(utterances: List[Utterance]) -> List[Utterance]:
""" Removes utterances with the same start_time, end_time and text. Other
metadata isn't considered.
"""
filtered_utters = []
utter_set = set() # type: Set[Tuple[int, int, str]]
for utter in utterances:
if (utter.sta... | [
"def",
"remove_duplicates",
"(",
"utterances",
":",
"List",
"[",
"Utterance",
"]",
")",
"->",
"List",
"[",
"Utterance",
"]",
":",
"filtered_utters",
"=",
"[",
"]",
"utter_set",
"=",
"set",
"(",
")",
"# type: Set[Tuple[int, int, str]]",
"for",
"utter",
"in",
... | Removes utterances with the same start_time, end_time and text. Other
metadata isn't considered. | [
"Removes",
"utterances",
"with",
"the",
"same",
"start_time",
"end_time",
"and",
"text",
".",
"Other",
"metadata",
"isn",
"t",
"considered",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utterance.py#L67-L80 |
13,829 | persephone-tools/persephone | persephone/utterance.py | make_speaker_utters | def make_speaker_utters(utterances: List[Utterance]) -> Dict[str, List[Utterance]]:
""" Creates a dictionary mapping from speakers to their utterances. """
speaker_utters = defaultdict(list) # type: DefaultDict[str, List[Utterance]]
for utter in utterances:
speaker_utters[utter.speaker].append(utte... | python | def make_speaker_utters(utterances: List[Utterance]) -> Dict[str, List[Utterance]]:
""" Creates a dictionary mapping from speakers to their utterances. """
speaker_utters = defaultdict(list) # type: DefaultDict[str, List[Utterance]]
for utter in utterances:
speaker_utters[utter.speaker].append(utte... | [
"def",
"make_speaker_utters",
"(",
"utterances",
":",
"List",
"[",
"Utterance",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"List",
"[",
"Utterance",
"]",
"]",
":",
"speaker_utters",
"=",
"defaultdict",
"(",
"list",
")",
"# type: DefaultDict[str, List[Utterance]]",... | Creates a dictionary mapping from speakers to their utterances. | [
"Creates",
"a",
"dictionary",
"mapping",
"from",
"speakers",
"to",
"their",
"utterances",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utterance.py#L106-L113 |
13,830 | persephone-tools/persephone | persephone/utterance.py | remove_too_short | def remove_too_short(utterances: List[Utterance],
_winlen=25, winstep=10) -> List[Utterance]:
""" Removes utterances that will probably have issues with CTC because of
the number of frames being less than the number of tokens in the
transcription. Assuming char tokenization to minimize ... | python | def remove_too_short(utterances: List[Utterance],
_winlen=25, winstep=10) -> List[Utterance]:
""" Removes utterances that will probably have issues with CTC because of
the number of frames being less than the number of tokens in the
transcription. Assuming char tokenization to minimize ... | [
"def",
"remove_too_short",
"(",
"utterances",
":",
"List",
"[",
"Utterance",
"]",
",",
"_winlen",
"=",
"25",
",",
"winstep",
"=",
"10",
")",
"->",
"List",
"[",
"Utterance",
"]",
":",
"def",
"is_too_short",
"(",
"utterance",
":",
"Utterance",
")",
"->",
... | Removes utterances that will probably have issues with CTC because of
the number of frames being less than the number of tokens in the
transcription. Assuming char tokenization to minimize false negatives. | [
"Removes",
"utterances",
"that",
"will",
"probably",
"have",
"issues",
"with",
"CTC",
"because",
"of",
"the",
"number",
"of",
"frames",
"being",
"less",
"than",
"the",
"number",
"of",
"tokens",
"in",
"the",
"transcription",
".",
"Assuming",
"char",
"tokenizati... | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utterance.py#L128-L141 |
13,831 | persephone-tools/persephone | persephone/distance.py | min_edit_distance | def min_edit_distance(
source: Sequence[T], target: Sequence[T],
ins_cost: Callable[..., int] = lambda _x: 1,
del_cost: Callable[..., int] = lambda _x: 1,
sub_cost: Callable[..., int] = lambda x, y: 0 if x == y else 1) -> int:
"""Calculates the minimum edit distance between two seque... | python | def min_edit_distance(
source: Sequence[T], target: Sequence[T],
ins_cost: Callable[..., int] = lambda _x: 1,
del_cost: Callable[..., int] = lambda _x: 1,
sub_cost: Callable[..., int] = lambda x, y: 0 if x == y else 1) -> int:
"""Calculates the minimum edit distance between two seque... | [
"def",
"min_edit_distance",
"(",
"source",
":",
"Sequence",
"[",
"T",
"]",
",",
"target",
":",
"Sequence",
"[",
"T",
"]",
",",
"ins_cost",
":",
"Callable",
"[",
"...",
",",
"int",
"]",
"=",
"lambda",
"_x",
":",
"1",
",",
"del_cost",
":",
"Callable",
... | Calculates the minimum edit distance between two sequences.
Uses the Levenshtein weighting as a default, but offers keyword arguments
to supply functions to measure the costs for editing with different
elements.
Args:
ins_cost: A function describing the cost of inserting a given char
d... | [
"Calculates",
"the",
"minimum",
"edit",
"distance",
"between",
"two",
"sequences",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/distance.py#L9-L51 |
13,832 | persephone-tools/persephone | persephone/distance.py | word_error_rate | def word_error_rate(ref: Sequence[T], hyp: Sequence[T]) -> float:
""" Calculate the word error rate of a sequence against a reference.
Args:
ref: The gold-standard reference sequence
hyp: The hypothesis to be evaluated against the reference.
Returns:
The word error rate of the supp... | python | def word_error_rate(ref: Sequence[T], hyp: Sequence[T]) -> float:
""" Calculate the word error rate of a sequence against a reference.
Args:
ref: The gold-standard reference sequence
hyp: The hypothesis to be evaluated against the reference.
Returns:
The word error rate of the supp... | [
"def",
"word_error_rate",
"(",
"ref",
":",
"Sequence",
"[",
"T",
"]",
",",
"hyp",
":",
"Sequence",
"[",
"T",
"]",
")",
"->",
"float",
":",
"if",
"len",
"(",
"ref",
")",
"==",
"0",
":",
"raise",
"EmptyReferenceException",
"(",
"\"Cannot calculating word e... | Calculate the word error rate of a sequence against a reference.
Args:
ref: The gold-standard reference sequence
hyp: The hypothesis to be evaluated against the reference.
Returns:
The word error rate of the supplied hypothesis with respect to the
reference string.
Raises:... | [
"Calculate",
"the",
"word",
"error",
"rate",
"of",
"a",
"sequence",
"against",
"a",
"reference",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/distance.py#L178-L200 |
13,833 | persephone-tools/persephone | persephone/model.py | dense_to_human_readable | def dense_to_human_readable(dense_repr: Sequence[Sequence[int]], index_to_label: Dict[int, str]) -> List[List[str]]:
""" Converts a dense representation of model decoded output into human
readable, using a mapping from indices to labels. """
transcripts = []
for dense_r in dense_repr:
non_empty... | python | def dense_to_human_readable(dense_repr: Sequence[Sequence[int]], index_to_label: Dict[int, str]) -> List[List[str]]:
""" Converts a dense representation of model decoded output into human
readable, using a mapping from indices to labels. """
transcripts = []
for dense_r in dense_repr:
non_empty... | [
"def",
"dense_to_human_readable",
"(",
"dense_repr",
":",
"Sequence",
"[",
"Sequence",
"[",
"int",
"]",
"]",
",",
"index_to_label",
":",
"Dict",
"[",
"int",
",",
"str",
"]",
")",
"->",
"List",
"[",
"List",
"[",
"str",
"]",
"]",
":",
"transcripts",
"=",... | Converts a dense representation of model decoded output into human
readable, using a mapping from indices to labels. | [
"Converts",
"a",
"dense",
"representation",
"of",
"model",
"decoded",
"output",
"into",
"human",
"readable",
"using",
"a",
"mapping",
"from",
"indices",
"to",
"labels",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/model.py#L36-L46 |
13,834 | persephone-tools/persephone | persephone/model.py | decode | def decode(model_path_prefix: Union[str, Path],
input_paths: Sequence[Path],
label_set: Set[str],
*,
feature_type: str = "fbank", #TODO Make this None and infer feature_type from dimension of NN input layer.
batch_size: int = 64,
feat_dir: Optional[Path]... | python | def decode(model_path_prefix: Union[str, Path],
input_paths: Sequence[Path],
label_set: Set[str],
*,
feature_type: str = "fbank", #TODO Make this None and infer feature_type from dimension of NN input layer.
batch_size: int = 64,
feat_dir: Optional[Path]... | [
"def",
"decode",
"(",
"model_path_prefix",
":",
"Union",
"[",
"str",
",",
"Path",
"]",
",",
"input_paths",
":",
"Sequence",
"[",
"Path",
"]",
",",
"label_set",
":",
"Set",
"[",
"str",
"]",
",",
"*",
",",
"feature_type",
":",
"str",
"=",
"\"fbank\"",
... | Use an existing tensorflow model that exists on disk to decode
WAV files.
Args:
model_path_prefix: The path to the saved tensorflow model.
This is the full prefix to the ".ckpt" file.
input_paths: A sequence of `pathlib.Path`s to WAV files to put through
... | [
"Use",
"an",
"existing",
"tensorflow",
"model",
"that",
"exists",
"on",
"disk",
"to",
"decode",
"WAV",
"files",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/model.py#L68-L153 |
13,835 | persephone-tools/persephone | persephone/model.py | Model.eval | def eval(self, restore_model_path: Optional[str]=None) -> None:
""" Evaluates the model on a test set."""
saver = tf.train.Saver()
with tf.Session(config=allow_growth_config) as sess:
if restore_model_path:
logger.info("restoring model from %s", restore_model_path)
... | python | def eval(self, restore_model_path: Optional[str]=None) -> None:
""" Evaluates the model on a test set."""
saver = tf.train.Saver()
with tf.Session(config=allow_growth_config) as sess:
if restore_model_path:
logger.info("restoring model from %s", restore_model_path)
... | [
"def",
"eval",
"(",
"self",
",",
"restore_model_path",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"saver",
"=",
"tf",
".",
"train",
".",
"Saver",
"(",
")",
"with",
"tf",
".",
"Session",
"(",
"config",
"=",
"allow_growth_co... | Evaluates the model on a test set. | [
"Evaluates",
"the",
"model",
"on",
"a",
"test",
"set",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/model.py#L258-L299 |
13,836 | persephone-tools/persephone | persephone/model.py | Model.output_best_scores | def output_best_scores(self, best_epoch_str: str) -> None:
"""Output best scores to the filesystem"""
BEST_SCORES_FILENAME = "best_scores.txt"
with open(os.path.join(self.exp_dir, BEST_SCORES_FILENAME),
"w", encoding=ENCODING) as best_f:
print(best_epoch_str, file=b... | python | def output_best_scores(self, best_epoch_str: str) -> None:
"""Output best scores to the filesystem"""
BEST_SCORES_FILENAME = "best_scores.txt"
with open(os.path.join(self.exp_dir, BEST_SCORES_FILENAME),
"w", encoding=ENCODING) as best_f:
print(best_epoch_str, file=b... | [
"def",
"output_best_scores",
"(",
"self",
",",
"best_epoch_str",
":",
"str",
")",
"->",
"None",
":",
"BEST_SCORES_FILENAME",
"=",
"\"best_scores.txt\"",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"exp_dir",
",",
"BEST_SCORES_FILENAM... | Output best scores to the filesystem | [
"Output",
"best",
"scores",
"to",
"the",
"filesystem"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/model.py#L301-L306 |
13,837 | persephone-tools/persephone | persephone/corpus.py | ensure_no_set_overlap | def ensure_no_set_overlap(train: Sequence[str], valid: Sequence[str], test: Sequence[str]) -> None:
""" Ensures no test set data has creeped into the training set."""
logger.debug("Ensuring that the training, validation and test data sets have no overlap")
train_s = set(train)
valid_s = set(valid)
... | python | def ensure_no_set_overlap(train: Sequence[str], valid: Sequence[str], test: Sequence[str]) -> None:
""" Ensures no test set data has creeped into the training set."""
logger.debug("Ensuring that the training, validation and test data sets have no overlap")
train_s = set(train)
valid_s = set(valid)
... | [
"def",
"ensure_no_set_overlap",
"(",
"train",
":",
"Sequence",
"[",
"str",
"]",
",",
"valid",
":",
"Sequence",
"[",
"str",
"]",
",",
"test",
":",
"Sequence",
"[",
"str",
"]",
")",
"->",
"None",
":",
"logger",
".",
"debug",
"(",
"\"Ensuring that the train... | Ensures no test set data has creeped into the training set. | [
"Ensures",
"no",
"test",
"set",
"data",
"has",
"creeped",
"into",
"the",
"training",
"set",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L31-L47 |
13,838 | persephone-tools/persephone | persephone/corpus.py | get_untranscribed_prefixes_from_file | def get_untranscribed_prefixes_from_file(target_directory: Path) -> List[str]:
"""
The file "untranscribed_prefixes.txt" will specify prefixes which
do not have an associated transcription file if placed in the target directory.
This will fetch those prefixes from that file and will return an empty
... | python | def get_untranscribed_prefixes_from_file(target_directory: Path) -> List[str]:
"""
The file "untranscribed_prefixes.txt" will specify prefixes which
do not have an associated transcription file if placed in the target directory.
This will fetch those prefixes from that file and will return an empty
... | [
"def",
"get_untranscribed_prefixes_from_file",
"(",
"target_directory",
":",
"Path",
")",
"->",
"List",
"[",
"str",
"]",
":",
"untranscribed_prefix_fn",
"=",
"target_directory",
"/",
"\"untranscribed_prefixes.txt\"",
"if",
"untranscribed_prefix_fn",
".",
"exists",
"(",
... | The file "untranscribed_prefixes.txt" will specify prefixes which
do not have an associated transcription file if placed in the target directory.
This will fetch those prefixes from that file and will return an empty
list if that file does not exist.
See find_untranscribed_wavs function for finding un... | [
"The",
"file",
"untranscribed_prefixes",
".",
"txt",
"will",
"specify",
"prefixes",
"which",
"do",
"not",
"have",
"an",
"associated",
"transcription",
"file",
"if",
"placed",
"in",
"the",
"target",
"directory",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L69-L94 |
13,839 | persephone-tools/persephone | persephone/corpus.py | determine_labels | def determine_labels(target_dir: Path, label_type: str) -> Set[str]:
""" Returns a set of all phonemes found in the corpus. Assumes that WAV files and
label files are split into utterances and segregated in a directory which contains a
"wav" subdirectory and "label" subdirectory.
Arguments:
tar... | python | def determine_labels(target_dir: Path, label_type: str) -> Set[str]:
""" Returns a set of all phonemes found in the corpus. Assumes that WAV files and
label files are split into utterances and segregated in a directory which contains a
"wav" subdirectory and "label" subdirectory.
Arguments:
tar... | [
"def",
"determine_labels",
"(",
"target_dir",
":",
"Path",
",",
"label_type",
":",
"str",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"logger",
".",
"info",
"(",
"\"Finding phonemes of type %s in directory %s\"",
",",
"label_type",
",",
"target_dir",
")",
"label_dir... | Returns a set of all phonemes found in the corpus. Assumes that WAV files and
label files are split into utterances and segregated in a directory which contains a
"wav" subdirectory and "label" subdirectory.
Arguments:
target_dir: A `Path` to the directory where the corpus data is found
lab... | [
"Returns",
"a",
"set",
"of",
"all",
"phonemes",
"found",
"in",
"the",
"corpus",
".",
"Assumes",
"that",
"WAV",
"files",
"and",
"label",
"files",
"are",
"split",
"into",
"utterances",
"and",
"segregated",
"in",
"a",
"directory",
"which",
"contains",
"a",
"w... | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L617-L645 |
13,840 | persephone-tools/persephone | persephone/corpus.py | Corpus.from_elan | def from_elan(cls: Type[CorpusT], org_dir: Path, tgt_dir: Path,
feat_type: str = "fbank", label_type: str = "phonemes",
utterance_filter: Callable[[Utterance], bool] = None,
label_segmenter: Optional[LabelSegmenter] = None,
speakers: List[str] = No... | python | def from_elan(cls: Type[CorpusT], org_dir: Path, tgt_dir: Path,
feat_type: str = "fbank", label_type: str = "phonemes",
utterance_filter: Callable[[Utterance], bool] = None,
label_segmenter: Optional[LabelSegmenter] = None,
speakers: List[str] = No... | [
"def",
"from_elan",
"(",
"cls",
":",
"Type",
"[",
"CorpusT",
"]",
",",
"org_dir",
":",
"Path",
",",
"tgt_dir",
":",
"Path",
",",
"feat_type",
":",
"str",
"=",
"\"fbank\"",
",",
"label_type",
":",
"str",
"=",
"\"phonemes\"",
",",
"utterance_filter",
":",
... | Construct a `Corpus` from ELAN files.
Args:
org_dir: A path to the directory containing the unpreprocessed
data.
tgt_dir: A path to the directory where the preprocessed data will
be stored.
feat_type: A string describing the input speech featu... | [
"Construct",
"a",
"Corpus",
"from",
"ELAN",
"files",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L236-L315 |
13,841 | persephone-tools/persephone | persephone/corpus.py | Corpus.set_and_check_directories | def set_and_check_directories(self, tgt_dir: Path) -> None:
"""
Make sure that the required directories exist in the target directory.
set variables accordingly.
"""
logger.info("Setting up directories for corpus in %s", tgt_dir)
# Check directories exist.
if not... | python | def set_and_check_directories(self, tgt_dir: Path) -> None:
"""
Make sure that the required directories exist in the target directory.
set variables accordingly.
"""
logger.info("Setting up directories for corpus in %s", tgt_dir)
# Check directories exist.
if not... | [
"def",
"set_and_check_directories",
"(",
"self",
",",
"tgt_dir",
":",
"Path",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Setting up directories for corpus in %s\"",
",",
"tgt_dir",
")",
"# Check directories exist.",
"if",
"not",
"tgt_dir",
".",
"is_dir",... | Make sure that the required directories exist in the target directory.
set variables accordingly. | [
"Make",
"sure",
"that",
"the",
"required",
"directories",
"exist",
"in",
"the",
"target",
"directory",
".",
"set",
"variables",
"accordingly",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L338-L355 |
13,842 | persephone-tools/persephone | persephone/corpus.py | Corpus.initialize_labels | def initialize_labels(self, labels: Set[str]) -> Tuple[dict, dict]:
"""Create mappings from label to index and index to label"""
logger.debug("Creating mappings for labels")
label_to_index = {label: index for index, label in enumerate(
["pad"] + sorted(list(labe... | python | def initialize_labels(self, labels: Set[str]) -> Tuple[dict, dict]:
"""Create mappings from label to index and index to label"""
logger.debug("Creating mappings for labels")
label_to_index = {label: index for index, label in enumerate(
["pad"] + sorted(list(labe... | [
"def",
"initialize_labels",
"(",
"self",
",",
"labels",
":",
"Set",
"[",
"str",
"]",
")",
"->",
"Tuple",
"[",
"dict",
",",
"dict",
"]",
":",
"logger",
".",
"debug",
"(",
"\"Creating mappings for labels\"",
")",
"label_to_index",
"=",
"{",
"label",
":",
"... | Create mappings from label to index and index to label | [
"Create",
"mappings",
"from",
"label",
"to",
"index",
"and",
"index",
"to",
"label"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L357-L366 |
13,843 | persephone-tools/persephone | persephone/corpus.py | Corpus.prepare_feats | def prepare_feats(self) -> None:
""" Prepares input features"""
logger.debug("Preparing input features")
self.feat_dir.mkdir(parents=True, exist_ok=True)
should_extract_feats = False
for path in self.wav_dir.iterdir():
if not path.suffix == ".wav":
l... | python | def prepare_feats(self) -> None:
""" Prepares input features"""
logger.debug("Preparing input features")
self.feat_dir.mkdir(parents=True, exist_ok=True)
should_extract_feats = False
for path in self.wav_dir.iterdir():
if not path.suffix == ".wav":
l... | [
"def",
"prepare_feats",
"(",
"self",
")",
"->",
"None",
":",
"logger",
".",
"debug",
"(",
"\"Preparing input features\"",
")",
"self",
".",
"feat_dir",
".",
"mkdir",
"(",
"parents",
"=",
"True",
",",
"exist_ok",
"=",
"True",
")",
"should_extract_feats",
"=",... | Prepares input features | [
"Prepares",
"input",
"features"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L368-L392 |
13,844 | persephone-tools/persephone | persephone/corpus.py | Corpus.make_data_splits | def make_data_splits(self, max_samples: int) -> None:
""" Splits the utterances into training, validation and test sets."""
train_f_exists = self.train_prefix_fn.is_file()
valid_f_exists = self.valid_prefix_fn.is_file()
test_f_exists = self.test_prefix_fn.is_file()
if train_f_e... | python | def make_data_splits(self, max_samples: int) -> None:
""" Splits the utterances into training, validation and test sets."""
train_f_exists = self.train_prefix_fn.is_file()
valid_f_exists = self.valid_prefix_fn.is_file()
test_f_exists = self.test_prefix_fn.is_file()
if train_f_e... | [
"def",
"make_data_splits",
"(",
"self",
",",
"max_samples",
":",
"int",
")",
"->",
"None",
":",
"train_f_exists",
"=",
"self",
".",
"train_prefix_fn",
".",
"is_file",
"(",
")",
"valid_f_exists",
"=",
"self",
".",
"valid_prefix_fn",
".",
"is_file",
"(",
")",
... | Splits the utterances into training, validation and test sets. | [
"Splits",
"the",
"utterances",
"into",
"training",
"validation",
"and",
"test",
"sets",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L394-L438 |
13,845 | persephone-tools/persephone | persephone/corpus.py | Corpus.divide_prefixes | def divide_prefixes(prefixes: List[str], seed:int=0) -> Tuple[List[str], List[str], List[str]]:
"""Divide data into training, validation and test subsets"""
if len(prefixes) < 3:
raise PersephoneException(
"{} cannot be split into 3 groups as it only has {} items".format(pref... | python | def divide_prefixes(prefixes: List[str], seed:int=0) -> Tuple[List[str], List[str], List[str]]:
"""Divide data into training, validation and test subsets"""
if len(prefixes) < 3:
raise PersephoneException(
"{} cannot be split into 3 groups as it only has {} items".format(pref... | [
"def",
"divide_prefixes",
"(",
"prefixes",
":",
"List",
"[",
"str",
"]",
",",
"seed",
":",
"int",
"=",
"0",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"str",
"]",
"]",
":",
"if",
"len",
"... | Divide data into training, validation and test subsets | [
"Divide",
"data",
"into",
"training",
"validation",
"and",
"test",
"subsets"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L464-L495 |
13,846 | persephone-tools/persephone | persephone/corpus.py | Corpus.indices_to_labels | def indices_to_labels(self, indices: Sequence[int]) -> List[str]:
""" Converts a sequence of indices into their corresponding labels."""
return [(self.INDEX_TO_LABEL[index]) for index in indices] | python | def indices_to_labels(self, indices: Sequence[int]) -> List[str]:
""" Converts a sequence of indices into their corresponding labels."""
return [(self.INDEX_TO_LABEL[index]) for index in indices] | [
"def",
"indices_to_labels",
"(",
"self",
",",
"indices",
":",
"Sequence",
"[",
"int",
"]",
")",
"->",
"List",
"[",
"str",
"]",
":",
"return",
"[",
"(",
"self",
".",
"INDEX_TO_LABEL",
"[",
"index",
"]",
")",
"for",
"index",
"in",
"indices",
"]"
] | Converts a sequence of indices into their corresponding labels. | [
"Converts",
"a",
"sequence",
"of",
"indices",
"into",
"their",
"corresponding",
"labels",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L497-L500 |
13,847 | persephone-tools/persephone | persephone/corpus.py | Corpus.labels_to_indices | def labels_to_indices(self, labels: Sequence[str]) -> List[int]:
""" Converts a sequence of labels into their corresponding indices."""
return [self.LABEL_TO_INDEX[label] for label in labels] | python | def labels_to_indices(self, labels: Sequence[str]) -> List[int]:
""" Converts a sequence of labels into their corresponding indices."""
return [self.LABEL_TO_INDEX[label] for label in labels] | [
"def",
"labels_to_indices",
"(",
"self",
",",
"labels",
":",
"Sequence",
"[",
"str",
"]",
")",
"->",
"List",
"[",
"int",
"]",
":",
"return",
"[",
"self",
".",
"LABEL_TO_INDEX",
"[",
"label",
"]",
"for",
"label",
"in",
"labels",
"]"
] | Converts a sequence of labels into their corresponding indices. | [
"Converts",
"a",
"sequence",
"of",
"labels",
"into",
"their",
"corresponding",
"indices",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L502-L505 |
13,848 | persephone-tools/persephone | persephone/corpus.py | Corpus.num_feats | def num_feats(self):
""" The number of features per time step in the corpus. """
if not self._num_feats:
filename = self.get_train_fns()[0][0]
feats = np.load(filename)
# pylint: disable=maybe-no-member
if len(feats.shape) == 3:
# Then ther... | python | def num_feats(self):
""" The number of features per time step in the corpus. """
if not self._num_feats:
filename = self.get_train_fns()[0][0]
feats = np.load(filename)
# pylint: disable=maybe-no-member
if len(feats.shape) == 3:
# Then ther... | [
"def",
"num_feats",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_num_feats",
":",
"filename",
"=",
"self",
".",
"get_train_fns",
"(",
")",
"[",
"0",
"]",
"[",
"0",
"]",
"feats",
"=",
"np",
".",
"load",
"(",
"filename",
")",
"# pylint: disable=m... | The number of features per time step in the corpus. | [
"The",
"number",
"of",
"features",
"per",
"time",
"step",
"in",
"the",
"corpus",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L508-L523 |
13,849 | persephone-tools/persephone | persephone/corpus.py | Corpus.prefixes_to_fns | def prefixes_to_fns(self, prefixes: List[str]) -> Tuple[List[str], List[str]]:
""" Fetches the file paths to the features files and labels files
corresponding to the provided list of features"""
# TODO Return pathlib.Paths
feat_fns = [str(self.feat_dir / ("%s.%s.npy" % (prefix, self.feat... | python | def prefixes_to_fns(self, prefixes: List[str]) -> Tuple[List[str], List[str]]:
""" Fetches the file paths to the features files and labels files
corresponding to the provided list of features"""
# TODO Return pathlib.Paths
feat_fns = [str(self.feat_dir / ("%s.%s.npy" % (prefix, self.feat... | [
"def",
"prefixes_to_fns",
"(",
"self",
",",
"prefixes",
":",
"List",
"[",
"str",
"]",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"str",
"]",
"]",
":",
"# TODO Return pathlib.Paths",
"feat_fns",
"=",
"[",
"str",
"(",
"self",
"... | Fetches the file paths to the features files and labels files
corresponding to the provided list of features | [
"Fetches",
"the",
"file",
"paths",
"to",
"the",
"features",
"files",
"and",
"labels",
"files",
"corresponding",
"to",
"the",
"provided",
"list",
"of",
"features"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L525-L533 |
13,850 | persephone-tools/persephone | persephone/corpus.py | Corpus.get_train_fns | def get_train_fns(self) -> Tuple[List[str], List[str]]:
""" Fetches the training set of the corpus.
Outputs a Tuple of size 2, where the first element is a list of paths
to input features files, one per utterance. The second element is a list
of paths to the transcriptions.
"""
... | python | def get_train_fns(self) -> Tuple[List[str], List[str]]:
""" Fetches the training set of the corpus.
Outputs a Tuple of size 2, where the first element is a list of paths
to input features files, one per utterance. The second element is a list
of paths to the transcriptions.
"""
... | [
"def",
"get_train_fns",
"(",
"self",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"str",
"]",
"]",
":",
"return",
"self",
".",
"prefixes_to_fns",
"(",
"self",
".",
"train_prefixes",
")"
] | Fetches the training set of the corpus.
Outputs a Tuple of size 2, where the first element is a list of paths
to input features files, one per utterance. The second element is a list
of paths to the transcriptions. | [
"Fetches",
"the",
"training",
"set",
"of",
"the",
"corpus",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L535-L542 |
13,851 | persephone-tools/persephone | persephone/corpus.py | Corpus.get_valid_fns | def get_valid_fns(self) -> Tuple[List[str], List[str]]:
""" Fetches the validation set of the corpus."""
return self.prefixes_to_fns(self.valid_prefixes) | python | def get_valid_fns(self) -> Tuple[List[str], List[str]]:
""" Fetches the validation set of the corpus."""
return self.prefixes_to_fns(self.valid_prefixes) | [
"def",
"get_valid_fns",
"(",
"self",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"str",
"]",
"]",
":",
"return",
"self",
".",
"prefixes_to_fns",
"(",
"self",
".",
"valid_prefixes",
")"
] | Fetches the validation set of the corpus. | [
"Fetches",
"the",
"validation",
"set",
"of",
"the",
"corpus",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L544-L546 |
13,852 | persephone-tools/persephone | persephone/corpus.py | Corpus.review | def review(self) -> None:
""" Used to play the WAV files and compare with the transcription. """
for prefix in self.determine_prefixes():
print("Utterance: {}".format(prefix))
wav_fn = self.feat_dir / "{}.wav".format(prefix)
label_fn = self.label_dir / "{}.{}".format... | python | def review(self) -> None:
""" Used to play the WAV files and compare with the transcription. """
for prefix in self.determine_prefixes():
print("Utterance: {}".format(prefix))
wav_fn = self.feat_dir / "{}.wav".format(prefix)
label_fn = self.label_dir / "{}.{}".format... | [
"def",
"review",
"(",
"self",
")",
"->",
"None",
":",
"for",
"prefix",
"in",
"self",
".",
"determine_prefixes",
"(",
")",
":",
"print",
"(",
"\"Utterance: {}\"",
".",
"format",
"(",
"prefix",
")",
")",
"wav_fn",
"=",
"self",
".",
"feat_dir",
"/",
"\"{}... | Used to play the WAV files and compare with the transcription. | [
"Used",
"to",
"play",
"the",
"WAV",
"files",
"and",
"compare",
"with",
"the",
"transcription",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L589-L599 |
13,853 | persephone-tools/persephone | persephone/corpus.py | Corpus.pickle | def pickle(self) -> None:
""" Pickles the Corpus object in a file in tgt_dir. """
pickle_path = self.tgt_dir / "corpus.p"
logger.debug("pickling %r object and saving it to path %s", self, pickle_path)
with pickle_path.open("wb") as f:
pickle.dump(self, f) | python | def pickle(self) -> None:
""" Pickles the Corpus object in a file in tgt_dir. """
pickle_path = self.tgt_dir / "corpus.p"
logger.debug("pickling %r object and saving it to path %s", self, pickle_path)
with pickle_path.open("wb") as f:
pickle.dump(self, f) | [
"def",
"pickle",
"(",
"self",
")",
"->",
"None",
":",
"pickle_path",
"=",
"self",
".",
"tgt_dir",
"/",
"\"corpus.p\"",
"logger",
".",
"debug",
"(",
"\"pickling %r object and saving it to path %s\"",
",",
"self",
",",
"pickle_path",
")",
"with",
"pickle_path",
".... | Pickles the Corpus object in a file in tgt_dir. | [
"Pickles",
"the",
"Corpus",
"object",
"in",
"a",
"file",
"in",
"tgt_dir",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus.py#L601-L607 |
13,854 | persephone-tools/persephone | persephone/utils.py | zero_pad | def zero_pad(matrix, to_length):
""" Zero pads along the 0th dimension to make sure the utterance array
x is of length to_length."""
assert matrix.shape[0] <= to_length
if not matrix.shape[0] <= to_length:
logger.error("zero_pad cannot be performed on matrix with shape {}"
... | python | def zero_pad(matrix, to_length):
""" Zero pads along the 0th dimension to make sure the utterance array
x is of length to_length."""
assert matrix.shape[0] <= to_length
if not matrix.shape[0] <= to_length:
logger.error("zero_pad cannot be performed on matrix with shape {}"
... | [
"def",
"zero_pad",
"(",
"matrix",
",",
"to_length",
")",
":",
"assert",
"matrix",
".",
"shape",
"[",
"0",
"]",
"<=",
"to_length",
"if",
"not",
"matrix",
".",
"shape",
"[",
"0",
"]",
"<=",
"to_length",
":",
"logger",
".",
"error",
"(",
"\"zero_pad canno... | Zero pads along the 0th dimension to make sure the utterance array
x is of length to_length. | [
"Zero",
"pads",
"along",
"the",
"0th",
"dimension",
"to",
"make",
"sure",
"the",
"utterance",
"array",
"x",
"is",
"of",
"length",
"to_length",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utils.py#L58-L69 |
13,855 | persephone-tools/persephone | persephone/utils.py | load_batch_x | def load_batch_x(path_batch,
flatten = False,
time_major = False):
""" Loads a batch of input features given a list of paths to numpy
arrays in that batch."""
utterances = [np.load(str(path)) for path in path_batch]
utter_lens = [utterance.shape[0] for utterance in utt... | python | def load_batch_x(path_batch,
flatten = False,
time_major = False):
""" Loads a batch of input features given a list of paths to numpy
arrays in that batch."""
utterances = [np.load(str(path)) for path in path_batch]
utter_lens = [utterance.shape[0] for utterance in utt... | [
"def",
"load_batch_x",
"(",
"path_batch",
",",
"flatten",
"=",
"False",
",",
"time_major",
"=",
"False",
")",
":",
"utterances",
"=",
"[",
"np",
".",
"load",
"(",
"str",
"(",
"path",
")",
")",
"for",
"path",
"in",
"path_batch",
"]",
"utter_lens",
"=",
... | Loads a batch of input features given a list of paths to numpy
arrays in that batch. | [
"Loads",
"a",
"batch",
"of",
"input",
"features",
"given",
"a",
"list",
"of",
"paths",
"to",
"numpy",
"arrays",
"in",
"that",
"batch",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utils.py#L88-L104 |
13,856 | persephone-tools/persephone | persephone/utils.py | batch_per | def batch_per(hyps: Sequence[Sequence[T]],
refs: Sequence[Sequence[T]]) -> float:
""" Calculates the phoneme error rate of a batch."""
macro_per = 0.0
for i in range(len(hyps)):
ref = [phn_i for phn_i in refs[i] if phn_i != 0]
hyp = [phn_i for phn_i in hyps[i] if phn_i != 0]
... | python | def batch_per(hyps: Sequence[Sequence[T]],
refs: Sequence[Sequence[T]]) -> float:
""" Calculates the phoneme error rate of a batch."""
macro_per = 0.0
for i in range(len(hyps)):
ref = [phn_i for phn_i in refs[i] if phn_i != 0]
hyp = [phn_i for phn_i in hyps[i] if phn_i != 0]
... | [
"def",
"batch_per",
"(",
"hyps",
":",
"Sequence",
"[",
"Sequence",
"[",
"T",
"]",
"]",
",",
"refs",
":",
"Sequence",
"[",
"Sequence",
"[",
"T",
"]",
"]",
")",
"->",
"float",
":",
"macro_per",
"=",
"0.0",
"for",
"i",
"in",
"range",
"(",
"len",
"("... | Calculates the phoneme error rate of a batch. | [
"Calculates",
"the",
"phoneme",
"error",
"rate",
"of",
"a",
"batch",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utils.py#L106-L115 |
13,857 | persephone-tools/persephone | persephone/utils.py | filter_by_size | def filter_by_size(feat_dir: Path, prefixes: List[str], feat_type: str,
max_samples: int) -> List[str]:
""" Sorts the files by their length and returns those with less
than or equal to max_samples length. Returns the filename prefixes of
those files. The main job of the method is to filte... | python | def filter_by_size(feat_dir: Path, prefixes: List[str], feat_type: str,
max_samples: int) -> List[str]:
""" Sorts the files by their length and returns those with less
than or equal to max_samples length. Returns the filename prefixes of
those files. The main job of the method is to filte... | [
"def",
"filter_by_size",
"(",
"feat_dir",
":",
"Path",
",",
"prefixes",
":",
"List",
"[",
"str",
"]",
",",
"feat_type",
":",
"str",
",",
"max_samples",
":",
"int",
")",
"->",
"List",
"[",
"str",
"]",
":",
"# TODO Tell the user what utterances we are removing."... | Sorts the files by their length and returns those with less
than or equal to max_samples length. Returns the filename prefixes of
those files. The main job of the method is to filter, but the sorting
may give better efficiency when doing dynamic batching unless it gets
shuffled downstream. | [
"Sorts",
"the",
"files",
"by",
"their",
"length",
"and",
"returns",
"those",
"with",
"less",
"than",
"or",
"equal",
"to",
"max_samples",
"length",
".",
"Returns",
"the",
"filename",
"prefixes",
"of",
"those",
"files",
".",
"The",
"main",
"job",
"of",
"the"... | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utils.py#L141-L154 |
13,858 | persephone-tools/persephone | persephone/utils.py | wav_length | def wav_length(fn: str) -> float:
""" Returns the length of the WAV file in seconds."""
args = [config.SOX_PATH, fn, "-n", "stat"]
p = subprocess.Popen(
args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
length_line = str(p.communicate()[1]).split("\\n")[1].split()
print(length_line)
assert le... | python | def wav_length(fn: str) -> float:
""" Returns the length of the WAV file in seconds."""
args = [config.SOX_PATH, fn, "-n", "stat"]
p = subprocess.Popen(
args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
length_line = str(p.communicate()[1]).split("\\n")[1].split()
print(length_line)
assert le... | [
"def",
"wav_length",
"(",
"fn",
":",
"str",
")",
"->",
"float",
":",
"args",
"=",
"[",
"config",
".",
"SOX_PATH",
",",
"fn",
",",
"\"-n\"",
",",
"\"stat\"",
"]",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"args",
",",
"stdin",
"=",
"PIPE",
",",
"... | Returns the length of the WAV file in seconds. | [
"Returns",
"the",
"length",
"of",
"the",
"WAV",
"file",
"in",
"seconds",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/utils.py#L170-L179 |
13,859 | persephone-tools/persephone | persephone/datasets/bkw.py | pull_en_words | def pull_en_words() -> None:
""" Fetches a repository containing English words. """
ENGLISH_WORDS_URL = "https://github.com/dwyl/english-words.git"
en_words_path = Path(config.EN_WORDS_PATH)
if not en_words_path.is_file():
subprocess.run(["git", "clone",
ENGLISH_WORDS_UR... | python | def pull_en_words() -> None:
""" Fetches a repository containing English words. """
ENGLISH_WORDS_URL = "https://github.com/dwyl/english-words.git"
en_words_path = Path(config.EN_WORDS_PATH)
if not en_words_path.is_file():
subprocess.run(["git", "clone",
ENGLISH_WORDS_UR... | [
"def",
"pull_en_words",
"(",
")",
"->",
"None",
":",
"ENGLISH_WORDS_URL",
"=",
"\"https://github.com/dwyl/english-words.git\"",
"en_words_path",
"=",
"Path",
"(",
"config",
".",
"EN_WORDS_PATH",
")",
"if",
"not",
"en_words_path",
".",
"is_file",
"(",
")",
":",
"su... | Fetches a repository containing English words. | [
"Fetches",
"a",
"repository",
"containing",
"English",
"words",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/bkw.py#L27-L34 |
13,860 | persephone-tools/persephone | persephone/datasets/bkw.py | get_en_words | def get_en_words() -> Set[str]:
"""
Returns a list of English words which can be used to filter out
code-switched sentences.
"""
pull_en_words()
with open(config.EN_WORDS_PATH) as words_f:
raw_words = words_f.readlines()
en_words = set([word.strip().lower() for word in raw_words])
... | python | def get_en_words() -> Set[str]:
"""
Returns a list of English words which can be used to filter out
code-switched sentences.
"""
pull_en_words()
with open(config.EN_WORDS_PATH) as words_f:
raw_words = words_f.readlines()
en_words = set([word.strip().lower() for word in raw_words])
... | [
"def",
"get_en_words",
"(",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"pull_en_words",
"(",
")",
"with",
"open",
"(",
"config",
".",
"EN_WORDS_PATH",
")",
"as",
"words_f",
":",
"raw_words",
"=",
"words_f",
".",
"readlines",
"(",
")",
"en_words",
"=",
"se... | Returns a list of English words which can be used to filter out
code-switched sentences. | [
"Returns",
"a",
"list",
"of",
"English",
"words",
"which",
"can",
"be",
"used",
"to",
"filter",
"out",
"code",
"-",
"switched",
"sentences",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/bkw.py#L36-L69 |
13,861 | persephone-tools/persephone | persephone/datasets/bkw.py | explore_elan_files | def explore_elan_files(elan_paths):
"""
A function to explore the tiers of ELAN files.
"""
for elan_path in elan_paths:
print(elan_path)
eafob = Eaf(elan_path)
tier_names = eafob.get_tier_names()
for tier in tier_names:
print("\t", tier)
try:
... | python | def explore_elan_files(elan_paths):
"""
A function to explore the tiers of ELAN files.
"""
for elan_path in elan_paths:
print(elan_path)
eafob = Eaf(elan_path)
tier_names = eafob.get_tier_names()
for tier in tier_names:
print("\t", tier)
try:
... | [
"def",
"explore_elan_files",
"(",
"elan_paths",
")",
":",
"for",
"elan_path",
"in",
"elan_paths",
":",
"print",
"(",
"elan_path",
")",
"eafob",
"=",
"Eaf",
"(",
"elan_path",
")",
"tier_names",
"=",
"eafob",
".",
"get_tier_names",
"(",
")",
"for",
"tier",
"... | A function to explore the tiers of ELAN files. | [
"A",
"function",
"to",
"explore",
"the",
"tiers",
"of",
"ELAN",
"files",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/bkw.py#L73-L90 |
13,862 | persephone-tools/persephone | persephone/preprocess/elan.py | sort_annotations | def sort_annotations(annotations: List[Tuple[int, int, str]]
) -> List[Tuple[int, int, str]]:
""" Sorts the annotations by their start_time. """
return sorted(annotations, key=lambda x: x[0]) | python | def sort_annotations(annotations: List[Tuple[int, int, str]]
) -> List[Tuple[int, int, str]]:
""" Sorts the annotations by their start_time. """
return sorted(annotations, key=lambda x: x[0]) | [
"def",
"sort_annotations",
"(",
"annotations",
":",
"List",
"[",
"Tuple",
"[",
"int",
",",
"int",
",",
"str",
"]",
"]",
")",
"->",
"List",
"[",
"Tuple",
"[",
"int",
",",
"int",
",",
"str",
"]",
"]",
":",
"return",
"sorted",
"(",
"annotations",
",",... | Sorts the annotations by their start_time. | [
"Sorts",
"the",
"annotations",
"by",
"their",
"start_time",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/elan.py#L62-L65 |
13,863 | persephone-tools/persephone | persephone/preprocess/elan.py | utterances_from_tier | def utterances_from_tier(eafob: Eaf, tier_name: str) -> List[Utterance]:
""" Returns utterances found in the given Eaf object in the given tier."""
try:
speaker = eafob.tiers[tier_name][2]["PARTICIPANT"]
except KeyError:
speaker = None # We don't know the name of the speaker.
tier_utte... | python | def utterances_from_tier(eafob: Eaf, tier_name: str) -> List[Utterance]:
""" Returns utterances found in the given Eaf object in the given tier."""
try:
speaker = eafob.tiers[tier_name][2]["PARTICIPANT"]
except KeyError:
speaker = None # We don't know the name of the speaker.
tier_utte... | [
"def",
"utterances_from_tier",
"(",
"eafob",
":",
"Eaf",
",",
"tier_name",
":",
"str",
")",
"->",
"List",
"[",
"Utterance",
"]",
":",
"try",
":",
"speaker",
"=",
"eafob",
".",
"tiers",
"[",
"tier_name",
"]",
"[",
"2",
"]",
"[",
"\"PARTICIPANT\"",
"]",
... | Returns utterances found in the given Eaf object in the given tier. | [
"Returns",
"utterances",
"found",
"in",
"the",
"given",
"Eaf",
"object",
"in",
"the",
"given",
"tier",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/elan.py#L68-L91 |
13,864 | persephone-tools/persephone | persephone/preprocess/elan.py | utterances_from_eaf | def utterances_from_eaf(eaf_path: Path, tier_prefixes: Tuple[str, ...]) -> List[Utterance]:
"""
Extracts utterances in tiers that start with tier_prefixes found in the ELAN .eaf XML file
at eaf_path.
For example, if xv@Mark is a tier in the eaf file, and
tier_prefixes = ["xv"], then utterances from... | python | def utterances_from_eaf(eaf_path: Path, tier_prefixes: Tuple[str, ...]) -> List[Utterance]:
"""
Extracts utterances in tiers that start with tier_prefixes found in the ELAN .eaf XML file
at eaf_path.
For example, if xv@Mark is a tier in the eaf file, and
tier_prefixes = ["xv"], then utterances from... | [
"def",
"utterances_from_eaf",
"(",
"eaf_path",
":",
"Path",
",",
"tier_prefixes",
":",
"Tuple",
"[",
"str",
",",
"...",
"]",
")",
"->",
"List",
"[",
"Utterance",
"]",
":",
"if",
"not",
"eaf_path",
".",
"is_file",
"(",
")",
":",
"raise",
"FileNotFoundErro... | Extracts utterances in tiers that start with tier_prefixes found in the ELAN .eaf XML file
at eaf_path.
For example, if xv@Mark is a tier in the eaf file, and
tier_prefixes = ["xv"], then utterances from that tier will be gathered. | [
"Extracts",
"utterances",
"in",
"tiers",
"that",
"start",
"with",
"tier_prefixes",
"found",
"in",
"the",
"ELAN",
".",
"eaf",
"XML",
"file",
"at",
"eaf_path",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/elan.py#L94-L113 |
13,865 | persephone-tools/persephone | persephone/preprocess/elan.py | utterances_from_dir | def utterances_from_dir(eaf_dir: Path,
tier_prefixes: Tuple[str, ...]) -> List[Utterance]:
""" Returns the utterances found in ELAN files in a directory.
Recursively explores the directory, gathering ELAN files and extracting
utterances from them for tiers that start with the specif... | python | def utterances_from_dir(eaf_dir: Path,
tier_prefixes: Tuple[str, ...]) -> List[Utterance]:
""" Returns the utterances found in ELAN files in a directory.
Recursively explores the directory, gathering ELAN files and extracting
utterances from them for tiers that start with the specif... | [
"def",
"utterances_from_dir",
"(",
"eaf_dir",
":",
"Path",
",",
"tier_prefixes",
":",
"Tuple",
"[",
"str",
",",
"...",
"]",
")",
"->",
"List",
"[",
"Utterance",
"]",
":",
"logger",
".",
"info",
"(",
"\"EAF from directory: {}, searching with tier_prefixes {}\"",
... | Returns the utterances found in ELAN files in a directory.
Recursively explores the directory, gathering ELAN files and extracting
utterances from them for tiers that start with the specified prefixes.
Args:
eaf_dir: A path to the directory to be searched
tier_prefixes: Stings matching the... | [
"Returns",
"the",
"utterances",
"found",
"in",
"ELAN",
"files",
"in",
"a",
"directory",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/elan.py#L116-L142 |
13,866 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.load_batch | def load_batch(self, fn_batch):
""" Loads a batch with the given prefixes. The prefixes is the full path to the
training example minus the extension.
"""
# TODO Assumes targets are available, which is how its distinct from
# utils.load_batch_x(). These functions need to change n... | python | def load_batch(self, fn_batch):
""" Loads a batch with the given prefixes. The prefixes is the full path to the
training example minus the extension.
"""
# TODO Assumes targets are available, which is how its distinct from
# utils.load_batch_x(). These functions need to change n... | [
"def",
"load_batch",
"(",
"self",
",",
"fn_batch",
")",
":",
"# TODO Assumes targets are available, which is how its distinct from",
"# utils.load_batch_x(). These functions need to change names to be",
"# clearer.",
"inverse",
"=",
"list",
"(",
"zip",
"(",
"*",
"fn_batch",
")"... | Loads a batch with the given prefixes. The prefixes is the full path to the
training example minus the extension. | [
"Loads",
"a",
"batch",
"with",
"the",
"given",
"prefixes",
".",
"The",
"prefixes",
"is",
"the",
"full",
"path",
"to",
"the",
"training",
"example",
"minus",
"the",
"extension",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L95-L117 |
13,867 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.train_batch_gen | def train_batch_gen(self) -> Iterator:
""" Returns a generator that outputs batches in the training data."""
if len(self.train_fns) == 0:
raise PersephoneException("""No training data available; cannot
generate training batches.""")
# Create b... | python | def train_batch_gen(self) -> Iterator:
""" Returns a generator that outputs batches in the training data."""
if len(self.train_fns) == 0:
raise PersephoneException("""No training data available; cannot
generate training batches.""")
# Create b... | [
"def",
"train_batch_gen",
"(",
"self",
")",
"->",
"Iterator",
":",
"if",
"len",
"(",
"self",
".",
"train_fns",
")",
"==",
"0",
":",
"raise",
"PersephoneException",
"(",
"\"\"\"No training data available; cannot\n generate training batch... | Returns a generator that outputs batches in the training data. | [
"Returns",
"a",
"generator",
"that",
"outputs",
"batches",
"in",
"the",
"training",
"data",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L125-L144 |
13,868 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.valid_batch | def valid_batch(self):
""" Returns a single batch with all the validation cases."""
valid_fns = list(zip(*self.corpus.get_valid_fns()))
return self.load_batch(valid_fns) | python | def valid_batch(self):
""" Returns a single batch with all the validation cases."""
valid_fns = list(zip(*self.corpus.get_valid_fns()))
return self.load_batch(valid_fns) | [
"def",
"valid_batch",
"(",
"self",
")",
":",
"valid_fns",
"=",
"list",
"(",
"zip",
"(",
"*",
"self",
".",
"corpus",
".",
"get_valid_fns",
"(",
")",
")",
")",
"return",
"self",
".",
"load_batch",
"(",
"valid_fns",
")"
] | Returns a single batch with all the validation cases. | [
"Returns",
"a",
"single",
"batch",
"with",
"all",
"the",
"validation",
"cases",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L146-L150 |
13,869 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.untranscribed_batch_gen | def untranscribed_batch_gen(self):
""" A batch generator for all the untranscribed data. """
feat_fns = self.corpus.get_untranscribed_fns()
fn_batches = self.make_batches(feat_fns)
for fn_batch in fn_batches:
batch_inputs, batch_inputs_lens = utils.load_batch_x(fn_batch,
... | python | def untranscribed_batch_gen(self):
""" A batch generator for all the untranscribed data. """
feat_fns = self.corpus.get_untranscribed_fns()
fn_batches = self.make_batches(feat_fns)
for fn_batch in fn_batches:
batch_inputs, batch_inputs_lens = utils.load_batch_x(fn_batch,
... | [
"def",
"untranscribed_batch_gen",
"(",
"self",
")",
":",
"feat_fns",
"=",
"self",
".",
"corpus",
".",
"get_untranscribed_fns",
"(",
")",
"fn_batches",
"=",
"self",
".",
"make_batches",
"(",
"feat_fns",
")",
"for",
"fn_batch",
"in",
"fn_batches",
":",
"batch_in... | A batch generator for all the untranscribed data. | [
"A",
"batch",
"generator",
"for",
"all",
"the",
"untranscribed",
"data",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L158-L167 |
13,870 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.human_readable_hyp_ref | def human_readable_hyp_ref(self, dense_decoded, dense_y):
""" Returns a human readable version of the hypothesis for manual
inspection, along with the reference.
"""
hyps = []
refs = []
for i in range(len(dense_decoded)):
ref = [phn_i for phn_i in dense_y[i] ... | python | def human_readable_hyp_ref(self, dense_decoded, dense_y):
""" Returns a human readable version of the hypothesis for manual
inspection, along with the reference.
"""
hyps = []
refs = []
for i in range(len(dense_decoded)):
ref = [phn_i for phn_i in dense_y[i] ... | [
"def",
"human_readable_hyp_ref",
"(",
"self",
",",
"dense_decoded",
",",
"dense_y",
")",
":",
"hyps",
"=",
"[",
"]",
"refs",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"dense_decoded",
")",
")",
":",
"ref",
"=",
"[",
"phn_i",
"for",
... | Returns a human readable version of the hypothesis for manual
inspection, along with the reference. | [
"Returns",
"a",
"human",
"readable",
"version",
"of",
"the",
"hypothesis",
"for",
"manual",
"inspection",
"along",
"with",
"the",
"reference",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L169-L184 |
13,871 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.human_readable | def human_readable(self, dense_repr: Sequence[Sequence[int]]) -> List[List[str]]:
""" Returns a human readable version of a dense representation of
either or reference to facilitate simple manual inspection.
"""
transcripts = []
for dense_r in dense_repr:
non_empty_p... | python | def human_readable(self, dense_repr: Sequence[Sequence[int]]) -> List[List[str]]:
""" Returns a human readable version of a dense representation of
either or reference to facilitate simple manual inspection.
"""
transcripts = []
for dense_r in dense_repr:
non_empty_p... | [
"def",
"human_readable",
"(",
"self",
",",
"dense_repr",
":",
"Sequence",
"[",
"Sequence",
"[",
"int",
"]",
"]",
")",
"->",
"List",
"[",
"List",
"[",
"str",
"]",
"]",
":",
"transcripts",
"=",
"[",
"]",
"for",
"dense_r",
"in",
"dense_repr",
":",
"non_... | Returns a human readable version of a dense representation of
either or reference to facilitate simple manual inspection. | [
"Returns",
"a",
"human",
"readable",
"version",
"of",
"a",
"dense",
"representation",
"of",
"either",
"or",
"reference",
"to",
"facilitate",
"simple",
"manual",
"inspection",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L186-L197 |
13,872 | persephone-tools/persephone | persephone/corpus_reader.py | CorpusReader.calc_time | def calc_time(self) -> None:
"""
Prints statistics about the the total duration of recordings in the
corpus.
"""
def get_number_of_frames(feat_fns):
""" fns: A list of numpy files which contain a number of feature
frames. """
total = 0
... | python | def calc_time(self) -> None:
"""
Prints statistics about the the total duration of recordings in the
corpus.
"""
def get_number_of_frames(feat_fns):
""" fns: A list of numpy files which contain a number of feature
frames. """
total = 0
... | [
"def",
"calc_time",
"(",
"self",
")",
"->",
"None",
":",
"def",
"get_number_of_frames",
"(",
"feat_fns",
")",
":",
"\"\"\" fns: A list of numpy files which contain a number of feature\n frames. \"\"\"",
"total",
"=",
"0",
"for",
"feat_fn",
"in",
"feat_fns",
":"... | Prints statistics about the the total duration of recordings in the
corpus. | [
"Prints",
"statistics",
"about",
"the",
"the",
"total",
"duration",
"of",
"recordings",
"in",
"the",
"corpus",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/corpus_reader.py#L205-L241 |
13,873 | persephone-tools/persephone | persephone/rnn_ctc.py | lstm_cell | def lstm_cell(hidden_size):
""" Wrapper function to create an LSTM cell. """
return tf.contrib.rnn.LSTMCell(
hidden_size, use_peepholes=True, state_is_tuple=True) | python | def lstm_cell(hidden_size):
""" Wrapper function to create an LSTM cell. """
return tf.contrib.rnn.LSTMCell(
hidden_size, use_peepholes=True, state_is_tuple=True) | [
"def",
"lstm_cell",
"(",
"hidden_size",
")",
":",
"return",
"tf",
".",
"contrib",
".",
"rnn",
".",
"LSTMCell",
"(",
"hidden_size",
",",
"use_peepholes",
"=",
"True",
",",
"state_is_tuple",
"=",
"True",
")"
] | Wrapper function to create an LSTM cell. | [
"Wrapper",
"function",
"to",
"create",
"an",
"LSTM",
"cell",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/rnn_ctc.py#L12-L16 |
13,874 | persephone-tools/persephone | persephone/rnn_ctc.py | Model.write_desc | def write_desc(self) -> None:
""" Writes a description of the model to the exp_dir. """
path = os.path.join(self.exp_dir, "model_description.txt")
with open(path, "w") as desc_f:
for key, val in self.__dict__.items():
print("%s=%s" % (key, val), file=desc_f)
... | python | def write_desc(self) -> None:
""" Writes a description of the model to the exp_dir. """
path = os.path.join(self.exp_dir, "model_description.txt")
with open(path, "w") as desc_f:
for key, val in self.__dict__.items():
print("%s=%s" % (key, val), file=desc_f)
... | [
"def",
"write_desc",
"(",
"self",
")",
"->",
"None",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"exp_dir",
",",
"\"model_description.txt\"",
")",
"with",
"open",
"(",
"path",
",",
"\"w\"",
")",
"as",
"desc_f",
":",
"for",
"ke... | Writes a description of the model to the exp_dir. | [
"Writes",
"a",
"description",
"of",
"the",
"model",
"to",
"the",
"exp_dir",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/rnn_ctc.py#L21-L58 |
13,875 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | empty_wav | def empty_wav(wav_path: Union[Path, str]) -> bool:
"""Check if a wav contains data"""
with wave.open(str(wav_path), 'rb') as wav_f:
return wav_f.getnframes() == 0 | python | def empty_wav(wav_path: Union[Path, str]) -> bool:
"""Check if a wav contains data"""
with wave.open(str(wav_path), 'rb') as wav_f:
return wav_f.getnframes() == 0 | [
"def",
"empty_wav",
"(",
"wav_path",
":",
"Union",
"[",
"Path",
",",
"str",
"]",
")",
"->",
"bool",
":",
"with",
"wave",
".",
"open",
"(",
"str",
"(",
"wav_path",
")",
",",
"'rb'",
")",
"as",
"wav_f",
":",
"return",
"wav_f",
".",
"getnframes",
"(",... | Check if a wav contains data | [
"Check",
"if",
"a",
"wav",
"contains",
"data"
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L19-L22 |
13,876 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | extract_energy | def extract_energy(rate, sig):
""" Extracts the energy of frames. """
mfcc = python_speech_features.mfcc(sig, rate, appendEnergy=True)
energy_row_vec = mfcc[:, 0]
energy_col_vec = energy_row_vec[:, np.newaxis]
return energy_col_vec | python | def extract_energy(rate, sig):
""" Extracts the energy of frames. """
mfcc = python_speech_features.mfcc(sig, rate, appendEnergy=True)
energy_row_vec = mfcc[:, 0]
energy_col_vec = energy_row_vec[:, np.newaxis]
return energy_col_vec | [
"def",
"extract_energy",
"(",
"rate",
",",
"sig",
")",
":",
"mfcc",
"=",
"python_speech_features",
".",
"mfcc",
"(",
"sig",
",",
"rate",
",",
"appendEnergy",
"=",
"True",
")",
"energy_row_vec",
"=",
"mfcc",
"[",
":",
",",
"0",
"]",
"energy_col_vec",
"=",... | Extracts the energy of frames. | [
"Extracts",
"the",
"energy",
"of",
"frames",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L25-L31 |
13,877 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | fbank | def fbank(wav_path, flat=True):
""" Currently grabs log Mel filterbank, deltas and double deltas."""
(rate, sig) = wav.read(wav_path)
if len(sig) == 0:
logger.warning("Empty wav: {}".format(wav_path))
fbank_feat = python_speech_features.logfbank(sig, rate, nfilt=40)
energy = extract_energy(... | python | def fbank(wav_path, flat=True):
""" Currently grabs log Mel filterbank, deltas and double deltas."""
(rate, sig) = wav.read(wav_path)
if len(sig) == 0:
logger.warning("Empty wav: {}".format(wav_path))
fbank_feat = python_speech_features.logfbank(sig, rate, nfilt=40)
energy = extract_energy(... | [
"def",
"fbank",
"(",
"wav_path",
",",
"flat",
"=",
"True",
")",
":",
"(",
"rate",
",",
"sig",
")",
"=",
"wav",
".",
"read",
"(",
"wav_path",
")",
"if",
"len",
"(",
"sig",
")",
"==",
"0",
":",
"logger",
".",
"warning",
"(",
"\"Empty wav: {}\"",
".... | Currently grabs log Mel filterbank, deltas and double deltas. | [
"Currently",
"grabs",
"log",
"Mel",
"filterbank",
"deltas",
"and",
"double",
"deltas",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L33-L56 |
13,878 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | mfcc | def mfcc(wav_path):
""" Grabs MFCC features with energy and derivates. """
(rate, sig) = wav.read(wav_path)
feat = python_speech_features.mfcc(sig, rate, appendEnergy=True)
delta_feat = python_speech_features.delta(feat, 2)
all_feats = [feat, delta_feat]
all_feats = np.array(all_feats)
# Ma... | python | def mfcc(wav_path):
""" Grabs MFCC features with energy and derivates. """
(rate, sig) = wav.read(wav_path)
feat = python_speech_features.mfcc(sig, rate, appendEnergy=True)
delta_feat = python_speech_features.delta(feat, 2)
all_feats = [feat, delta_feat]
all_feats = np.array(all_feats)
# Ma... | [
"def",
"mfcc",
"(",
"wav_path",
")",
":",
"(",
"rate",
",",
"sig",
")",
"=",
"wav",
".",
"read",
"(",
"wav_path",
")",
"feat",
"=",
"python_speech_features",
".",
"mfcc",
"(",
"sig",
",",
"rate",
",",
"appendEnergy",
"=",
"True",
")",
"delta_feat",
"... | Grabs MFCC features with energy and derivates. | [
"Grabs",
"MFCC",
"features",
"with",
"energy",
"and",
"derivates",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L58-L71 |
13,879 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | from_dir | def from_dir(dirpath: Path, feat_type: str) -> None:
""" Performs feature extraction from the WAV files in a directory.
Args:
dirpath: A `Path` to the directory where the WAV files reside.
feat_type: The type of features that are being used.
"""
logger.info("Extracting features from di... | python | def from_dir(dirpath: Path, feat_type: str) -> None:
""" Performs feature extraction from the WAV files in a directory.
Args:
dirpath: A `Path` to the directory where the WAV files reside.
feat_type: The type of features that are being used.
"""
logger.info("Extracting features from di... | [
"def",
"from_dir",
"(",
"dirpath",
":",
"Path",
",",
"feat_type",
":",
"str",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Extracting features from directory {}\"",
".",
"format",
"(",
"dirpath",
")",
")",
"dirname",
"=",
"str",
"(",
"dirpath",
"... | Performs feature extraction from the WAV files in a directory.
Args:
dirpath: A `Path` to the directory where the WAV files reside.
feat_type: The type of features that are being used. | [
"Performs",
"feature",
"extraction",
"from",
"the",
"WAV",
"files",
"in",
"a",
"directory",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L117-L173 |
13,880 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | convert_wav | def convert_wav(org_wav_fn: Path, tgt_wav_fn: Path) -> None:
""" Converts the wav into a 16bit mono 16000Hz wav.
Args:
org_wav_fn: A `Path` to the original wave file
tgt_wav_fn: The `Path` to output the processed wave file
"""
if not org_wav_fn.exists():
raise FileNo... | python | def convert_wav(org_wav_fn: Path, tgt_wav_fn: Path) -> None:
""" Converts the wav into a 16bit mono 16000Hz wav.
Args:
org_wav_fn: A `Path` to the original wave file
tgt_wav_fn: The `Path` to output the processed wave file
"""
if not org_wav_fn.exists():
raise FileNo... | [
"def",
"convert_wav",
"(",
"org_wav_fn",
":",
"Path",
",",
"tgt_wav_fn",
":",
"Path",
")",
"->",
"None",
":",
"if",
"not",
"org_wav_fn",
".",
"exists",
"(",
")",
":",
"raise",
"FileNotFoundError",
"args",
"=",
"[",
"config",
".",
"FFMPEG_PATH",
",",
"\"-... | Converts the wav into a 16bit mono 16000Hz wav.
Args:
org_wav_fn: A `Path` to the original wave file
tgt_wav_fn: The `Path` to output the processed wave file | [
"Converts",
"the",
"wav",
"into",
"a",
"16bit",
"mono",
"16000Hz",
"wav",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L175-L186 |
13,881 | persephone-tools/persephone | persephone/preprocess/feat_extract.py | kaldi_pitch | def kaldi_pitch(wav_dir: str, feat_dir: str) -> None:
""" Extract Kaldi pitch features. Assumes 16k mono wav files."""
logger.debug("Make wav.scp and pitch.scp files")
# Make wav.scp and pitch.scp files
prefixes = []
for fn in os.listdir(wav_dir):
prefix, ext = os.path.splitext(fn)
... | python | def kaldi_pitch(wav_dir: str, feat_dir: str) -> None:
""" Extract Kaldi pitch features. Assumes 16k mono wav files."""
logger.debug("Make wav.scp and pitch.scp files")
# Make wav.scp and pitch.scp files
prefixes = []
for fn in os.listdir(wav_dir):
prefix, ext = os.path.splitext(fn)
... | [
"def",
"kaldi_pitch",
"(",
"wav_dir",
":",
"str",
",",
"feat_dir",
":",
"str",
")",
"->",
"None",
":",
"logger",
".",
"debug",
"(",
"\"Make wav.scp and pitch.scp files\"",
")",
"# Make wav.scp and pitch.scp files",
"prefixes",
"=",
"[",
"]",
"for",
"fn",
"in",
... | Extract Kaldi pitch features. Assumes 16k mono wav files. | [
"Extract",
"Kaldi",
"pitch",
"features",
".",
"Assumes",
"16k",
"mono",
"wav",
"files",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/feat_extract.py#L188-L230 |
13,882 | persephone-tools/persephone | persephone/experiment.py | get_exp_dir_num | def get_exp_dir_num(parent_dir: str) -> int:
""" Gets the number of the current experiment directory."""
return max([int(fn.split(".")[0])
for fn in os.listdir(parent_dir) if fn.split(".")[0].isdigit()]
+ [-1]) | python | def get_exp_dir_num(parent_dir: str) -> int:
""" Gets the number of the current experiment directory."""
return max([int(fn.split(".")[0])
for fn in os.listdir(parent_dir) if fn.split(".")[0].isdigit()]
+ [-1]) | [
"def",
"get_exp_dir_num",
"(",
"parent_dir",
":",
"str",
")",
"->",
"int",
":",
"return",
"max",
"(",
"[",
"int",
"(",
"fn",
".",
"split",
"(",
"\".\"",
")",
"[",
"0",
"]",
")",
"for",
"fn",
"in",
"os",
".",
"listdir",
"(",
"parent_dir",
")",
"if... | Gets the number of the current experiment directory. | [
"Gets",
"the",
"number",
"of",
"the",
"current",
"experiment",
"directory",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/experiment.py#L18-L22 |
13,883 | persephone-tools/persephone | persephone/experiment.py | transcribe | def transcribe(model_path, corpus):
""" Applies a trained model to untranscribed data in a Corpus. """
exp_dir = prep_exp_dir()
model = get_simple_model(exp_dir, corpus)
model.transcribe(model_path) | python | def transcribe(model_path, corpus):
""" Applies a trained model to untranscribed data in a Corpus. """
exp_dir = prep_exp_dir()
model = get_simple_model(exp_dir, corpus)
model.transcribe(model_path) | [
"def",
"transcribe",
"(",
"model_path",
",",
"corpus",
")",
":",
"exp_dir",
"=",
"prep_exp_dir",
"(",
")",
"model",
"=",
"get_simple_model",
"(",
"exp_dir",
",",
"corpus",
")",
"model",
".",
"transcribe",
"(",
"model_path",
")"
] | Applies a trained model to untranscribed data in a Corpus. | [
"Applies",
"a",
"trained",
"model",
"to",
"untranscribed",
"data",
"in",
"a",
"Corpus",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/experiment.py#L106-L111 |
13,884 | persephone-tools/persephone | persephone/preprocess/wav.py | trim_wav_ms | def trim_wav_ms(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Extracts part of a WAV File.
First attempts to call sox. If sox is unavailable, it backs off to
pydub+ffmpeg.
Args:
in_path: A path to the source file to extract a portion of
out... | python | def trim_wav_ms(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Extracts part of a WAV File.
First attempts to call sox. If sox is unavailable, it backs off to
pydub+ffmpeg.
Args:
in_path: A path to the source file to extract a portion of
out... | [
"def",
"trim_wav_ms",
"(",
"in_path",
":",
"Path",
",",
"out_path",
":",
"Path",
",",
"start_time",
":",
"int",
",",
"end_time",
":",
"int",
")",
"->",
"None",
":",
"try",
":",
"trim_wav_sox",
"(",
"in_path",
",",
"out_path",
",",
"start_time",
",",
"e... | Extracts part of a WAV File.
First attempts to call sox. If sox is unavailable, it backs off to
pydub+ffmpeg.
Args:
in_path: A path to the source file to extract a portion of
out_path: A path describing the to-be-created WAV file.
start_time: The point in the source WAV file at whi... | [
"Extracts",
"part",
"of",
"a",
"WAV",
"File",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/wav.py#L18-L43 |
13,885 | persephone-tools/persephone | persephone/preprocess/wav.py | trim_wav_pydub | def trim_wav_pydub(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Crops the wav file. """
logger.info(
"Using pydub/ffmpeg to create {} from {}".format(out_path, in_path) +
" using a start_time of {} and an end_time of {}".format(start_time,
... | python | def trim_wav_pydub(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Crops the wav file. """
logger.info(
"Using pydub/ffmpeg to create {} from {}".format(out_path, in_path) +
" using a start_time of {} and an end_time of {}".format(start_time,
... | [
"def",
"trim_wav_pydub",
"(",
"in_path",
":",
"Path",
",",
"out_path",
":",
"Path",
",",
"start_time",
":",
"int",
",",
"end_time",
":",
"int",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Using pydub/ffmpeg to create {} from {}\"",
".",
"format",
... | Crops the wav file. | [
"Crops",
"the",
"wav",
"file",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/wav.py#L45-L70 |
13,886 | persephone-tools/persephone | persephone/preprocess/wav.py | trim_wav_sox | def trim_wav_sox(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Crops the wav file at in_fn so that the audio between start_time and
end_time is output to out_fn. Measured in milliseconds.
"""
if out_path.is_file():
logger.info("Output path %s alrea... | python | def trim_wav_sox(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
""" Crops the wav file at in_fn so that the audio between start_time and
end_time is output to out_fn. Measured in milliseconds.
"""
if out_path.is_file():
logger.info("Output path %s alrea... | [
"def",
"trim_wav_sox",
"(",
"in_path",
":",
"Path",
",",
"out_path",
":",
"Path",
",",
"start_time",
":",
"int",
",",
"end_time",
":",
"int",
")",
"->",
"None",
":",
"if",
"out_path",
".",
"is_file",
"(",
")",
":",
"logger",
".",
"info",
"(",
"\"Outp... | Crops the wav file at in_fn so that the audio between start_time and
end_time is output to out_fn. Measured in milliseconds. | [
"Crops",
"the",
"wav",
"file",
"at",
"in_fn",
"so",
"that",
"the",
"audio",
"between",
"start_time",
"and",
"end_time",
"is",
"output",
"to",
"out_fn",
".",
"Measured",
"in",
"milliseconds",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/wav.py#L72-L88 |
13,887 | persephone-tools/persephone | persephone/preprocess/wav.py | extract_wavs | def extract_wavs(utterances: List[Utterance], tgt_dir: Path,
lazy: bool) -> None:
""" Extracts WAVs from the media files associated with a list of Utterance
objects and stores it in a target directory.
Args:
utterances: A list of Utterance objects, which include information
... | python | def extract_wavs(utterances: List[Utterance], tgt_dir: Path,
lazy: bool) -> None:
""" Extracts WAVs from the media files associated with a list of Utterance
objects and stores it in a target directory.
Args:
utterances: A list of Utterance objects, which include information
... | [
"def",
"extract_wavs",
"(",
"utterances",
":",
"List",
"[",
"Utterance",
"]",
",",
"tgt_dir",
":",
"Path",
",",
"lazy",
":",
"bool",
")",
"->",
"None",
":",
"tgt_dir",
".",
"mkdir",
"(",
"parents",
"=",
"True",
",",
"exist_ok",
"=",
"True",
")",
"for... | Extracts WAVs from the media files associated with a list of Utterance
objects and stores it in a target directory.
Args:
utterances: A list of Utterance objects, which include information
about the source media file, and the offset of the utterance in the
media_file.
tg... | [
"Extracts",
"WAVs",
"from",
"the",
"media",
"files",
"associated",
"with",
"a",
"list",
"of",
"Utterance",
"objects",
"and",
"stores",
"it",
"in",
"a",
"target",
"directory",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/wav.py#L90-L114 |
13,888 | persephone-tools/persephone | persephone/results.py | filter_labels | def filter_labels(sent: Sequence[str], labels: Set[str] = None) -> List[str]:
""" Returns only the tokens present in the sentence that are in labels."""
if labels:
return [tok for tok in sent if tok in labels]
return list(sent) | python | def filter_labels(sent: Sequence[str], labels: Set[str] = None) -> List[str]:
""" Returns only the tokens present in the sentence that are in labels."""
if labels:
return [tok for tok in sent if tok in labels]
return list(sent) | [
"def",
"filter_labels",
"(",
"sent",
":",
"Sequence",
"[",
"str",
"]",
",",
"labels",
":",
"Set",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"str",
"]",
":",
"if",
"labels",
":",
"return",
"[",
"tok",
"for",
"tok",
"in",
"sent",
"if",
... | Returns only the tokens present in the sentence that are in labels. | [
"Returns",
"only",
"the",
"tokens",
"present",
"in",
"the",
"sentence",
"that",
"are",
"in",
"labels",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/results.py#L11-L16 |
13,889 | persephone-tools/persephone | persephone/results.py | filtered_error_rate | def filtered_error_rate(hyps_path: Union[str, Path], refs_path: Union[str, Path], labels: Set[str]) -> float:
""" Returns the error rate of hypotheses in hyps_path against references in refs_path after filtering only for labels in labels.
"""
if isinstance(hyps_path, Path):
hyps_path = str(hyps_path... | python | def filtered_error_rate(hyps_path: Union[str, Path], refs_path: Union[str, Path], labels: Set[str]) -> float:
""" Returns the error rate of hypotheses in hyps_path against references in refs_path after filtering only for labels in labels.
"""
if isinstance(hyps_path, Path):
hyps_path = str(hyps_path... | [
"def",
"filtered_error_rate",
"(",
"hyps_path",
":",
"Union",
"[",
"str",
",",
"Path",
"]",
",",
"refs_path",
":",
"Union",
"[",
"str",
",",
"Path",
"]",
",",
"labels",
":",
"Set",
"[",
"str",
"]",
")",
"->",
"float",
":",
"if",
"isinstance",
"(",
... | Returns the error rate of hypotheses in hyps_path against references in refs_path after filtering only for labels in labels. | [
"Returns",
"the",
"error",
"rate",
"of",
"hypotheses",
"in",
"hyps_path",
"against",
"references",
"in",
"refs_path",
"after",
"filtering",
"only",
"for",
"labels",
"in",
"labels",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/results.py#L18-L42 |
13,890 | persephone-tools/persephone | persephone/results.py | fmt_latex_output | def fmt_latex_output(hyps: Sequence[Sequence[str]],
refs: Sequence[Sequence[str]],
prefixes: Sequence[str],
out_fn: Path,
) -> None:
""" Output the hypotheses and references to a LaTeX source file for
pretty printing.
"""
... | python | def fmt_latex_output(hyps: Sequence[Sequence[str]],
refs: Sequence[Sequence[str]],
prefixes: Sequence[str],
out_fn: Path,
) -> None:
""" Output the hypotheses and references to a LaTeX source file for
pretty printing.
"""
... | [
"def",
"fmt_latex_output",
"(",
"hyps",
":",
"Sequence",
"[",
"Sequence",
"[",
"str",
"]",
"]",
",",
"refs",
":",
"Sequence",
"[",
"Sequence",
"[",
"str",
"]",
"]",
",",
"prefixes",
":",
"Sequence",
"[",
"str",
"]",
",",
"out_fn",
":",
"Path",
",",
... | Output the hypotheses and references to a LaTeX source file for
pretty printing. | [
"Output",
"the",
"hypotheses",
"and",
"references",
"to",
"a",
"LaTeX",
"source",
"file",
"for",
"pretty",
"printing",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/results.py#L57-L96 |
13,891 | persephone-tools/persephone | persephone/results.py | fmt_confusion_matrix | def fmt_confusion_matrix(hyps: Sequence[Sequence[str]],
refs: Sequence[Sequence[str]],
label_set: Set[str] = None,
max_width: int = 25) -> str:
""" Formats a confusion matrix over substitutions, ignoring insertions
and deletions. """
... | python | def fmt_confusion_matrix(hyps: Sequence[Sequence[str]],
refs: Sequence[Sequence[str]],
label_set: Set[str] = None,
max_width: int = 25) -> str:
""" Formats a confusion matrix over substitutions, ignoring insertions
and deletions. """
... | [
"def",
"fmt_confusion_matrix",
"(",
"hyps",
":",
"Sequence",
"[",
"Sequence",
"[",
"str",
"]",
"]",
",",
"refs",
":",
"Sequence",
"[",
"Sequence",
"[",
"str",
"]",
"]",
",",
"label_set",
":",
"Set",
"[",
"str",
"]",
"=",
"None",
",",
"max_width",
":"... | Formats a confusion matrix over substitutions, ignoring insertions
and deletions. | [
"Formats",
"a",
"confusion",
"matrix",
"over",
"substitutions",
"ignoring",
"insertions",
"and",
"deletions",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/results.py#L132-L167 |
13,892 | persephone-tools/persephone | persephone/results.py | fmt_latex_untranscribed | def fmt_latex_untranscribed(hyps: Sequence[Sequence[str]],
prefixes: Sequence[str],
out_fn: Path) -> None:
""" Formats automatic hypotheses that have not previously been
transcribed in LaTeX. """
hyps_prefixes = list(zip(hyps, prefixes))
def utter... | python | def fmt_latex_untranscribed(hyps: Sequence[Sequence[str]],
prefixes: Sequence[str],
out_fn: Path) -> None:
""" Formats automatic hypotheses that have not previously been
transcribed in LaTeX. """
hyps_prefixes = list(zip(hyps, prefixes))
def utter... | [
"def",
"fmt_latex_untranscribed",
"(",
"hyps",
":",
"Sequence",
"[",
"Sequence",
"[",
"str",
"]",
"]",
",",
"prefixes",
":",
"Sequence",
"[",
"str",
"]",
",",
"out_fn",
":",
"Path",
")",
"->",
"None",
":",
"hyps_prefixes",
"=",
"list",
"(",
"zip",
"(",... | Formats automatic hypotheses that have not previously been
transcribed in LaTeX. | [
"Formats",
"automatic",
"hypotheses",
"that",
"have",
"not",
"previously",
"been",
"transcribed",
"in",
"LaTeX",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/results.py#L169-L192 |
13,893 | persephone-tools/persephone | persephone/preprocess/labels.py | segment_into_chars | def segment_into_chars(utterance: str) -> str:
""" Segments an utterance into space delimited characters. """
if not isinstance(utterance, str):
raise TypeError("Input type must be a string. Got {}.".format(type(utterance)))
utterance.strip()
utterance = utterance.replace(" ", "")
return "... | python | def segment_into_chars(utterance: str) -> str:
""" Segments an utterance into space delimited characters. """
if not isinstance(utterance, str):
raise TypeError("Input type must be a string. Got {}.".format(type(utterance)))
utterance.strip()
utterance = utterance.replace(" ", "")
return "... | [
"def",
"segment_into_chars",
"(",
"utterance",
":",
"str",
")",
"->",
"str",
":",
"if",
"not",
"isinstance",
"(",
"utterance",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"Input type must be a string. Got {}.\"",
".",
"format",
"(",
"type",
"(",
"uttera... | Segments an utterance into space delimited characters. | [
"Segments",
"an",
"utterance",
"into",
"space",
"delimited",
"characters",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/labels.py#L28-L36 |
13,894 | persephone-tools/persephone | persephone/preprocess/labels.py | make_indices_to_labels | def make_indices_to_labels(labels: Set[str]) -> Dict[int, str]:
""" Creates a mapping from indices to labels. """
return {index: label for index, label in
enumerate(["pad"] + sorted(list(labels)))} | python | def make_indices_to_labels(labels: Set[str]) -> Dict[int, str]:
""" Creates a mapping from indices to labels. """
return {index: label for index, label in
enumerate(["pad"] + sorted(list(labels)))} | [
"def",
"make_indices_to_labels",
"(",
"labels",
":",
"Set",
"[",
"str",
"]",
")",
"->",
"Dict",
"[",
"int",
",",
"str",
"]",
":",
"return",
"{",
"index",
":",
"label",
"for",
"index",
",",
"label",
"in",
"enumerate",
"(",
"[",
"\"pad\"",
"]",
"+",
... | Creates a mapping from indices to labels. | [
"Creates",
"a",
"mapping",
"from",
"indices",
"to",
"labels",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/preprocess/labels.py#L81-L85 |
13,895 | persephone-tools/persephone | persephone/datasets/na.py | preprocess_french | def preprocess_french(trans, fr_nlp, remove_brackets_content=True):
""" Takes a list of sentences in french and preprocesses them."""
if remove_brackets_content:
trans = pangloss.remove_content_in_brackets(trans, "[]")
# Not sure why I have to split and rejoin, but that fixes a Spacy token
# er... | python | def preprocess_french(trans, fr_nlp, remove_brackets_content=True):
""" Takes a list of sentences in french and preprocesses them."""
if remove_brackets_content:
trans = pangloss.remove_content_in_brackets(trans, "[]")
# Not sure why I have to split and rejoin, but that fixes a Spacy token
# er... | [
"def",
"preprocess_french",
"(",
"trans",
",",
"fr_nlp",
",",
"remove_brackets_content",
"=",
"True",
")",
":",
"if",
"remove_brackets_content",
":",
"trans",
"=",
"pangloss",
".",
"remove_content_in_brackets",
"(",
"trans",
",",
"\"[]\"",
")",
"# Not sure why I hav... | Takes a list of sentences in french and preprocesses them. | [
"Takes",
"a",
"list",
"of",
"sentences",
"in",
"french",
"and",
"preprocesses",
"them",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/na.py#L209-L220 |
13,896 | persephone-tools/persephone | persephone/datasets/na.py | trim_wavs | def trim_wavs(org_wav_dir=ORG_WAV_DIR,
tgt_wav_dir=TGT_WAV_DIR,
org_xml_dir=ORG_XML_DIR):
""" Extracts sentence-level transcriptions, translations and wavs from the
Na Pangloss XML and WAV files. But otherwise doesn't preprocess them."""
logging.info("Trimming wavs...")
if ... | python | def trim_wavs(org_wav_dir=ORG_WAV_DIR,
tgt_wav_dir=TGT_WAV_DIR,
org_xml_dir=ORG_XML_DIR):
""" Extracts sentence-level transcriptions, translations and wavs from the
Na Pangloss XML and WAV files. But otherwise doesn't preprocess them."""
logging.info("Trimming wavs...")
if ... | [
"def",
"trim_wavs",
"(",
"org_wav_dir",
"=",
"ORG_WAV_DIR",
",",
"tgt_wav_dir",
"=",
"TGT_WAV_DIR",
",",
"org_xml_dir",
"=",
"ORG_XML_DIR",
")",
":",
"logging",
".",
"info",
"(",
"\"Trimming wavs...\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"("... | Extracts sentence-level transcriptions, translations and wavs from the
Na Pangloss XML and WAV files. But otherwise doesn't preprocess them. | [
"Extracts",
"sentence",
"-",
"level",
"transcriptions",
"translations",
"and",
"wavs",
"from",
"the",
"Na",
"Pangloss",
"XML",
"and",
"WAV",
"files",
".",
"But",
"otherwise",
"doesn",
"t",
"preprocess",
"them",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/na.py#L222-L265 |
13,897 | persephone-tools/persephone | persephone/datasets/na.py | prepare_labels | def prepare_labels(label_type, org_xml_dir=ORG_XML_DIR, label_dir=LABEL_DIR):
""" Prepare the neural network output targets."""
if not os.path.exists(os.path.join(label_dir, "TEXT")):
os.makedirs(os.path.join(label_dir, "TEXT"))
if not os.path.exists(os.path.join(label_dir, "WORDLIST")):
os... | python | def prepare_labels(label_type, org_xml_dir=ORG_XML_DIR, label_dir=LABEL_DIR):
""" Prepare the neural network output targets."""
if not os.path.exists(os.path.join(label_dir, "TEXT")):
os.makedirs(os.path.join(label_dir, "TEXT"))
if not os.path.exists(os.path.join(label_dir, "WORDLIST")):
os... | [
"def",
"prepare_labels",
"(",
"label_type",
",",
"org_xml_dir",
"=",
"ORG_XML_DIR",
",",
"label_dir",
"=",
"LABEL_DIR",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"label_dir",
",",
"\"TEXT\"",
")",
... | Prepare the neural network output targets. | [
"Prepare",
"the",
"neural",
"network",
"output",
"targets",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/na.py#L267-L289 |
13,898 | persephone-tools/persephone | persephone/datasets/na.py | prepare_untran | def prepare_untran(feat_type, tgt_dir, untran_dir):
""" Preprocesses untranscribed audio."""
org_dir = str(untran_dir)
wav_dir = os.path.join(str(tgt_dir), "wav", "untranscribed")
feat_dir = os.path.join(str(tgt_dir), "feat", "untranscribed")
if not os.path.isdir(wav_dir):
os.makedirs(wav_di... | python | def prepare_untran(feat_type, tgt_dir, untran_dir):
""" Preprocesses untranscribed audio."""
org_dir = str(untran_dir)
wav_dir = os.path.join(str(tgt_dir), "wav", "untranscribed")
feat_dir = os.path.join(str(tgt_dir), "feat", "untranscribed")
if not os.path.isdir(wav_dir):
os.makedirs(wav_di... | [
"def",
"prepare_untran",
"(",
"feat_type",
",",
"tgt_dir",
",",
"untran_dir",
")",
":",
"org_dir",
"=",
"str",
"(",
"untran_dir",
")",
"wav_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"str",
"(",
"tgt_dir",
")",
",",
"\"wav\"",
",",
"\"untranscribed\... | Preprocesses untranscribed audio. | [
"Preprocesses",
"untranscribed",
"audio",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/na.py#L292-L337 |
13,899 | persephone-tools/persephone | persephone/datasets/na.py | prepare_feats | def prepare_feats(feat_type, org_wav_dir=ORG_WAV_DIR, feat_dir=FEAT_DIR, tgt_wav_dir=TGT_WAV_DIR,
org_xml_dir=ORG_XML_DIR, label_dir=LABEL_DIR):
""" Prepare the input features."""
if not os.path.isdir(TGT_DIR):
os.makedirs(TGT_DIR)
if not os.path.isdir(FEAT_DIR):
os.maked... | python | def prepare_feats(feat_type, org_wav_dir=ORG_WAV_DIR, feat_dir=FEAT_DIR, tgt_wav_dir=TGT_WAV_DIR,
org_xml_dir=ORG_XML_DIR, label_dir=LABEL_DIR):
""" Prepare the input features."""
if not os.path.isdir(TGT_DIR):
os.makedirs(TGT_DIR)
if not os.path.isdir(FEAT_DIR):
os.maked... | [
"def",
"prepare_feats",
"(",
"feat_type",
",",
"org_wav_dir",
"=",
"ORG_WAV_DIR",
",",
"feat_dir",
"=",
"FEAT_DIR",
",",
"tgt_wav_dir",
"=",
"TGT_WAV_DIR",
",",
"org_xml_dir",
"=",
"ORG_XML_DIR",
",",
"label_dir",
"=",
"LABEL_DIR",
")",
":",
"if",
"not",
"os",... | Prepare the input features. | [
"Prepare",
"the",
"input",
"features",
"."
] | f94c63e4d5fe719fb1deba449b177bb299d225fb | https://github.com/persephone-tools/persephone/blob/f94c63e4d5fe719fb1deba449b177bb299d225fb/persephone/datasets/na.py#L340-L402 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.