Home > AI Solutions > Artificial Intelligence > White Papers > An AI Language Translation Project ─ AI Translations: Machine and Creature Languages > Translation shell and parameterized template files
#!/bin/bash
# Execute as $0 <source_file_name> <source_language> <target_language> <friend_name>
# where <source_language> and <target_language> are two-letter model identifiers.
if [ $# -ne 4 ]
then
echo "Syntax is: $0 <template_file name> <source_language_id> <target language id> <name to substitute in template file>"
else
temp_file="/tmp/customized_name"
cmd="sed 's/##NAME##/$4/' $1 > $temp_file "
eval $cmd
if [ ! -f $2_$3_24x6.nemo ]
then
echo"We must have the model file named \"$2_$3_24x.nemo\" to translate, but it does not exist in the current directory!. Bye."
else
cmd="time python3 /workspace/nemo/examples/nlp/machine_translation/nmt_transformer_infer.py --model $2_$3_24x6.nemo --srctext=$temp_file --tgtout ./$1.$3 --target_lang $3 --source_lang $2"
echo "Executing \"$cmd\""
eval $cmd
echo "Translated $1 from $2 to $3 as $1.$3, and substituted {NAME} with $4."
fi;
# Rest of this file is optional and illustrative.
if [ -f $3_$2_24x6.nemo ]
then
temp_file="/tmp/generic"
echo "Let's translate back for the fun of it. We expect to get materially similar original file back (assuming $4 did not appear in the original file $1 ) !"
cmd="sed s/$4/##NAME##/ $1 > $temp_file"
eval $cmd
cmd="time python3 /workspace/nemo/examples/nlp/machine_translation/nmt_transformer_infer.py --model $3_$2_24x6.nemo --srctext=$temp_file --tgtout ./$1.$2 --target_lang $2 --source_lang $3"
echo "Executing \"$cmd\""
eval $cmd
cmd="diff -w ./$1 ./$1.$2"
eval $cmd
fi;
fi;