forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[src,scripts] adding more scripts and binaries
- Loading branch information
Showing
19 changed files
with
635 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script makes sure that a <text-dir>, as validated by validate_text_dir.py, | ||
# has unigram counts present (*.counts). | ||
|
||
|
||
if [ $# != 1 ]; then | ||
echo "Usage: $0 <text-dir>" | ||
echo "Makes sure unigram counts (*.counts) are present in <text-dir>," | ||
echo "and if not, sets them up." | ||
exit 1; | ||
fi | ||
|
||
|
||
dir=$1 | ||
|
||
all_ok=true | ||
for f in `ls $dir/*.txt`; do | ||
counts_file=$(echo $f | sed s/.txt$/.counts/) | ||
if [ ! -f $counts_file -o $counts_file -ot $f ]; then | ||
echo "$0: generating counts file for $f" | ||
cat $f | awk '{for(i = 1; i <= NF; i++) {print $i;} print "</s>"}' | \ | ||
sort | uniq -c | awk '{print $2,$1}' > $counts_file | ||
fi | ||
done | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2017 Johns Hopkins University (author: Daniel Povey) | ||
# License: Apache 2.0. | ||
|
||
import os | ||
import argparse | ||
import subprocess | ||
import sys | ||
import re | ||
|
||
|
||
parser = argparse.ArgumentParser(description="This script works out the embedding dimension from a " | ||
"nnet3 neural network (e.g. 0.raw). It does this by invoking " | ||
"nnet3-info to print information about the neural network, and " | ||
"parsing it. You should make sure nnet3-info is on your path " | ||
"before you call this script. It is an error if the input and " | ||
"output dimensions of the neural network are not the same. This " | ||
"script prints the embedding dimension to the standard output.", | ||
epilog="E.g. " + sys.argv[0] + " 0.raw", | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
|
||
parser.add_argument("nnet", | ||
help="Path for raw neural net (e.g. 0.raw)") | ||
|
||
args = parser.parse_args() | ||
|
||
if not os.path.exists(args.nnet): | ||
sys.exit(sys.argv[0] + ": input neural net '{0}' does not exist.".format(args.nnet)) | ||
|
||
proc = subprocess.Popen(["nnet3-info", args.nnet], stdout=subprocess.PIPE) | ||
out_lines = proc.stdout.readlines() | ||
proc.communicate() | ||
if proc.returncode != 0: | ||
sys.exit(sys.argv[0] + ": error running command 'nnet3-info {0}'".format(args.nnet)) | ||
|
||
|
||
# we're looking for lines like: | ||
# input-node name=input dim=600 | ||
# output-node name=output input=output.affine dim=600 | ||
|
||
input_dim=-1 | ||
output_dim=-1 | ||
for line in out_lines: | ||
m = re.match(r'input-node name=input dim=(\d+)', line) | ||
if m is not None: | ||
try: | ||
input_dim = int(m.group(1)) | ||
except: | ||
sys.exit(sys.argv[0] + ": error processing line {0}".format(line)) | ||
|
||
m = re.match(r'output-node name=output .* dim=(\d+)', line) | ||
if m is not None: | ||
try: | ||
output_dim = int(m.group(1)) | ||
except: | ||
sys.exit(sys.argv[0] + ": error processing line {0}".format(line)) | ||
|
||
|
||
if input_dim == -1: | ||
sys.exit(sys.argv[0] + ": could not get input dim from output " | ||
"of 'nnet3-info {0}'".format(args.nnet)) | ||
|
||
if output_dim == -1: | ||
sys.exit(sys.argv[0] + ": could not get output dim from output " | ||
"of 'nnet3-info {0}'".format(args.nnet)) | ||
|
||
if input_dim != output_dim: | ||
sys.exit(sys.argv[0] + ": input and output dims differ for " | ||
"nnet '{0}': {1} != {2}".format( | ||
args.nnet, input_dim, output_dim)) | ||
|
||
print(str(input_dim)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.